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 v4 2/2] resize.f2fs: add caution message for resize
Date: Mon, 14 Apr 2025 10:38:19 +0800	[thread overview]
Message-ID: <20250414023819.581303-2-chao@kernel.org> (raw)
In-Reply-To: <20250414023819.581303-1-chao@kernel.org>

resize.f2fs doesn't guarantee atomically resizing f2fs image,
so that potential suddent power cut, IO error, out of memory,
SIGKILL received or program exits due to other reasons may cause
data corruption.

This patch adds caution message for resize users to notice
potential risk of using resizing tool, and remind them to backup
data before resize.

resize.f2fs <partition>

"Resize operation is currently experimental, please backup your data.
Do you want to continue? [y/n]y
Proceeding to resize"

If we want to force to use resize.f2fs, we can use -F option, let's
enable -F option in Android by default to avoid breaking any usage.

Cc: Juhyung Park <qkrwngud825@gmail.com>
Signed-off-by: Chao Yu <chao@kernel.org>
---
v4:
Fix issues pointed out by Juhyung:
- fix typos
- fix wrong fallthrough
- clean up caution message w/ unaggressive words
 fsck/main.c       | 25 ++++++++++++++++++++++++-
 fsck/resize.c     |  2 +-
 include/f2fs_fs.h |  1 +
 man/resize.f2fs.8 | 12 ++++++++++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index af40613..3a116e1 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -222,6 +222,8 @@ static void add_default_options(void)
 		if (c.func == FSCK) {
 			/* -a */
 			c.auto_fix = 1;
+		} else if (c.func == RESIZE) {
+			c.force = 1;
 		}
 
 		/*
@@ -601,7 +603,7 @@ void f2fs_parse_options(int argc, char *argv[])
 #endif
 	} else if (!strcmp("resize.f2fs", prog)) {
 #ifdef WITH_RESIZE
-		const char *option_string = "d:fHst:o:V";
+		const char *option_string = "d:fFHst:o:V";
 
 		c.func = RESIZE;
 		while ((option = getopt(argc, argv, option_string)) != EOF) {
@@ -618,6 +620,10 @@ void f2fs_parse_options(int argc, char *argv[])
 							c.dbg_lv);
 				break;
 			case 'f':
+				c.ignore_error = 1;
+				MSG(0, "Info: Ignore errors during resize\n");
+				break;
+			case 'F':
 				c.force = 1;
 				MSG(0, "Info: Force to resize\n");
 				break;
@@ -1104,6 +1110,23 @@ out_range:
 #ifdef WITH_RESIZE
 static int do_resize(struct f2fs_sb_info *sbi)
 {
+	char answer[255] = {0};
+	int ret;
+
+	if (!c.force) {
+retry:
+		printf("\nResize operation is currently experimental, please "
+			"backup your data.\nDo you want to continue? [y/n]");
+		ret = scanf("%s", answer);
+		ASSERT(ret >= 0);
+		if (!strcasecmp(answer, "y"))
+			printf("Proceeding to resize\n");
+		else if (!strcasecmp(answer, "n"))
+			return 0;
+		else
+			goto retry;
+	}
+
 	if (!c.target_sectors)
 		c.target_sectors = c.total_sectors;
 
diff --git a/fsck/resize.c b/fsck/resize.c
index 2681b9f..1ab7d75 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -765,7 +765,7 @@ int f2fs_resize(struct f2fs_sb_info *sbi)
 		}
 	else if (((c.target_sectors * c.sector_size >>
 			get_sb(log_blocksize)) > get_sb(block_count)) ||
-			c.force)
+			c.ignore_error)
 		return f2fs_resize_grow(sbi);
 	else {
 		MSG(0, "Nothing to resize.\n");
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 7e3f25b..928f963 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1528,6 +1528,7 @@ struct f2fs_configuration {
 	int no_kernel_check;
 	int fix_on;
 	int force;
+	int ignore_error;
 	int defset;
 	int bug_on;
 	unsigned int invalid_sb;
diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8
index 02ff245..bdda4fd 100644
--- a/man/resize.f2fs.8
+++ b/man/resize.f2fs.8
@@ -18,6 +18,12 @@ resize.f2fs \- resize filesystem size
 .I overprovision-ratio-percentage
 ]
 [
+.B \-f
+]
+[
+.B \-F
+]
+[
 .B \-H
 ]
 [
@@ -53,6 +59,12 @@ Specify the percentage of the volume that will be used as overprovision area.
 This area is hidden to users, and utilized by F2FS cleaner. If not specified, the
 best number will be assigned automatically according to the partition size.
 .TP
+.BI \-f
+Force to fix any inconsistent data during resize.
+.TP
+.BI \-F
+Skip caution dialogue and resize partition directly.
+.TP
 .BI \-H
 Specify support write hint.
 .TP
-- 
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  2:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14  2:38 [f2fs-dev] [PATCH v4 1/2] Revert "resize.f2fs: add option for large_nat_bitmap feature" Chao Yu via Linux-f2fs-devel
2025-04-14  2:38 ` Chao Yu via Linux-f2fs-devel [this message]

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=20250414023819.581303-2-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.