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
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>
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
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);
43 - inode->i_ctime = ext4_current_time(inode);
44 + inode->i_ctime = current_time(inode);
45 ext4_mark_inode_dirty(handle, inode);
48 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
49 index 282a51b..6789379 100644
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);
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)
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,
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);
78 @@ -4853,7 +4853,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
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,
87 @@ -4878,7 +4878,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
91 - inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
92 + inode->i_mtime = inode->i_ctime = current_time(inode);
94 ext4_update_inode_size(inode, new_size);
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);
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);
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);
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 */
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.
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);
139 ext4_mark_inode_dirty(handle, dir);
140 @@ -1971,7 +1971,7 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
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);
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)
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);
161 ext4_journal_stop(handle);
162 @@ -4183,7 +4183,7 @@ void ext4_truncate(struct inode *inode)
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
175 - inode->i_mtime = ext4_current_time(inode);
176 + inode->i_mtime = current_time(inode);
177 inode->i_ctime = inode->i_mtime;
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,
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);
202 @@ -368,7 +368,7 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
205 EXT4_I(inode)->i_projid = kprojid;
206 - inode->i_ctime = ext4_current_time(inode);
207 + inode->i_ctime = current_time(inode);
209 rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
211 @@ -500,7 +500,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
213 err = ext4_reserve_inode_write(handle, inode, &iloc);
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);
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.
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);
232 ext4_mark_inode_dirty(handle, dir);
233 @@ -2987,7 +2987,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
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);
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);
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);
258 @@ -3254,7 +3254,7 @@ static int ext4_link(struct dentry *old_dentry,
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);
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");
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
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);
285 @@ -3663,9 +3663,9 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
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);
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);
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,
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
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);
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,
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);
341 ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND);
342 error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);