All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] btrfs-progs:btrfstune:force to set seeding flags
@ 2015-01-19  7:27 Fan Chengniang
  2015-01-19  7:27 ` [PATCH v2 2/2] btrfs-progs:btrfstune:fix multiple options error Fan Chengniang
  0 siblings, 1 reply; 2+ messages in thread
From: Fan Chengniang @ 2015-01-19  7:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, Fan Chengniang

Now we can use -f with -S option when setting seeding flags or clearing
seeding flags

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

diff --git a/Documentation/btrfstune.txt b/Documentation/btrfstune.txt
index d49a974..2448e27 100644
--- a/Documentation/btrfstune.txt
+++ b/Documentation/btrfstune.txt
@@ -25,7 +25,7 @@ Enable extended inode refs.
 -x::
 Enable skinny metadata extent refs.
 -f::
-Allow dangerous changes, e.g. clear the seeding flag
+Force to set or clear seeding flag. Allow dangerous changes, e.g. clear the seeding flag
 
 When mounting the new device, btrfs will check whether the seeding flag is set
 when try to open seeding device.  If the user clears the seeding flag of the
diff --git a/btrfstune.c b/btrfstune.c
index 050418a..15f68c8 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -33,6 +33,7 @@
 #include "version.h"
 
 static char *device;
+static int force = 0;
 
 static int update_seeding_flag(struct btrfs_root *root, int set_flag)
 {
@@ -44,8 +45,10 @@ 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);
+			if (force)
+				return 0;
+			else
+				fprintf(stderr, "seeding flag is already set on %s\n", device);
 			return 1;
 		}
 		super_flags |= BTRFS_SUPER_FLAG_SEEDING;
@@ -104,7 +107,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-f \t\tforce to clear flags, make sure that you are aware of the dangers\n");
+	fprintf(stderr, "\t-f \t\tforce to set or clear flags, make sure that you are aware of the dangers\n");
 }
 
 int main(int argc, char *argv[])
@@ -115,7 +118,6 @@ int main(int argc, char *argv[])
 	int seeding_flag = 0;
 	u64 seeding_value = 0;
 	int skinny_flag = 0;
-	int force = 0;
 	int ret;
 
 	optind = 1;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2 2/2] btrfs-progs:btrfstune:fix multiple options error
  2015-01-19  7:27 [PATCH v2 1/2] btrfs-progs:btrfstune:force to set seeding flags Fan Chengniang
@ 2015-01-19  7:27 ` Fan Chengniang
  0 siblings, 0 replies; 2+ messages in thread
From: Fan Chengniang @ 2015-01-19  7:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, Fan Chengniang

when we use multiple options, error return status will be override by the
last option status.
example: btrfstune -S 1 -r /dev/loop0
when -S option fails and -r option succeeds, return value is 0, rather than
1, where 1 is the right return status.

Reported-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
---
 btrfstune.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/btrfstune.c b/btrfstune.c
index 15f68c8..075fbc6 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -114,6 +114,7 @@ int main(int argc, char *argv[])
 {
 	struct btrfs_root *root;
 	int success = 0;
+	int total = 0;
 	int extrefs_flag = 0;
 	int seeding_flag = 0;
 	u64 seeding_value = 0;
@@ -190,19 +191,22 @@ int main(int argc, char *argv[])
 		ret = update_seeding_flag(root, seeding_value);
 		if (!ret)
 			success++;
+		total++;
 	}
 
 	if (extrefs_flag) {
 		enable_extrefs_flag(root);
 		success++;
+		total++;
 	}
 
 	if (skinny_flag) {
 		enable_skinny_metadata(root);
 		success++;
+		total++;
 	}
 
-	if (success > 0) {
+	if (success == total) {
 		ret = 0;
 	} else {
 		root->fs_info->readonly = 1;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-19  7:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-19  7:27 [PATCH v2 1/2] btrfs-progs:btrfstune:force to set seeding flags Fan Chengniang
2015-01-19  7:27 ` [PATCH v2 2/2] btrfs-progs:btrfstune:fix multiple options error Fan Chengniang

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.