On 2026/3/12 11:59, Yongpeng Yang wrote:
On 3/12/26 09:06, Chao Yu via Linux-f2fs-devel wrote:
On 2026/2/16 19:28, Yongpeng Yang wrote:
From: Yongpeng Yang <[email protected]>
After the device is mounted, f2fs updates on-disk metadata without
updating the block device page cache. As a result, f2fs-tools may read
stale metadata from the page cache.
For example:
mount /dev/vdb /mnt/f2fs
touch mx // ino = 4
sync
dump.f2fs -i 4 /dev/vdb
touch mx2 // ino = 5
sync
dump.f2fs -i 5 /dev/vdb // block addr is 0
Actually, it will be better to wait for /mnt/f2fs being umounted first
and then
call dump.f2fs, as if there are two users on the device, we can not
guarantee
dump.f2fs can always flush and clean up all cache while another user
continue
to update the data via /mnt/f2fs mount point.
If the kernel guarantees that there is no non-uptodate data in the block
device page cache after unmount, this ioctl does not need to be
Well, maybe another sync & drop_cache could be followed after umount() to
make sure to clean all stale data in block device cache. But, integrating
all cleanup operation into dump.f2fs also looks fine.
executed. The main purpose of this patch is to make it possible to
inspect the metadata of a mounted f2fs instance as much as possible, in
order to assist with debugging and analysis, especially in adb shell.
So, we don't need to check the return value of ioctl.
Alright, if you think it will help you on debug purpose, I'm fine on this
change. But you know, I still think that for such scenario in where there are
multiple user accessing the same device, it's hard to guarantee each of them
can get non-stale data. On your case, we can not guarantee android apps won't
touch ino 4 or 5, while we running dump.f2fs on the inode.
Thanks,
Thanks
Yongpeng,
Thanks,
Since `dump.f2fs -i 4 /dev/vdb` has already populated the metadata area
into the block device page cache, the cached pages remain resident in
memory. After creating mx2, the page cache is not updated accordingly.
Therefore, `dump.f2fs -i 5 /dev/vdb` reads stale metadata, and the
physical block address of inode 5 is incorrectly reported as 0.
This patch issues a BLKFLSBUF ioctl to the block device before reading
metadata. The kernel then invalidates the block device page cache,
ensuring that subsequent reads fetch uptodate metadata from disk.
Signed-off-by: Yongpeng Yang <[email protected]>
---
lib/libf2fs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 1a496b7..31b5924 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -1027,6 +1027,7 @@ int get_device_info(int i)
}
dev->fd = fd;
+ ioctl(fd, BLKFLSBUF);
if (c.sparse_mode && i == 0) {
if (f2fs_init_sparse_file()) {
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel