Skip to content

Commit

Permalink
fs: Replace CURRENT_TIME with current_time() for inode timestamps
Browse files Browse the repository at this point in the history
CURRENT_TIME macro is not appropriate for filesystems as it
doesn't use the right granularity for filesystem timestamps.
Use current_time() instead.

CURRENT_TIME is also not y2038 safe.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. As part of the effort current_time() will be
extended to do range checks. Hence, it is necessary for all
file system timestamps to use current_time(). Also,
current_time() will be transitioned along with vfs to be
y2038 safe.

Note that whenever a single call to current_time() is used
to change timestamps in different inodes, it is because they
share the same time granularity.

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Felipe Balbi <balbi@kernel.org>
Acked-by: Steven Whitehouse <swhiteho@redhat.com>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: David Sterba <dsterba@suse.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
deepa-hub authored and Al Viro committed Sep 28, 2016
1 parent 2554c72 commit 078cd82
Show file tree
Hide file tree
Showing 76 changed files with 182 additions and 182 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/cell/spufs/inode.c
Expand Up @@ -103,7 +103,7 @@ spufs_new_inode(struct super_block *sb, umode_t mode)
inode->i_mode = mode;
inode->i_uid = current_fsuid();
inode->i_gid = current_fsgid();
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
out:
return inode;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/s390/hypfs/inode.c
Expand Up @@ -51,7 +51,7 @@ static void hypfs_update_update(struct super_block *sb)
struct inode *inode = d_inode(sb_info->update_file);

sb_info->last_update = get_seconds();
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
}

