Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: convert to ctime accessor functions

In later patches, we're going to change how the inode's ctime field is
used. Switch to using accessor functions instead of raw accesses of
inode->i_ctime.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Message-Id: <20230705190309.579783-40-jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Jeff Layton and committed by
Christian Brauner
1bc33893 fc4eed64

+90 -87
+1 -1
fs/ext4/acl.c
··· 259 259 error = __ext4_set_acl(handle, inode, type, acl, 0 /* xattr_flags */); 260 260 if (!error && update_mode) { 261 261 inode->i_mode = mode; 262 - inode->i_ctime = current_time(inode); 262 + inode_set_ctime_current(inode); 263 263 error = ext4_mark_inode_dirty(handle, inode); 264 264 } 265 265 out_stop:
+49 -43
fs/ext4/ext4.h
··· 868 868 * affected filesystem before 2242. 869 869 */ 870 870 871 - static inline __le32 ext4_encode_extra_time(struct timespec64 *time) 871 + static inline __le32 ext4_encode_extra_time(struct timespec64 ts) 872 872 { 873 - u32 extra =((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK; 874 - return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS)); 873 + u32 extra = ((ts.tv_sec - (s32)ts.tv_sec) >> 32) & EXT4_EPOCH_MASK; 874 + return cpu_to_le32(extra | (ts.tv_nsec << EXT4_EPOCH_BITS)); 875 875 } 876 876 877 - static inline void ext4_decode_extra_time(struct timespec64 *time, 878 - __le32 extra) 877 + static inline struct timespec64 ext4_decode_extra_time(__le32 base, 878 + __le32 extra) 879 879 { 880 + struct timespec64 ts = { .tv_sec = (signed)le32_to_cpu(base) }; 881 + 880 882 if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) 881 - time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32; 882 - time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 883 + ts.tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32; 884 + ts.tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 885 + return ts; 883 886 } 887 + 888 + #define EXT4_INODE_SET_XTIME_VAL(xtime, inode, raw_inode, ts) \ 889 + do { \ 890 + if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) { \ 891 + (raw_inode)->xtime = cpu_to_le32((ts).tv_sec); \ 892 + (raw_inode)->xtime ## _extra = ext4_encode_extra_time(ts); \ 893 + } else \ 894 + (raw_inode)->xtime = cpu_to_le32(clamp_t(int32_t, (ts).tv_sec, S32_MIN, S32_MAX)); \ 895 + } while (0) 884 896 885 897 #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \ 886 - do { \ 887 - if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) {\ 888 - (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \ 889 - (raw_inode)->xtime ## _extra = \ 890 - ext4_encode_extra_time(&(inode)->xtime); \ 891 - } \ 892 - else \ 893 - (raw_inode)->xtime = cpu_to_le32(clamp_t(int32_t, (inode)->xtime.tv_sec, S32_MIN, S32_MAX)); \ 894 - } while (0) 898 + EXT4_INODE_SET_XTIME_VAL(xtime, inode, raw_inode, (inode)->xtime) 895 899 896 - #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \ 897 - do { \ 898 - if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 899 - (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \ 900 - if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 901 - (raw_inode)->xtime ## _extra = \ 902 - ext4_encode_extra_time(&(einode)->xtime); \ 903 - } while (0) 900 + #define EXT4_INODE_SET_CTIME(inode, raw_inode) \ 901 + EXT4_INODE_SET_XTIME_VAL(i_ctime, inode, raw_inode, inode_get_ctime(inode)) 902 + 903 + #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \ 904 + if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 905 + EXT4_INODE_SET_XTIME_VAL(xtime, &((einode)->vfs_inode), \ 906 + raw_inode, (einode)->xtime) 907 + 908 + #define EXT4_INODE_GET_XTIME_VAL(xtime, inode, raw_inode) \ 909 + (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra) ? \ 910 + ext4_decode_extra_time((raw_inode)->xtime, \ 911 + (raw_inode)->xtime ## _extra) : \ 912 + (struct timespec64) { \ 913 + .tv_sec = (signed)le32_to_cpu((raw_inode)->xtime) \ 914 + }) 904 915 905 916 #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \ 906 917 do { \ 907 - (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \ 908 - if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) { \ 909 - ext4_decode_extra_time(&(inode)->xtime, \ 910 - raw_inode->xtime ## _extra); \ 911 - } \ 912 - else \ 913 - (inode)->xtime.tv_nsec = 0; \ 918 + (inode)->xtime = EXT4_INODE_GET_XTIME_VAL(xtime, inode, raw_inode); \ 914 919 } while (0) 915 920 921 + #define EXT4_INODE_GET_CTIME(inode, raw_inode) \ 922 + do { \ 923 + inode_set_ctime_to_ts(inode, \ 924 + EXT4_INODE_GET_XTIME_VAL(i_ctime, inode, raw_inode)); \ 925 + } while (0) 916 926 917 - #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \ 918 - do { \ 919 - if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 920 - (einode)->xtime.tv_sec = \ 921 - (signed)le32_to_cpu((raw_inode)->xtime); \ 922 - else \ 923 - (einode)->xtime.tv_sec = 0; \ 924 - if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 925 - ext4_decode_extra_time(&(einode)->xtime, \ 926 - raw_inode->xtime ## _extra); \ 927 - else \ 928 - (einode)->xtime.tv_nsec = 0; \ 927 + #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \ 928 + do { \ 929 + if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 930 + (einode)->xtime = \ 931 + EXT4_INODE_GET_XTIME_VAL(xtime, &(einode->vfs_inode), \ 932 + raw_inode); \ 933 + else \ 934 + (einode)->xtime = (struct timespec64){0, 0}; \ 929 935 } while (0) 930 936 931 937 #define i_disk_version osd1.linux1.l_i_version
+6 -6
fs/ext4/extents.c
··· 4476 4476 map.m_lblk += ret; 4477 4477 map.m_len = len = len - ret; 4478 4478 epos = (loff_t)map.m_lblk << inode->i_blkbits; 4479 - inode->i_ctime = current_time(inode); 4479 + inode_set_ctime_current(inode); 4480 4480 if (new_size) { 4481 4481 if (epos > new_size) 4482 4482 epos = new_size; 4483 4483 if (ext4_update_inode_size(inode, epos) & 0x1) 4484 - inode->i_mtime = inode->i_ctime; 4484 + inode->i_mtime = inode_get_ctime(inode); 4485 4485 } 4486 4486 ret2 = ext4_mark_inode_dirty(handle, inode); 4487 4487 ext4_update_inode_fsync_trans(handle, inode, 1); ··· 4617 4617 4618 4618 /* Now release the pages and zero block aligned part of pages */ 4619 4619 truncate_pagecache_range(inode, start, end - 1); 4620 - inode->i_mtime = inode->i_ctime = current_time(inode); 4620 + inode->i_mtime = inode_set_ctime_current(inode); 4621 4621 4622 4622 ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size, 4623 4623 flags); ··· 4642 4642 goto out_mutex; 4643 4643 } 4644 4644 4645 - inode->i_mtime = inode->i_ctime = current_time(inode); 4645 + inode->i_mtime = inode_set_ctime_current(inode); 4646 4646 if (new_size) 4647 4647 ext4_update_inode_size(inode, new_size); 4648 4648 ret = ext4_mark_inode_dirty(handle, inode); ··· 5378 5378 up_write(&EXT4_I(inode)->i_data_sem); 5379 5379 if (IS_SYNC(inode)) 5380 5380 ext4_handle_sync(handle); 5381 - inode->i_mtime = inode->i_ctime = current_time(inode); 5381 + inode->i_mtime = inode_set_ctime_current(inode); 5382 5382 ret = ext4_mark_inode_dirty(handle, inode); 5383 5383 ext4_update_inode_fsync_trans(handle, inode, 1); 5384 5384 ··· 5488 5488 /* Expand file to avoid data loss if there is error while shifting */ 5489 5489 inode->i_size += len; 5490 5490 EXT4_I(inode)->i_disksize += len; 5491 - inode->i_mtime = inode->i_ctime = current_time(inode); 5491 + inode->i_mtime = inode_set_ctime_current(inode); 5492 5492 ret = ext4_mark_inode_dirty(handle, inode); 5493 5493 if (ret) 5494 5494 goto out_stop;
+1 -1
fs/ext4/ialloc.c
··· 1250 1250 inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb); 1251 1251 /* This is the optimal IO size (for stat), not the fs block size */ 1252 1252 inode->i_blocks = 0; 1253 - inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); 1253 + inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode); 1254 1254 ei->i_crtime = inode->i_mtime; 1255 1255 1256 1256 memset(ei->i_data, 0, sizeof(ei->i_data));
+2 -2
fs/ext4/inline.c
··· 1037 1037 * happen is that the times are slightly out of date 1038 1038 * and/or different from the directory change time. 1039 1039 */ 1040 - dir->i_mtime = dir->i_ctime = current_time(dir); 1040 + dir->i_mtime = inode_set_ctime_current(dir); 1041 1041 ext4_update_dx_flag(dir); 1042 1042 inode_inc_iversion(dir); 1043 1043 return 1; ··· 1991 1991 ext4_orphan_del(handle, inode); 1992 1992 1993 1993 if (err == 0) { 1994 - inode->i_mtime = inode->i_ctime = current_time(inode); 1994 + inode->i_mtime = inode_set_ctime_current(inode); 1995 1995 err = ext4_mark_inode_dirty(handle, inode); 1996 1996 if (IS_SYNC(inode)) 1997 1997 ext4_handle_sync(handle);
+3 -3
fs/ext4/inode-test.c
··· 245 245 struct timestamp_expectation *test_param = 246 246 (struct timestamp_expectation *)(test->param_value); 247 247 248 - timestamp.tv_sec = get_32bit_time(test_param); 249 - ext4_decode_extra_time(&timestamp, 250 - cpu_to_le32(test_param->extra_bits)); 248 + timestamp = ext4_decode_extra_time( 249 + cpu_to_le32(get_32bit_time(test_param)), 250 + cpu_to_le32(test_param->extra_bits)); 251 251 252 252 KUNIT_EXPECT_EQ_MSG(test, 253 253 test_param->expected.tv_sec,
+7 -9
fs/ext4/inode.c
··· 3986 3986 if (IS_SYNC(inode)) 3987 3987 ext4_handle_sync(handle); 3988 3988 3989 - inode->i_mtime = inode->i_ctime = current_time(inode); 3989 + inode->i_mtime = inode_set_ctime_current(inode); 3990 3990 ret2 = ext4_mark_inode_dirty(handle, inode); 3991 3991 if (unlikely(ret2)) 3992 3992 ret = ret2; ··· 4146 4146 if (inode->i_nlink) 4147 4147 ext4_orphan_del(handle, inode); 4148 4148 4149 - inode->i_mtime = inode->i_ctime = current_time(inode); 4149 + inode->i_mtime = inode_set_ctime_current(inode); 4150 4150 err2 = ext4_mark_inode_dirty(handle, inode); 4151 4151 if (unlikely(err2 && !err)) 4152 4152 err = err2; ··· 4249 4249 } 4250 4250 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); 4251 4251 4252 - EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode); 4252 + EXT4_INODE_SET_CTIME(inode, raw_inode); 4253 4253 EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode); 4254 4254 EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); 4255 4255 EXT4_EINODE_SET_XTIME(i_crtime, ei, raw_inode); ··· 4858 4858 } 4859 4859 } 4860 4860 4861 - EXT4_INODE_GET_XTIME(i_ctime, inode, raw_inode); 4861 + EXT4_INODE_GET_CTIME(inode, raw_inode); 4862 4862 EXT4_INODE_GET_XTIME(i_mtime, inode, raw_inode); 4863 4863 EXT4_INODE_GET_XTIME(i_atime, inode, raw_inode); 4864 4864 EXT4_EINODE_GET_XTIME(i_crtime, ei, raw_inode); ··· 4981 4981 spin_unlock(&inode->i_lock); 4982 4982 4983 4983 spin_lock(&ei->i_raw_lock); 4984 - EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode); 4984 + EXT4_INODE_SET_CTIME(inode, raw_inode); 4985 4985 EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode); 4986 4986 EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); 4987 4987 ext4_inode_csum_set(inode, raw_inode, ei); ··· 5376 5376 * Update c/mtime on truncate up, ext4_truncate() will 5377 5377 * update c/mtime in shrink case below 5378 5378 */ 5379 - if (!shrink) { 5380 - inode->i_mtime = current_time(inode); 5381 - inode->i_ctime = inode->i_mtime; 5382 - } 5379 + if (!shrink) 5380 + inode->i_mtime = inode_set_ctime_current(inode); 5383 5381 5384 5382 if (shrink) 5385 5383 ext4_fc_track_range(handle, inode,
+5 -4
fs/ext4/ioctl.c
··· 449 449 diff = size - size_bl; 450 450 swap_inode_data(inode, inode_bl); 451 451 452 - inode->i_ctime = inode_bl->i_ctime = current_time(inode); 452 + inode_set_ctime_current(inode); 453 + inode_set_ctime_current(inode_bl); 453 454 inode_inc_iversion(inode); 454 455 455 456 inode->i_generation = get_random_u32(); ··· 664 663 665 664 ext4_set_inode_flags(inode, false); 666 665 667 - inode->i_ctime = current_time(inode); 666 + inode_set_ctime_current(inode); 668 667 inode_inc_iversion(inode); 669 668 670 669 err = ext4_mark_iloc_dirty(handle, inode, &iloc); ··· 775 774 } 776 775 777 776 EXT4_I(inode)->i_projid = kprojid; 778 - inode->i_ctime = current_time(inode); 777 + inode_set_ctime_current(inode); 779 778 inode_inc_iversion(inode); 780 779 out_dirty: 781 780 rc = ext4_mark_iloc_dirty(handle, inode, &iloc); ··· 1267 1266 } 1268 1267 err = ext4_reserve_inode_write(handle, inode, &iloc); 1269 1268 if (err == 0) { 1270 - inode->i_ctime = current_time(inode); 1269 + inode_set_ctime_current(inode); 1271 1270 inode_inc_iversion(inode); 1272 1271 inode->i_generation = generation; 1273 1272 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
+12 -14
fs/ext4/namei.c
··· 2203 2203 * happen is that the times are slightly out of date 2204 2204 * and/or different from the directory change time. 2205 2205 */ 2206 - dir->i_mtime = dir->i_ctime = current_time(dir); 2206 + dir->i_mtime = inode_set_ctime_current(dir); 2207 2207 ext4_update_dx_flag(dir); 2208 2208 inode_inc_iversion(dir); 2209 2209 err2 = ext4_mark_inode_dirty(handle, dir); ··· 3197 3197 * recovery. */ 3198 3198 inode->i_size = 0; 3199 3199 ext4_orphan_add(handle, inode); 3200 - inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode); 3200 + dir->i_mtime = inode_set_ctime_current(dir); 3201 + inode_set_ctime_current(inode); 3201 3202 retval = ext4_mark_inode_dirty(handle, inode); 3202 3203 if (retval) 3203 3204 goto end_rmdir; ··· 3272 3271 retval = ext4_delete_entry(handle, dir, de, bh); 3273 3272 if (retval) 3274 3273 goto out_handle; 3275 - dir->i_ctime = dir->i_mtime = current_time(dir); 3274 + dir->i_mtime = inode_set_ctime_current(dir); 3276 3275 ext4_update_dx_flag(dir); 3277 3276 retval = ext4_mark_inode_dirty(handle, dir); 3278 3277 if (retval) ··· 3287 3286 drop_nlink(inode); 3288 3287 if (!inode->i_nlink) 3289 3288 ext4_orphan_add(handle, inode); 3290 - inode->i_ctime = current_time(inode); 3289 + inode_set_ctime_current(inode); 3291 3290 retval = ext4_mark_inode_dirty(handle, inode); 3292 3291 if (dentry && !retval) 3293 3292 ext4_fc_track_unlink(handle, dentry); ··· 3464 3463 if (IS_DIRSYNC(dir)) 3465 3464 ext4_handle_sync(handle); 3466 3465 3467 - inode->i_ctime = current_time(inode); 3466 + inode_set_ctime_current(inode); 3468 3467 ext4_inc_count(inode); 3469 3468 ihold(inode); 3470 3469 ··· 3642 3641 if (ext4_has_feature_filetype(ent->dir->i_sb)) 3643 3642 ent->de->file_type = file_type; 3644 3643 inode_inc_iversion(ent->dir); 3645 - ent->dir->i_ctime = ent->dir->i_mtime = 3646 - current_time(ent->dir); 3644 + ent->dir->i_mtime = inode_set_ctime_current(ent->dir); 3647 3645 retval = ext4_mark_inode_dirty(handle, ent->dir); 3648 3646 BUFFER_TRACE(ent->bh, "call ext4_handle_dirty_metadata"); 3649 3647 if (!ent->inlined) { ··· 3941 3941 * Like most other Unix systems, set the ctime for inodes on a 3942 3942 * rename. 3943 3943 */ 3944 - old.inode->i_ctime = current_time(old.inode); 3944 + inode_set_ctime_current(old.inode); 3945 3945 retval = ext4_mark_inode_dirty(handle, old.inode); 3946 3946 if (unlikely(retval)) 3947 3947 goto end_rename; ··· 3955 3955 3956 3956 if (new.inode) { 3957 3957 ext4_dec_count(new.inode); 3958 - new.inode->i_ctime = current_time(new.inode); 3958 + inode_set_ctime_current(new.inode); 3959 3959 } 3960 - old.dir->i_ctime = old.dir->i_mtime = current_time(old.dir); 3960 + old.dir->i_mtime = inode_set_ctime_current(old.dir); 3961 3961 ext4_update_dx_flag(old.dir); 3962 3962 if (old.dir_bh) { 3963 3963 retval = ext4_rename_dir_finish(handle, &old, new.dir->i_ino); ··· 4053 4053 }; 4054 4054 u8 new_file_type; 4055 4055 int retval; 4056 - struct timespec64 ctime; 4057 4056 4058 4057 if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT) && 4059 4058 !projid_eq(EXT4_I(new_dir)->i_projid, ··· 4146 4147 * Like most other Unix systems, set the ctime for inodes on a 4147 4148 * rename. 4148 4149 */ 4149 - ctime = current_time(old.inode); 4150 - old.inode->i_ctime = ctime; 4151 - new.inode->i_ctime = ctime; 4150 + inode_set_ctime_current(old.inode); 4151 + inode_set_ctime_current(new.inode); 4152 4152 retval = ext4_mark_inode_dirty(handle, old.inode); 4153 4153 if (unlikely(retval)) 4154 4154 goto end_rename;
+1 -1
fs/ext4/super.c
··· 7103 7103 } 7104 7104 EXT4_I(inode)->i_flags &= ~(EXT4_NOATIME_FL | EXT4_IMMUTABLE_FL); 7105 7105 inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE); 7106 - inode->i_mtime = inode->i_ctime = current_time(inode); 7106 + inode->i_mtime = inode_set_ctime_current(inode); 7107 7107 err = ext4_mark_inode_dirty(handle, inode); 7108 7108 ext4_journal_stop(handle); 7109 7109 out_unlock:
+3 -3
fs/ext4/xattr.c
··· 356 356 357 357 static u64 ext4_xattr_inode_get_ref(struct inode *ea_inode) 358 358 { 359 - return ((u64)ea_inode->i_ctime.tv_sec << 32) | 359 + return ((u64) inode_get_ctime(ea_inode).tv_sec << 32) | 360 360 (u32) inode_peek_iversion_raw(ea_inode); 361 361 } 362 362 363 363 static void ext4_xattr_inode_set_ref(struct inode *ea_inode, u64 ref_count) 364 364 { 365 - ea_inode->i_ctime.tv_sec = (u32)(ref_count >> 32); 365 + inode_set_ctime(ea_inode, (u32)(ref_count >> 32), 0); 366 366 inode_set_iversion_raw(ea_inode, ref_count & 0xffffffff); 367 367 } 368 368 ··· 2459 2459 } 2460 2460 if (!error) { 2461 2461 ext4_xattr_update_super_block(handle, inode->i_sb); 2462 - inode->i_ctime = current_time(inode); 2462 + inode_set_ctime_current(inode); 2463 2463 inode_inc_iversion(inode); 2464 2464 if (!value) 2465 2465 no_expand = 0;