From patchwork Mon Jul 15 12:48:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733441 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 E444CC3DA4B for ; Mon, 15 Jul 2024 12:49:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B101C6B0098; Mon, 15 Jul 2024 08:49:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A96836B0099; Mon, 15 Jul 2024 08:49:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C4126B009A; Mon, 15 Jul 2024 08:49:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 64FA56B0098 for ; Mon, 15 Jul 2024 08:49:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2CD301A15CF for ; Mon, 15 Jul 2024 12:49:25 +0000 (UTC) X-FDA: 82341967890.29.F058921 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 64147140013 for ; Mon, 15 Jul 2024 12:49:23 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GiWQXcYj; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721047735; a=rsa-sha256; cv=none; b=dVsldKwq3ye3Q/36xTWenfMNKoY7YcjeTg1Yu/d690RnZ9Wv9b+l3d7GHxzLA3J9j16eUG +5yodFJPk5/VbaKaJApLjGLu88iU7LnNJ99R7XwSYIITqRFpQXpCPYG7NeP61GIMKWb/mb eMYdDjwBxI1i3ZIRTdJ8DCrEo8FUllQ= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GiWQXcYj; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721047735; 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=VtMJfkimg5Ssr9JPagx2sf6tC2jf6PpiLuy7lmXdaTY=; b=EsMaZtGKCcQGhB46mHBNxS3RuhMZs5zKapEwYLKBi5urNAPLXdBX4htfn9FxDtczww6x88 VXvQvRPRpTI96jwF3T+qiVGzLXO3B+yi6+zWMAQ4dZZc8Mb+9K0J+CxYcMR+g8qBdf71v8 Qij4XVOUt8EUuhcbb6sTSk9qIX/OzXo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8696E61087; Mon, 15 Jul 2024 12:49:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB26DC4AF0E; Mon, 15 Jul 2024 12:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047762; bh=QeVccJxIIqw839FMAslwYN0cCtumM5RGorsmI4f3Ba8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GiWQXcYj1to6dm4zqB3WZcP047jHZ6ztSMtTi+WxEaaMYw+niVkY9vKzScQredr+L OvHfw134L8C7mHiOMPXDdO0VZiYVW34o6XUZAONLlvhtC4N5fPTgckq8KgS2iO6BmQ zkfHj7wkaflVGgU4Jgpu3lhmTzfasIAtVteUGf9cgKR/Cc05mBM9z5kzj9GCiLb71/ C4bUPXIS6p1E/ZaQx7MUg0mdkuHVcCPzEAFMCE7HxyzaHJK7vKlYy3HmERyREnj/sB egfTLiRvHuyGjPIGvm2Qpzy8c7O4wLLogMgKEJvzvlpBC9CwslWSvDuhzRRJQn/nVG 9/Kipe3dKWfAA== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:55 -0400 Subject: [PATCH v6 4/9] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20240715-mgtime-v6-4-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3502; i=jlayton@kernel.org; h=from:subject:message-id; bh=QeVccJxIIqw839FMAslwYN0cCtumM5RGorsmI4f3Ba8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrCv6y9K94MS/Va6IMTGYStbxE7qbrcFZ0Ck ktMIQhcUj+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawgAKCRAADmhBGVaC FXaTD/4+907j6epNme39/Jvo42T2sVT8Gr4WtDO44maokkPWgfEq/tA5OdSZsLRKdQnyuOtxDZa KCzRZScbuIWev9UWubIT11gAkcf2at6Wu20ez7swsPIwbw8+BHd8+2cjjN1XFbuTEaQ2QMW1Ruo 6MQEsCv+EgExV27/ORkA6sizkDMDb2m8dtxZ5YXpZnp9WOiF1QKDAJBU5JtgYklvKnxacG13xgd Wws5jbg+9FxOokzjJ5G2DHUGC5/JxmiJAx5Zf1OIqOhIEUrYzaQv/3Yo36AeskCYUqbA2q2MqH9 j5of3fjIixxU7GHEkmq3+CdclNooG7OAIpnb7lGEHj56qewVRnxrbZBRK1z159RcXYicVi6qF65 i1mTSjcgcz4fJ/BG1oNHRxR1S3ivBPlycHN3Y5AHr6WApq6eK9wU1sQ6X+pGdi8TttQg1K9AHOE Zq2mBVjy3m/YcpxJgUiYnrwiVwgq3/MQ1yOLfrczrXzkGon/hUelkp8pB96JI6yE/UsNc0eYlXM OA69o9g7LUH+JN5sfl0/r5jwABDL3lm5ZJXtIZXjaDklDWQUT1r2RNcjcwS4pdgRXKyhT4HZ+Hs Z1h74eWkZ/uHYdiWIEwtzOBFNHRHIn1eNloZ2T05WWNowSmDtEJAerXDjpCNdDrLdHvZMo7zxVC 0Vy0lk5VKnmahgA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 64147140013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ahs84j8t7rfpjwjohga7g6p5onminjdf X-HE-Tag: 1721047763-389517 X-HE-Meta: U2FsdGVkX18U6PkYY5/2K4/DNwYSnSmEc/gUtVlHsEQla1phaxVJF0NhMd1yopEU0CXHbAs0xw9XK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QRkr68DbLwfHZBgwfwMK3Q2vHalKGMCIZHNvWw8YQTVsGIf0o0SIqdU6LZ9JR68uCM6x/qILaV63F/ADE1AsHKQNKWVzqvmy5hkbWVDapRhRXXYtFO0uhsvc9JLUVwFKjMdQ/tvXoBBYkROI+Nvp+Gl1hIvUC6/+b1YwjEdPd8nDcmTehNdUI/y5rQcBTLizfVKjbrY 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. Reviewed-by: Darrick J. Wong Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- 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);