From patchwork Mon Jul 1 10:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717785 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 98A53C30653 for ; Mon, 1 Jul 2024 10:27:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82C776B00A0; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 790966B009F; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56D186B00A0; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2A90B6B009E for ; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DB4ABA46F2 for ; Mon, 1 Jul 2024 10:27:24 +0000 (UTC) X-FDA: 82290806808.29.D076AB5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 1524540014 for ; Mon, 1 Jul 2024 10:27:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rAq/h+Og"; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 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=1719829621; 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=Vs0Ekwm25QoGoMOvZzxvz7nLVATokl2Rh9dq5Ge9TnmlXpAThHEXTMIvjfaia8T+2aMmHv uKfOQy48pDP7Jr7RDVoSSXpWfuMJeNOeXHVG3+lWIe9Ppzh1mUtnFbvIiUTrnTYwB5lXi2 YLv3R8+zaWeZNFZq0Dy7degjht8O45U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829621; a=rsa-sha256; cv=none; b=sNMNfCHr7H08hw+o+HqOiQNc/SZLzH1R7O9wdAHV9mc6+X7sAKbkJVVvtgDCGRDJoYHl0J z6iq2s2L17mdj6Cb9CJgoWG3bG6r/GIb2rWLD0XbWc0JQ01uFuNKIT+eDves7H+JKDncOy O62f+vIVa4oUkzgjW1Awz9OQXriM3a4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rAq/h+Og"; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 44A9A6123E; Mon, 1 Jul 2024 10:27:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07FDAC4AF0E; Mon, 1 Jul 2024 10:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829642; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rAq/h+OgmIHQ3zIMfxX5Nuh5uArKUwvnAQ5rWPuLEqT+4ESYLcn2+s1iNn4IGVUPq N7swqaL3CTB0PdUqHWJ9SubqD3nH71n7W/o1mN29bXoOWHACe4NqegsWU8PiQPR8ah oUEzcWEwpwsJJoDzzvpir8kZH4qbg+7bKMjYC0GxxTnplvJUP02GdTCqqHoOIyJS9c jkWX8+1eDjx7q3QpnEZY3Fb090XnzRKi/KlvE06DyPMUynB3PeuNoYLj2yp4bxxeSe 7361qvaMwFlGPQOD813l+53urert7qzRw8sAwh/N6p7+KS++d/BjFguSwdMj5FW5rn 6L/peMMFmlglQ== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:42 -0400 Subject: [PATCH v2 06/11] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-6-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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: Andi Kleen , 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/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR58LRBm5BdNBCR+TQergAamM4jMJnuDIZZS 0IWUHHOHNWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeQAKCRAADmhBGVaC FZfqD/4vNuUYPBi66c7J5PKDuQoOJPTZ2eyZ2nWW1bPmwywtj35VKbgYYgxU4MJDDMRd64oP3NI 24gdEfnDRr62udorC7vft1gdWkaoEHOgTnIowpeTOif6eWWMfHLtvEf4ufB7qWjv6HiiQXt6FWs XUZE/TixP/ajfJvyLsXnJxY2gl26mob5W3HcHZWs2VjJ01bunCKF9z7SlSzWWjfNpRb9IOIBWTq YQG/90bLm7SLCygE64o8fLAjfPV2/v8/G/aeyGKkKtBdu3Uc7x8Vspwrm/aDlqBRJ1XC98bY4HU s5Fkzi7qN/V+eBZ+4mYBNzd93T+Wx17Ecw11QqmT7ifv/108rmjfo+spE3rMBzVBq2Zh9VZGT7N Qf/+TzlzcpRl7L89fCFtJ76kjXWb2phjeMClxn2lvkJwr9oVjeOJyoKcbw9TeE4FQN3LiYghU2m MwiaGUVHC7njwSvbjhFjnImAoEXZGyQs+9yYCyhPxzsFxWyCWxzh2hXqNUUhM7k12s1X3SWZT8o CbHvLMVs0MUFu8ac/a2pNs9d1acf5vTsZw0KmsivcZhL7pAJHfWDUYamlJaQXAIL2q4lDHL4uTk CtMaR4MfeiwBBJ24nwgCpUftL1f/t6d1Z7o72PuSUKGqurGllmzX/bG3Ine+IKa1KwQeqhuiGDk UId2Z/axztB/vFw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: ksx9g398i38ps6b7a4hjg8ucf3o5wz8u X-Rspamd-Queue-Id: 1524540014 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719829642-378419 X-HE-Meta: U2FsdGVkX19WCKOeXUBkLXVgusKcNhi9tVhgJziQgfUxtTDrsxRPw4vw1Qj/7dcD9M2siSleqTHJtoYXNN12SoI0bFPjNJcP+tBgqV0A6W73/IMGIsxydD3kouAQT2kS5wdQENidzUWwgRJ/rKB0unP4uCt3Smi7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5ELDoV+TLJJV0hugFF08LuByTaIWRkxls0jqiraDXJ0dRLHm5gdx7oLHEXkDFak5RV0Sn9BQfIN4gFDgRmtYAvxbX/fRU5Y+ywrfVp3i0Y/atURuLMSYTj7XJo6bc+1q5rV6MaG389/TuGbaQEQb57uP6f8JPeX07feK5T1z 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);