Skip to content

Commit 16a9496

Browse files
jtlaytonbrauner
authored andcommitted
fs: convert core infrastructure to new timestamp accessors
Convert the core vfs code to use the new timestamp accessor functions. Signed-off-by: Jeff Layton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 077c212 commit 16a9496

File tree

8 files changed

+31
-24
lines changed

8 files changed

+31
-24
lines changed

fs/attr.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode,
308308
i_uid_update(idmap, attr, inode);
309309
i_gid_update(idmap, attr, inode);
310310
if (ia_valid & ATTR_ATIME)
311-
inode->i_atime = attr->ia_atime;
311+
inode_set_atime_to_ts(inode, attr->ia_atime);
312312
if (ia_valid & ATTR_MTIME)
313-
inode->i_mtime = attr->ia_mtime;
313+
inode_set_mtime_to_ts(inode, attr->ia_mtime);
314314
if (ia_valid & ATTR_CTIME)
315315
inode_set_ctime_to_ts(inode, attr->ia_ctime);
316316
if (ia_valid & ATTR_MODE) {

fs/bad_inode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void make_bad_inode(struct inode *inode)
208208
remove_inode_hash(inode);
209209

210210
inode->i_mode = S_IFREG;
211-
inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
211+
simple_inode_init_ts(inode);
212212
inode->i_op = &bad_inode_ops;
213213
inode->i_opflags &= ~IOP_XATTR;
214214
inode->i_fop = &bad_file_ops;

fs/binfmt_misc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static struct inode *bm_get_inode(struct super_block *sb, int mode)
547547
if (inode) {
548548
inode->i_ino = get_next_ino();
549549
inode->i_mode = mode;
550-
inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
550+
simple_inode_init_ts(inode);
551551
}
552552
return inode;
553553
}

fs/inode.c

+21-14
Original file line numberDiff line numberDiff line change
@@ -1837,27 +1837,29 @@ EXPORT_SYMBOL(bmap);
18371837
static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
18381838
struct timespec64 now)
18391839
{
1840-
struct timespec64 ctime;
1840+
struct timespec64 atime, mtime, ctime;
18411841

18421842
if (!(mnt->mnt_flags & MNT_RELATIME))
18431843
return 1;
18441844
/*
18451845
* Is mtime younger than or equal to atime? If yes, update atime:
18461846
*/
1847-
if (timespec64_compare(&inode->i_mtime, &inode->i_atime) >= 0)
1847+
atime = inode_get_atime(inode);
1848+
mtime = inode_get_mtime(inode);
1849+
if (timespec64_compare(&mtime, &atime) >= 0)
18481850
return 1;
18491851
/*
18501852
* Is ctime younger than or equal to atime? If yes, update atime:
18511853
*/
18521854
ctime = inode_get_ctime(inode);
1853-
if (timespec64_compare(&ctime, &inode->i_atime) >= 0)
1855+
if (timespec64_compare(&ctime, &atime) >= 0)
18541856
return 1;
18551857

18561858
/*
18571859
* Is the previous atime value older than a day? If yes,
18581860
* update atime:
18591861
*/
1860-
if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60)
1862+
if ((long)(now.tv_sec - atime.tv_sec) >= 24*60*60)
18611863
return 1;
18621864
/*
18631865
* Good, we can skip the atime update:
@@ -1888,12 +1890,13 @@ int inode_update_timestamps(struct inode *inode, int flags)
18881890

18891891
if (flags & (S_MTIME|S_CTIME|S_VERSION)) {
18901892
struct timespec64 ctime = inode_get_ctime(inode);
1893+
struct timespec64 mtime = inode_get_mtime(inode);
18911894

18921895
now = inode_set_ctime_current(inode);
18931896
if (!timespec64_equal(&now, &ctime))
18941897
updated |= S_CTIME;
1895-
if (!timespec64_equal(&now, &inode->i_mtime)) {
1896-
inode->i_mtime = now;
1898+
if (!timespec64_equal(&now, &mtime)) {
1899+
inode_set_mtime_to_ts(inode, now);
18971900
updated |= S_MTIME;
18981901
}
18991902
if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated))
@@ -1903,8 +1906,10 @@ int inode_update_timestamps(struct inode *inode, int flags)
19031906
}
19041907

19051908
if (flags & S_ATIME) {
1906-
if (!timespec64_equal(&now, &inode->i_atime)) {
1907-
inode->i_atime = now;
1909+
struct timespec64 atime = inode_get_atime(inode);
1910+
1911+
if (!timespec64_equal(&now, &atime)) {
1912+
inode_set_atime_to_ts(inode, now);
19081913
updated |= S_ATIME;
19091914
}
19101915
}
@@ -1963,7 +1968,7 @@ EXPORT_SYMBOL(inode_update_time);
19631968
bool atime_needs_update(const struct path *path, struct inode *inode)
19641969
{
19651970
struct vfsmount *mnt = path->mnt;
1966-
struct timespec64 now;
1971+
struct timespec64 now, atime;
19671972

19681973
if (inode->i_flags & S_NOATIME)
19691974
return false;
@@ -1989,7 +1994,8 @@ bool atime_needs_update(const struct path *path, struct inode *inode)
19891994
if (!relatime_need_update(mnt, inode, now))
19901995
return false;
19911996

1992-
if (timespec64_equal(&inode->i_atime, &now))
1997+
atime = inode_get_atime(inode);
1998+
if (timespec64_equal(&atime, &now))
19931999
return false;
19942000

19952001
return true;
@@ -2106,17 +2112,18 @@ static int inode_needs_update_time(struct inode *inode)
21062112
{
21072113
int sync_it = 0;
21082114
struct timespec64 now = current_time(inode);
2109-
struct timespec64 ctime;
2115+
struct timespec64 ts;
21102116

21112117
/* First try to exhaust all avenues to not sync */
21122118
if (IS_NOCMTIME(inode))
21132119
return 0;
21142120

