On 2026/2/16 19:27, Yongpeng Yang wrote:
From: Yongpeng Yang <[email protected]>
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.
This patch calls invalidate_bdev during umount to invalidate the block
device page cache, preventing stale metadata from being read.
Signed-off-by: Yongpeng Yang <[email protected]>
---
fs/f2fs/super.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 1a755997aff5..39d3b52ceac1 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2091,6 +2091,12 @@ static void f2fs_put_super(struct super_block *sb)
#if IS_ENABLED(CONFIG_UNICODE)
utf8_unload(sb->s_encoding);
#endif
+ sync_blockdev(sb->s_bdev);
We will call sync_blockdev in below path?
- kill_f2fs_super
- kill_block_super
- generic_shutdown_super
- put_super
- sync_blockdev
1721 void kill_block_super(struct super_block *sb)
1722 {
1723 struct block_device *bdev = sb->s_bdev;
1724
1725 generic_shutdown_super(sb);
1726 if (bdev) {
1727 sync_blockdev(bdev);
1728 bdev_fput(sb->s_bdev_file);
1729 }
1730 }
+ invalidate_bdev(sb->s_bdev);
I guess we can leave the device w/ uptodate cache, in case if there are
multiple user on the device?
Thanks,
+ for (i = 1; i < sbi->s_ndevs; i++) {
+ sync_blockdev(FDEV(i).bdev);
+ invalidate_bdev(FDEV(i).bdev);
+ }
}
int f2fs_sync_fs(struct super_block *sb, int sync)
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel