* [f2fs-dev] [PATCH] resize.f2fs: fix to check free space before shrink
@ 2021-04-06 1:31 Chao Yu
0 siblings, 0 replies; only message in thread
From: Chao Yu @ 2021-04-06 1:31 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel
Otherwise, after shrink, kernel will report below error message
when we mount the image:
F2FS-fs (loop0): invalid crc_offset: 0
F2FS-fs (loop0): Wrong valid_user_blocks: 16404, user_block_count: 13312
F2FS-fs (loop0): Failed to get valid F2FS checkpoint
mount(2) system call failed: Structure needs cleaning.
Reported-by: beroal <me@beroal.in.ua>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fsck/resize.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/fsck/resize.c b/fsck/resize.c
index a083f68a809f..b043cd984dc6 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -650,8 +650,11 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi)
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
struct f2fs_super_block new_sb_raw;
struct f2fs_super_block *new_sb = &new_sb_raw;
+ struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
block_t old_end_blkaddr, old_main_blkaddr;
block_t new_end_blkaddr, new_main_blkaddr, tmp_end_blkaddr;
+ block_t user_block_count;
+ unsigned int overprov_segment_count;
unsigned int offset;
int err = -1;
@@ -662,6 +665,17 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi)
if (get_new_sb(new_sb))
return -1;
+ overprov_segment_count = (get_newsb(segment_count_main) -
+ c.new_reserved_segments) *
+ c.new_overprovision / 100;
+ overprov_segment_count += c.new_reserved_segments;
+
+ user_block_count = (get_newsb(segment_count_main) -
+ overprov_segment_count) * c.blks_per_seg;
+
+ if (get_cp(valid_block_count) > user_block_count)
+ return -1;
+
/* check nat availability */
if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) {
err = shrink_nats(sbi, new_sb);
--
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-06 1:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-06 1:31 [f2fs-dev] [PATCH] resize.f2fs: fix to check free space before shrink 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).