From patchwork Thu Jun 27 01:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13713678 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 6383EC27C4F for ; Thu, 27 Jun 2024 01:00:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1487E6B009C; Wed, 26 Jun 2024 21:00:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F52D6B00BC; Wed, 26 Jun 2024 21:00:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E88436B00BE; Wed, 26 Jun 2024 21:00:53 -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 C062D6B00BC for ; Wed, 26 Jun 2024 21:00:53 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 75D1CC1869 for ; Thu, 27 Jun 2024 01:00:53 +0000 (UTC) X-FDA: 82274863986.29.2EBFE19 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf17.hostedemail.com (Postfix) with ESMTP id 1E34C40008 for ; Thu, 27 Jun 2024 01:00:50 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KSM4D+ht; spf=pass (imf17.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719450043; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bJddfqUYKfPkL5IaapNTI+DPloFTuokezQWldk1boEE=; b=Q4cV5ZS2xpKMma+twJ/QLIcECSKthinPvG7DUwYW4USwOZn0JXqlX7m4Y+PjcQqAsVtInC 7lbxg4YfQhmdi10OJ0R7txW7R4eAtr/U2H3uDcTE0Iek9QiXvoGBD5yYTy5IsUViGT3cuA Phlv9v3q5/E8vFx/9Vi9b76dC+9UrYQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KSM4D+ht; spf=pass (imf17.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719450043; a=rsa-sha256; cv=none; b=U3bMh7THXxbWY5IgQBOyaXTMD52sflVxWEtoxnEC8miCXwJKi6jHoB1Mzz8JRxvUiTyrgZ XbdRQ/MtqFu1G5ezKr9ES7OzFKEIXF0f1empayXOU5+MiFazWyUBQhAxyb9hxMyalQhXwe ipAOq/tvD3XDGG4LcVF5jq/EM5Q7zVA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 8FEEFCE2C25; Thu, 27 Jun 2024 01:00:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3019C4AF0E; Thu, 27 Jun 2024 01:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719450047; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KSM4D+htEiLS5wQkJ0zKSjaJMxEwEGG22qWwF5spro00SlDHI78pzriunnpq0F0r0 SEiKrQAn1yP0PiAuxzXGm/wpgfD6W7meGA/ajicCqaKrmAGh0UdMrYy+9VbOvrR4xn wZVLZQ/sAbDRmk40zheaQiul+emOnfSR5ZIlq8Mmjva2FuMDNaAHR7SwxUqbvNUrn+ dgEHvLNTiA+ojAscpgRun2J2bDaZdpcD8nJqbdH934KxKG/9g0VcIGFwJ1LbbsHKP7 k6VTzDDiPm6BUQBeYGVtOEt7lA76YYCB6lEyFiOLjVl1fO0jBTHHTIJNN6c25FUKkG VFQjHsF6PG5mQ== From: Jeff Layton Date: Wed, 26 Jun 2024 21:00:26 -0400 Subject: [PATCH 06/10] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20240626-mgtime-v1-6-a189352d0f8f@kernel.org> References: <20240626-mgtime-v1-0-a189352d0f8f@kernel.org> In-Reply-To: <20240626-mgtime-v1-0-a189352d0f8f@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton Cc: 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3403; i=jlayton@kernel.org; h=from:subject:message-id; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmfLmvt5FijKuOW1vA/E+4WT59dqYyFM7dMPgmC 4a5LSWoXmeJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZny5rwAKCRAADmhBGVaC FXZUD/9B/x8/Zq9asfvRQABKDRs5+rE6zIeYgHTsok96TS49jId7AW+yvJZzcQ60z97OjtIAwTo YkmpaooiGCxQNKKMQAna8eVpiHzmg9VJIeDL9bZiWowREYsAWCOpDXRAMJo1s90ZIiSDa0WrmRh 5b/wgqt63vJ2eAJJxLQXFkbsv3j+brsUJRCCZXZBQq0Ray0Zqczrdc66Lr08hFF00X0OYtkkh+f mguCF4lxXVmuLkVvakLq46OWh7scp0GkjI4CmJflY11gO1qdhzjiiUCtdLok9uUjracDuHQVslb Q8j+odXGCtFdhLXrIWYVn5w3RQIsbGnSa2kNZTYpYKojuj8gRFXsUQksMEfOyegcLoSrWojFfci WoiEmrLy6Z+nOrsixHBXd0N2ePqm8cgf5l1M+ybnnIKsrBHoFN2mioRSQv2rFGIcD940lBwMCL2 UOmWHXsj7KU/boDxh5NhAAT7uKUc8wQUrrRqZk2bt1kp3G4EY5wMkZlz+Hv9p6DjLFzMuz7oaqk NY/ITCGlhOXe1tBCHwLKEKYef7RQ4Hp/DiPJSJ/mxYfissEXHANFM9kcATDHFqeLC9asainf8m7 8TUD1m1SxoBCy9x1KRRD/VsvxGq0eU3u6xtnOggG360rkUMuCK43V4F9y8eR45mYIg0XVjj/BTY Y7he/1P2G/b39LA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 1E34C40008 X-Stat-Signature: o7tcfd8iahkn47d9o3nto5w6ouygqqun X-HE-Tag: 1719450050-555264 X-HE-Meta: U2FsdGVkX1/BAymY8tYy+37Btebmhw39yVA0Du3fHE/seXPZWmS6Hmm4BEEF63sbePg1yHQ8tewa2hWXM84TsCsmvfpIDqEVm+6LVL4/zWGyqcESIGDSSwdRX2dnjsUeRx/6gcjnsptYLK5c+Jadhx/niuJKv1A1T+lNOjd5Or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MjqxaclFRX15TQjT9tU+evreTTgXxaoRlcdkfuYaxC 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: 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 --- 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);