]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ext4: use current_time() for inode timestamps
authorDeepa Dinamani <deepa.kernel@gmail.com>
Tue, 15 Nov 2016 02:40:10 +0000 (21:40 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 15 Nov 2016 02:40:10 +0000 (21:40 -0500)
CURRENT_TIME_SEC and CURRENT_TIME are not y2038 safe.
current_time() will be transitioned to be y2038 safe
along with vfs.

current_time() returns timestamps according to the
granularities set in the super_block.
The granularity check in ext4_current_time() to call
current_time() or CURRENT_TIME_SEC is not required.
Use current_time() directly to obtain timestamps
unconditionally, and remove ext4_current_time().

Quota files are assumed to be on the same filesystem.
Hence, use current_time() for these files as well.

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
fs/ext4/acl.c
fs/ext4/ext4.h
fs/ext4/extents.c
fs/ext4/ialloc.c
fs/ext4/inline.c
fs/ext4/inode.c
fs/ext4/ioctl.c
fs/ext4/namei.c
fs/ext4/super.c
fs/ext4/xattr.c

index dfa519979038b9c2475f335a1f44e8326eb8f799..fd389935ecd1629f402128518f63fd7d851e2a84 100644 (file)
@@ -196,7 +196,7 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
                        error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
                        if (error)
                                return error;
-                       inode->i_ctime = ext4_current_time(inode);
+                       inode->i_ctime = current_time(inode);
                        ext4_mark_inode_dirty(handle, inode);
                }
                break;
index 54211c7876f85f748ec21e8d4cf9a43af11d55bd..53d6d463ac4d62436973b6c7a2fcfb9302c628f3 100644 (file)
@@ -1532,12 +1532,6 @@ static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
        return container_of(inode, struct ext4_inode_info, vfs_inode);
 }
 
-static inline struct timespec ext4_current_time(struct inode *inode)
-{
-       return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
-               current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
-}
-
 static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
 {
        return ino == EXT4_ROOT_INO ||
index d3b119499c53d881b09a67e15daa7a6f7d6729e5..65dbd2bcf7755116c9c4d6f260033cc75a135fc1 100644 (file)
@@ -4724,7 +4724,7 @@ retry:
                map.m_lblk += ret;
                map.m_len = len = len - ret;
                epos = (loff_t)map.m_lblk << inode->i_blkbits;
-               inode->i_ctime = ext4_current_time(inode);
+               inode->i_ctime = current_time(inode);
                if (new_size) {
                        if (epos > new_size)
                                epos = new_size;
@@ -4852,7 +4852,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
                }
                /* Now release the pages and zero block aligned part of pages */
                truncate_pagecache_range(inode, start, end - 1);
-               inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+               inode->i_mtime = inode->i_ctime = current_time(inode);
 
                ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size,
                                             flags, mode);
@@ -4877,7 +4877,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
                goto out_dio;
        }
 
