From patchwork Sat Sep 14 17:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13804443 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 88130C021A9 for ; Sat, 14 Sep 2024 17:07:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9779D6B008A; Sat, 14 Sep 2024 13:07:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FF1F6B008C; Sat, 14 Sep 2024 13:07:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 751846B0092; Sat, 14 Sep 2024 13:07:33 -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 542896B008A for ; Sat, 14 Sep 2024 13:07:33 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CF0711A0470 for ; Sat, 14 Sep 2024 17:07:32 +0000 (UTC) X-FDA: 82563975144.15.CDEE8A9 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id 12F5D1A0010 for ; Sat, 14 Sep 2024 17:07:30 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZCOpnIci; spf=pass (imf19.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726333543; 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=D1ojAc6klVsoiH5Op6GfluCcOgdtDcrJ6dSTmDLx0Ck=; b=r3ukyvZeqmSmpnbW1MfbgPkV2rzRFSKPepIpbc93jmkzPnpU5cVF5jzeeZjLm6q8a3Fnkc FUXnNvsF2hDrExY7CDG1Ug7zhU+S5bOgySBcXW9s7ZqHYx4LrB6i6eOFmOMhdxzgNHJhTM UTPd8KM6IV/ss68xlL8xzYhQcE8sOBw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726333543; a=rsa-sha256; cv=none; b=PMnXVt7EbYdqTLsZtjscAhX3xikJcD8MyVbamvtUnWEXd8Jq836g8pPlX0KYbGiXrXLa1R qdjD3prfT+zBgIJma9hUPhAVJBG6Sr6nmm6/Fy3UaDZl5hKqHSev8epXE3HlTklqOKh7zm plaDt5D+rKtO2OVmTSc/hIDojsz6fJA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZCOpnIci; spf=pass (imf19.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id BF343A40209; Sat, 14 Sep 2024 17:07:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A40BFC4CED2; Sat, 14 Sep 2024 17:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726333650; bh=9/XBaGHpEs7172AZ1LJbIYF77AkYkko2J3CyGkwFfPc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZCOpnIci9ttfjhsJzdlcwY1nYcNFUbiD1dipumSZt87w3MACEWPzaGdku7J58Ocut 7HnIhiMDQAIoUXSnyL904jY9IAOTXxIxiIR1LWhnuDUgwkupg8+oSupET1iJss0j6j 58zUooisPaBhdB4W13l3tpEKZ/zhOH9LDKDAINhpnCC8r6Ajx/nmf0AhEdr/uUo0Oc CjPVoNLSKEWHCQEGyvzxrzRJEqsldglkPe2BcUgUhDpbf1SwnPrBrDTtNubansxew5 /6dR/EZrDa8YIK8KYySDQSYx4czlItz8HflLG4e7RWbLXVLXgWgfxKuTUczpylZw1Y XmuT7q3oYEnbw== From: Jeff Layton Date: Sat, 14 Sep 2024 13:07:16 -0400 Subject: [PATCH v8 03/11] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20240914-mgtime-v8-3-5bd872330bed@kernel.org> References: <20240914-mgtime-v8-0-5bd872330bed@kernel.org> In-Reply-To: <20240914-mgtime-v8-0-5bd872330bed@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: Randy Dunlap , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3540; i=jlayton@kernel.org; h=from:subject:message-id; bh=9/XBaGHpEs7172AZ1LJbIYF77AkYkko2J3CyGkwFfPc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm5cLFOqolNl/xZsf6WUTQki64XUYvRpIiwgA6E 8I95y8GTEWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZuXCxQAKCRAADmhBGVaC FV3xEACKkDWRY2iDTOCIYD0Vc9W6MmuR9SEw96FMPF1lO+jbD26E8dxf0hrkhre9oBUikVhQVAK mso6eiHYIR5pTUeQadzyNEdK8QQwVDVIq95IG5F1sp5NZBdW+myoBZzaVbX6i42BeAmKBFm+EAR uc0WhyS1vxp/5G2TzkAGEot1iMRUtgptkCYA1ksBNkbAQuAUpc28ksyE7gtXE+XTYRjt1+h7lb8 cXQakAWWrU9Q6lvD5Eu3kI30Ml47tKa/aLFyPct/CMVP1wzQT79+5bCbUQeoa3EmPsYZG3i6tgS TXVg1FFqlViABoU1Khb1RT0U4PY2i8jCrcZbncFaS2IJqlBSy2X3Eq618IyGtKF2ZOLoZV80axd hJFet3BIa4P64HQ4Fwjedi/V4OdyKodhAbbAzinWTRT89vH6DMI6nNlFCRSayI4PGlcoqrD4gZK rDvvA59XFLCJ978lHKKngt2iaKf3f90k955si5r2iZahPIjkJNnt1y1GRg1hVrP8NwwI2cyrNxV q0N4yXSUlEdwbb42iJKH5aKp7AADnCwtFkCZ/W3qxfAyhlm3eVtV/60AuQS3lzjIXr+TYqy5CWC BFUrQdbfj9XMZMNWLwf4qTQqvZKxw+Pt2OUbDcndFIk5qB1yYq0dgaRpOrtgUPx9FAtsIGGKb+8 vkCknd986DS7deg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 12F5D1A0010 X-Stat-Signature: nyk5do5wbxw9ttf43r6y49gneowywm3k X-HE-Tag: 1726333650-362806 X-HE-Meta: U2FsdGVkX1/Nxj+uSRyvu1lEcXeZISho1TfUEWeGBQOORtNL5EapoCyHMBa4yISNgmuZXQFqBx9d6j0lrLnpKp9dW7Mg9y80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t6rj2B6PNwdZAR77DFPkz8DgU7rYzqgJd1PEbOzamWB7VfXlFC1nZ14vJ98Vz0VH7QxixU4o0lFPfD2SEEt7yXqOSWZOtMZCMAG0KCinJRi/M1BlR66fMtCHpA5S7Lmd47gw+OGknGfj9d79i2TGQ8WuqUBCrpplKjXZ6Fi9TVfe0yQQb2oEoLt73s9SnG+HbBwaUuctSV+/VneU4nxye/8WMvhqMSJ4GHwMd+LV3UEoT1RYQOIxM+WHd1YNKHZqG/+tIzzS/QsU+C/n9dyg3aK2DEyYnzxhq6f4ZLA8CtrOIwtPazF 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 Reviewed-by: Jan Kara 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 c04d19b58f12..3bcbc45708a3 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);