Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4734252rwb; Tue, 8 Aug 2023 13:00:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlzP2uZComvb6DeB/UQAh+Bv6oOREcNeXNW3IkZ8iNs7Ul3dvCeNlFpq4LlPRAg+godxVA X-Received: by 2002:a17:90a:6b08:b0:268:5bc6:dc6e with SMTP id v8-20020a17090a6b0800b002685bc6dc6emr478474pjj.42.1691524829296; Tue, 08 Aug 2023 13:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691524829; cv=none; d=google.com; s=arc-20160816; b=Tp1T/YT7duDlcnnMUHf8QEkQaGQtlct/PJd/BuEqFb4HwUa8aU5a7ae6kbeYtznwIF obGbJpRKx/oY1sIbVWUbKcEIYJwgPHPekdekn8f01F02DPOeVMbsklK0GRlELJ/ASb1j 0Lfr5JPlreiw7oiRNdodvXyxuS1XjC+wvqKhiNjvnteyM0XWRp7PyiOBa5NLwn5aCmtS wAvySWQ7TJpChiKl8htLmmwEY6DO66m2NO3RIbzHOnwVPs+rk80/TX85HSubbhiaaRoQ Sw0VqjmizAsE50YCmlVPawxib3fsuj0PTP3nIoggncC+SkiAU5vksbq1TIAu2UXn5GYD ECYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=1DEnEiKO284zxT4/+fvA4uuffbMofkDORo642+Wc/io=; fh=VDS1Ji1Jg94b8HYa+h+b069MTX7Y1JPYBeWAMaZH+VI=; b=hiK78uZYNRxtG9FKClz24ugsozsvIvWWrxl/dKhK586V/WT5/xhy8TFUDB8CNgZ4rW N6ONL5cr2J2BlPZyMkyVWvrNiYY+MZvmNc8cq1Szv7/+Nsw7A9lHkFRwUO71iTx5UKLL r92LV8sJjGtRNpmUlWaJd4Hvzjyc9fbdYtunS3iA2weEsOHDyNY6gbcWUIpX/u+w+JtA C4iVOi2REn7zUllsxoJy/UxG0IEfgTB1djmQapTUpvCkC+wUWynmMpWSDch/xpSQv0Og 5QN8twzkKMiXSDC59dnbpTShi5Ji2qmY3FO3QsrqkqGudGjDoiQARaZGRgF/XTFoJTfz pqjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=ix372cs3; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=nz47Gajx; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qe2-20020a17090b4f8200b002630c9e77ddsi8302302pjb.46.2023.08.08.12.59.45; Tue, 08 Aug 2023 13:00:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@suse.cz header.s=susede2_rsa header.b=ix372cs3; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=nz47Gajx; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233707AbjHHSmi (ORCPT + 99 others); Tue, 8 Aug 2023 14:42:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231990AbjHHSmT (ORCPT ); Tue, 8 Aug 2023 14:42:19 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2985BDE9ED; Tue, 8 Aug 2023 09:33:07 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0187B22484; Tue, 8 Aug 2023 09:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691486712; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1DEnEiKO284zxT4/+fvA4uuffbMofkDORo642+Wc/io=; b=ix372cs3mbIkTWg1MsYpwEmHKxymfpU2fRqMoB3bdsY5L5+d88wTzMILXUNjN2Hey8brqp /zdSMsRPF0pQ9mO8VTms56EAKaxrkXcWWBEAdzVrBPrId8dDBBUjH8L2jH5yiaPdY8XiST M7jwu5Zs1qGSi0jn9fW7GgGyREZQvck= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691486712; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1DEnEiKO284zxT4/+fvA4uuffbMofkDORo642+Wc/io=; b=nz47GajxRXd1Kr3p+NB1XcBjrQKYlyuj0q3UvQcQR7hQOVOIMR3ZkrS9KehXlRYW0RhdS3 rOQzce0ROF9jIWAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DE500139E9; Tue, 8 Aug 2023 09:25:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KHTeNfcJ0mSOFwAAMHmgww (envelope-from ); Tue, 08 Aug 2023 09:25:11 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 5F488A0769; Tue, 8 Aug 2023 11:25:11 +0200 (CEST) Date: Tue, 8 Aug 2023 11:25:11 +0200 From: Jan Kara To: Jeff Layton Cc: Alexander Viro , Christian Brauner , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , David Howells , Marc Dionne , Chris Mason , Josef Bacik , David Sterba , Xiubo Li , Ilya Dryomov , Jan Harkes , coda@cs.cmu.edu, Tyler Hicks , Gao Xiang , Chao Yu , Yue Hu , Jeffle Xu , Namjae Jeon , Sungjong Seo , Jan Kara , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , OGAWA Hirofumi , Miklos Szeredi , Bob Peterson , Andreas Gruenbacher , Greg Kroah-Hartman , Tejun Heo , Trond Myklebust , Anna Schumaker , Konstantin Komarov , Mark Fasheh , Joel Becker , Joseph Qi , Mike Marshall , Martin Brandenburg , Luis Chamberlain , Kees Cook , Iurii Zaikin , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Sergey Senozhatsky , Richard Weinberger , Hans de Goede , Hugh Dickins , Andrew Morton , Amir Goldstein , "Darrick J. Wong" , Benjamin Coddington , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, v9fs@lists.linux.dev, linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, ceph-devel@vger.kernel.org, codalist@coda.cs.cmu.edu, ecryptfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, ntfs3@lists.linux.dev, ocfs2-devel@lists.linux.dev, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, linux-mm@kvack.org, linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org Subject: Re: [PATCH v7 03/13] fs: drop the timespec64 arg from generic_update_time Message-ID: <20230808092511.jh4lxer2dztdajpo@quack3> References: <20230807-mgctime-v7-0-d1dec143a704@kernel.org> <20230807-mgctime-v7-3-d1dec143a704@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230807-mgctime-v7-3-d1dec143a704@kernel.org> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL,URIBL_BLOCKED autolearn=no 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-ext4@vger.kernel.org On Mon 07-08-23 15:38:34, Jeff Layton wrote: > In future patches we're going to change how the ctime is updated > to keep track of when it has been queried. The way that the update_time > operation works (and a lot of its callers) make this difficult, since > they grab a timestamp early and then pass it down to eventually be > copied into the inode. > > All of the existing update_time callers pass in the result of > current_time() in some fashion. Drop the "time" parameter from > generic_update_time, and rework it to fetch its own timestamp. > > This change means that an update_time could fetch a different timestamp > than was seen in inode_needs_update_time. update_time is only ever > called with one of two flag combinations: Either S_ATIME is set, or > S_MTIME|S_CTIME|S_VERSION are set. > > With this change we now treat the flags argument as an indicator that > some value needed to be updated when last checked, rather than an > indication to update specific timestamps. > > Rework the logic for updating the timestamps and put it in a new > inode_update_timestamps helper that other update_time routines can use. > S_ATIME is as treated as we always have, but if any of the other three > are set, then we attempt to update all three. > > Also, some callers of generic_update_time need to know what timestamps > were actually updated. Change it to return an S_* flag mask to indicate > that and rework the callers to expect it. > > Signed-off-by: Jeff Layton Looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/gfs2/inode.c | 3 +- > fs/inode.c | 84 +++++++++++++++++++++++++++++++++++++++++------------ > fs/orangefs/inode.c | 3 +- > fs/ubifs/file.c | 6 ++-- > fs/xfs/xfs_iops.c | 6 ++-- > include/linux/fs.h | 3 +- > 6 files changed, 80 insertions(+), 25 deletions(-) > > diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c > index 200cabf3b393..f1f04557aa21 100644 > --- a/fs/gfs2/inode.c > +++ b/fs/gfs2/inode.c > @@ -2155,7 +2155,8 @@ static int gfs2_update_time(struct inode *inode, struct timespec64 *time, > if (error) > return error; > } > - return generic_update_time(inode, time, flags); > + generic_update_time(inode, flags); > + return 0; > } > > static const struct inode_operations gfs2_file_iops = { > diff --git a/fs/inode.c b/fs/inode.c > index 3fc251bfaf73..e07e45f6cd01 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -1881,29 +1881,76 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode, > return 0; > } > > -int generic_update_time(struct inode *inode, struct timespec64 *time, int flags) > +/** > + * inode_update_timestamps - update the timestamps on the inode > + * @inode: inode to be updated > + * @flags: S_* flags that needed to be updated > + * > + * The update_time function is called when an inode's timestamps need to be > + * updated for a read or write operation. This function handles updating the > + * actual timestamps. It's up to the caller to ensure that the inode is marked > + * dirty appropriately. > + * > + * In the case where any of S_MTIME, S_CTIME, or S_VERSION need to be updated, > + * attempt to update all three of them. S_ATIME updates can be handled > + * independently of the rest. > + * > + * Returns a set of S_* flags indicating which values changed. > + */ > +int inode_update_timestamps(struct inode *inode, int flags) > { > - int dirty_flags = 0; > + int updated = 0; > + struct timespec64 now; > + > + if (flags & (S_MTIME|S_CTIME|S_VERSION)) { > + struct timespec64 ctime = inode_get_ctime(inode); > > - if (flags & (S_ATIME | S_CTIME | S_MTIME)) { > - if (flags & S_ATIME) > - inode->i_atime = *time; > - if (flags & S_CTIME) > - inode_set_ctime_to_ts(inode, *time); > - if (flags & S_MTIME) > - inode->i_mtime = *time; > - > - if (inode->i_sb->s_flags & SB_LAZYTIME) > - dirty_flags |= I_DIRTY_TIME; > - else > - dirty_flags |= I_DIRTY_SYNC; > + now = inode_set_ctime_current(inode); > + if (!timespec64_equal(&now, &ctime)) > + updated |= S_CTIME; > + if (!timespec64_equal(&now, &inode->i_mtime)) { > + inode->i_mtime = now; > + updated |= S_MTIME; > + } > + if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated)) > + updated |= S_VERSION; > + } else { > + now = current_time(inode); > } > > - if ((flags & S_VERSION) && inode_maybe_inc_iversion(inode, false)) > - dirty_flags |= I_DIRTY_SYNC; > + if (flags & S_ATIME) { > + if (!timespec64_equal(&now, &inode->i_atime)) { > + inode->i_atime = now; > + updated |= S_ATIME; > + } > + } > + return updated; > +} > +EXPORT_SYMBOL(inode_update_timestamps); > + > +/** > + * generic_update_time - update the timestamps on the inode > + * @inode: inode to be updated > + * @flags: S_* flags that needed to be updated > + * > + * The update_time function is called when an inode's timestamps need to be > + * updated for a read or write operation. In the case where any of S_MTIME, S_CTIME, > + * or S_VERSION need to be updated we attempt to update all three of them. S_ATIME > + * updates can be handled done independently of the rest. > + * > + * Returns a S_* mask indicating which fields were updated. > + */ > +int generic_update_time(struct inode *inode, int flags) > +{ > + int updated = inode_update_timestamps(inode, flags); > + int dirty_flags = 0; > > + if (updated & (S_ATIME|S_MTIME|S_CTIME)) > + dirty_flags = inode->i_sb->s_flags & SB_LAZYTIME ? I_DIRTY_TIME : I_DIRTY_SYNC; > + if (updated & S_VERSION) > + dirty_flags |= I_DIRTY_SYNC; > __mark_inode_dirty(inode, dirty_flags); > - return 0; > + return updated; > } > EXPORT_SYMBOL(generic_update_time); > > @@ -1915,7 +1962,8 @@ int inode_update_time(struct inode *inode, struct timespec64 *time, int flags) > { > if (inode->i_op->update_time) > return inode->i_op->update_time(inode, time, flags); > - return generic_update_time(inode, time, flags); > + generic_update_time(inode, flags); > + return 0; > } > EXPORT_SYMBOL(inode_update_time); > > diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c > index a52c30e80f45..3afa2a69bc63 100644 > --- a/fs/orangefs/inode.c > +++ b/fs/orangefs/inode.c > @@ -903,9 +903,10 @@ int orangefs_permission(struct mnt_idmap *idmap, > int orangefs_update_time(struct inode *inode, struct timespec64 *time, int flags) > { > struct iattr iattr; > + > gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_update_time: %pU\n", > get_khandle_from_ino(inode)); > - generic_update_time(inode, time, flags); > + flags = generic_update_time(inode, flags); > memset(&iattr, 0, sizeof iattr); > if (flags & S_ATIME) > iattr.ia_valid |= ATTR_ATIME; > diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c > index 436b27d7c58f..df9086b19cd0 100644 > --- a/fs/ubifs/file.c > +++ b/fs/ubifs/file.c > @@ -1387,8 +1387,10 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time, > .dirtied_ino_d = ALIGN(ui->data_len, 8) }; > int err, release; > > - if (!IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT)) > - return generic_update_time(inode, time, flags); > + if (!IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT)) { > + generic_update_time(inode, flags); > + return 0; > + } > > err = ubifs_budget_space(c, &req); > if (err) > diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c > index 3a9363953ef2..731f45391baa 100644 > --- a/fs/xfs/xfs_iops.c > +++ b/fs/xfs/xfs_iops.c > @@ -1042,8 +1042,10 @@ xfs_vn_update_time( > > if (inode->i_sb->s_flags & SB_LAZYTIME) { > if (!((flags & S_VERSION) && > - inode_maybe_inc_iversion(inode, false))) > - return generic_update_time(inode, now, flags); > + inode_maybe_inc_iversion(inode, false))) { > + generic_update_time(inode, flags); > + return 0; > + } > > /* Capture the iversion update that just occurred */ > log_flags |= XFS_ILOG_CORE; > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 85977cdeda94..bb3c2c4f871f 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2343,7 +2343,8 @@ extern int current_umask(void); > > extern void ihold(struct inode * inode); > extern void iput(struct inode *); > -extern int generic_update_time(struct inode *, struct timespec64 *, int); > +int inode_update_timestamps(struct inode *inode, int flags); > +int generic_update_time(struct inode *, int); > > /* /sys/fs */ > extern struct kobject *fs_kobj; > > -- > 2.41.0 > -- Jan Kara SUSE Labs, CR