-       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        if (new_size) {
                ext4_update_inode_size(inode, new_size);
        } else {
@@ -5567,7 +5567,7 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
        up_write(&EXT4_I(inode)->i_data_sem);
        if (IS_SYNC(inode))
                ext4_handle_sync(handle);
-       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
 
 out_stop:
@@ -5677,7 +5677,7 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
        /* Expand file to avoid data loss if there is error while shifting */
        inode->i_size += len;
        EXT4_I(inode)->i_disksize += len;
-       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        ret = ext4_mark_inode_dirty(handle, inode);
        if (ret)
                goto out_stop;
index 170421edfdfe19567007be1b2b1d0a45cf9920fb..088afe07ddda24b7fe1f2a42e9674679941d1f73 100644 (file)
@@ -1039,7 +1039,7 @@ got:
        /* This is the optimal IO size (for stat), not the fs block size */
        inode->i_blocks = 0;
        inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
-                                                      ext4_current_time(inode);
+                                                      current_time(inode);
 
        memset(ei->i_data, 0, sizeof(ei->i_data));
        ei->i_dir_start_lookup = 0;
index f74d5ee2cdec095c5406677014c6a7141d17cdb2..cfa87bd49c5a61b904d7e960da1a61c39cfd874a 100644 (file)
@@ -1028,7 +1028,7 @@ static int ext4_add_dirent_to_inline(handle_t *handle,
         * happen is that the times are slightly out of date
         * and/or different from the directory change time.
         */
-       dir->i_mtime = dir->i_ctime = ext4_current_time(dir);
+       dir->i_mtime = dir->i_ctime = current_time(dir);
        ext4_update_dx_flag(dir);
        dir->i_version++;
        ext4_mark_inode_dirty(handle, dir);
@@ -1971,7 +1971,7 @@ out:
        if (inode->i_nlink)
                ext4_orphan_del(handle, inode);
 
-       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
        if (IS_SYNC(inode))
                ext4_handle_sync(handle);
index 79f46f4b43b8432a379d99ef00953440732a014c..e821ee28fa33cee75ef91f0dfd45863b58eb39fc 100644 (file)
@@ -4039,7 +4039,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
        if (IS_SYNC(inode))
                ext4_handle_sync(handle);
 
-       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
 out_stop:
        ext4_journal_stop(handle);
@@ -4195,7 +4195,7 @@ out_stop:
        if (inode->i_nlink)
                ext4_orphan_del(handle, inode);
 
-       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
        ext4_journal_stop(handle);
 
@@ -5170,7 +5170,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
                         * update c/mtime in shrink case below
                         */
                        if (!shrink) {
-                               inode->i_mtime = ext4_current_time(inode);
+                               inode->i_mtime = current_time(inode);
                                inode->i_ctime = inode->i_mtime;
                        }
                        down_write(&EXT4_I(inode)->i_data_sem);
index 99862a3726fc0849fa4600f34551107206dc8990..fc1cd37ba2d960709d21e1ce75b847bf5f5ea1b6 100644 (file)
@@ -153,7 +153,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
 
        swap_inode_data(inode, inode_bl);
 
-       inode->i_ctime = inode_bl->i_ctime = ext4_current_time(inode);
+       inode->i_ctime = inode_bl->i_ctime = current_time(inode);
 
        spin_lock(&sbi->s_next_gen_lock);
        inode->i_generation = sbi->s_next_generation++;
@@ -275,7 +275,7 @@ static int ext4_ioctl_setflags(struct inode *inode,
        }
 
        ext4_set_inode_flags(inode);
-       inode->i_ctime = ext4_current_time(inode);
+       inode->i_ctime = current_time(inode);
 
        err = ext4_mark_iloc_dirty(handle, inode, &iloc);
 flags_err:
@@ -371,7 +371,7 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
        }
 
        EXT4_I(inode)->i_projid = kprojid;
-       inode->i_ctime = ext4_current_time(inode);
+       inode->i_ctime = current_time(inode);
 out_dirty:
        rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
        if (!err)
@@ -503,7 +503,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                }
                err = ext4_reserve_inode_write(handle, inode, &iloc);
                if (err == 0) {
-                       inode->i_ctime = ext4_current_time(inode);
+                       inode->i_ctime = current_time(inode);
                        inode->i_generation = generation;
                        err = ext4_mark_iloc_dirty(handle, inode, &iloc);
                }
