Skip to content

Commit 3a3a5fe

Browse files
deepa-hubgregkh
authored andcommitted
fs: kernfs: Replace CURRENT_TIME by current_fs_time()
This is in preparation for the series that transitions filesystem timestamps to use 64 bit time and hence make them y2038 safe. CURRENT_TIME macro will be deleted before merging the aforementioned series. Use current_fs_time() instead of CURRENT_TIME for inode timestamps. struct kernfs_node is associated with a sysfs file/ directory. Truncate the values to appropriate time granularity when writing to inode timestamps of the files. ktime_get_real_ts() is used to obtain times for struct kernfs_iattrs. Since these times are later assigned to inode times using timespec_truncate() for all filesystem based operations, we can save the supers list traversal time here by using ktime_get_real_ts() directly. Signed-off-by: Deepa Dinamani <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1b48b53 commit 3a3a5fe

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

fs/kernfs/dir.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ int kernfs_add_one(struct kernfs_node *kn)
753753
ps_iattr = parent->iattr;
754754
if (ps_iattr) {
755755
struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
756-
ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
756+
ktime_get_real_ts(&ps_iattrs->ia_ctime);
757+
ps_iattrs->ia_mtime = ps_iattrs->ia_ctime;
757758
}
758759

759760
mutex_unlock(&kernfs_mutex);
@@ -1279,8 +1280,9 @@ static void __kernfs_remove(struct kernfs_node *kn)
12791280

12801281
/* update timestamps on the parent */
12811282
if (ps_iattr) {
1282-
ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME;
1283-
ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME;
1283+
ktime_get_real_ts(&ps_iattr->ia_iattr.ia_ctime);
1284+
ps_iattr->ia_iattr.ia_mtime =
1285+
ps_iattr->ia_iattr.ia_ctime;
12841286
}
12851287

12861288
kernfs_put(pos);

fs/kernfs/inode.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
5454
iattrs->ia_mode = kn->mode;
5555
iattrs->ia_uid = GLOBAL_ROOT_UID;
5656
iattrs->ia_gid = GLOBAL_ROOT_GID;
57-
iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME;
57+
58+
ktime_get_real_ts(&iattrs->ia_atime);
59+
iattrs->ia_mtime = iattrs->ia_atime;
60+
iattrs->ia_ctime = iattrs->ia_atime;
5861

5962
simple_xattrs_init(&kn->iattr->xattrs);
6063
out_unlock:
@@ -236,16 +239,18 @@ ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)
236239
static inline void set_default_inode_attr(struct inode *inode, umode_t mode)
237240
{
238241
inode->i_mode = mode;
239-
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
242+
inode->i_atime = inode->i_mtime =
243+
inode->i_ctime = current_fs_time(inode->i_sb);
240244
}
241245

242246
static inline void set_inode_attr(struct inode *inode, struct iattr *iattr)
243247
{
248+
struct super_block *sb = inode->i_sb;
244249
inode->i_uid = iattr->ia_uid;
245250
inode->i_gid = iattr->ia_gid;
246-
inode->i_atime = iattr->ia_atime;
247-
inode->i_mtime = iattr->ia_mtime;
248-
inode->i_ctime = iattr->ia_ctime;
251+
inode->i_atime = timespec_trunc(iattr->ia_atime, sb->s_time_gran);
252+
inode->i_mtime = timespec_trunc(iattr->ia_mtime, sb->s_time_gran);
253+
inode->i_ctime = timespec_trunc(iattr->ia_ctime, sb->s_time_gran);
249254
}
250255

251256
static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)

0 commit comments

Comments
 (0)