From patchwork Tue Apr 11 14:27:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13207679 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 D8538C77B70 for ; Tue, 11 Apr 2023 14:27:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4197428000B; Tue, 11 Apr 2023 10:27:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CAAB280001; Tue, 11 Apr 2023 10:27:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21E2228000B; Tue, 11 Apr 2023 10:27:17 -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 02CF7280001 for ; Tue, 11 Apr 2023 10:27:17 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C3D951A06A9 for ; Tue, 11 Apr 2023 14:27:16 +0000 (UTC) X-FDA: 80669337672.20.F061A3E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id F097210001F for ; Tue, 11 Apr 2023 14:27:13 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Elt7PpUm; 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=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681223234; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YHYJ58zGg50V/rRl2bjqWR/GYgPheUUBpiJEBWpxlTQ=; b=llAZY9AhX+MGM31MV+MfjAIrirAQsIKS80VoyPZvWBGZSWz0qzHortAt7RDEhrdSJiiJQb F9BTjCZIGU0yWKuLBdMrezL+lbUpbJEuChTwbHN/kuXv6MD7MRVVY+urNhXjXnK2BeFDm3 T5j5XXcjQ8PxHCq6t42WzgPpCWPaFJ4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Elt7PpUm; 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=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681223234; a=rsa-sha256; cv=none; b=dFtuI8FAXrW1QE1+CAEbIrlyvTA2l3rK9JvIWShtVd1ttQ7aqTNxrETNmkHJ1JmlvEpXkF W47TLUYXJM9HHiQ7cSZfomgccM1jNhFVVa5HAjH1Sg2N05VrFS/HUOKGGG0M8uUjUbtbQI qprqVtRZ9ikURUSIgwwxnt/lvKlINLM= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F3EB3627C1; Tue, 11 Apr 2023 14:27:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 036DCC433EF; Tue, 11 Apr 2023 14:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681223231; bh=Awb6q4i/Q5m9mXXhrXc+BP9AQEQgndLooZSbj9YNpPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Elt7PpUmN0Sf29ltkewWu6mezvigmPVjaCJ1Pxmswax9INQvsH/Q5/v+Fzlomn9BX fQrHnCzxZwcyaI2LVGbjh/nxPiZeknvdVI/SmuK1yQ728RCdLvTYkpM6Mx/7Ameo/d h+T86Q6B0zczecQdQfyI4AW1D84JOnFnz9aCFFbfGEIgss//ZEsoHPleDKhe7iD5Xx NkTZ+Ka8BHvEoru3NnidwGOZ1/pU4TriVilasgaTGtD5o28X9CMavUhDFVq585K5zB JApn8vXWxHQI7DA+5OZAq+60Ecvb/nizrYnNmclf3kc9mOk6lN3KIcmHJc3mW07KZu rqxN1TMpY4xDg== From: Jeff Layton To: Alexander Viro , Christian Brauner , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Dave Chinner Subject: [RFC PATCH 1/3] fs: add infrastructure for opportunistic high-res ctime/mtime updates Date: Tue, 11 Apr 2023 10:27:06 -0400 Message-Id: <20230411142708.62475-2-jlayton@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411142708.62475-1-jlayton@kernel.org> References: <20230411142708.62475-1-jlayton@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 4h4qbfps19swstzteumntetj4s1n6nbm X-Rspam-User: X-Rspamd-Queue-Id: F097210001F X-Rspamd-Server: rspam06 X-HE-Tag: 1681223233-211717 X-HE-Meta: U2FsdGVkX19GhQrTgE5OJAIZNudWWs5lOJ78TSbIN0lthN92JAuNc0CtTS+4e+J80AuEM6lG/IOD+uH0mdNjnUoYI4QmNVcwMyw19ZngtXJXYRjFUJogbcQGGpLxX6rcNr1deC5Lg2uaLiHg12tSBh/0dwoMytgOMVpGWNS3bX+Dp7bHUTmukL6Py3712n1OYvUWYUdFSp5GFTIRL6WB/c7jm3C273tGtBbwsQcEsXa8nieaQ83qdqevbIj33UXZqjZWH4kwLWQ7qUxSabENZ+uXpSka0eZn/OCNXUTMuK4wKDA2MLsYyhqJ2lx47Wichv4moHuI6URDJ7oBerPSrdUCKSXsFGyPVOp6uP6vCxOQGWidr+XYAm3Pd8GjAEPpdk2FcPHeHu3I2KeIbtCgeYJexior6db3Csq77lSr4YrrJjzW9gGh5yqY+d1/t2qUVP1LilEveVfg+CYisHkYjgDBBRE5VECx3es51aJIKrqisKHzrrqpT3EADPxSKeqPWO4gUkpC8yHGBwQuSy1KKDrmYy+3ZNAa5X1xP8zllk3yxmUjYIlEqD7wt8J7/4ZEGM4MnrgUUF7HmLH30XcnJTlhjex61bUd9/B5gv30S2/pH5F2s7I6u7lRSOLWpZgzhYmA2eg2QCaIMmWk4W6GFFp0x25Dm8iJFh7zLOQuoQWwDNgBdU/OEMyvA4ye8XXmGObXxNt5+uNtnplU2WRrU+fB1Iq01NthH5hc3F9HDu8BiBi6gQXpVBJvrMF3ACfkc/0BHRNeB+yejk59js7G4xsZKtm/vE4/ucGA01N4HC3BzbSq69eP/5ghWppUKhTInnVBnYXbPSmMeFQh4h68vdpST9ErWmwwHqXbY88/6SCTuZ71YqpgUEMZj01wC6EevryGcAZAsXs/fSmquNTdgXJJldjAKmgS4T8QfOikEjg1Cyq8MRjOgtFVv4zN0UhiZPaZ2XjVA8j94SLsBar sC6Xzu3t nd4T4NhXjivWzlJr5Ij5W4g7l8QM78bTCXR/1/r7Y7DDYfLoIyEXLPDz8QHl56pkZy6oepurWGC48sAG7camkM6z9EOqnx8S7CVJ2nDYTo8swIJ/n3wuoILXeNn2GsyM8zJoboHLAGoIsQIZhUhyk/QiT7rFwgHMLFIcrVMwEvZ2QV3d5pJ8XohyanTmFyvc+nNfxTLkR61H+DGZtPjZmQQahvG1AMjzW7EIcSf14bPY7LK++xN1LFYpMNYI9x5KDAiQmc6e4kkCS+pY9FfXFkD6PDxQknNhTdY72hU9R/SCl60q2x1AtkENWAYaPwggr8/r2ymTM2JkdXd4JLhIZxdaqd1//VDQvnu67IYmVYT3rOkfMipCG7tDm5lHSeM7btA7s0giTlBo7UssAsr+rFVQZQRNC67FQ3kk9 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: The VFS always uses coarse-grained timestamp updates for filling out the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away metadata updates. Unfortunately, this has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. Even with NFSv4, a lot of exported filesystems don't properly support a change attribute and are subject to the same problem of timestamp granularity. Other applications have similar issues (e.g backup applications). Switching to always using high resolution timestamps would improve the situation for NFS, but that becomes rather expensive, as we'd have to log a lot more metadata updates. This patch grabs a new i_state bit to use as a flag that filesystems can set in their getattr routine to indicate that the mtime or ctime was queried since it was last updated. It then adds a new current_cmtime function that acts like the current_time helper, but will conditionally grab high-res timestamps when the i_state flag is set in the inode. This allows NFS and other applications to reap the benefits of high-res ctime and mtime timestamps, but at a substantially lower cost than fetching them every time. Cc: Dave Chinner Signed-off-by: Jeff Layton --- fs/inode.c | 40 ++++++++++++++++++++++++++++++++++++++-- fs/stat.c | 10 ++++++++++ include/linux/fs.h | 5 ++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 4558dc2f1355..3630f67fd042 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2062,6 +2062,42 @@ static int __file_update_time(struct file *file, struct timespec64 *now, return ret; } +/** + * current_cmtime - Return FS time (possibly high-res) + * @inode: inode. + * + * Return the current time truncated to the time granularity supported by + * the fs, as suitable for a ctime or mtime change. If something recently + * fetched the ctime or mtime out of the inode via getattr, then get a + * high-resolution timestamp. + * + * Note that inode and inode->sb cannot be NULL. + * Otherwise, the function warns and returns coarse time without truncation. + */ +struct timespec64 current_cmtime(struct inode *inode) +{ + struct timespec64 now; + + if (unlikely(!inode->i_sb)) { + WARN(1, "%s() called with uninitialized super_block in the inode", __func__); + ktime_get_coarse_real_ts64(&now); + return now; + } + + /* Do a lockless check for the flag before taking the spinlock */ + if (READ_ONCE(inode->i_state) & I_CMTIME_QUERIED) { + ktime_get_real_ts64(&now); + spin_lock(&inode->i_lock); + inode->i_state &= ~I_CMTIME_QUERIED; + spin_unlock(&inode->i_lock); + } else { + ktime_get_coarse_real_ts64(&now); + } + + return timestamp_truncate(now, inode); +} +EXPORT_SYMBOL(current_cmtime); + /** * file_update_time - update mtime and ctime time * @file: file accessed @@ -2080,7 +2116,7 @@ int file_update_time(struct file *file) { int ret; struct inode *inode = file_inode(file); - struct timespec64 now = current_time(inode); + struct timespec64 now = current_cmtime(inode); ret = inode_needs_update_time(inode, &now); if (ret <= 0) @@ -2109,7 +2145,7 @@ static int file_modified_flags(struct file *file, int flags) { int ret; struct inode *inode = file_inode(file); - struct timespec64 now = current_time(inode); + struct timespec64 now = current_cmtime(inode); /* * Clear the security bits if the process is not being run by root. diff --git a/fs/stat.c b/fs/stat.c index 7c238da22ef0..d8b80a2e36b7 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -64,6 +64,16 @@ void generic_fillattr(struct mnt_idmap *idmap, struct inode *inode, } EXPORT_SYMBOL(generic_fillattr); +void fill_cmtime_and_mark(struct inode *inode, struct kstat *stat) +{ + spin_lock(&inode->i_lock); + inode->i_state |= I_CMTIME_QUERIED; + stat->ctime = inode->i_ctime; + stat->mtime = inode->i_mtime; + spin_unlock(&inode->i_lock); +} +EXPORT_SYMBOL(fill_cmtime_and_mark); + /** * generic_fill_statx_attr - Fill in the statx attributes from the inode flags * @inode: Inode to use as the source diff --git a/include/linux/fs.h b/include/linux/fs.h index c85916e9f7db..7dece4390979 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1457,7 +1457,8 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb, kgid_has_mapping(fs_userns, kgid); } -extern struct timespec64 current_time(struct inode *inode); +struct timespec64 current_time(struct inode *inode); +struct timespec64 current_cmtime(struct inode *inode); /* * Snapshotting support. @@ -2116,6 +2117,7 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src, #define I_DONTCACHE (1 << 16) #define I_SYNC_QUEUED (1 << 17) #define I_PINNING_FSCACHE_WB (1 << 18) +#define I_CMTIME_QUERIED (1 << 19) #define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC) #define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES) @@ -2839,6 +2841,7 @@ extern int page_symlink(struct inode *inode, const char *symname, int len); extern const struct inode_operations page_symlink_inode_operations; extern void kfree_link(void *); void generic_fillattr(struct mnt_idmap *, struct inode *, struct kstat *); +void fill_cmtime_and_mark(struct inode *inode, struct kstat *stat); void generic_fill_statx_attr(struct inode *inode, struct kstat *stat); extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int); extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int); From patchwork Tue Apr 11 14:27:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13207678 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 C6309C77B6F for ; Tue, 11 Apr 2023 14:27:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63BBA28000A; Tue, 11 Apr 2023 10:27:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EC06280001; Tue, 11 Apr 2023 10:27:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43F3128000A; Tue, 11 Apr 2023 10:27:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2B223280001 for ; Tue, 11 Apr 2023 10:27:16 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EC111120CB9 for ; Tue, 11 Apr 2023 14:27:15 +0000 (UTC) X-FDA: 80669337630.29.1ACCCF3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id 17D3020028 for ; Tue, 11 Apr 2023 14:27:13 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DS4Rz6ur; spf=pass (imf03.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=1681223234; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cmsV/BNDrmF6zQdi+rsdgHY9rce/ydYxUGcPmL06UuA=; b=WAoi51A1ZfCExn/x0VKiZealZSw8UmnMbzAHHTuCNKegYhfMTkJjyZb4vPC/876y7sQ9pj PK988j7AX8e9BMyywyJh01gDj3xyRaVUJVHzgdKd/V61gj63NfGfznjnQtjrj92UF7cW5f T+42JsGL83rpq0k/WbBuPVMTa55rfWA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DS4Rz6ur; spf=pass (imf03.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681223234; a=rsa-sha256; cv=none; b=baLyD/HTv9xAgnH8ybMOp5CR342bibm+W7Qvz6zzGuaKOa8gxETYF3IXivTz1Kw3XLTWkd u8qJqn+39vvi7mPiQqulsOgPhdy5UMtE0YGHHKe3j/hd1GCRP5dcfQKzH6u+d3E5Gbukmk SUynqcv3GednuxItt0zIs3LbzwWMOqY= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3DE45627CC; Tue, 11 Apr 2023 14:27:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31189C4331F; Tue, 11 Apr 2023 14:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681223233; bh=0tABut1wgcVqOORC6SjkhEn9chzMnRxYPBvizenz41c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DS4Rz6ur+uD+K6rkXA92so5T/79mNn9H+8znTY8wB7jXea7DFFL2hylu15eAboI8U +NwNnnDUpM0JkKdjFtiVhLxydSgQP9/MkwjC5IgmD9qA1WElWwCnf2kJSjDoBf4N0C 7mmobbjHwcugmS66AbgRFw3DcEJaAIV8DegHfzh44DwPA7X8xHn+m4kcyLDRjNWNBo Xwz/V7r+7W+/Fya6R9kn7D0lRo99+0Aogd2YXcSnfxhX/o8IaoXGZF9gZLHuPvstsq catZYcZ9OryZNJyGG7evnrJybTfo32CYs/9Go5Qo4yIavZZHXp9+WXuiMCGiCC8KnS X8Uw8Yf4lfLsw== From: Jeff Layton To: Alexander Viro , Christian Brauner , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 2/3] shmem: mark for high-res timestamps on next update after getattr Date: Tue, 11 Apr 2023 10:27:07 -0400 Message-Id: <20230411142708.62475-3-jlayton@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411142708.62475-1-jlayton@kernel.org> References: <20230411142708.62475-1-jlayton@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 17D3020028 X-Stat-Signature: xqtd4qm7utrf3o5ks76jfhw9q85yg9et X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681223233-670888 X-HE-Meta: U2FsdGVkX19I5MFBz3rBOW7THNbtWE6AMhJBj3PdF08eHimXJ/wDsiLSQ5vhStkd9uaJkzXUovSvBaWcN6DqotW7V7FlL2ndcG9S50tgdOu3InSK6kRQvuFtDYY95lVpyRjEXvM5J5slPobK5mwIXCTZwbns4IR0OzQWjtDFKJB4WjT067Sa7jQ0e3tsnZgQlbvR53eK1zOUqE3SI3imfPOlF8gcW1SToVufk6RQ03DcTx3u29rpiyuWspmG2Y++9d1kTiKTqAHyR/dBXo66ZDw6VdyFfvsMn66ViYuW9D0Sv7xR8auG/J/FBJ13BNhXFKrrt2eNnTjad7mcG5BRKR2RHv68MxnbZtb4imaR8UypJ2EhpVakJsjoc2/raFhQHFKExlJJ++fDVbnQG8vkb4gNpNm9dWPLvL+ooz2xjH0xgEO1x9q3FBxsUsy0crBEtwcKQKzuFQ1O7cvrKcSeTS5hxQ8FUtG8C+IjhXEgCIV0gUb1kXgFsahYv0UyBk3pdMAMSh+VUrM19imPoB9RzlZ2z3OZWJbsBvXLMexBCf8xYKIRLASntDwShalfBd4ugkJkNhk7uobbtzpnvhqK2ma3iQyFykB/O4vBVKUOgiVJeciX9L9CiI4qKfxbsyJbcMTKL4VQ8K54wotwtqvJixv77UfxwVtGWwAHsmAO1HWKExOGCL18y6YJb357vYlttdH/GyDfg55VGWubTz89HFThG+qkDKmlUComOPob/t6Fd5f0CqMkfdYqk9zjQ/OtyIy5ud9ZGpWm5fU/Rm0qG6kXRsT/alEjf61YREPeYoPtHZaKVPVnwRDiNmaDQB2PmY37pfqtKOZppq0UwZhBD2d4c/rWXeTsgbASFlRTwcAxVz8Micw9tKMyEbye06vE6iV/oBsQbxCR0tJ9Ul5PnykLA7DDb/mCcwLpMK86CSbq5IjV0aoRz4xCGxRB19navORvSxrgUTurSur8s0P HLkU0EP9 o8WsgDytZfQQ0FtCOX1ootkrP9Tqt5fJiTi/0/BBcLJdXKEuEXSaWnrrK2FOdvs/UUNj2oQct7ToOxXL7d4S6hr22DeeYD46jQZd2IiQCd9VC+YxmBIg5P9UR820ZOIb+4DtO+lrIZ3BeB1RCCMYcm5K4NkirhGL/8UJsXg2rOxymaqleH9S75darHEsJuLLB6WfOlSQ8cpMt9QE3EqS8jrlgP98IXBJ1N1COEoVMguvCdGA9kXFB0B3zuvhxL0w8WqfzUlJeyWTgT0ha7z3tyWVSgFl4zorCnfzCRz1tBPhlQ/bwn1Cq1Ae6qRv6XXCQHlZ0xYQfcVqAzpT9rbISnOV9dJtJFNQJRi5n 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: When the mtime or ctime is being queried via getattr, ensure that we mark the inode for a high-res timestamp update on the next pass. Also, switch to current_cmtime for other c/mtime updates. Signed-off-by: Jeff Layton --- mm/shmem.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 448f393d8ab2..75dd09492c36 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1039,7 +1039,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend) { shmem_undo_range(inode, lstart, lend, false); - inode->i_ctime = inode->i_mtime = current_time(inode); + inode->i_ctime = inode->i_mtime = current_cmtime(inode); inode_inc_iversion(inode); } EXPORT_SYMBOL_GPL(shmem_truncate_range); @@ -1065,7 +1065,10 @@ static int shmem_getattr(struct mnt_idmap *idmap, stat->attributes_mask |= (STATX_ATTR_APPEND | STATX_ATTR_IMMUTABLE | STATX_ATTR_NODUMP); + generic_fillattr(idmap, inode, stat); + if (request_mask & (STATX_CTIME|STATX_MTIME)) + fill_cmtime_and_mark(inode, stat); if (shmem_is_huge(inode, 0, false, NULL, 0)) stat->blksize = HPAGE_PMD_SIZE; @@ -1136,7 +1139,7 @@ static int shmem_setattr(struct mnt_idmap *idmap, if (attr->ia_valid & ATTR_MODE) error = posix_acl_chmod(idmap, dentry, inode->i_mode); if (!error && update_ctime) { - inode->i_ctime = current_time(inode); + inode->i_ctime = current_cmtime(inode); if (update_mtime) inode->i_mtime = inode->i_ctime; inode_inc_iversion(inode); @@ -2361,7 +2364,7 @@ static struct inode *shmem_get_inode(struct mnt_idmap *idmap, struct super_block inode->i_ino = ino; inode_init_owner(idmap, inode, dir, mode); inode->i_blocks = 0; - inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); + inode->i_atime = inode->i_mtime = inode->i_ctime = current_cmtime(inode); inode->i_generation = get_random_u32(); info = SHMEM_I(inode); memset(info, 0, (char *)inode - (char *)info); @@ -2940,7 +2943,7 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir, error = 0; dir->i_size += BOGO_DIRENT_SIZE; - dir->i_ctime = dir->i_mtime = current_time(dir); + dir->i_ctime = dir->i_mtime = current_cmtime(dir); inode_inc_iversion(dir); d_instantiate(dentry, inode); dget(dentry); /* Extra count - pin the dentry in core */ @@ -3016,7 +3019,7 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr } dir->i_size += BOGO_DIRENT_SIZE; - inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode); + inode->i_ctime = dir->i_ctime = dir->i_mtime = current_cmtime(inode); inode_inc_iversion(dir); inc_nlink(inode); ihold(inode); /* New dentry reference */ @@ -3034,7 +3037,7 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry) shmem_free_inode(inode->i_sb); dir->i_size -= BOGO_DIRENT_SIZE; - inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode); + inode->i_ctime = dir->i_ctime = dir->i_mtime = current_cmtime(inode); inode_inc_iversion(dir); drop_nlink(inode); dput(dentry); /* Undo the count from "create" - this does all the work */ @@ -3124,7 +3127,7 @@ static int shmem_rename2(struct mnt_idmap *idmap, new_dir->i_size += BOGO_DIRENT_SIZE; old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime = new_dir->i_mtime = - inode->i_ctime = current_time(old_dir); + inode->i_ctime = current_cmtime(old_dir); inode_inc_iversion(old_dir); inode_inc_iversion(new_dir); return 0; @@ -3178,7 +3181,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, folio_put(folio); } dir->i_size += BOGO_DIRENT_SIZE; - dir->i_ctime = dir->i_mtime = current_time(dir); + dir->i_ctime = dir->i_mtime = current_cmtime(dir); inode_inc_iversion(dir); d_instantiate(dentry, inode); dget(dentry); @@ -3250,7 +3253,7 @@ static int shmem_fileattr_set(struct mnt_idmap *idmap, (fa->flags & SHMEM_FL_USER_MODIFIABLE); shmem_set_inode_flags(inode, info->fsflags); - inode->i_ctime = current_time(inode); + inode->i_ctime = current_cmtime(inode); inode_inc_iversion(inode); return 0; } @@ -3320,7 +3323,7 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler, name = xattr_full_name(handler, name); err = simple_xattr_set(&info->xattrs, name, value, size, flags, NULL); if (!err) { - inode->i_ctime = current_time(inode); + inode->i_ctime = current_cmtime(inode); inode_inc_iversion(inode); } return err; From patchwork Tue Apr 11 14:27:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13207680 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 A76DCC77B73 for ; Tue, 11 Apr 2023 14:27:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E54BB28000C; Tue, 11 Apr 2023 10:27:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DDB2D280001; Tue, 11 Apr 2023 10:27:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7BB828000C; Tue, 11 Apr 2023 10:27:17 -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 B16B0280001 for ; Tue, 11 Apr 2023 10:27:17 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5F8251A0D15 for ; Tue, 11 Apr 2023 14:27:17 +0000 (UTC) X-FDA: 80669337714.16.B1CFF82 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 9DAEB100003 for ; Tue, 11 Apr 2023 14:27:15 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IymI7Pv0; spf=pass (imf05.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=1681223235; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VVCfke3ZCxYsghQLpATwfwjekyzkEVZd5h7+Voop3jo=; b=ZkSSuFha+kxKUMKrj15RTpM6kGz8sXqN+8Ykq+IU32+dXbpmuNgUoXN+PlYvJ6fKhE0iJN NDVIU2kc9oRdy7DZgQ/8mYGRGYvS0CHiZsE2z7OBkIQXQvgDG+jEKH/pbP796iKfozUdqg JIdBm+Txt0nNJwF7odXryPB8zqyWlK8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IymI7Pv0; spf=pass (imf05.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681223235; a=rsa-sha256; cv=none; b=vLxVsobF2VQ/lUzBdCEXcYKd+/EF5lVpWd+65lmu9y2djtpbsnab96V5PRZzww2CFtDBMJ GveZgebDXiDOzz1AU8QjHZXFdvyFVImgpfG+HIg6EM9akOizx0jGhE+z+kYc0M072YF3G1 TdVFs7HQd0UJw3S1zCoXbhuzQQxFcnM= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B81A362769; Tue, 11 Apr 2023 14:27:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C100C433D2; Tue, 11 Apr 2023 14:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681223234; bh=6y1YeGPH/VDzbluu556WvHbrgod71MAnILEUbvu4oy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IymI7Pv0rtcsh15nq7onOJEP+gWsO4qna8uXbEuQwaEVOvwsKzPwh2hcFyUaF4Lrx XdYZai9OWXt7UKRbAg3BTWw/42rJ4yWtC+dwFzLLGNkVahk09bUFcduCvRM1PtXiLw m002LBg/IFOgaiQgOCspNScOrKbSzHygYmekp4HClAirdjNF3Mjta7Br3SMRvZ1Rs8 HM61/lARWL0KAgsdQWzwTlXzaSZNHX9lmToIXAubJkrWLNqd+vMAe3mM1m2rG32YBI zDM8U6NpOEBIgE7Bl5vD5FaLjbFdKLB2ciLTdgD7mHHnnRJDt6pdJ3S+AA+P2K6IHv ChJgZLWcjeELQ== From: Jeff Layton To: Alexander Viro , Christian Brauner , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 3/3] xfs: mark the inode for high-res timestamp update in getattr Date: Tue, 11 Apr 2023 10:27:08 -0400 Message-Id: <20230411142708.62475-4-jlayton@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411142708.62475-1-jlayton@kernel.org> References: <20230411142708.62475-1-jlayton@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9DAEB100003 X-Rspam-User: X-Stat-Signature: ecjwgdnc1cprxcccj9fm5yz3634rzmwg X-HE-Tag: 1681223235-765265 X-HE-Meta: U2FsdGVkX1+lA39EXV7wluNq3fci2Acv/3wgfBgEqOnDi/Ec0ksVN5ri//lmtfEUJkT8DQjmWrO8ni5VebzAG/wRZ4X7fqQcUciryML9wk0m1ntrQU/iS/VGJ43T6Ag1R56fAUn0NLl9SWnTTTF9JgMYvxbGALKuzhI1cIrGeIHwLDLxxF7+XxNUNKu+FHsoh7QSw3gcuYHNoI9+HqL+J1w0llR+V3kUcLc3U5bg41Jb9bLjvZ3Znv0CgniakKJ8unXQZ2GD4wY0jn4MVs2DIZjozu1o6YdtKPjK6K7srAtKc9FT7pnetZ7xfB5bvl5FnDplu925955COBFow4htUenWMSb3DI+7jAsL8pvsJqqTE+xXkeDEuUcqcHx9vZblK4AOPhcklB8kYazSggCUE+Hd1FJlCElDhP7moIr92ou6KG3zCgaTdbtF+D5rGQXeazvhaShIGhPsRu+xI/jxrnenoO0e3lLCBdwDa9U3FrVJFQXyIa9HsyOUsdL6d0I1VSKS2kjfrBXvPwwRwYjrETjwdMd3ErvUaDlbj/Yw48UQnodl2njR8ZVNhFVMyaqwok3PjViXZWYBd61sA3ekgZ99YRdRCUDbVKgpYpqlgrEmRo2IZfx4ggESM3ZdNzZXBUCIQPzUGjVCZePhTP1qNq9A4+Sdem4mVxupovQwegWtjE70g6+DIP9JmktR5T3Buz8wxgoK4AWmygD05Wqb+jWySq9bFgp6Q7iitJQPZBaL51hpkM7P5x1OkJyd1IOVL3u+Sp1w6A/Ox1F6JQNtlY30T3V/nIclFzR+Kl0W7j0dbKKukP8Pa13Dot/gI/pQhFVZoO/bPrXbvfEV1w+wWlTxzZQuItkc82DFZZKSNfltxnKo5JVW410SR+Ugmi0Yri0jEqkZmaylRv2HferpLOWtSZX9uCP9lxcaKDIn73VakZVEByAU2KVXAJArLnj8PAsQYixMR5sfy/G+VN0 895hs6OD qqMtbP7tUregO8vj+t6s9uQ6YXd7lu+mQMaCpITtiqv+wFo5yp/s2auKIBQyfbDyogNskuIOKX5OxpdoeiVyyFEm8RYsESlnKpgb78mGaSlC610kIqRPtISaUnBxTiIKEaRn9t1WmHZFhvwuzNn960PFNFbjZ4DPXenxFCj00SNz+JL6hsYIc6o8bYMgOxx4xsbcRF2e7G5uR3U5P/RBL98D17XT++W4BhNw5R/xiifSrWiP1iYsKagel4gyVJjo2+CfZUfFvUhT56u+lBdrfxImRmwelSohwYP458xD/wQ21Nma5z4eNn50enDPms8BZkuD77VtchFc6TrOSEqE6hTupXKacUi/Zy1cm 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: When the mtime or ctime is being queried via getattr, ensure that we mark the inode for a high-res timestamp update on the next pass. Also, switch to current_cmtime for other c/mtime updates. With this change, we're better off having the NFS server just ignore the i_version field and have it use the ctime instead, so clear the STATX_CHANGE_COOKIE flag in the result mask in ->getattr. Signed-off-by: Jeff Layton --- fs/xfs/libxfs/xfs_trans_inode.c | 2 +- fs/xfs/xfs_acl.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_iops.c | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c index 8b5547073379..9ad7c229c617 100644 --- a/fs/xfs/libxfs/xfs_trans_inode.c +++ b/fs/xfs/libxfs/xfs_trans_inode.c @@ -63,7 +63,7 @@ xfs_trans_ichgtime( ASSERT(tp); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); - tv = current_time(inode); + tv = current_cmtime(inode); if (flags & XFS_ICHGTIME_MOD) inode->i_mtime = tv; diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c index 791db7d9c849..461adc58cf8c 100644 --- a/fs/xfs/xfs_acl.c +++ b/fs/xfs/xfs_acl.c @@ -233,7 +233,7 @@ xfs_acl_set_mode( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); inode->i_mode = mode; - inode->i_ctime = current_time(inode); + inode->i_ctime = current_cmtime(inode); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); if (xfs_has_wsync(mp)) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 5808abab786c..80f9d731e261 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -843,7 +843,7 @@ xfs_init_new_inode( ip->i_df.if_nextents = 0; ASSERT(ip->i_nblocks == 0); - tv = current_time(inode); + tv = current_cmtime(inode); inode->i_mtime = tv; inode->i_atime = tv; inode->i_ctime = tv; diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 24718adb3c16..a0b07f90e16c 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -565,6 +565,15 @@ xfs_vn_getattr( if (xfs_is_shutdown(mp)) return -EIO; + /* + * XFS uses the i_version infrastructure to track any change to + * the inode, including atime updates. This means that the i_version + * returned by getattr doesn't conform to what the callers expect. + * Clear it here so that nfsd will fake up a change cookie from the + * ctime instead. + */ + stat->result_mask &= ~STATX_CHANGE_COOKIE; + stat->size = XFS_ISIZE(ip); stat->dev = inode->i_sb->s_dev; stat->mode = inode->i_mode; @@ -573,8 +582,8 @@ xfs_vn_getattr( stat->gid = vfsgid_into_kgid(vfsgid); stat->ino = ip->i_ino; stat->atime = inode->i_atime; - stat->mtime = inode->i_mtime; - stat->ctime = inode->i_ctime; + if (request_mask & (STATX_CTIME|STATX_MTIME)) + fill_cmtime_and_mark(inode, stat); stat->blocks = XFS_FSB_TO_BB(mp, ip->i_nblocks + ip->i_delayed_blks); if (xfs_has_v3inodes(mp)) { @@ -917,7 +926,7 @@ xfs_setattr_size( if (newsize != oldsize && !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) { iattr->ia_ctime = iattr->ia_mtime = - current_time(inode); + current_cmtime(inode); iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME; }