index 104f8bfba71822dd55f05b0caaebbf41aa2eb941..eadba919f26b1484c10125739a0e684fe49b7273 100644 (file)
@@ -1941,7 +1941,7 @@ static int add_dirent_to_buf(handle_t *handle, struct ext4_filename *fname,
         * happen is that the times are slightly out of date
         * and/or different from the directory change time.
         */
-       dir->i_mtime = dir->i_ctime = ext4_current_time(dir);
+       dir->i_mtime = dir->i_ctime = current_time(dir);
        ext4_update_dx_flag(dir);
        dir->i_version++;
        ext4_mark_inode_dirty(handle, dir);
@@ -2987,7 +2987,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
         * recovery. */
        inode->i_size = 0;
        ext4_orphan_add(handle, inode);
-       inode->i_ctime = dir->i_ctime = dir->i_mtime = ext4_current_time(inode);
+       inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
        ext4_dec_count(handle, dir);
        ext4_update_dx_flag(dir);
@@ -3050,13 +3050,13 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
        retval = ext4_delete_entry(handle, dir, de, bh);
        if (retval)
                goto end_unlink;
-       dir->i_ctime = dir->i_mtime = ext4_current_time(dir);
+       dir->i_ctime = dir->i_mtime = current_time(dir);
        ext4_update_dx_flag(dir);
        ext4_mark_inode_dirty(handle, dir);
        drop_nlink(inode);
        if (!inode->i_nlink)
                ext4_orphan_add(handle, inode);
-       inode->i_ctime = ext4_current_time(inode);
+       inode->i_ctime = current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
 
 end_unlink:
@@ -3254,7 +3254,7 @@ retry:
        if (IS_DIRSYNC(dir))
                ext4_handle_sync(handle);
 
-       inode->i_ctime = ext4_current_time(inode);
+       inode->i_ctime = current_time(inode);
        ext4_inc_count(handle, inode);
        ihold(inode);
 
@@ -3381,7 +3381,7 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent,
                ent->de->file_type = file_type;
        ent->dir->i_version++;
        ent->dir->i_ctime = ent->dir->i_mtime =
-               ext4_current_time(ent->dir);
+               current_time(ent->dir);
        ext4_mark_inode_dirty(handle, ent->dir);
        BUFFER_TRACE(ent->bh, "call ext4_handle_dirty_metadata");
        if (!ent->inlined) {
@@ -3651,7 +3651,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
         * Like most other Unix systems, set the ctime for inodes on a
         * rename.
         */
-       old.inode->i_ctime = ext4_current_time(old.inode);
+       old.inode->i_ctime = current_time(old.inode);
        ext4_mark_inode_dirty(handle, old.inode);
 
        if (!whiteout) {
@@ -3663,9 +3663,9 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
 
        if (new.inode) {
                ext4_dec_count(handle, new.inode);
-               new.inode->i_ctime = ext4_current_time(new.inode);
+               new.inode->i_ctime = current_time(new.inode);
        }
-       old.dir->i_ctime = old.dir->i_mtime = ext4_current_time(old.dir);
+       old.dir->i_ctime = old.dir->i_mtime = current_time(old.dir);
        ext4_update_dx_flag(old.dir);
        if (old.dir_bh) {
                retval = ext4_rename_dir_finish(handle, &old, new.dir->i_ino);
@@ -3723,6 +3723,7 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
        };
        u8 new_file_type;
        int retval;
+       struct timespec ctime;
 
        if ((ext4_encrypted_inode(old_dir) ||
             ext4_encrypted_inode(new_dir)) &&
@@ -3823,8 +3824,9 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
         * Like most other Unix systems, set the ctime for inodes on a
         * rename.
         */
-       old.inode->i_ctime = ext4_current_time(old.inode);
-       new.inode->i_ctime = ext4_current_time(new.inode);
+       ctime = current_time(old.inode);
+       old.inode->i_ctime = ctime;
+       new.inode->i_ctime = ctime;
        ext4_mark_inode_dirty(handle, old.inode);
        ext4_mark_inode_dirty(handle, new.inode);
 
index ff6f3ab09c7ea2e171690f3d30ab9e86a41f8063..35ccbdc2d64e4072071409813a959ed3b922e5f5 100644 (file)
@@ -5354,7 +5354,7 @@ static int ext4_quota_off(struct super_block *sb, int type)
        handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 1);
        if (IS_ERR(handle))
                goto out;
-       inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
        ext4_journal_stop(handle);
 
index d77be9e9f5352f2eedd1ab005dba20a899bbbbf6..9c1bb5cd89d20ec66cad3f03a26490eedbe38c0e 100644 (file)
@@ -1249,7 +1249,7 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
        }
        if (!error) {
                ext4_xattr_update_super_block(handle, inode->i_sb);
-               inode->i_ctime = ext4_current_time(inode);
+               inode->i_ctime = current_time(inode);
                if (!value)
                        ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND);
                error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);