2115-
if (!timespec64_equal(&inode->i_mtime, &now))
2121+
ts = inode_get_mtime(inode);
2122+
if (!timespec64_equal(&ts, &now))
21162123
sync_it = S_MTIME;
21172124

2118-
ctime = inode_get_ctime(inode);
2119-
if (!timespec64_equal(&ctime, &now))
2125+
ts = inode_get_ctime(inode);
2126+
if (!timespec64_equal(&ts, &now))
21202127
sync_it |= S_CTIME;
21212128

21222129
if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode))

fs/nsfs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int __ns_get_path(struct path *path, struct ns_common *ns)
8484
return -ENOMEM;
8585
}
8686
inode->i_ino = ns->inum;
87-
inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode);
87+
simple_inode_init_ts(inode);
8888
inode->i_flags |= S_IMMUTABLE;
8989
inode->i_mode = S_IFREG | S_IRUGO;
9090
inode->i_fop = &ns_file_operations;

fs/pipe.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ static struct inode * get_pipe_inode(void)
898898
inode->i_mode = S_IFIFO | S_IRUSR | S_IWUSR;
899899
inode->i_uid = current_fsuid();
900900
inode->i_gid = current_fsgid();
901-
inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
901+
simple_inode_init_ts(inode);
902902

903903
return inode;
904904

fs/stack.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ void fsstack_copy_attr_all(struct inode *dest, const struct inode *src)
6666
dest->i_uid = src->i_uid;
6767
dest->i_gid = src->i_gid;
6868
dest->i_rdev = src->i_rdev;
69-
dest->i_atime = src->i_atime;
70-
dest->i_mtime = src->i_mtime;
69+
inode_set_atime_to_ts(dest, inode_get_atime(src));
70+
inode_set_mtime_to_ts(dest, inode_get_mtime(src));
7171
inode_set_ctime_to_ts(dest, inode_get_ctime(src));
7272
dest->i_blkbits = src->i_blkbits;
7373
dest->i_flags = src->i_flags;

fs/stat.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask,
5757
stat->gid = vfsgid_into_kgid(vfsgid);
5858
stat->rdev = inode->i_rdev;
5959
stat->size = i_size_read(inode);
60-
stat->atime = inode->i_atime;
61-
stat->mtime = inode->i_mtime;
60+
stat->atime = inode_get_atime(inode);
61+
stat->mtime = inode_get_mtime(inode);
6262
stat->ctime = inode_get_ctime(inode);
6363
stat->blksize = i_blocksize(inode);
6464
stat->blocks = inode->i_blocks;

0 commit comments

Comments
 (0)