From patchwork Thu Sep 28 11:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13402652 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 3881CE732C1 for ; Thu, 28 Sep 2023 11:04:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7FB98D00A7; Thu, 28 Sep 2023 07:04:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C57DD8D0038; Thu, 28 Sep 2023 07:04:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B46D98D00A7; Thu, 28 Sep 2023 07:04:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A53948D0038 for ; Thu, 28 Sep 2023 07:04:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 82E261CA522 for ; Thu, 28 Sep 2023 11:04:21 +0000 (UTC) X-FDA: 81285722322.03.7A62A68 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 30760100021 for ; Thu, 28 Sep 2023 11:04:18 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V6CAZGur; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695899059; a=rsa-sha256; cv=none; b=CmzVSIbTpYHMpL4tTTDfr/9y1oHUGM571KcnynyGa7A2J6QtE8k6OkXoqJorgl2LDkIKJg 6EgTtzDzFaZJL1jNUV1Uz4x9EMXwew4NeKU37YNNbqWlpP56nuJ0vY2jbmpXTidIiKXOPq 1801d4ag9XG4YeAbxAlLm8/sFXOqND4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V6CAZGur; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 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=1695899059; 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=26QZJkXyCteUGIdsYDAprJvEMbX5nG5qrG3vbj0j++g=; b=tQcmdhusN1ER9Yv/QNH2dkSQ1+8n5j6Znj3DO5ejFpQvG6XzlN0RuY+UmoOkS1Q87/PmdU 34R2ORb0s0shr6DCthexFcm1jbcaPJiMI68ULBuO/Pw+nR9CmmZO9LfESjjagM5G2V6rNw dZz2rtQ94K7a/AnS8ug3wN11cKc/DMU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 8F242CE1AA5; Thu, 28 Sep 2023 11:04:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 810CDC433CC; Thu, 28 Sep 2023 11:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695899055; bh=UA17NieiKuJUQtAvlfYpTNXdsMGRKLLOw/Cz8ngzkD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V6CAZGurZISIkQMn+b7qANzD5KkJ97vaooKgKjDX0Cks6k8TEzUpepVAKk4oIlWwG +jzZnGzmicw5BtfxrPApbAGLtk/nvnTQ9Jv5ftuLQnDZfLM3d7WMfTSLDLANOnprnD D/mwlEpY82WLyYRan0BMiKRvcSd4JFXXqoXYLCSAZDxaDWLf2nc6sEoEg8+eUfCBAv 7JWU5Ug2iCxLmiKovVzNi+U0ye7uC7YDSrGbPNkjbeysP1E8oTSNAnrj2sLl7jo+Sp 5PrpsKTxEDXT9eYDzu2B5nmLgbMV6ozOr+FCNbxbj2dfcUC4IxYnKsLUmfp2/y31CZ mKGPuQvOuScJA== From: Jeff Layton To: Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Eric Biederman , Kees Cook , linux-mm@kvack.org Subject: [PATCH 02/87] fs: convert core infrastructure to new {a,m}time accessors Date: Thu, 28 Sep 2023 07:02:11 -0400 Message-ID: <20230928110413.33032-1-jlayton@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230928110300.32891-1-jlayton@kernel.org> References: <20230928110300.32891-1-jlayton@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 30760100021 X-Stat-Signature: sucg377jrw6mzuwxharn3d6b8ix94g7t X-HE-Tag: 1695899058-296409 X-HE-Meta: U2FsdGVkX1+dpcuJigDWhTDO9CzAKFhQRRa8xqYusmI3Uw7vj8Z1S44QW9Dnevx+zOhkbdpKpjuBMgh7/hDeCpvrweVNHPHzl/sn33idsjwCBMNPbrPbQ2hnFMhdL4skEHY1qqgkn0nNA/DGiRInWZGur0O1J5ImykoEMyBiLfkjyBlb7MjfmiVkrsR19Jk01BXewd54druD/Fj5qQcJGM4YCS8N8nnjy+aabyrOc4zKTfnlqDBu1tmjkvD9+GyNV4Hh2m7fc5pc6V9h7A0df5PmWXmU1q6FI08hgQSEZoZuHpvppkiBFqVPgVMumN7YUqHyivASokPY6bU5AyhUtHviFArIosHMxdFgFsmuVHHvtLZuPRN1DKr+PlFUvTgc7VSZrZRAspwaplbK0lfSvh0ntGANsXLm0U1Q37AMFkWRz8MdZMjpBnLjF4xvSTV/od+f9+zJBhT7pUyCgjyVmvn75/E/qdxU7d+Kb2WaJa7O2hM2VzSdkAhH8p2YtfTDL97BBNhzEfejr9CEomYBaEygEQZwdDzHuBGtORk5H/IujZhJ7fXP5YbXXg+eD/2mr9L/Mb/Glgb/cITZWLwaCyZTmgs90sJPdvps/tjoTjLPKDM3X5mh1RXjE4dRuAXLJFW+l7DwMNUAdAWHWJioBzptU2E0yF+oWhWnkDjKN17v2Z88CiSuyckfyVgvcgEITnEaJ8AiTy1opJkxP2zDSTDMrkfVN9CWqBqbfJ+WZN/Fja3eCt1LETM8NDTf1Osskev/pV/d3OBMQaluRQM4Ya0G/nQUOrIKMn0UecoKNyIU1w2Qs00AiviPy63E1HsZddfQTRr6GxKwUQsoenFz5r4/T0umXGVnYSfMUUp+1XBto7FM11yQIm1rwOXFwWmneHKpd/22o8VJVMD7MtQUMQeeDm7jEPm8ECbEQiIYhMCRZJcf9mnMR1dy+vdxGWj4EKNALcybP2qKBqAF10y z1nvNO9x W9pnyW2wyOLCApakZ75/xrj076H8Z6uozusteSN3FU37WdFtUqBy5mosiedYrfhfPKEgyYT4S7VUAfKTfz9r8R7zXkzEeHKUyIe2zcKH3OootJH5QvbdRCI+lUk41M6pxYXrFuQ9dJcSxMwqxSDDUJK+h53fu1nCF+zcqJKyzZ1LoEbkhLVC26pFOq9d9Uhk+ts6+Lfm8eUEECWpeL/+UKNV9JqkAWi+hjceSCbxpo6E5ej3wMlxlw1jMOQ== 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: Convert the core filesystem code to use the new atime and mtime accessor functions. Signed-off-by: Jeff Layton --- fs/attr.c | 4 ++-- fs/bad_inode.c | 2 +- fs/binfmt_misc.c | 2 +- fs/inode.c | 35 +++++++++++++++++++++-------------- fs/libfs.c | 32 +++++++++++++++++++------------- fs/nsfs.c | 2 +- fs/pipe.c | 2 +- fs/stack.c | 4 ++-- fs/stat.c | 4 ++-- include/linux/fs_stack.h | 6 +++--- 10 files changed, 53 insertions(+), 40 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index a8ae5f6d9b16..bdf5deb06ea9 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -308,9 +308,9 @@ 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->i_atime = attr->ia_atime; + inode_set_atime_to_ts(inode, attr->ia_atime); if (ia_valid & ATTR_MTIME) - inode->i_mtime = attr->ia_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) { diff --git a/fs/bad_inode.c b/fs/bad_inode.c index 83f9566c973b..316d88da2ce1 100644 --- a/fs/bad_inode.c +++ b/fs/bad_inode.c @@ -208,7 +208,7 @@ void make_bad_inode(struct inode *inode) remove_inode_hash(inode); inode->i_mode = S_IFREG; - inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); + simple_inode_init_ts(inode); inode->i_op = &bad_inode_ops; inode->i_opflags &= ~IOP_XATTR; inode->i_fop = &bad_file_ops; diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c index e0108d17b085..5d2be9b0a0a5 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c @@ -547,7 +547,7 @@ static struct inode *bm_get_inode(struct super_block *sb, int mode) if (inode) { inode->i_ino = get_next_ino(); inode->i_mode = mode; - inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); + simple_inode_init_ts(inode); } return inode; } diff --git a/fs/inode.c b/fs/inode.c index 84bc3c76e5cc..0612ad9c0227 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1837,27 +1837,29 @@ EXPORT_SYMBOL(bmap); static int relatime_need_update(struct vfsmount *mnt, struct inode *inode, struct timespec64 now) { - struct timespec64 ctime; + struct timespec64 atime, mtime, ctime; if (!(mnt->mnt_flags & MNT_RELATIME)) return 1; /* * Is mtime younger than or equal to atime? If yes, update atime: */ - if (timespec64_compare(&inode->i_mtime, &inode->i_atime) >= 0) + atime = inode_get_atime(inode); + mtime = inode_get_mtime(inode); + if (timespec64_compare(&mtime, &atime) >= 0) return 1; /* * Is ctime younger than or equal to atime? If yes, update atime: */ ctime = inode_get_ctime(inode); - if (timespec64_compare(&ctime, &inode->i_atime) >= 0) + if (timespec64_compare(&ctime, &atime) >= 0) return 1; /* * Is the previous atime value older than a day? If yes, * update atime: */ - if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60) + if ((long)(now.tv_sec - atime.tv_sec) >= 24*60*60) return 1; /* * Good, we can skip the atime update: @@ -1888,12 +1890,13 @@ int inode_update_timestamps(struct inode *inode, int flags) if (flags & (S_MTIME|S_CTIME|S_VERSION)) { struct timespec64 ctime = inode_get_ctime(inode); + struct timespec64 mtime = inode_get_mtime(inode); 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; + if (!timespec64_equal(&now, &mtime)) { + inode_set_mtime_to_ts(inode, now); updated |= S_MTIME; } if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated)) @@ -1903,8 +1906,10 @@ int inode_update_timestamps(struct inode *inode, int flags) } if (flags & S_ATIME) { - if (!timespec64_equal(&now, &inode->i_atime)) { - inode->i_atime = now; + struct timespec64 atime = inode_get_atime(inode); + + if (!timespec64_equal(&now, &atime)) { + inode_set_atime_to_ts(inode, now); updated |= S_ATIME; } } @@ -1963,7 +1968,7 @@ EXPORT_SYMBOL(inode_update_time); bool atime_needs_update(const struct path *path, struct inode *inode) { struct vfsmount *mnt = path->mnt; - struct timespec64 now; + struct timespec64 now, atime; if (inode->i_flags & S_NOATIME) return false; @@ -1989,7 +1994,8 @@ bool atime_needs_update(const struct path *path, struct inode *inode) if (!relatime_need_update(mnt, inode, now)) return false; - if (timespec64_equal(&inode->i_atime, &now)) + atime = inode_get_atime(inode); + if (timespec64_equal(&atime, &now)) return false; return true; @@ -2106,17 +2112,18 @@ static int inode_needs_update_time(struct inode *inode) { int sync_it = 0; struct timespec64 now = current_time(inode); - struct timespec64 ctime; + struct timespec64 ts; /* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME(inode)) return 0; - if (!timespec64_equal(&inode->i_mtime, &now)) + ts = inode_get_mtime(inode); + if (!timespec64_equal(&ts, &now)) sync_it = S_MTIME; - ctime = inode_get_ctime(inode); - if (!timespec64_equal(&ctime, &now)) + ts = inode_get_ctime(inode); + if (!timespec64_equal(&ts, &now)) sync_it |= S_CTIME; if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode)) diff --git a/fs/libfs.c b/fs/libfs.c index f5cdc7f7f5b5..abe2b5a40ba1 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -541,7 +541,8 @@ void simple_recursive_removal(struct dentry *dentry, dput(victim); // unpin it } if (victim == dentry) { - inode->i_mtime = inode_set_ctime_current(inode); + inode_set_mtime_to_ts(inode, + inode_set_ctime_current(inode)); if (d_is_dir(dentry)) drop_nlink(inode); inode_unlock(inode); @@ -582,7 +583,7 @@ static int pseudo_fs_fill_super(struct super_block *s, struct fs_context *fc) */ root->i_ino = 1; root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR; - root->i_atime = root->i_mtime = inode_set_ctime_current(root); + simple_inode_init_ts(root); s->s_root = d_make_root(root); if (!s->s_root) return -ENOMEM; @@ -638,8 +639,8 @@ int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *den { struct inode *inode = d_inode(old_dentry); - dir->i_mtime = inode_set_ctime_to_ts(dir, - inode_set_ctime_current(inode)); + inode_set_mtime_to_ts(dir, + inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode))); inc_nlink(inode); ihold(inode); dget(dentry); @@ -673,8 +674,8 @@ int simple_unlink(struct inode *dir, struct dentry *dentry) { struct inode *inode = d_inode(dentry); - dir->i_mtime = inode_set_ctime_to_ts(dir, - inode_set_ctime_current(inode)); + inode_set_mtime_to_ts(dir, + inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode))); drop_nlink(inode); dput(dentry); return 0; @@ -709,9 +710,10 @@ void simple_rename_timestamp(struct inode *old_dir, struct dentry *old_dentry, { struct inode *newino = d_inode(new_dentry); - old_dir->i_mtime = inode_set_ctime_current(old_dir); + inode_set_mtime_to_ts(old_dir, inode_set_ctime_current(old_dir)); if (new_dir != old_dir) - new_dir->i_mtime = inode_set_ctime_current(new_dir); + inode_set_mtime_to_ts(new_dir, + inode_set_ctime_current(new_dir)); inode_set_ctime_current(d_inode(old_dentry)); if (newino) inode_set_ctime_current(newino); @@ -926,7 +928,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic, */ inode->i_ino = 1; inode->i_mode = S_IFDIR | 0755; - inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); + simple_inode_init_ts(inode); inode->i_op = &simple_dir_inode_operations; inode->i_fop = &simple_dir_operations; set_nlink(inode, 2); @@ -952,7 +954,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic, goto out; } inode->i_mode = S_IFREG | files->mode; - inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); + simple_inode_init_ts(inode); inode->i_fop = files->ops; inode->i_ino = i; d_add(dentry, inode); @@ -1520,7 +1522,7 @@ struct inode *alloc_anon_inode(struct super_block *s) inode->i_uid = current_fsuid(); inode->i_gid = current_fsgid(); inode->i_flags |= S_PRIVATE; - inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); + simple_inode_init_ts(inode); return inode; } EXPORT_SYMBOL(alloc_anon_inode); @@ -1920,8 +1922,12 @@ EXPORT_SYMBOL_GPL(direct_write_fallback); * When a new inode is created, most filesystems set the timestamps to the * current time. Add a helper to do this. */ -struct timespec64 simple_inode_init_ts(struct inode *inode); +struct timespec64 simple_inode_init_ts(struct inode *inode) { - return inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); + struct timespec64 ts = inode_set_ctime_current(inode); + + inode_set_atime_to_ts(inode, ts); + inode_set_mtime_to_ts(inode, ts); + return ts; } EXPORT_SYMBOL(simple_inode_init_ts); diff --git a/fs/nsfs.c b/fs/nsfs.c index 647a22433bd8..9a4b228d42fa 100644 --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -84,7 +84,7 @@ static int __ns_get_path(struct path *path, struct ns_common *ns) return -ENOMEM; } inode->i_ino = ns->inum; - inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode); + simple_inode_init_ts(inode); inode->i_flags |= S_IMMUTABLE; inode->i_mode = S_IFREG | S_IRUGO; inode->i_fop = &ns_file_operations; diff --git a/fs/pipe.c b/fs/pipe.c index 139190165a1c..b96a5918d064 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -898,7 +898,7 @@ static struct inode * get_pipe_inode(void) inode->i_mode = S_IFIFO | S_IRUSR | S_IWUSR; inode->i_uid = current_fsuid(); inode->i_gid = current_fsgid(); - inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); + simple_inode_init_ts(inode); return inode; diff --git a/fs/stack.c b/fs/stack.c index b5e01bdb5f5f..f18920119944 100644 --- a/fs/stack.c +++ b/fs/stack.c @@ -66,8 +66,8 @@ void fsstack_copy_attr_all(struct inode *dest, const struct inode *src) dest->i_uid = src->i_uid; dest->i_gid = src->i_gid; dest->i_rdev = src->i_rdev; - dest->i_atime = src->i_atime; - dest->i_mtime = src->i_mtime; + inode_set_atime_to_ts(dest, inode_get_atime(src)); + inode_set_mtime_to_ts(dest, inode_get_mtime(src)); inode_set_ctime_to_ts(dest, inode_get_ctime(src)); dest->i_blkbits = src->i_blkbits; dest->i_flags = src->i_flags; diff --git a/fs/stat.c b/fs/stat.c index d43a5cc1bfa4..24bb0209e459 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -57,8 +57,8 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->gid = vfsgid_into_kgid(vfsgid); stat->rdev = inode->i_rdev; stat->size = i_size_read(inode); - stat->atime = inode->i_atime; - stat->mtime = inode->i_mtime; + stat->atime = inode_get_atime(inode); + stat->mtime = inode_get_mtime(inode); stat->ctime = inode_get_ctime(inode); stat->blksize = i_blocksize(inode); stat->blocks = inode->i_blocks; diff --git a/include/linux/fs_stack.h b/include/linux/fs_stack.h index 010d39d0dc1c..2b1f74b24070 100644 --- a/include/linux/fs_stack.h +++ b/include/linux/fs_stack.h @@ -16,14 +16,14 @@ extern void fsstack_copy_inode_size(struct inode *dst, struct inode *src); static inline void fsstack_copy_attr_atime(struct inode *dest, const struct inode *src) { - dest->i_atime = src->i_atime; + inode_set_atime_to_ts(dest, inode_get_atime(src)); } static inline void fsstack_copy_attr_times(struct inode *dest, const struct inode *src) { - dest->i_atime = src->i_atime; - dest->i_mtime = src->i_mtime; + inode_set_atime_to_ts(dest, inode_get_atime(src)); + inode_set_mtime_to_ts(dest, inode_get_mtime(src)); inode_set_ctime_to_ts(dest, inode_get_ctime(src)); }