Skip to content

Commit 8979bc3

Browse files
Yongpeng YangJaegeuk Kim
authored andcommitted
f2fs: invalidate block device page cache on umount
Neither F2FS nor VFS invalidates the block device page cache, which results in reading stale metadata. An example scenario is shown below: Terminal A Terminal B mount /dev/vdb /mnt/f2fs touch mx // ino = 4 sync dump.f2fs -i 4 /dev/vdb// block on "[Y/N]" touch mx2 // ino = 5 sync umount /mnt/f2fs dump.f2fs -i 5 /dev/vdb // block addr is 0 After umount, the block device page cache is not purged, causing `dump.f2fs -i 5 /dev/vdb` to read stale metadata and see inode 5 with block address 0. Btrfs has encountered a similar issue before, the solution there was to call sync_blockdev() and invalidate_bdev() when the device is closed: mail-archive.com/[email protected]/msg54188.html For the root user, the f2fs kernel calls sync_blockdev() on umount to flush all cached data to disk, and f2fs-tools can release the page cache by issuing ioctl(fd, BLKFLSBUF) when accessing the device. However, non-root users are not permitted to drop the page cache, and may still observe stale data. This patch calls sync_blockdev() and invalidate_bdev() during umount to invalidate the block device page cache, thereby preventing stale metadata from being read. Note that this may result in an extra sync_blockdev() call on the first device, in both f2fs_put_super() and kill_block_super(). The second call do nothing, as there are no dirty pages left to flush. It ensures that non-root users do not observe stale data. Signed-off-by: Yongpeng Yang <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 02d9139 commit 8979bc3

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

fs/f2fs/super.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,12 @@ static void f2fs_put_super(struct super_block *sb)
20882088
#if IS_ENABLED(CONFIG_UNICODE)
20892089
utf8_unload(sb->s_encoding);
20902090
#endif
2091+
sync_blockdev(sb->s_bdev);
2092+
invalidate_bdev(sb->s_bdev);
2093+
for (i = 1; i < sbi->s_ndevs; i++) {
2094+
sync_blockdev(FDEV(i).bdev);
2095+
invalidate_bdev(FDEV(i).bdev);
2096+
}
20912097
}
20922098

20932099
int f2fs_sync_fs(struct super_block *sb, int sync)

0 commit comments

Comments
 (0)