From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEB34C3DA49 for ; Thu, 11 Jul 2024 16:51:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 767D76B009F; Thu, 11 Jul 2024 12:51:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7178C6B00A0; Thu, 11 Jul 2024 12:51:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6069F6B00A1; Thu, 11 Jul 2024 12:51:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 41BBB6B009F for ; Thu, 11 Jul 2024 12:51:46 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E0A4E12019A for ; Thu, 11 Jul 2024 16:51:45 +0000 (UTC) X-FDA: 82328063370.30.7557400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 26D391C0024 for ; Thu, 11 Jul 2024 16:51:43 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=e6jgLrTt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of djwong@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=djwong@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720716679; a=rsa-sha256; cv=none; b=R37MQCABOdjJ4kgUo2Zb31GfAyqGW3NXt2OSN1PJL0iaEGJBp10fenu4mAncgYSq/uqaPh MfL8ajWk73XhULG1Tugqzi9iRY8CGQX0Peo2oTU0YOZUbZX/oyVprh80P2H5l1PuWi63jz 7qHvt/oND0iLRtOuhg1hpkL+FkgEaaI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=e6jgLrTt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of djwong@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=djwong@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720716679; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7ssCsJ+WCMPeMQKTWHWylucJPiPkOkkOiF1Hu6NF81E=; b=5aEMTAxyAYvbDo8C5NpbYK9xLGAAZH9HVd+Jz4UnFlYohDTNdmR7KSVMYS1Sy+guN/tmUa ZI8KjTTmP44+/QhQWu3d5vNi7dTK7jr4Pe8xdbhBscnPRlYcGeR4887W72lUf01qW4qR7e vjVRi9O4elAUZDNF/3/VmGpOuFO/oWo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1293661DC6; Thu, 11 Jul 2024 16:51:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1F39C116B1; Thu, 11 Jul 2024 16:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720716702; bh=kmGbtXEsMjJy/wpU2hA6AuW+oaSd10dmF9hCafZ07GI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=e6jgLrTtoFWdwMS9eTSIt8y+gfMtPQ6WtVeTi1Jm5Rq6rJCBtKhgBiX0lwnGPSYjz POgkbYDJfaPdVrYeQQGmx4PJsSG4cOb1yCZtWnD3QLF1Tcu07O28a7iM3Ib8SCmAba JCIqali4EF+aY3T9oeQZMZXdXI0fMkjynqP+7mzVM5WSTUgZj6kIvgwZVpG0cgcp+W e8q6UrKbd27jWhCKkIc3AoSE6kxE8nUsGAsUBC1eSgA/xf4Xr5ZSYa6nPHeCw0XVqp qdkcXBQXKoXs8bxCODrFuPDRFEVzsL979JH7tQAhIa9HLRl39RllYBG+c3j0n63EdM pAgpLsnfPQNcQ== Date: Thu, 11 Jul 2024 09:51:42 -0700 From: "Darrick J. Wong" To: Jeff Layton Cc: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet , Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v5 4/9] fs: have setattr_copy handle multigrain timestamps appropriately Message-ID: <20240711165142.GP612460@frogsfrogsfrogs> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> <20240711-mgtime-v5-4-37bb5b465feb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240711-mgtime-v5-4-37bb5b465feb@kernel.org> X-Rspamd-Queue-Id: 26D391C0024 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6rnpu9g3gy8p1g66ytfg4nhagocok9ms X-HE-Tag: 1720716703-26574 X-HE-Meta: U2FsdGVkX1/qUtfMG8aRCBKxEgP9gvU3hCtK0B3Z57DMKrcEI51hh/AxIZ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EXF5l7xh3z+ANiHrHiUXqRnJgRpWAubK+xbVk8ee4uG6sm+XDbsLOb9MiN/GcfPcgXTQ5Y9PFQhlY1UH944t+VYF7UnaLQwr/tOkh5rX6U6AssRZRnmUN1UgNdZ6ZqxKcfJoRM8YFQmBg6FyKWWZYHaBBKOyTMD2DZeSnHH27N2Jb6t+WGkV3tkuXzvoKN1SE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jul 11, 2024 at 07:08:08AM -0400, Jeff Layton wrote: > The setattr codepath is still using coarse-grained timestamps, even on > multigrain filesystems. To fix this, we need to fetch the timestamp for > ctime updates later, at the point where the assignment occurs in > setattr_copy. > > On a multigrain inode, ignore the ia_ctime in the attrs, and always > update the ctime to the current clock value. Update the atime and mtime > with the same value (if needed) unless they are being set to other > specific values, a'la utimes(). > > Note that we don't want to do this universally however, as some > filesystems (e.g. most networked fs) want to do an explicit update > elsewhere before updating the local inode. > > Signed-off-by: Jeff Layton Makes sense to me, Reviewed-by: Darrick J. Wong --D > --- > fs/attr.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 46 insertions(+), 6 deletions(-) > > diff --git a/fs/attr.c b/fs/attr.c > index 825007d5cda4..e03ea6951864 100644 > --- a/fs/attr.c > +++ b/fs/attr.c > @@ -271,6 +271,42 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset) > } > EXPORT_SYMBOL(inode_newsize_ok); > > +/** > + * setattr_copy_mgtime - update timestamps for mgtime inodes > + * @inode: inode timestamps to be updated > + * @attr: attrs for the update > + * > + * With multigrain timestamps, we need to take more care to prevent races > + * when updating the ctime. Always update the ctime to the very latest > + * using the standard mechanism, and use that to populate the atime and > + * mtime appropriately (unless we're setting those to specific values). > + */ > +static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr) > +{ > + unsigned int ia_valid = attr->ia_valid; > + struct timespec64 now; > + > + /* > + * If the ctime isn't being updated then nothing else should be > + * either. > + */ > + if (!(ia_valid & ATTR_CTIME)) { > + WARN_ON_ONCE(ia_valid & (ATTR_ATIME|ATTR_MTIME)); > + return; > + } > + > + now = inode_set_ctime_current(inode); > + if (ia_valid & ATTR_ATIME_SET) > + inode_set_atime_to_ts(inode, attr->ia_atime); > + else if (ia_valid & ATTR_ATIME) > + inode_set_atime_to_ts(inode, now); > + > + if (ia_valid & ATTR_MTIME_SET) > + inode_set_mtime_to_ts(inode, attr->ia_mtime); > + else if (ia_valid & ATTR_MTIME) > + inode_set_mtime_to_ts(inode, now); > +} > + > /** > * setattr_copy - copy simple metadata updates into the generic inode > * @idmap: idmap of the mount the inode was found from > @@ -303,12 +339,6 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, > > i_uid_update(idmap, attr, inode); > i_gid_update(idmap, attr, inode); > - if (ia_valid & ATTR_ATIME) > - inode_set_atime_to_ts(inode, attr->ia_atime); > - if (ia_valid & ATTR_MTIME) > - inode_set_mtime_to_ts(inode, attr->ia_mtime); > - if (ia_valid & ATTR_CTIME) > - inode_set_ctime_to_ts(inode, attr->ia_ctime); > if (ia_valid & ATTR_MODE) { > umode_t mode = attr->ia_mode; > if (!in_group_or_capable(idmap, inode, > @@ -316,6 +346,16 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, > mode &= ~S_ISGID; > inode->i_mode = mode; > } > + > + if (is_mgtime(inode)) > + return setattr_copy_mgtime(inode, attr); > + > + if (ia_valid & ATTR_ATIME) > + inode_set_atime_to_ts(inode, attr->ia_atime); > + if (ia_valid & ATTR_MTIME) > + inode_set_mtime_to_ts(inode, attr->ia_mtime); > + if (ia_valid & ATTR_CTIME) > + inode_set_ctime_to_ts(inode, attr->ia_ctime); > } > EXPORT_SYMBOL(setattr_copy); > > > -- > 2.45.2 > >