* [f2fs-dev] [PATCH] resize.f2fs: fix wrong sit/nat bitmap during rebuild_checkpoint()
@ 2021-04-02 7:12 Chao Yu
0 siblings, 0 replies; only message in thread
From: Chao Yu @ 2021-04-02 7:12 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel
As beroal <me@beroal.in.ua> reported: f2fs image can be corrupted
after below testcase:
1. truncate -s $((256*1024*1024)) img
2. mkfs.f2fs -f img
3. mount -t f2fs -o loop img /mnt
4. xfs_io -f /mnt/file -c "pwrite 0 2M" -c "fsync"
5. umount /mnt
6. resize.f2fs -s -t 262144 img
7. fsck.f2fs img
The root cause is we forgot to copy original sit/nat bitmap to
new checkpoint during rebuild_checkpoint(), fix it.
Reported-by: beroal <me@beroal.in.ua>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fsck/resize.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fsck/resize.c b/fsck/resize.c
index 46b1cfb218cf..b3920560974b 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -526,6 +526,11 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
memcpy(new_cp, cp, (unsigned char *)cp->sit_nat_version_bitmap -
(unsigned char *)cp);
+ if (c.safe_resize)
+ memcpy((void *)new_cp + CP_BITMAP_OFFSET,
+ (void *)cp + CP_BITMAP_OFFSET,
+ F2FS_BLKSIZE - CP_BITMAP_OFFSET);
+
new_cp->checkpoint_ver = cpu_to_le64(cp_ver + 1);
crc = f2fs_checkpoint_chksum(new_cp);
--
2.29.2
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-02 7:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-02 7:12 [f2fs-dev] [PATCH] resize.f2fs: fix wrong sit/nat bitmap during rebuild_checkpoint() Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).