All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Subject: [PATCH 1/2] btrfs-progs: add ask_user confirmation for btrfstune clear seeding flag
Date: Thu, 3 Jul 2014 10:06:33 +0800	[thread overview]
Message-ID: <1404353196-10914-1-git-send-email-guihc.fnst@cn.fujitsu.com> (raw)

Clear the seeding flag may cause the original filesystem to be writable,
which is dangerous.
In this case, add user confirmation check when clearing seeding flag.
Also warn the user that the fs is in a dangerous condition when
the seeding flag is cleared if it it forced to.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 btrfstune.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/btrfstune.c b/btrfstune.c
index 3f2f0cd..0e18088 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -56,6 +56,7 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag)
 			return 1;
 		}
 		super_flags &= ~BTRFS_SUPER_FLAG_SEEDING;
+		fprintf(stderr, "Warning: Seeding flag cleared. This could be dangerous!\n");
 	}
 
 	trans = btrfs_start_transaction(root, 1);
@@ -103,6 +104,7 @@ static void print_usage(void)
 	fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed\n");
 	fprintf(stderr, "\t-r \t\tenable extended inode refs\n");
 	fprintf(stderr, "\t-x \t\tenable skinny metadata extent refs\n");
+	fprintf(stderr, "\t-y \t\tsay yes to clear the seeding flag, make sure that you are aware of the danger\n");
 }
 
 int main(int argc, char *argv[])
@@ -113,11 +115,12 @@ int main(int argc, char *argv[])
 	int seeding_flag = 0;
 	u64 seeding_value = 0;
 	int skinny_flag = 0;
+	int force_clear = 0;
 	int ret;
 
 	optind = 1;
 	while(1) {
-		int c = getopt(argc, argv, "S:rx");
+		int c = getopt(argc, argv, "S:rxy");
 		if (c < 0)
 			break;
 		switch(c) {
@@ -131,6 +134,9 @@ int main(int argc, char *argv[])
 		case 'x':
 			skinny_flag = 1;
 			break;
+		case 'y':
+			force_clear = 1;
+			break;
 		default:
 			print_usage();
 			return 1;
@@ -151,6 +157,13 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	if (!seeding_flag && force_clear) {
+		fprintf(stderr,
+			"ERROR: -y option only work with -S option.\n");
+		print_usage();
+		return 1;
+	}
+
 	ret = check_mounted(device);
 	if (ret < 0) {
 		fprintf(stderr, "Could not check mount status: %s\n",
@@ -169,6 +182,15 @@ int main(int argc, char *argv[])
 	}
 
 	if (seeding_flag) {
+		if (!seeding_value && !force_clear) {
+			fprintf(stderr, "Warning: This is dangerous, clearing the seeding flag will make the original filesystem writable.\n");
+			ret = ask_user("We are going to clear the seeding flag, are you sure?");
+			if (!ret) {
+				fprintf(stderr, "Clear seeding flag canceled\n");
+				return 1;
+			}
+		}
+
 		ret = update_seeding_flag(root, seeding_value);
 		if (!ret)
 			success++;
-- 
1.8.1.4


             reply	other threads:[~2014-07-03  2:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-03  2:06 Gui Hecheng [this message]
2014-07-03  2:06 ` [PATCH] btrfs-progs: add mount status check for btrfs-image Gui Hecheng
2014-07-03 16:58   ` David Sterba
2014-07-04  1:57     ` Gui Hecheng
2014-07-07  1:56     ` [PATCH v2] " Gui Hecheng
2014-07-03  2:06 ` [PATCH] btrfs-progs: prevent select invalid dev super after dev replace Gui Hecheng
2014-07-03 18:10   ` David Sterba
2014-07-04  1:09     ` Gui Hecheng
2014-07-03  2:06 ` [PATCH 2/2] btrfs-progs: update manpage with new option -y for btrfstune Gui Hecheng
2014-07-03 16:51 ` [PATCH 1/2] btrfs-progs: add ask_user confirmation for btrfstune clear seeding flag David Sterba
2014-07-04  1:59   ` Gui Hecheng
2014-07-04 13:05     ` David Sterba
2014-07-07  1:54   ` [PATCH v2] " Gui Hecheng
2014-07-07  1:54     ` [PATCH v2] btrfs-progs: update manpage with new option -f for btrfstune Gui Hecheng
2014-08-19 16:32       ` David Sterba

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=1404353196-10914-1-git-send-email-guihc.fnst@cn.fujitsu.com \
    --to=guihc.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.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.