diff mbox

[1/2] btrfs-progs:btrfstune: choose to ignore error when setting seeding enabled

Message ID 1420791102-9948-1-git-send-email-fancn.fnst@cn.fujitsu.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Fan Chengniang Jan. 9, 2015, 8:11 a.m. UTC
Before with -S option, setting positive value on seeding-enabled btrfs
filesystem will cause error. So I add -i option which can ignore it.

Reported-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
---
 Documentation/btrfstune.txt |  9 +++++++--
 btrfstune.c                 | 25 ++++++++++++++++++-------
 2 files changed, 25 insertions(+), 9 deletions(-)

Comments

David Sterba Jan. 14, 2015, 3:48 p.m. UTC | #1
On Fri, Jan 09, 2015 at 04:11:41PM +0800, Fan Chengniang wrote:
> Before with -S option, setting positive value on seeding-enabled btrfs
> filesystem will cause error. So I add -i option which can ignore it.

Why can't we use the existing --force/-f option for that?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Fan Chengniang Jan. 15, 2015, 5:07 a.m. UTC | #2
? 2015?01?14? 23:48, David Sterba ??:
> On Fri, Jan 09, 2015 at 04:11:41PM +0800, Fan Chengniang wrote:
>> Before with -S option, setting positive value on seeding-enabled btrfs
>> filesystem will cause error. So I add -i option which can ignore it.
> Why can't we use the existing --force/-f option for that?
That is a good idea. I will use -f instead of adding -i.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/btrfstune.txt b/Documentation/btrfstune.txt
index d49a974..494a716 100644
--- a/Documentation/btrfstune.txt
+++ b/Documentation/btrfstune.txt
@@ -18,8 +18,13 @@  OPTIONS
 -------
 -S <value>::
 Updates the seeding value.
-A positive value will enable seeding, zero will disable seeding, negtive is not allowed.
-Enable seeding forces a fs readonly so that you can use it to build other filesystems.
+A positive value will enable seeding, zero will disable seeding, negtive is not
+allowed. If seeding is already enabled, positive value will cause reporting
+error. Enable seeding forces a fs readonly so that you can use it to build other
+filesystems.
+-i::
+Use with -S option. If seeding is already enabled, ignore it and do not report
+error.
 -r::
 Enable extended inode refs.
 -x::
diff --git a/btrfstune.c b/btrfstune.c
index 050418a..9a9e855 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -34,7 +34,8 @@ 
 
 static char *device;
 
-static int update_seeding_flag(struct btrfs_root *root, int set_flag)
+static int update_seeding_flag(struct btrfs_root *root, int set_flag,
+		int ignore_enabled_seeding)
 {
 	struct btrfs_trans_handle *trans;
 	struct btrfs_super_block *disk_super;
@@ -44,9 +45,12 @@  static int update_seeding_flag(struct btrfs_root *root, int set_flag)
 	super_flags = btrfs_super_flags(disk_super);
 	if (set_flag) {
 		if (super_flags & BTRFS_SUPER_FLAG_SEEDING) {
-			fprintf(stderr, "seeding flag is already set on %s\n",
-				device);
-			return 1;
+			if (!ignore_enabled_seeding) {
+				fprintf(stderr, "seeding flag is already set on %s\n",
+					device);
+				return 1;
+			}
+			return 0;
 		}
 		super_flags |= BTRFS_SUPER_FLAG_SEEDING;
 	} else {
@@ -101,7 +105,9 @@  static int enable_skinny_metadata(struct btrfs_root *root)
 static void print_usage(void)
 {
 	fprintf(stderr, "usage: btrfstune [options] device\n");
-	fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed\n");
+	fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed. "
+			"If seeding is already enabled, positive value will cause reporting error\n");
+	fprintf(stderr, "\t-i \t\tuse with -S option. If seeding is already enabled, ignore it and do not report error\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-f \t\tforce to clear flags, make sure that you are aware of the dangers\n");
@@ -114,13 +120,14 @@  int main(int argc, char *argv[])
 	int extrefs_flag = 0;
 	int seeding_flag = 0;
 	u64 seeding_value = 0;
+	int ignore_enabled_seeding = 0;
 	int skinny_flag = 0;
 	int force = 0;
 	int ret;
 
 	optind = 1;
 	while(1) {
-		int c = getopt(argc, argv, "S:rxf");
+		int c = getopt(argc, argv, "S:irxf");
 		if (c < 0)
 			break;
 		switch(c) {
@@ -128,6 +135,9 @@  int main(int argc, char *argv[])
 			seeding_flag = 1;
 			seeding_value = arg_strtou64(optarg);
 			break;
+		case 'i':
+			ignore_enabled_seeding = 1;
+			break;
 		case 'r':
 			extrefs_flag = 1;
 			break;
@@ -185,7 +195,8 @@  int main(int argc, char *argv[])
 			}
 		}
 
-		ret = update_seeding_flag(root, seeding_value);
+		ret = update_seeding_flag(root, seeding_value,
+			ignore_enabled_seeding);
 		if (!ret)
 			success++;
 	}