[RFC,1/3] btrfs-progs: lowmem: delay before lowmem repair starts
diff mbox

Message ID 20180702092820.16285-2-suy.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Su Yue July 2, 2018, 9:28 a.m. UTC
Since lowmem mode repair is so dangerous, delay 10 seconds before
start.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/main.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

Patch
diff mbox

diff --git a/check/main.c b/check/main.c
index 3190b5d4f293..b9997460162f 100644
--- a/check/main.c
+++ b/check/main.c
@@ -9553,12 +9553,6 @@  int cmd_check(int argc, char **argv)
 		exit(1);
 	}
 
-	/*
-	 * experimental and dangerous
-	 */
-	if (repair && check_mode == CHECK_MODE_LOWMEM)
-		warning("low-memory mode repair support is only partial");
-
 	radix_tree_init();
 	cache_tree_init(&root_cache);
 
@@ -9600,6 +9594,28 @@  int cmd_check(int argc, char **argv)
 	if (repair)
 		ctree_flags |= OPEN_CTREE_PARTIAL;
 
+	/*
+	 * experimental and dangerous
+	 */
+	if (repair && check_mode == CHECK_MODE_LOWMEM) {
+		int delay = 10;
+
+		printf("WARNING:\n\n");
+		printf("\tLow-memory mode repair support is only partial.\n");
+		printf("\tIt's experimental and very dangerous.\n");
+		printf("\tIt may run slow or crash unexpectedly.\n");
+		printf("\tPlease backup device before running low-memory mode repair.\n");
+		printf("\tThe operation will start in %d seconds.\n", delay);
+		printf("\tUse Ctrl-C to stop it.\n");
+
+		while (delay) {
+			printf("%2d", delay--);
+			fflush(stdout);
+			sleep(1);
+		}
+		printf("\nStarting to check and repair filesystem.\n");
+	}
+
 	info = open_ctree_fs_info(argv[optind], bytenr, tree_root_bytenr,
 				  chunk_root_bytenr, ctree_flags);
 	if (!info) {