add patch add-select-for-CONFIG_FS_IOMAP
[ext4-patch-queue.git] / use-current_time-for-inode-timestamps
blob8676317056b1ef5eb13c80ebc05561f4a04bdb4d
1 ext4: use current_time() for inode timestamps
3 From: Deepa Dinamani <deepa.kernel@gmail.com>
5 CURRENT_TIME_SEC and CURRENT_TIME are not y2038 safe.
6 current_time() will be transitioned to be y2038 safe
7 along with vfs.
9 current_time() returns timestamps according to the
10 granularities set in the super_block.
11 The granularity check in ext4_current_time() to call
12 current_time() or CURRENT_TIME_SEC is not required.
13 Use current_time() directly to obtain timestamps
14 unconditionally, and remove ext4_current_time().
16 Quota files are assumed to be on the same filesystem.
17 Hence, use current_time() for these files as well.
19 Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
20 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 Reviewed-by: Arnd Bergmann <arnd@arndb.de>
22 ---
23  fs/ext4/acl.c     |  2 +-
24  fs/ext4/ext4.h    |  6 ------
25  fs/ext4/extents.c | 10 +++++-----
26  fs/ext4/ialloc.c  |  2 +-
27  fs/ext4/inline.c  |  4 ++--
28  fs/ext4/inode.c   |  6 +++---
29  fs/ext4/ioctl.c   |  8 ++++----
30  fs/ext4/namei.c   | 24 +++++++++++++-----------
31  fs/ext4/super.c   |  2 +-
32  fs/ext4/xattr.c   |  2 +-
33  10 files changed, 31 insertions(+), 35 deletions(-)
35 diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
36 index dfa5199..fd38993 100644
37 --- a/fs/ext4/acl.c
38 +++ b/fs/ext4/acl.c
39 @@ -196,7 +196,7 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type,
40                         error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
41                         if (error)
42                                 return error;
43 -                       inode->i_ctime = ext4_current_time(inode);
44 +                       inode->i_ctime = current_time(inode);
45                         ext4_mark_inode_dirty(handle, inode);
46                 }
47                 break;
48 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
49 index 282a51b..6789379 100644
50 --- a/fs/ext4/ext4.h
51 +++ b/fs/ext4/ext4.h
52 @@ -1532,12 +1532,6 @@ static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
53         return container_of(inode, struct ext4_inode_info, vfs_inode);
54  }
56 -static inline struct timespec ext4_current_time(struct inode *inode)
58 -       return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
59 -               current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
62  static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
63  {
64         return ino == EXT4_ROOT_INO ||
65 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
66 index c930a01..786be87 100644
67 --- a/fs/ext4/extents.c
68 +++ b/fs/ext4/extents.c
69 @@ -4725,7 +4725,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
70                 map.m_lblk += ret;
71                 map.m_len = len = len - ret;
72                 epos = (loff_t)map.m_lblk << inode->i_blkbits;
73 -               inode->i_ctime = ext4_current_time(inode);
74 +               inode->i_ctime = current_time(inode);
75                 if (new_size) {
76                         if (epos > new_size)
77                                 epos = new_size;
78 @@ -4853,7 +4853,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
79                 }
80                 /* Now release the pages and zero block aligned part of pages */
81                 truncate_pagecache_range(inode, start, end - 1);
82 -               inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
83 +               inode->i_mtime = inode->i_ctime = current_time(inode);
85                 ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size,
86                                              flags, mode);
87 @@ -4878,7 +4878,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
88                 goto out_dio;
89         }
91 -       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
92 +       inode->i_mtime = inode->i_ctime = current_time(inode);
93         if (new_size) {
94                 ext4_update_inode_size(inode, new_size);
95         } else {
96 @@ -5568,7 +5568,7 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
97         up_write(&EXT4_I(inode)->i_data_sem);
98         if (IS_SYNC(inode))
99                 ext4_handle_sync(handle);
100 -       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
101 +       inode->i_mtime = inode->i_ctime = current_time(inode);
102         ext4_mark_inode_dirty(handle, inode);
104  out_stop:
105 @@ -5678,7 +5678,7 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
106         /* Expand file to avoid data loss if there is error while shifting */
107         inode->i_size += len;
108         EXT4_I(inode)->i_disksize += len;
109 -       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
110 +       inode->i_mtime = inode->i_ctime = current_time(inode);
111         ret = ext4_mark_inode_dirty(handle, inode);
112         if (ret)
113                 goto out_stop;
114 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
115 index 170421e..088afe0 100644
116 --- a/fs/ext4/ialloc.c
117 +++ b/fs/ext4/ialloc.c
118 @@ -1039,7 +1039,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
119         /* This is the optimal IO size (for stat), not the fs block size */
120         inode->i_blocks = 0;
121         inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
122 -                                                      ext4_current_time(inode);
123 +                                                      current_time(inode);
125         memset(ei->i_data, 0, sizeof(ei->i_data));
126         ei->i_dir_start_lookup = 0;
127 diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
128 index f74d5ee..cfa87bd 100644
129 --- a/fs/ext4/inline.c
130 +++ b/fs/ext4/inline.c
131 @@ -1028,7 +1028,7 @@ static int ext4_add_dirent_to_inline(handle_t *handle,
132          * happen is that the times are slightly out of date
133          * and/or different from the directory change time.
134          */
135 -       dir->i_mtime = dir->i_ctime = ext4_current_time(dir);
136 +       dir->i_mtime = dir->i_ctime = current_time(dir);
137         ext4_update_dx_flag(dir);
138         dir->i_version++;
139         ext4_mark_inode_dirty(handle, dir);
140 @@ -1971,7 +1971,7 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
141         if (inode->i_nlink)
142                 ext4_orphan_del(handle, inode);
144 -       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
145 +       inode->i_mtime = inode->i_ctime = current_time(inode);
146         ext4_mark_inode_dirty(handle, inode);
147         if (IS_SYNC(inode))
148                 ext4_handle_sync(handle);
149 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
150 index 3d58b2b..926ed1f 100644
151 --- a/fs/ext4/inode.c
152 +++ b/fs/ext4/inode.c
153 @@ -4029,7 +4029,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
154         if (IS_SYNC(inode))
155                 ext4_handle_sync(handle);
157 -       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
158 +       inode->i_mtime = inode->i_ctime = current_time(inode);
159         ext4_mark_inode_dirty(handle, inode);
160  out_stop:
161         ext4_journal_stop(handle);
162 @@ -4183,7 +4183,7 @@ void ext4_truncate(struct inode *inode)
163         if (inode->i_nlink)
164                 ext4_orphan_del(handle, inode);
166 -       inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
167 +       inode->i_mtime = inode->i_ctime = current_time(inode);
168         ext4_mark_inode_dirty(handle, inode);
169         ext4_journal_stop(handle);
171 @@ -5157,7 +5157,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
172                          * update c/mtime in shrink case below
173                          */
174                         if (!shrink) {
175 -                               inode->i_mtime = ext4_current_time(inode);
176 +                               inode->i_mtime = current_time(inode);
177                                 inode->i_ctime = inode->i_mtime;
178                         }
179                         down_write(&EXT4_I(inode)->i_data_sem);
180 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
181 index bf5ae8e..3bba9e9 100644
182 --- a/fs/ext4/ioctl.c
183 +++ b/fs/ext4/ioctl.c
184 @@ -153,7 +153,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
186         swap_inode_data(inode, inode_bl);
188 -       inode->i_ctime = inode_bl->i_ctime = ext4_current_time(inode);
189 +       inode->i_ctime = inode_bl->i_ctime = current_time(inode);
191         spin_lock(&sbi->s_next_gen_lock);
192         inode->i_generation = sbi->s_next_generation++;
193 @@ -272,7 +272,7 @@ static int ext4_ioctl_setflags(struct inode *inode,
194         }
196         ext4_set_inode_flags(inode);
197 -       inode->i_ctime = ext4_current_time(inode);
198 +       inode->i_ctime = current_time(inode);
200         err = ext4_mark_iloc_dirty(handle, inode, &iloc);
201  flags_err:
202 @@ -368,7 +368,7 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
203         }
205         EXT4_I(inode)->i_projid = kprojid;
206 -       inode->i_ctime = ext4_current_time(inode);
207 +       inode->i_ctime = current_time(inode);
208  out_dirty:
209         rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
210         if (!err)
211 @@ -500,7 +500,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
212                 }
213                 err = ext4_reserve_inode_write(handle, inode, &iloc);
214                 if (err == 0) {
215 -                       inode->i_ctime = ext4_current_time(inode);
216 +                       inode->i_ctime = current_time(inode);
217                         inode->i_generation = generation;
218                         err = ext4_mark_iloc_dirty(handle, inode, &iloc);
219                 }
220 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
221 index 104f8bf..eadba91 100644
222 --- a/fs/ext4/namei.c
223 +++ b/fs/ext4/namei.c
224 @@ -1941,7 +1941,7 @@ static int add_dirent_to_buf(handle_t *handle, struct ext4_filename *fname,
225          * happen is that the times are slightly out of date
226          * and/or different from the directory change time.
227          */
228 -       dir->i_mtime = dir->i_ctime = ext4_current_time(dir);
229 +       dir->i_mtime = dir->i_ctime = current_time(dir);
230         ext4_update_dx_flag(dir);
231         dir->i_version++;
232         ext4_mark_inode_dirty(handle, dir);
233 @@ -2987,7 +2987,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
234          * recovery. */
235         inode->i_size = 0;
236         ext4_orphan_add(handle, inode);
237 -       inode->i_ctime = dir->i_ctime = dir->i_mtime = ext4_current_time(inode);
238 +       inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
239         ext4_mark_inode_dirty(handle, inode);
240         ext4_dec_count(handle, dir);
241         ext4_update_dx_flag(dir);
242 @@ -3050,13 +3050,13 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
243         retval = ext4_delete_entry(handle, dir, de, bh);
244         if (retval)
245                 goto end_unlink;
246 -       dir->i_ctime = dir->i_mtime = ext4_current_time(dir);
247 +       dir->i_ctime = dir->i_mtime = current_time(dir);
248         ext4_update_dx_flag(dir);
249         ext4_mark_inode_dirty(handle, dir);
250         drop_nlink(inode);
251         if (!inode->i_nlink)
252                 ext4_orphan_add(handle, inode);
253 -       inode->i_ctime = ext4_current_time(inode);
254 +       inode->i_ctime = current_time(inode);
255         ext4_mark_inode_dirty(handle, inode);
257  end_unlink:
258 @@ -3254,7 +3254,7 @@ static int ext4_link(struct dentry *old_dentry,
259         if (IS_DIRSYNC(dir))
260                 ext4_handle_sync(handle);
262 -       inode->i_ctime = ext4_current_time(inode);
263 +       inode->i_ctime = current_time(inode);
264         ext4_inc_count(handle, inode);
265         ihold(inode);
267 @@ -3381,7 +3381,7 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent,
268                 ent->de->file_type = file_type;
269         ent->dir->i_version++;
270         ent->dir->i_ctime = ent->dir->i_mtime =
271 -               ext4_current_time(ent->dir);
272 +               current_time(ent->dir);
273         ext4_mark_inode_dirty(handle, ent->dir);
274         BUFFER_TRACE(ent->bh, "call ext4_handle_dirty_metadata");
275         if (!ent->inlined) {
276 @@ -3651,7 +3651,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
277          * Like most other Unix systems, set the ctime for inodes on a
278          * rename.
279          */
280 -       old.inode->i_ctime = ext4_current_time(old.inode);
281 +       old.inode->i_ctime = current_time(old.inode);
282         ext4_mark_inode_dirty(handle, old.inode);
284         if (!whiteout) {
285 @@ -3663,9 +3663,9 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
287         if (new.inode) {
288                 ext4_dec_count(handle, new.inode);
289 -               new.inode->i_ctime = ext4_current_time(new.inode);
290 +               new.inode->i_ctime = current_time(new.inode);
291         }
292 -       old.dir->i_ctime = old.dir->i_mtime = ext4_current_time(old.dir);
293 +       old.dir->i_ctime = old.dir->i_mtime = current_time(old.dir);
294         ext4_update_dx_flag(old.dir);
295         if (old.dir_bh) {
296                 retval = ext4_rename_dir_finish(handle, &old, new.dir->i_ino);
297 @@ -3723,6 +3723,7 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
298         };
299         u8 new_file_type;
300         int retval;
301 +       struct timespec ctime;
303         if ((ext4_encrypted_inode(old_dir) ||
304              ext4_encrypted_inode(new_dir)) &&
305 @@ -3823,8 +3824,9 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
306          * Like most other Unix systems, set the ctime for inodes on a
307          * rename.
308          */
309 -       old.inode->i_ctime = ext4_current_time(old.inode);
310 -       new.inode->i_ctime = ext4_current_time(new.inode);
311 +       ctime = current_time(old.inode);
312 +       old.inode->i_ctime = ctime;
313 +       new.inode->i_ctime = ctime;
314         ext4_mark_inode_dirty(handle, old.inode);
315         ext4_mark_inode_dirty(handle, new.inode);
317 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
318 index 45589c8..f86d0cb 100644
319 --- a/fs/ext4/super.c
320 +++ b/fs/ext4/super.c
321 @@ -5351,7 +5351,7 @@ static int ext4_quota_off(struct super_block *sb, int type)
322         handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 1);
323         if (IS_ERR(handle))
324                 goto out;
325 -       inode->i_mtime = inode->i_ctime = CURRENT_TIME;
326 +       inode->i_mtime = inode->i_ctime = current_time(inode);
327         ext4_mark_inode_dirty(handle, inode);
328         ext4_journal_stop(handle);
330 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
331 index d77be9e..9c1bb5c 100644
332 --- a/fs/ext4/xattr.c
333 +++ b/fs/ext4/xattr.c
334 @@ -1249,7 +1249,7 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
335         }
336         if (!error) {
337                 ext4_xattr_update_super_block(handle, inode->i_sb);
338 -               inode->i_ctime = ext4_current_time(inode);
339 +               inode->i_ctime = current_time(inode);
340                 if (!value)
341                         ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND);
342                 error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);