All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize
Date: Mon, 14 Apr 2025 19:11:41 +0800	[thread overview]
Message-ID: <20250414111141.735081-1-chao@kernel.org> (raw)

w/ below testcase, resize will generate a corrupted image which
contains inconsistent metadata:

touch img
truncate -s $((512*1024*1024*1024)) img
mkfs.f2fs -f img $((256*1024*1024))
resize.f2fs -s img -t $((1024*1024*1024))
mount img /mnt/f2fs

[   31.725200] F2FS-fs (loop0): Wrong bitmap size: sit: 192, sit_blk_cnt:4762
[   31.728441] F2FS-fs (loop0): Failed to get valid F2FS checkpoint

The root cause is safe mode (via -s option) is not compatible
w/ expand resize, due to in safe mode, we will keep all parameters
related to NAT, SIT, SSA area, e.g. sit_bitmap_size, however, we
will update segment_count_main according new partition size, result
in there is no enough sit_bitmap and SIT blocks to address the
entire block address of new partition.

Adding a check condition to avoid expanding partition in safe
mode, and change manual accordingly.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fsck/resize.c     | 12 ++++++++----
 man/resize.f2fs.8 |  2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/fsck/resize.c b/fsck/resize.c
index 1ab7d75..58914ec 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -756,18 +756,22 @@ int f2fs_resize(struct f2fs_sb_info *sbi)
 
 	/* may different sector size */
 	if ((c.target_sectors * c.sector_size >>
-			get_sb(log_blocksize)) < get_sb(block_count))
+			get_sb(log_blocksize)) < get_sb(block_count)) {
 		if (!c.safe_resize) {
 			ASSERT_MSG("Nothing to resize, now only supports resizing with safe resize flag\n");
 			return -1;
 		} else {
 			return f2fs_resize_shrink(sbi);
 		}
-	else if (((c.target_sectors * c.sector_size >>
+	} else if (((c.target_sectors * c.sector_size >>
 			get_sb(log_blocksize)) > get_sb(block_count)) ||
-			c.ignore_error)
+			c.ignore_error) {
+		if (c.safe_resize) {
+			ASSERT_MSG("Expanding resize doesn't support safe resize flag");
+			return -1;
+		}
 		return f2fs_resize_grow(sbi);
-	else {
+	} else {
 		MSG(0, "Nothing to resize.\n");
 		return 0;
 	}
diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8
index bdda4fd..5b6daf5 100644
--- a/man/resize.f2fs.8
+++ b/man/resize.f2fs.8
@@ -69,7 +69,7 @@ Skip caution dialogue and resize partition directly.
 Specify support write hint.
 .TP
 .BI \-s
-Enable safe resize.
+Enable safe resize, it can only be used w/ shrink resize.
 .TP
 .BI \-V
 Print the version number and exit.
-- 
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

             reply	other threads:[~2025-04-14 11:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14 11:11 Chao Yu via Linux-f2fs-devel [this message]
2025-04-15 19:28 ` [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize Juhyung Park
2025-04-16  3:33   ` Chao Yu via Linux-f2fs-devel
2025-04-16  3:40     ` Juhyung Park
2025-04-16  5:51       ` Chao Yu via Linux-f2fs-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250414111141.735081-1-chao@kernel.org \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.