Commit 16a94965 authored by Jeff Layton's avatar Jeff Layton Committed by Christian Brauner

fs: convert core infrastructure to new timestamp accessors

Convert the core vfs code to use the new timestamp accessor functions.
Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20231004185239.80830-2-jlayton@kernel.orgSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 077c212f
...@@ -308,9 +308,9 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, ...@@ -308,9 +308,9 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode,
i_uid_update(idmap, attr, inode); i_uid_update(idmap, attr, inode);
i_gid_update(idmap, attr, inode); i_gid_update(idmap, attr, inode);
if (ia_valid & ATTR_ATIME) 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) 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) if (ia_valid & ATTR_CTIME)
inode_set_ctime_to_ts(inode, attr->ia_ctime); inode_set_ctime_to_ts(inode, attr->ia_ctime);
if (ia_valid & ATTR_MODE) { if (ia_valid & ATTR_MODE) {
......
...@@ -208,7 +208,7 @@ void make_bad_inode(struct inode *inode) ...@@ -208,7 +208,7 @@ void make_bad_inode(struct inode *inode)
remove_inode_hash(inode); remove_inode_hash(inode);
inode->i_mode = S_IFREG; 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_op = &bad_inode_ops;
inode->i_opflags &= ~IOP_XATTR; inode->i_opflags &= ~IOP_XATTR;
inode->i_fop = &bad_file_ops; inode->i_fop = &bad_file_ops;
......
...@@ -547,7 +547,7 @@ static struct inode *bm_get_inode(struct super_block *sb, int mode) ...@@ -547,7 +547,7 @@ static struct inode *bm_get_inode(struct super_block *sb, int mode)
if (inode) { if (inode) {
inode->i_ino = get_next_ino(); inode->i_ino = get_next_ino();
inode->i_mode = mode; inode->i_mode = mode;
inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); simple_inode_init_ts(inode);
} }
return inode; return inode;
} }
......
...@@ -1837,27 +1837,29 @@ EXPORT_SYMBOL(bmap); ...@@ -1837,27 +1837,29 @@ EXPORT_SYMBOL(bmap);
static int relatime_need_update(struct vfsmount *mnt, struct inode *inode, static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
struct timespec64 now) struct timespec64 now)
{ {
struct timespec64 ctime; struct timespec64 atime, mtime, ctime;
if (!(mnt->mnt_flags & MNT_RELATIME)) if (!(mnt->mnt_flags & MNT_RELATIME))
return 1; return 1;
/* /*
* Is mtime younger than or equal to atime? If yes, update atime: * 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; return 1;
/* /*
* Is ctime younger than or equal to atime? If yes, update atime: * Is ctime younger than or equal to atime? If yes, update atime:
*/ */
ctime = inode_get_ctime(inode); ctime = inode_get_ctime(inode);
if (timespec64_compare(&ctime, &inode->i_atime) >= 0) if (timespec64_compare(&ctime, &atime) >= 0)
return 1; return 1;
/* /*
* Is the previous atime value older than a day? If yes, * Is the previous atime value older than a day? If yes,
* update atime: * 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; return 1;
/* /*
* Good, we can skip the atime update: * Good, we can skip the atime update:
...@@ -1888,12 +1890,13 @@ int inode_update_timestamps(struct inode *inode, int flags) ...@@ -1888,12 +1890,13 @@ int inode_update_timestamps(struct inode *inode, int flags)
if (flags & (S_MTIME|S_CTIME|S_VERSION)) { if (flags & (S_MTIME|S_CTIME|S_VERSION)) {
struct timespec64 ctime = inode_get_ctime(inode); struct timespec64 ctime = inode_get_ctime(inode);
struct timespec64 mtime = inode_get_mtime(inode);
now = inode_set_ctime_current(inode); now = inode_set_ctime_current(inode);
if (!timespec64_equal(&now, &ctime)) if (!timespec64_equal(&now, &ctime))
updated |= S_CTIME; updated |= S_CTIME;
if (!timespec64_equal(&now, &inode->i_mtime)) { if (!timespec64_equal(&now, &mtime)) {
inode->i_mtime = now; inode_set_mtime_to_ts(inode, now);
updated |= S_MTIME; updated |= S_MTIME;
} }
if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated)) if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated))
...@@ -1903,8 +1906,10 @@ int inode_update_timestamps(struct inode *inode, int flags) ...@@ -1903,8 +1906,10 @@ int inode_update_timestamps(struct inode *inode, int flags)
} }
if (flags & S_ATIME) { if (flags & S_ATIME) {
if (!timespec64_equal(&now, &inode->i_atime)) { struct timespec64 atime = inode_get_atime(inode);
inode->i_atime = now;
if (!timespec64_equal(&now, &atime)) {
inode_set_atime_to_ts(inode, now);
updated |= S_ATIME; updated |= S_ATIME;
} }
} }
...@@ -1963,7 +1968,7 @@ EXPORT_SYMBOL(inode_update_time); ...@@ -1963,7 +1968,7 @@ EXPORT_SYMBOL(inode_update_time);
bool atime_needs_update(const struct path *path, struct inode *inode) bool atime_needs_update(const struct path *path, struct inode *inode)
{ {
struct vfsmount *mnt = path->mnt; struct vfsmount *mnt = path->mnt;
struct timespec64 now; struct timespec64 now, atime;
if (inode->i_flags & S_NOATIME) if (inode->i_flags & S_NOATIME)
return false; return false;
...@@ -1989,7 +1994,8 @@ bool atime_needs_update(const struct path *path, struct inode *inode) ...@@ -1989,7 +1994,8 @@ bool atime_needs_update(const struct path *path, struct inode *inode)
if (!relatime_need_update(mnt, inode, now)) if (!relatime_need_update(mnt, inode, now))
return false; return false;
if (timespec64_equal(&inode->i_atime, &now)) atime = inode_get_atime(inode);
if (timespec64_equal(&atime, &now))
return false; return false;
return true; return true;
...@@ -2106,17 +2112,18 @@ static int inode_needs_update_time(struct inode *inode) ...@@ -2106,17 +2112,18 @@ static int inode_needs_update_time(struct inode *inode)
{ {
int sync_it = 0; int sync_it = 0;
struct timespec64 now = current_time(inode); struct timespec64 now = current_time(inode);
struct timespec64 ctime; struct timespec64 ts;
/* First try to exhaust all avenues to not sync */ /* First try to exhaust all avenues to not sync */
if (IS_NOCMTIME(inode)) if (IS_NOCMTIME(inode))
return 0; return 0;
if (!timespec64_equal(&inode->i_mtime, &now)) ts = inode_get_mtime(inode);
if (!timespec64_equal(&ts, &now))
sync_it = S_MTIME; sync_it = S_MTIME;
ctime = inode_get_ctime(inode); ts = inode_get_ctime(inode);
if (!timespec64_equal(&ctime, &now)) if (!timespec64_equal(&ts, &now))
sync_it |= S_CTIME; sync_it |= S_CTIME;
if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode)) if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode))
......
...@@ -84,7 +84,7 @@ static int __ns_get_path(struct path *path, struct ns_common *ns) ...@@ -84,7 +84,7 @@ static int __ns_get_path(struct path *path, struct ns_common *ns)
return -ENOMEM; return -ENOMEM;
} }
inode->i_ino = ns->inum; 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_flags |= S_IMMUTABLE;
inode->i_mode = S_IFREG | S_IRUGO; inode->i_mode = S_IFREG | S_IRUGO;
inode->i_fop = &ns_file_operations; inode->i_fop = &ns_file_operations;
......
...@@ -898,7 +898,7 @@ static struct inode * get_pipe_inode(void) ...@@ -898,7 +898,7 @@ static struct inode * get_pipe_inode(void)
inode->i_mode = S_IFIFO | S_IRUSR | S_IWUSR; inode->i_mode = S_IFIFO | S_IRUSR | S_IWUSR;
inode->i_uid = current_fsuid(); inode->i_uid = current_fsuid();
inode->i_gid = current_fsgid(); inode->i_gid = current_fsgid();
inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode); simple_inode_init_ts(inode);
return inode; return inode;
......
...@@ -66,8 +66,8 @@ void fsstack_copy_attr_all(struct inode *dest, const struct inode *src) ...@@ -66,8 +66,8 @@ void fsstack_copy_attr_all(struct inode *dest, const struct inode *src)
dest->i_uid = src->i_uid; dest->i_uid = src->i_uid;
dest->i_gid = src->i_gid; dest->i_gid = src->i_gid;
dest->i_rdev = src->i_rdev; dest->i_rdev = src->i_rdev;
dest->i_atime = src->i_atime; inode_set_atime_to_ts(dest, inode_get_atime(src));
dest->i_mtime = src->i_mtime; inode_set_mtime_to_ts(dest, inode_get_mtime(src));
inode_set_ctime_to_ts(dest, inode_get_ctime(src)); inode_set_ctime_to_ts(dest, inode_get_ctime(src));
dest->i_blkbits = src->i_blkbits; dest->i_blkbits = src->i_blkbits;
dest->i_flags = src->i_flags; dest->i_flags = src->i_flags;
......
...@@ -57,8 +57,8 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, ...@@ -57,8 +57,8 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask,
stat->gid = vfsgid_into_kgid(vfsgid); stat->gid = vfsgid_into_kgid(vfsgid);
stat->rdev = inode->i_rdev; stat->rdev = inode->i_rdev;
stat->size = i_size_read(inode); stat->size = i_size_read(inode);
stat->atime = inode->i_atime; stat->atime = inode_get_atime(inode);
stat->mtime = inode->i_mtime; stat->mtime = inode_get_mtime(inode);
stat->ctime = inode_get_ctime(inode); stat->ctime = inode_get_ctime(inode);
stat->blksize = i_blocksize(inode); stat->blksize = i_blocksize(inode);
stat->blocks = inode->i_blocks; stat->blocks = inode->i_blocks;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment