From patchwork Wed Oct 2 18:49:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820254 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 2A195CF3189 for ; Wed, 2 Oct 2024 18:50:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BC476B01A6; Wed, 2 Oct 2024 14:50:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CE026B01FA; Wed, 2 Oct 2024 14:50:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54B236B01F2; Wed, 2 Oct 2024 14:50:05 -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 146AF6B0167 for ; Wed, 2 Oct 2024 14:50:05 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B50F3120ED7 for ; Wed, 2 Oct 2024 18:50:04 +0000 (UTC) X-FDA: 82629551928.22.0B2FDE0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id DC58F1C0003 for ; Wed, 2 Oct 2024 18:50:01 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="b/usSVuS"; spf=pass (imf18.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 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=1727894873; 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=cetM6DcUpL/i5MVkjPYtC/6TXnwcPmwMNQbZo+1PDmA=; b=zZJyi8EgJGa/9GegG7w5h87oIhwaJmERfFQ/AYItRIjbNTpvxVH2xHx7ASCzia5D/7wf58 nHPVSMXinIY7Amb5LNcR3nzgWeP2auEB3JlyQGaovNifaJX4C8GNG8d77rpIa1VV7kQvIQ nlBjGQ+spHl0delf6M8/gs2EzceLvqA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894873; a=rsa-sha256; cv=none; b=beK6I6J8cdbpeW2vrH5c9yl6wOh8W29g+mlC/nhdCHg96e9O1QQOPwHHleEQ3oWA9UmRB0 OHoe23pxET/v6Ff7wB2dXauLacDKy9FOX5ODLuTQhP8HdLKym4dBZZPWSeah2FJFwvDATw Q7V677XHKxHFFrxP2hVgO+MkLbHli+U= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="b/usSVuS"; spf=pass (imf18.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 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 dfw.source.kernel.org (Postfix) with ESMTP id DB7045C3F98; Wed, 2 Oct 2024 18:49:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 493A0C4CED5; Wed, 2 Oct 2024 18:49:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895000; bh=lFYSNqHeRNdwWK/XmB3fXwkWmQ/Yur1I7QduAGtTJ+o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=b/usSVuScvrhwtxn3KQ3g8X7gxx+GLcKCda37HDaKPKadL7yvk4Qxq6H7ckAaZwnZ ybxJcUQK6FOY+03t4AL49mpKmpcBoZpKGCMNKYC+DAFlO0/9Co2eSvxg77BVwhF4F7 RqGep6DbLs92sxXLQgsQGQCheuqGJwPkgrMZZuHwGNm5HoaLqXomIdAm62ThqgDsWF litXVEKjtv1iuby+l0bSGF5LglapLW+nGjAkxKlGfHV3MV0RQ3JE2xopJQqnnzjF3Z hhtx3uNEUPqlJNsoitanLbQVTESccX/tuKGHFmiQzJGS3sNQbaWB2ZUcnlUiXXj5N6 pkkReY8oZEE+w== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:31 -0400 Subject: [PATCH v9 03/12] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-3-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , 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: 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=3567; i=jlayton@kernel.org; h=from:subject:message-id; bh=lFYSNqHeRNdwWK/XmB3fXwkWmQ/Yur1I7QduAGtTJ+o=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXLyz50rdlWAisS9Rf+dtjs/DFcV4kQkosAS gsaH3DiB1eJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VywAKCRAADmhBGVaC FdnyD/0T67VbA87szAGb/s1YdZ5BTkf8gOF2Numd/G9SJyW8QcFJ6/yvfLD4bdsK4CpgmSinn/M krQHTiP3fLpmQLCFa41sT/mzaXSvPE9nTGuhJcM0UDjUJ1U5Tho484hKLCp+80b1o6WaSytN9DA LeLu3X35R/BoMq58P3wpvEqZC7nMtUH4WdC0uD6wjBxZG4VjTqIBh3+ur5DefXYKFYvRFpLIRmN FjVHQ/1vkuteTVAiEFNVAaz3wRu51qO++aatDnPpEujYwdW4R52GpCZasPXNLAlovjocwJF7vTr AlEV7hs1LvxxsCptjClbAltWbbrZdQi04CBS+88BhDb524XUpqJjsYc8KvNXs+IVy0qYBJZZn8b IGWgT+mvBgUfqTb2CR/KocbLTHQlNSIKFakoIiike8KdNFl0pky+9ZpZT+pLYe9M5f1pzgzeWWk c7lTuQKw5CPpDrlQSBs8egJZx1F33lrdtTuGJngk2rJpxpkd/8BF+3FTlFPfUkNoNLMNRj72FWx y2ssowrBJF8YWClqMU7xkMwq/uJBL7xkCQJPv/o24YQ8ruFoYC76JwYwD5kcQA58wg+radHxDei kVBt9tfuyNeKuDFuY1rdUimnUXnnJjPEto+PvVjgvvVVgbH2y4Qr4t4+qMI01h7Uva5k1X6+i7Z brYV4SA9Mhi5igA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DC58F1C0003 X-Stat-Signature: omffhrtct4c5mjgt9j3uuq6xhxbkdde7 X-HE-Tag: 1727895001-954228 X-HE-Meta: U2FsdGVkX1/tS4uqGow5AQbpk0Cu9Q38sXNbQaOEyXO+mQqorESyYN1Uf988PjN3uoyET9WAF3ALv4zixm1SNisxan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/3BUm/eKKIKTF53HKuQklJcRlRLVRYOMjCY+dxGX/AiDnwsZPpdpOdCo0Q6wySLQrlJhJTtokrqj5/eO7/EPXJZ0zVMmyzAsPLd+HsXK9FQ0RT8uNuPsM3cp7jnTOc+U8nXnxKB6CVZRB7YgOrDvVpu1FubXDhv305yZm9caj3CDHYc1bcESI86Xp1RO3AP663oTCkb75p0/HNUSCWLTpIRLf705UUKJq8kfAla 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, 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(). Do not 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 Tested-by: Randy Dunlap # documentation bits 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..0309c2bd8afa 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, 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 those are being set 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);