From patchwork Wed Oct 2 21:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820396 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 8C28ACF8543 for ; Wed, 2 Oct 2024 21:27:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B39366B03E1; Wed, 2 Oct 2024 17:27:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE94C6B03E2; Wed, 2 Oct 2024 17:27:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9625F6B03E4; Wed, 2 Oct 2024 17:27:46 -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 6C5076B03E1 for ; Wed, 2 Oct 2024 17:27:46 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1E0FE121063 for ; Wed, 2 Oct 2024 21:27:46 +0000 (UTC) X-FDA: 82629949332.05.9321B28 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 53272180007 for ; Wed, 2 Oct 2024 21:27:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rrg8jFdo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904358; a=rsa-sha256; cv=none; b=bAZTe530yrqIe77zPLGRk9EotG10sbDgRrAzwe329QDyJu3hffjL1343dtzU3MBgtGCrUV z+6g/3ALXUHRyku1mNY5Zlat7z/KzvU+AKly/Z1HD1U3GM3zKuMicBQbwnHcVEUGWQ1/Gz LrotUJwVn5nrQbEjOGwfhqz92+b7rSc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rrg8jFdo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727904358; 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=hRA5VBTxRD83D2Dn/4CC8fdkCWkafHdvui7Kuu5BnTo=; b=OZlnwKAme4VPoe3UY4bsBiWQpk7W64qQIyAta6Z11D9e9vDa0/AnhDJvqBzmbOZNrnRpFp TJHcWl6bSBYjQ7T+/Neo0yksM74TrDE2ooIGmUXw6sBNF2FbuJWLI4c14UMvZybWDMFsPc hgeJMbB6LJ/hCUIxaXrsPU0ytCAwMJE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 2DD36A44020; Wed, 2 Oct 2024 21:27:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEAC9C4CED0; Wed, 2 Oct 2024 21:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904462; bh=nWAObiv1pT63De3yrHB7U+GTf1hLNrlZ3AMOKfvjPAI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rrg8jFdosDYWMwAA92V2hbU+Yuic3cTXnqQJL7/CjaS4rr5GNRsDVyFogFc7wde8b 3+ytxmfZcVBW7BHEAGL4MUuw8r8fjtd6551m/mw3PBYEMfUcJX5EVnFh9Dl4h9g9bq E+0f3RyVBQuyVN+jR02fOAGU05QU3hphedY25tfubjbgoT7Ovjfw1tUksa+EGwTKEP cQw9zf61IzShMjY9Nc7Pn7ReERF7yn1KIs8f8bQPZs7a9O4goDuhvZZeDLeqBbBWs0 G1gFKZ/7FA/CHJ+OL4QeRprqQq6UL2esAzsdREnCvyhDIodZoeCmPj/niFarTH0M/n olAqzjyT6/E3Q== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:19 -0400 Subject: [PATCH v10 04/12] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-4-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3623; i=jlayton@kernel.org; h=from:subject:message-id; bh=nWAObiv1pT63De3yrHB7U+GTf1hLNrlZ3AMOKfvjPAI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/ifAGWvuvl6BRwMs4Uby9r2RObyp81rJWQ t0O66nsopCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FUFdEACg0WGt0WZDsR4lYHjv29oOUq3iMhe6DMxJ/AIvWuxlPjl9W5bf1/v4xbhac64hqIi9t75 Ed8baE1O4menek+QPLY2fRZnnBQGeQXQg9S9rBIhp0xF3IDD+27FJYF8TT5BItAgxM+tE08Jj79 TxEMXfS4ytrx3H/6P8gkkrxj/Vq2KgyY+pXxhr6SJL09O3NDWwkl+CmZlhsbJqaDtd0Bu2Nkqoc 7XU2I/HmGc9+oXYAi4FK+WjMwm+NdZxBDxUf+mxJELst25MI6Gn7ZqLMfihTZDlg/lkXmnjoMYc CpIIZoyJ+HTB+U9Kge0Knzi+yySpldS6Jv2RXPCtm4ptKKFDi2JO1mhHQyQ6U0oVux1XaGQMEda hhXz0O+U2tobDuICI10a29pVUBbbzgFMTN60MymsFmu7SunVDjCCb1GVEoIOOfAITwjZdcdxth/ d8tPUuSxoGy4Xm9bPfSc6kUuaWp/GqTpsjbtT22UjDOKz1DJfLRmBLrSNeW2c+1WW6yPWoA5wCX gAjJGRkY+f5UkqUIhYc/guqwfh2fkG5UVSrwX7YjFkNlNJjQxYPkFfaC5YpfqjGNJjS8Mm/XNw8 RuKnlGcHgkVhCZdFDdF9m9DCLNYtwbNGQmPRyak0iaHm3uyL+MOfkADpMxPn3YOLLNHu/1Gw7j9 rHKf7yUI65eskTQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 53272180007 X-Stat-Signature: 861mo56a7xry5aj3nobbf7r4o4tkdij9 X-Rspam-User: X-HE-Tag: 1727904463-866613 X-HE-Meta: U2FsdGVkX19DDk/K4+MS9kvRDljLh1IJNo9Jep6brmCWjqbeznTuiACVQvynnixNn9fFoxAj6H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oSRatB8LpW4T+QG2f13LgK9F99Qtfr4lQTK1wg8xUeGD3bqPJIkF1d/lJTTgAGwLmyWnZSCaSDCh1IAhQp74B5eckNZCm5mdZpb3iEk6rApBVvXE3xSk+fJQc6lzjwkkCr0gPtxCHjdlJJROH5tXIRidhluPGgwJfD8t53sVs0XzDz+8jonHNYaIN2N1vbLowSk2FLfjRDdtqmpoDebW0Wot3lXLc3gY52mqngPcWRvkl3OjkxaAV5qhmRjwCQKtLbuMp41yJmvEdWK3POPfZkuVl3uwID2fUV+ph+mwMj7VuVmEgnZHdwlEyW+rDF6ej72yTGfzwQDXX3oUt8DkJkEekurcppjy65CetMv2O2u2q8ygu1gkK5PdA4Kyg== 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 c04d19b58f1224c2149da57e3224b7bbbc83561f..0309c2bd8afa04bc43db6ff207f8a58d9f6a617d 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);