From patchwork Tue Apr 11 14:37:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 82009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2631111vqo; Tue, 11 Apr 2023 07:47:40 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/Dj/Cn790WzW4C62RfZTpdSpqq8AQhrjJlbE6IBVyum6VKlsvZZ41EBc/KHgFNKZpPXCu X-Received: by 2002:a05:6a20:12c2:b0:d9:7a97:a7b9 with SMTP id v2-20020a056a2012c200b000d97a97a7b9mr21259892pzg.6.1681224460688; Tue, 11 Apr 2023 07:47:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681224460; cv=none; d=google.com; s=arc-20160816; b=Xj18fD+3iryonJ64GG7codvd2D2LrhfD04XlO7l6+NKk3ipVLx74L1jrzf+eOFAYss Wc8wn+l2TJbJYpXubkVKTMsyJd2F9Ook/BuoG0VswkrwaAfMAE9Jm/taxxXsXurQVtN9 uIBxjqGiNm3KFDP/QCU+5iY7DMpPHvrkiQmfESJpru2qBk9xe0zOev0ifQjCTXacFzTv aj4LM/kvhy8cNyiu9EY4Npo10whPct34PxW69vsyboRsVNx2JmXVi3wVyyvzjzoKXqBC jnLw6n5UXN2pGN7TzPg/rqHcg8atZgd1Jy7YOL1q8RHzUGoAC4eerqJvsq0kSb43UiUX DoaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YHYJ58zGg50V/rRl2bjqWR/GYgPheUUBpiJEBWpxlTQ=; b=PReH1jujbZ46OXIDke1EUn8f8iyWpChUp/a65ixU+YDDFup4tuHfTHEBcpd4ETcJJ1 Ceu3Nk2Ml5m7ZfBC+DANkxfTgCchK4LJdxzF/qAbocgxRrB9dzB47Yh3zXzuNNGVi1By TcWicnpO6+1iU4IjnQag3bz1XYHcbO4bnmyqnrbZfPYlUYNIXggmwpvNuWZAuFeNheZC fW9G0aNjQKYHyGWebEGZQBqXOZxWoUCXcpkRdPzM0IXAwx3F2jcGiP+o/vbwRJQCHmZ5 yoRyA/0NPL2hVKCtTY2XiADc+NhG7mAaHqZ5aaeL/u43ZfZKDiruRivGLuHi/+KjWUwW 6Jsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fzPI7v3S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a63dc01000000b0050f975790dcsi14445250pgg.464.2023.04.11.07.47.28; Tue, 11 Apr 2023 07:47:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fzPI7v3S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230257AbjDKOhR (ORCPT + 99 others); Tue, 11 Apr 2023 10:37:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbjDKOhK (ORCPT ); Tue, 11 Apr 2023 10:37:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14DBA4690; Tue, 11 Apr 2023 07:37:07 -0700 (PDT) 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 6453F627D0; Tue, 11 Apr 2023 14:37:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7C8FC433EF; Tue, 11 Apr 2023 14:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681223826; bh=Awb6q4i/Q5m9mXXhrXc+BP9AQEQgndLooZSbj9YNpPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzPI7v3S7qN/G08Aq6LYTNv0NKM9fu4g0hJuZR6XFHbF7ihRuAeDxXOaXuJOkOTVp Vk1rmLqrdQE0rlLC/CqOsDXA3rEJ9n0UM7RjrHyyKk3FVCDD25Qocp/JA7evtaJrhV fse4d3jnaSqKPSTcjkn8BOl1WiY49jRMMJhM7BkLjuN7pwpyoeLx2J1lcU37Hfc8DK mqhThaLYJP7Y8795gicp9jSzG+8qpuHu1agOLxRQt7yjqMcbNzujso+isKjTK0A89U SpipD7P5bfXbxPE0ogu3SQv3WdMP94X/44cbGZwZLuRJbwRL3WiXIL9dI8iJf00K76 cY2LycIOshb4A== From: Jeff Layton To: Alexander Viro , Christian Brauner , "Darrick J. Wong" , Hugh Dickins , Andrew Morton , Dave Chinner , Chuck Lever Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org Subject: [RFC PATCH 1/3][RESEND] fs: add infrastructure for opportunistic high-res ctime/mtime updates Date: Tue, 11 Apr 2023 10:37:00 -0400 Message-Id: <20230411143702.64495-2-jlayton@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411143702.64495-1-jlayton@kernel.org> References: <20230411143702.64495-1-jlayton@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762891619784354496?= X-GMAIL-MSGID: =?utf-8?q?1762891619784354496?= 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: 82017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2638418vqo; Tue, 11 Apr 2023 08:00:20 -0700 (PDT) X-Google-Smtp-Source: AKy350ZHC8nPDvuvUn0aHvJ/hi97RT5YeiAWoWNWiTg1xIoUo+pAYu+iYf0K+2Z4LZiR0Bv3FHtf X-Received: by 2002:a05:6a20:a91f:b0:cb:f76c:ceda with SMTP id cd31-20020a056a20a91f00b000cbf76ccedamr13996078pzb.22.1681225220463; Tue, 11 Apr 2023 08:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681225220; cv=none; d=google.com; s=arc-20160816; b=ghrjvUfw9Dhjwz94pWCeMdifYWkRjc1L1jcn1ja95P+SyZaEDOZl6UhAVaLA4i0MRn yLIz1n9e7zJy16qorsMLkMwgTcmwNC5udKHESgN4Sx+dHpDbOZ3BhgXlmXPKFtuW5Uhv lOhU9BkULIgFDon5uD8oI1iJ/b4YD4va9fctAHtwdHqdgEyFjdQZFKWw1GSGR3TmBCWh 7cdWBNopmbNLvGdiCcQu7vTKj+lph+1J/A1U0SfA1sAp1lBal9hTS9uQahzfUQ6B0IoS u7Gf9/w0y2WZopLjWzclNzagcnFcvkr7PTJYuT6+aX3bPjQnALHN0rGFQXYA4h4q1LBD BfeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cmsV/BNDrmF6zQdi+rsdgHY9rce/ydYxUGcPmL06UuA=; b=Jun0upCLvxnRarTFQNyGoC18uZguGAS1VRoM+e2fZRrOlz8b0O0KR6/UuCaxS1V8MY euJSe/kT3q0G47Ll2PRoapRMGiJ6jFRKKZXjFsLw4OfRQ77rqdU9KnJwyilrjSSkMPlC OV41fwkVIdkibOvYgxfxS59cyG/1bf81DZ46t4ztlYuPIuAsMkg4lj7CsZF5d0SAm5KU PtapLDceM/wz6uHTSOIOyND8s+Ybn9BByJKOx3yn+z60WvEYF1Fi/G+lznsDBLU551yx 750tq/+Gqd3MTgQOISWUyX2xPnfRW+O5Yu2JG+UFfoxUaECGPB1lEqp5b+mF3Aov47hx Ax2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DS4Rz6ur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c11-20020a65618b000000b005138c1f1fcasi13335776pgv.149.2023.04.11.08.00.06; Tue, 11 Apr 2023 08:00:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DS4Rz6ur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbjDKO17 (ORCPT + 99 others); Tue, 11 Apr 2023 10:27:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbjDKO1m (ORCPT ); Tue, 11 Apr 2023 10:27:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 156AB4698; Tue, 11 Apr 2023 07:27:16 -0700 (PDT) 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 A1352627A9; 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-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762892416440961235?= X-GMAIL-MSGID: =?utf-8?q?1762892416440961235?= 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: 82007 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2623657vqo; Tue, 11 Apr 2023 07:35:54 -0700 (PDT) X-Google-Smtp-Source: AKy350a2q29vlxITPx4tOGwWp0o2bQ9nmgsRFbSfJrqeZC1kbDc+fQo3bJB/nlf19s1/yjtQjGsf X-Received: by 2002:a17:903:1252:b0:1a6:3d8e:face with SMTP id u18-20020a170903125200b001a63d8efacemr8848890plh.0.1681223753664; Tue, 11 Apr 2023 07:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681223753; cv=none; d=google.com; s=arc-20160816; b=Acs10yNP/Mi5/3XhdV2hzTpLj2GuBIS3o9IIswzSklk4QnAT+Z51uV7yAjaiWSfJG1 RFH1IDQJXA7yPHS17RvGXd5e2TIgIhAfQiRkbJQx7f1C3Od5/EcMG3Q3YaX2iHX49j0l HxJmdbPd1Lv16vYakSiO3UUqCSlxo7a33em99jEWDfHoAy5y4uU1RsGktKrxlPuzr+cl ihSf44HcsiPw3ID/lLR1K4caBMK/ki/DLBOA1bNkqvQ3tTxFQTx8WxE+Lvvv6LzQBmxB Rz4NgMhC8ozlAHeTfoHiLJViO2Zextynzij5Ep/Lh5bMexgXQb17TktocsR/GlELAOTb jwIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VVCfke3ZCxYsghQLpATwfwjekyzkEVZd5h7+Voop3jo=; b=I5EN6l7h1MmfQJyCfKWrv7+EcXlRHfke6MiVwS0fHzlsCn4OOcde1nFRTxP9oZefvb moKiROBHjqGn21P/9zd5SUKoe53UitmkZz9vRNuLU3K2uLtRsxCdCmSDoiQcyUQN+bmv eQj+ND+ZiEUlcrTbxO78BC9RB+s2tuTPXjtcU6mkWyV/CtGVcZv3kd4LII9Z+N134hS9 EQc5cKaX4HotP/hTEZt8yCj2oCdAODqRWwF+kr1btbxy9YouFJhHgxGa7FRIDVErM6bO Pw7uRbN8h/A9CpEiKUWk9J2hlP0Y/Ryl6uRcGn4uvR1KGCSljaBrsu3mlhERt+exfYsk Jj8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IymI7Pv0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a170902b49000b001a1a1023808si12914351plr.603.2023.04.11.07.35.41; Tue, 11 Apr 2023 07:35:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IymI7Pv0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbjDKO2C (ORCPT + 99 others); Tue, 11 Apr 2023 10:28:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229757AbjDKO1q (ORCPT ); Tue, 11 Apr 2023 10:27:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 604D35BB6; Tue, 11 Apr 2023 07:27:20 -0700 (PDT) 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 B67C962799; 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-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762890878347415968?= X-GMAIL-MSGID: =?utf-8?q?1762890878347415968?= 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; }