/* directory tree removal functions */
Expand Down Expand Up @@ -99,7 +99,7 @@ static struct inode *hypfs_make_inode(struct super_block *sb, umode_t mode)
ret->i_mode = mode;
ret->i_uid = hypfs_info->uid;
ret->i_gid = hypfs_info->gid;
ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
if (S_ISDIR(mode))
set_nlink(ret, 2);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/hw/qib/qib_fs.c
Expand Up @@ -64,7 +64,7 @@ static int qibfs_mknod(struct inode *dir, struct dentry *dentry,
inode->i_uid = GLOBAL_ROOT_UID;
inode->i_gid = GLOBAL_ROOT_GID;
inode->i_blocks = 0;
inode->i_atime = CURRENT_TIME;
inode->i_atime = current_time(inode);
inode->i_mtime = inode->i_atime;
inode->i_ctime = inode->i_atime;
inode->i_private = data;
Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/ibmasm/ibmasmfs.c
Expand Up @@ -144,7 +144,7 @@ static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
if (ret) {
ret->i_ino = get_next_ino();
ret->i_mode = mode;
ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/oprofile/oprofilefs.c
Expand Up @@ -30,7 +30,7 @@ static struct inode *oprofilefs_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->i_ctime = CURRENT_TIME;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
}
return inode;
}
Expand Down
18 changes: 9 additions & 9 deletions drivers/usb/core/devio.c
Expand Up @@ -2409,21 +2409,21 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
snoop(&dev->dev, "%s: CONTROL\n", __func__);
ret = proc_control(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

case USBDEVFS_BULK:
snoop(&dev->dev, "%s: BULK\n", __func__);
ret = proc_bulk(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

case USBDEVFS_RESETEP:
snoop(&dev->dev, "%s: RESETEP\n", __func__);
ret = proc_resetep(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

case USBDEVFS_RESET:
Expand All @@ -2435,7 +2435,7 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
snoop(&dev->dev, "%s: CLEAR_HALT\n", __func__);
ret = proc_clearhalt(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

case USBDEVFS_GETDRIVER:
Expand All @@ -2462,22 +2462,22 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
snoop(&dev->dev, "%s: SUBMITURB\n", __func__);
ret = proc_submiturb(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

#ifdef CONFIG_COMPAT
case USBDEVFS_CONTROL32:
snoop(&dev->dev, "%s: CONTROL32\n", __func__);
ret = proc_control_compat(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

case USBDEVFS_BULK32:
snoop(&dev->dev, "%s: BULK32\n", __func__);
ret = proc_bulk_compat(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

case USBDEVFS_DISCSIGNAL32:
Expand All @@ -2489,7 +2489,7 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
snoop(&dev->dev, "%s: SUBMITURB32\n", __func__);
ret = proc_submiturb_compat(ps, p);
if (ret >= 0)
inode->i_mtime = CURRENT_TIME;
inode->i_mtime = current_time(inode);
break;

case USBDEVFS_IOCTL32:
Expand Down Expand Up @@ -2552,7 +2552,7 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
done:
usb_unlock_device(dev);
if (ret >= 0)
inode->i_atime = CURRENT_TIME;
inode->i_atime = current_time(inode);
return ret;
}

Expand Down
8 changes: 4 additions & 4 deletions drivers/usb/gadget/function/f_fs.c
Expand Up @@ -1193,15 +1193,15 @@ ffs_sb_make_inode(struct super_block *sb, void *data,
inode = new_inode(sb);

if (likely(inode)) {
struct timespec current_time = CURRENT_TIME;
struct timespec ts = current_time(inode);

inode->i_ino = get_next_ino();
inode->i_mode = perms->mode;
inode->i_uid = perms->uid;
inode->i_gid = perms->gid;
inode->i_atime = current_time;
inode->i_mtime = current_time;
inode->i_ctime = current_time;
inode->i_atime = ts;
inode->i_mtime = ts;
inode->i_ctime = ts;
inode->i_private = data;
if (fops)
inode->i_fop = fops;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/gadget/legacy/inode.c
Expand Up @@ -1913,7 +1913,7 @@ gadgetfs_make_inode (struct super_block *sb,
inode->i_uid = make_kuid(&init_user_ns, default_uid);
inode->i_gid = make_kgid(&init_user_ns, default_gid);
inode->i_atime = inode->i_mtime = inode->i_ctime
= CURRENT_TIME;
= current_time(inode);
inode->i_private = data;
inode->i_fop = fops;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/9p/vfs_inode.c
Expand Up @@ -276,7 +276,7 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
inode_init_owner(inode, NULL, mode);
inode->i_blocks = 0;
inode->i_rdev = rdev;
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_mapping->a_ops = &v9fs_addr_operations;

switch (mode & S_IFMT) {
Expand Down
2 changes: 1 addition & 1 deletion fs/adfs/inode.c
Expand Up @@ -199,7 +199,7 @@ adfs_adfs2unix_time(struct timespec *tv, struct inode *inode)
return;

cur_time:
*tv = CURRENT_TIME;
*tv = current_time(inode);
return;

too_early:
Expand Down
2 changes: 1 addition & 1 deletion fs/autofs4/inode.c
Expand Up @@ -359,7 +359,7 @@ struct inode *autofs4_get_inode(struct super_block *sb, umode_t mode)
inode->i_uid = d_inode(sb->s_root)->i_uid;
inode->i_gid = d_inode(sb->s_root)->i_gid;
}
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_ino = get_next_ino();

if (S_ISDIR(mode)) {
Expand Down
6 changes: 3 additions & 3 deletions fs/autofs4/root.c
Expand Up @@ -591,7 +591,7 @@ static int autofs4_dir_symlink(struct inode *dir,
if (p_ino && !IS_ROOT(dentry))
atomic_inc(&p_ino->count);

dir->i_mtime = CURRENT_TIME;
dir->i_mtime = current_time(dir);

return 0;
}
Expand Down Expand Up @@ -631,7 +631,7 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
d_inode(dentry)->i_size = 0;
clear_nlink(d_inode(dentry));

dir->i_mtime = CURRENT_TIME;
dir->i_mtime = current_time(dir);

spin_lock(&sbi->lookup_lock);
__autofs4_add_expiring(dentry);
Expand Down Expand Up @@ -762,7 +762,7 @@ static int autofs4_dir_mkdir(struct inode *dir,
if (p_ino && !IS_ROOT(dentry))
atomic_inc(&p_ino->count);
inc_nlink(dir);
dir->i_mtime = CURRENT_TIME;
dir->i_mtime = current_time(dir);

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions fs/devpts/inode.c
Expand Up @@ -305,7 +305,7 @@ static int mknod_ptmx(struct super_block *sb)
}

inode->i_ino = 2;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);

mode = S_IFCHR|opts->ptmxmode;
init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2));
Expand Down Expand Up @@ -411,7 +411,7 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
if (!inode)
goto fail;
inode->i_ino = 1;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
inode->i_op = &simple_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
Expand Down Expand Up @@ -559,7 +559,7 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
inode->i_ino = index + 3;
inode->i_uid = opts->setuid ? opts->uid : current_fsuid();
inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
init_special_inode(inode, S_IFCHR|opts->mode, MKDEV(UNIX98_PTY_SLAVE_MAJOR, index));

sprintf(s, "%d", index);
Expand Down
2 changes: 1 addition & 1 deletion fs/efivarfs/inode.c
Expand Up @@ -24,7 +24,7 @@ struct inode *efivarfs_get_inode(struct super_block *sb,
if (inode) {
inode->i_ino = get_next_ino();
inode->i_mode = mode;
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_flags = is_removable ? 0 : S_IMMUTABLE;
switch (mode & S_IFMT) {
case S_IFREG:
Expand Down
6 changes: 3 additions & 3 deletions fs/exofs/dir.c
Expand Up @@ -416,7 +416,7 @@ int exofs_set_link(struct inode *dir, struct exofs_dir_entry *de,
if (likely(!err))
err = exofs_commit_chunk(page, pos, len);
exofs_put_page(page);
dir->i_mtime = dir->i_ctime = CURRENT_TIME;
dir->i_mtime = dir->i_ctime = current_time(dir);
mark_inode_dirty(dir);
return err;
}
Expand Down Expand Up @@ -503,7 +503,7 @@ int exofs_add_link(struct dentry *dentry, struct inode *inode)
de->inode_no = cpu_to_le64(inode->i_ino);
exofs_set_de_type(de, inode);
err = exofs_commit_chunk(page, pos, rec_len);
dir->i_mtime = dir->i_ctime = CURRENT_TIME;
dir->i_mtime = dir->i_ctime = current_time(dir);
mark_inode_dirty(dir);
sbi->s_numfiles++;

Expand Down Expand Up @@ -554,7 +554,7 @@ int exofs_delete_entry(struct exofs_dir_entry *dir, struct page *page)
dir->inode_no = 0;
if (likely(!err))
err = exofs_commit_chunk(page, pos, to - from);
inode->i_ctime = inode->i_mtime = CURRENT_TIME;
inode->i_ctime = inode->i_mtime = current_time(inode);
mark_inode_dirty(inode);
sbi->s_numfiles--;
out:
Expand Down
4 changes: 2 additions & 2 deletions fs/exofs/inode.c
Expand Up @@ -1007,7 +1007,7 @@ static int _do_truncate(struct inode *inode, loff_t newsize)
struct exofs_sb_info *sbi = inode->i_sb->s_fs_info;
int ret;

inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_mtime = inode->i_ctime = current_time(inode);

ret = ore_truncate(&sbi->layout, &oi->oc, (u64)newsize);
if (likely(!ret))
Expand Down Expand Up @@ -1313,7 +1313,7 @@ struct inode *exofs_new_inode(struct inode *dir, umode_t mode)
inode_init_owner(inode, dir, mode);
inode->i_ino = sbi->s_nextid++;
inode->i_blkbits = EXOFS_BLKSHIFT;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
oi->i_commit_size = inode->i_size = 0;
spin_lock(&sbi->s_next_gen_lock);
inode->i_generation = sbi->s_next_generation++;
Expand Down
6 changes: 3 additions & 3 deletions fs/exofs/namei.c
Expand Up @@ -142,7 +142,7 @@ static int exofs_link(struct dentry *old_dentry, struct inode *dir,
{
struct inode *inode = d_inode(old_dentry);

inode->i_ctime = CURRENT_TIME;
inode->i_ctime = current_time(inode);
inode_inc_link_count(inode);
ihold(inode);

Expand Down Expand Up @@ -261,7 +261,7 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (!new_de)
goto out_dir;
err = exofs_set_link(new_dir, new_de, new_page, old_inode);
new_inode->i_ctime = CURRENT_TIME;
new_inode->i_ctime = current_time(new_inode);
if (dir_de)
drop_nlink(new_inode);
inode_dec_link_count(new_inode);
Expand All @@ -275,7 +275,7 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
inode_inc_link_count(new_dir);
}

old_inode->i_ctime = CURRENT_TIME;
old_inode->i_ctime = current_time(old_inode);

exofs_delete_entry(old_de, old_page);
mark_inode_dirty(old_inode);
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/super.c
Expand Up @@ -1543,7 +1543,7 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type,
if (inode->i_size < off+len-towrite)
i_size_write(inode, off+len-towrite);
inode->i_version++;
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_mtime = inode->i_ctime = current_time(inode);
mark_inode_dirty(inode);
return len - towrite;
}
Expand Down
8 changes: 4 additions & 4 deletions fs/f2fs/dir.c
Expand Up @@ -299,7 +299,7 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
f2fs_dentry_kunmap(dir, page);
set_page_dirty(page);

dir->i_mtime = dir->i_ctime = CURRENT_TIME;
dir->i_mtime = dir->i_ctime = current_time(dir);
f2fs_mark_inode_dirty_sync(dir);
f2fs_put_page(page, 1);
}
Expand Down Expand Up @@ -451,7 +451,7 @@ void update_parent_metadata(struct inode *dir, struct inode *inode,
f2fs_i_links_write(dir, true);
clear_inode_flag(inode, FI_NEW_INODE);
}
dir->i_mtime = dir->i_ctime = CURRENT_TIME;
dir->i_mtime = dir->i_ctime = current_time(dir);
f2fs_mark_inode_dirty_sync(dir);

if (F2FS_I(dir)->i_current_depth != current_depth)
Expand Down Expand Up @@ -656,7 +656,7 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode)

if (S_ISDIR(inode->i_mode))
f2fs_i_links_write(dir, false);
inode->i_ctime = CURRENT_TIME;
inode->i_ctime = current_time(inode);

f2fs_i_links_write(inode, false);
if (S_ISDIR(inode->i_mode)) {
Expand Down Expand Up @@ -703,7 +703,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
kunmap(page); /* kunmap - pair of f2fs_find_entry */
set_page_dirty(page);

dir->i_ctime = dir->i_mtime = CURRENT_TIME;
dir->i_ctime = dir->i_mtime = current_time(dir);
f2fs_mark_inode_dirty_sync(dir);

if (inode)
Expand Down

0 comments on commit 078cd82

Please sign in to comment.