From patchwork Fri Sep 13 13:54:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13803489 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 259FCFA3757 for ; Fri, 13 Sep 2024 13:54:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B118B6B00D2; Fri, 13 Sep 2024 09:54:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC0DD6B00D4; Fri, 13 Sep 2024 09:54:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 913E66B00D5; Fri, 13 Sep 2024 09:54:33 -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 68A626B00D2 for ; Fri, 13 Sep 2024 09:54:33 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2B7C61A1F22 for ; Fri, 13 Sep 2024 13:54:33 +0000 (UTC) X-FDA: 82559860026.30.418C63A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 586BE10000D for ; Fri, 13 Sep 2024 13:54:30 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=W2SMFOaD; spf=pass (imf14.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=1726235529; 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=rjugL3ygWOG5ESysRSvO9p89rikcF2oDUmqNgpdqcoRGLmhLmUvf0WQTyR/ELUlVCXNVLg MJDDpjVeSWszt83u4QeUrtJpyZ3gTNpYxIy2FS9n+BjOiq5fxaYaC/4Dwu6LyG5fO65kGE o9VZmMi0n2a2bAFRZ6Un3oDUbt0hftY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=W2SMFOaD; spf=pass (imf14.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726235529; a=rsa-sha256; cv=none; b=O6iJoI7E6Y1YbxHvc6VPnp3Csg7pUOpIxMnfVPYE8N04QNtkMyvebBACyNEku2os7MBC/O iy1MXfNazuZOW8fxsKIdshTcIeGbnAyDQEf/SzUpL3S+97PMGq7IH1AtCiqtOKP04xS9zr QijPx0lBHTVx9ssYcCsHlxbH3luxaBo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 971945C0274; Fri, 13 Sep 2024 13:54:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D1C5C4CEC0; Fri, 13 Sep 2024 13:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726235669; bh=9/XBaGHpEs7172AZ1LJbIYF77AkYkko2J3CyGkwFfPc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=W2SMFOaD/89VPA5TaMWz4z9E/674HUT6m4iHpbL3vTaL4DJSVwBzyOmAMPCWFE39N skL/RIsa0bOJ/FRylz7xBNdG5GKXLRcTvLLURGA0Qcf9Ik/UPyCZRbVxRsqDQ8o1+U GSI5Ou0ElKh+z3NZrjh7QMMwDJ6zLwkYAkfiJpmPedXrIDR6e2+C1poHGnP+ztI5z3 jspgihAV0GEBOhcO0QGYg4zJsGxGgeRYsJpFRJIc+X89rv0udITx1oOx4Jmlet/t+n gijgkPjqIRcPQqzLJLIIN9OHMOAgpnn/1lx9ilKxviTD4S7I8Q+8avsWCvhv9sz4ZY uSA0geUmOyQjA== From: Jeff Layton Date: Fri, 13 Sep 2024 09:54:12 -0400 Subject: [PATCH v7 03/11] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20240913-mgtime-v7-3-92d4020e3b00@kernel.org> References: <20240913-mgtime-v7-0-92d4020e3b00@kernel.org> In-Reply-To: <20240913-mgtime-v7-0-92d4020e3b00@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: 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/ZANAwAIAQAOaEEZVoIVAcsmYgBm5EQI+jqtPOSShNNpOHPlbChfIJYBk0V5nXAwT cwVRFG+pq2JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZuRECAAKCRAADmhBGVaC FT/JD/9/ovwyjr6zVFnxHSlE4yPi9XMFFRZ6vjJ3PSEqTzowQ6D7m1OOjDEUp49lWuXYBm+sfsE 6jJI40GaUDtkQKPk+I2tI1G5ki0jglFmBIIu/iJ0MJ0f7/jpwbkiyePe0oGBdlWNeyAkJQr5jII YDbAMtiqzB9siTAmRM4BLsZ1myu4a+sIJhiWnMx1kZM32aSfbJvcCtE50DkwrHS9CY7u5jX6spz oRNSNw/+Qy8FpH0KSMBa2dbO2pz0mBfz2lb1/ISS3q2FOMDPnkiB6glD40gYckHfCsffRx8hPPq B2qsSHoRbJXcX9+5mtH7VTfU6RMWlQ5S9J+p4bYDhGFPu6wtBvTOoxp5TpxOABtfI3R7FmwWT5P A/SIXpKhEaTI49RZHyO8JB2TGaPLGfZSapX2YxdUQa9+BZ5eVGjjmJjUqyV83EWu+I5japZEyMg cgzsE5m9Df/8Ze7c1zAdYSfUk79juoorEinuJy+qv9aX+ESEOIvU6ODnjrbeOozttxQ1FGqkjed CPpcP0o81OnRMHHBFutelQ5ZhKMaF3jRb0PA46kUrgY/RuJ4wqkk4+34wsmI9N0F5K9uLthvSYo u+NLE7I7ctuXPtJsaNXE8l/yf9yXCmc5pru6aOkDEotvqbSlojPt6Aypm4ju81hA57KsiiqVgTE OHDghWrSIt8b1Zg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 586BE10000D X-Stat-Signature: sfxix1w1wu6rt36zctpd1m94gcdq3jaa X-Rspam-User: X-HE-Tag: 1726235670-990690 X-HE-Meta: U2FsdGVkX1/p6laVOYz4FwbV3vTQT6q1XW+mnAxTuDx77UUMKR7mIxN2TkYVkLzoCjaUV+y1shV7g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+uiVmmpsTztEfRb4wJzbgf2IXpnMBxntRmfzdUvpjQ7UTGN5UBlJ6o24adGaT9Ai995FBuEUrpuXMQhlsMIFz+5xmTfx0c0BLAsi9eZrjkNDIVacV8PsmwvN4ntiz2cIIQfubqAtAI8CO3NBdu0XTTjZFXFs09TcsjE99u/DZTTfCBDcs9sH8yxkIN1U9vkrwn 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);