Skip to content

Commit fe1897e

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to update time in lazytime mode
generic/018 reports an inconsistent status of atime, the testcase is as below: - open file with O_SYNC - write file to construct fraged space - calc md5 of file - record {a,c,m}time - defrag file --- do nothing - umount & mount - check {a,c,m}time The root cause is, as f2fs enables lazytime by default, atime update will dirty vfs inode, rather than dirtying f2fs inode (by set with FI_DIRTY_INODE), so later f2fs_write_inode() called from VFS will fail to update inode page due to our skip: f2fs_write_inode() if (is_inode_flag_set(inode, FI_DIRTY_INODE)) return 0; So eventually, after evict(), we lose last atime for ever. To fix this issue, we need to check whether {a,c,m,cr}time is consistent in between inode cache and inode page, and only skip f2fs_update_inode() if f2fs inode is not dirty and time is consistent as well. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent b145b0e commit fe1897e

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎fs/f2fs/f2fs.h‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,20 @@ static inline void clear_file(struct inode *inode, int type)
27042704
f2fs_mark_inode_dirty_sync(inode, true);
27052705
}
27062706

2707+
static inline bool f2fs_is_time_consistent(struct inode *inode)
2708+
{
2709+
if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime))
2710+
return false;
2711+
if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime))
2712+
return false;
2713+
if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime))
2714+
return false;
2715+
if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3,
2716+
&F2FS_I(inode)->i_crtime))
2717+
return false;
2718+
return true;
2719+
}
2720+
27072721
static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
27082722
{
27092723
bool ret;
@@ -2721,14 +2735,7 @@ static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
27212735
i_size_read(inode) & ~PAGE_MASK)
27222736
return false;
27232737

2724-
if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime))
2725-
return false;
2726-
if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime))
2727-
return false;
2728-
if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime))
2729-
return false;
2730-
if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3,
2731-
&F2FS_I(inode)->i_crtime))
2738+
if (!f2fs_is_time_consistent(inode))
27322739
return false;
27332740

27342741
down_read(&F2FS_I(inode)->i_sem);

‎fs/f2fs/inode.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
615615
inode->i_ino == F2FS_META_INO(sbi))
616616
return 0;
617617

618-
if (!is_inode_flag_set(inode, FI_DIRTY_INODE))
618+
/*
619+
* atime could be updated without dirtying f2fs inode in lazytime mode
620+
*/
621+
if (f2fs_is_time_consistent(inode) &&
622+
!is_inode_flag_set(inode, FI_DIRTY_INODE))
619623
return 0;
620624

621625
if (!f2fs_is_checkpoint_ready(sbi))

0 commit comments

Comments
 (0)