All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] RAID-level terminology change
@ 2013-03-11 20:17 Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 1/5] Use NcMsPp format for mkfs Hugo Mills
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Hugo Mills @ 2013-03-11 20:17 UTC (permalink / raw)
  To: linux-btrfs, Goffredo Baroncelli, Harald Glatt, Roger Binns,
	Martin Steigerwald, Diego Calleja, sam tygier, David Sterba

   Some time ago, and occasionally since, we've discussed altering the
"RAID-n" terminology to change it to an "NcMsPp" format, where N is the
number of copies, M is the number of (data) devices in a stripe per copy,
and P is the number of parity devices in a stripe.

   The current kernel implementation uses as many devices as it can in the
striped modes (RAID-0, -10, -5, -6), and in this implementation, that is
written as "Xs" (with a literal "X"). The Ms and Pp sections are omitted
if the value is 1s or 0p.

   The magic look-up table for old-style / new-style is:

single 		 1c (or omitted, in btrfs fi df output)
RAID-0		 1cXs
RAID-1		 2c
DUP			 2cd
RAID-10		 2cXs
RAID-5		 1cXs1p
RAID-6		 1cXs2p

   The following patch set modifies userspace tools to accept c/s/p formats
in input (mkfs and the restriper). The older formats are also accepted. It
also prints the newer formats by default in btrfs fi df, with an option to
show the older format for the traditionalists, and to expand the abbreviation
verbosely for those unfamiliar with it.

v1 -> v2: Changed to use lower-case letters for c/s/p, for readability
   	  	  Changed mS to Xs for readability
		  Added "explain" option to df
		  Switched option parsing for df to getopt_long

   Hugo.

Hugo Mills (5):
  Use NcMsPp format for mkfs
  Move parse_profile to utils.c
  Convert balance filter parser to use common NcMsPp replication-level
    parser
  Change output of btrfs fi df to report new (or old) RAID names
  Add man page description for NcMsPp replication levels

 cmds-balance.c      |   23 +++----
 cmds-filesystem.c   |  173 ++++++++++++++++++++++++++++++++++++++++++++-------
 man/btrfs.8.in      |   16 +++++
 man/mkfs.btrfs.8.in |   24 ++++++-
 mkfs.c              |   35 +++--------
 utils.c             |   94 ++++++++++++++++++++++++++++
 utils.h             |    1 +
 7 files changed, 303 insertions(+), 63 deletions(-)

-- 
1.7.10.4


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

* [PATCH v2 1/5] Use NcMsPp format for mkfs
  2013-03-11 20:17 [PATCH v2 0/5] RAID-level terminology change Hugo Mills
@ 2013-03-11 20:17 ` Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 2/5] Move parse_profile to utils.c Hugo Mills
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hugo Mills @ 2013-03-11 20:17 UTC (permalink / raw)
  To: linux-btrfs, Goffredo Baroncelli, Harald Glatt, Roger Binns,
	Martin Steigerwald, Diego Calleja, sam tygier, David Sterba

Teach mkfs.btrfs about ncmspp format for replication levels, which avoids
the semantic uncertainty over the "RAID-XYZ" naming.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
 mkfs.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 84 insertions(+), 7 deletions(-)

diff --git a/mkfs.c b/mkfs.c
index b2520ce..70df5db 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -326,7 +326,9 @@ static void print_usage(void)
 	fprintf(stderr, "options:\n");
 	fprintf(stderr, "\t -A --alloc-start the offset to start the FS\n");
 	fprintf(stderr, "\t -b --byte-count total number of bytes in the FS\n");
-	fprintf(stderr, "\t -d --data data profile, raid0, raid1, raid5, raid6, raid10, dup or single\n");
+	fprintf(stderr, "\t -d --data data profile: <n>c[d][<m>s[<p>p]]\n");
+	fprintf(stderr, "\t\tfor n copies (d=reduced dev redundancy), m stripes, p parity stripes\n");
+	fprintf(stderr, "\t\tor raid0, raid1, raid10, dup or single (deprecated)\n");
 	fprintf(stderr, "\t -l --leafsize size of btree leaves\n");
 	fprintf(stderr, "\t -L --label set a label\n");
 	fprintf(stderr, "\t -m --metadata metadata profile, values like data profile\n");
@@ -346,8 +348,36 @@ static void print_version(void)
 	exit(0);
 }
 
-static u64 parse_profile(char *s)
+static u64 make_profile(int copies, int dup, int stripes, int parity)
 {
+	if(copies == 1 && !dup && stripes == 0 && parity == 0)
+		return 0;
+	else if(copies == 2 && dup && stripes == 0 && parity == 0)
+		return BTRFS_BLOCK_GROUP_DUP;
+	else if(copies == 2 && !dup && stripes == 0 && parity == 0)
+		return BTRFS_BLOCK_GROUP_RAID1;
+	else if(copies == 2 && !dup && stripes == -1 && parity == 0)
+		return BTRFS_BLOCK_GROUP_RAID10;
+	else if(copies == 1 && !dup && stripes == -1 && parity == 0)
+		return BTRFS_BLOCK_GROUP_RAID0;
+	else if(copies == 1 && !dup && stripes == -1 && parity == 1)
+		return BTRFS_BLOCK_GROUP_RAID5;
+	else if(copies == 1 && !dup && stripes == -1 && parity == 2)
+		return BTRFS_BLOCK_GROUP_RAID6;
+
+	return (u64)-1;
+}
+
+static u64 parse_profile(const char *s)
+{
+	char *pos, *parse_end;
+	int copies = 1;
+	int stripes = 0;
+	int parity = 0;
+	int dup = 0;
+	u64 profile = (u64)-1;
+
+	/* Look for exact match with historical forms first */
 	if (strcmp(s, "raid0") == 0) {
 		return BTRFS_BLOCK_GROUP_RAID0;
 	} else if (strcmp(s, "raid1") == 0) {
@@ -362,12 +392,54 @@ static u64 parse_profile(char *s)
 		return BTRFS_BLOCK_GROUP_DUP;
 	} else if (strcmp(s, "single") == 0) {
 		return 0;
+	}
+
+	/* Attempt to parse new ncmspp form */
+	/* <n>c is required and n must be an unsigned decimal number */
+	copies = strtoul(s, &parse_end, 10);
+	if(parse_end == s || (*parse_end != 'c' && *parse_end != 'C'))
+		goto unknown;
+
+	/* c may be followed by d to indicate non-redundant/DUP */
+	pos = parse_end + 1;
+	if(*pos == 'd' || *pos == 'D') {
+		dup = 1;
+		pos++;
+	}
+	if(*pos == 0)
+		goto done;
+
+	/* <m>s is optional, and <m> may be an integer, or a literal "x" */
+	if(*pos == 'x' || *pos == 'X') {
+		stripes = -1;
+		parse_end = pos+1;
 	} else {
-		fprintf(stderr, "Unknown profile %s\n", s);
-		print_usage();
+		stripes = strtoul(pos, &parse_end, 10);
 	}
-	/* not reached */
-	return 0;
+	if(parse_end == pos || (*parse_end != 's' && *parse_end != 'S'))
+		goto unknown;
+
+	pos = parse_end + 1;
+	if(*pos == 0)
+		goto done;
+
+	/* <p>p is optional, and p must be an integer */
+	parity = strtoul(pos, &parse_end, 10);
+	if(parse_end == pos || (*parse_end != 'p' && *parse_end != 'P'))
+		goto unknown;
+	pos = parse_end + 1;
+	if(*pos != 0)
+		goto unknown;
+
+done:
+	profile = make_profile(copies, dup, stripes, parity);
+	if(profile == (u64)-1)
+		fprintf(stderr, "Unknown or unavailable profile '%s'\n", s);
+	return profile;
+
+unknown:
+	fprintf(stderr, "Unparseable profile '%s'\n", s);
+	return (u64)-1;
 }
 
 static char *parse_label(char *input)
@@ -1447,6 +1519,11 @@ int main(int ac, char **av)
 	printf("\nWARNING! - %s IS EXPERIMENTAL\n", BTRFS_BUILD_VERSION);
 	printf("WARNING! - see http://btrfs.wiki.kernel.org before using\n\n");
 
+	if (data_profile == (u64)-1 || metadata_profile == (u64)-1) {
+		fprintf(stderr, "Cannot handle requested replication profile. Aborting\n");
+		exit(1);
+	}
+
 	if (source_dir == 0) {
 		file = av[optind++];
 		ret = is_swap_device(file);
@@ -1666,7 +1743,7 @@ raid_groups:
 
 		flags |= BTRFS_FEATURE_INCOMPAT_RAID56;
 		btrfs_set_super_incompat_flags(super, flags);
-		printf("Setting RAID5/6 feature flag\n");
+		printf("Setting parity-RAID feature flag\n");
 	}
 
 	printf("fs created label %s on %s\n\tnodesize %u leafsize %u "
-- 
1.7.10.4


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

* [PATCH v2 2/5] Move parse_profile to utils.c
  2013-03-11 20:17 [PATCH v2 0/5] RAID-level terminology change Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 1/5] Use NcMsPp format for mkfs Hugo Mills
@ 2013-03-11 20:17 ` Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 3/5] Convert balance filter parser to use common NcMsPp replication-level parser Hugo Mills
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hugo Mills @ 2013-03-11 20:17 UTC (permalink / raw)
  To: linux-btrfs, Goffredo Baroncelli, Harald Glatt, Roger Binns,
	Martin Steigerwald, Diego Calleja, sam tygier, David Sterba

Make parse_profile a shared function so it can be used across the
code-base.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
 mkfs.c  |   94 ---------------------------------------------------------------
 utils.c |   94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 utils.h |    1 +
 3 files changed, 95 insertions(+), 94 deletions(-)

diff --git a/mkfs.c b/mkfs.c
index 70df5db..0facf13 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -348,100 +348,6 @@ static void print_version(void)
 	exit(0);
 }
 
-static u64 make_profile(int copies, int dup, int stripes, int parity)
-{
-	if(copies == 1 && !dup && stripes == 0 && parity == 0)
-		return 0;
-	else if(copies == 2 && dup && stripes == 0 && parity == 0)
-		return BTRFS_BLOCK_GROUP_DUP;
-	else if(copies == 2 && !dup && stripes == 0 && parity == 0)
-		return BTRFS_BLOCK_GROUP_RAID1;
-	else if(copies == 2 && !dup && stripes == -1 && parity == 0)
-		return BTRFS_BLOCK_GROUP_RAID10;
-	else if(copies == 1 && !dup && stripes == -1 && parity == 0)
-		return BTRFS_BLOCK_GROUP_RAID0;
-	else if(copies == 1 && !dup && stripes == -1 && parity == 1)
-		return BTRFS_BLOCK_GROUP_RAID5;
-	else if(copies == 1 && !dup && stripes == -1 && parity == 2)
-		return BTRFS_BLOCK_GROUP_RAID6;
-
-	return (u64)-1;
-}
-
-static u64 parse_profile(const char *s)
-{
-	char *pos, *parse_end;
-	int copies = 1;
-	int stripes = 0;
-	int parity = 0;
-	int dup = 0;
-	u64 profile = (u64)-1;
-
-	/* Look for exact match with historical forms first */
-	if (strcmp(s, "raid0") == 0) {
-		return BTRFS_BLOCK_GROUP_RAID0;
-	} else if (strcmp(s, "raid1") == 0) {
-		return BTRFS_BLOCK_GROUP_RAID1;
-	} else if (strcmp(s, "raid5") == 0) {
-		return BTRFS_BLOCK_GROUP_RAID5;
-	} else if (strcmp(s, "raid6") == 0) {
-		return BTRFS_BLOCK_GROUP_RAID6;
-	} else if (strcmp(s, "raid10") == 0) {
-		return BTRFS_BLOCK_GROUP_RAID10;
-	} else if (strcmp(s, "dup") == 0) {
-		return BTRFS_BLOCK_GROUP_DUP;
-	} else if (strcmp(s, "single") == 0) {
-		return 0;
-	}
-
-	/* Attempt to parse new ncmspp form */
-	/* <n>c is required and n must be an unsigned decimal number */
-	copies = strtoul(s, &parse_end, 10);
-	if(parse_end == s || (*parse_end != 'c' && *parse_end != 'C'))
-		goto unknown;
-
-	/* c may be followed by d to indicate non-redundant/DUP */
-	pos = parse_end + 1;
-	if(*pos == 'd' || *pos == 'D') {
-		dup = 1;
-		pos++;
-	}
-	if(*pos == 0)
-		goto done;
-
-	/* <m>s is optional, and <m> may be an integer, or a literal "x" */
-	if(*pos == 'x' || *pos == 'X') {
-		stripes = -1;
-		parse_end = pos+1;
-	} else {
-		stripes = strtoul(pos, &parse_end, 10);
-	}
-	if(parse_end == pos || (*parse_end != 's' && *parse_end != 'S'))
-		goto unknown;
-
-	pos = parse_end + 1;
-	if(*pos == 0)
-		goto done;
-
-	/* <p>p is optional, and p must be an integer */
-	parity = strtoul(pos, &parse_end, 10);
-	if(parse_end == pos || (*parse_end != 'p' && *parse_end != 'P'))
-		goto unknown;
-	pos = parse_end + 1;
-	if(*pos != 0)
-		goto unknown;
-
-done:
-	profile = make_profile(copies, dup, stripes, parity);
-	if(profile == (u64)-1)
-		fprintf(stderr, "Unknown or unavailable profile '%s'\n", s);
-	return profile;
-
-unknown:
-	fprintf(stderr, "Unparseable profile '%s'\n", s);
-	return (u64)-1;
-}
-
 static char *parse_label(char *input)
 {
 	int len = strlen(input);
diff --git a/utils.c b/utils.c
index f68436d..f1d2432 100644
--- a/utils.c
+++ b/utils.c
@@ -1420,6 +1420,100 @@ u64 parse_size(char *s)
 	return strtoull(s, NULL, 10) * mult;
 }
 
+static u64 make_profile(int copies, int dup, int stripes, int parity)
+{
+	if(copies == 1 && !dup && stripes == 0 && parity == 0)
+		return 0;
+	else if(copies == 2 && dup && stripes == 0 && parity == 0)
+		return BTRFS_BLOCK_GROUP_DUP;
+	else if(copies == 2 && !dup && stripes == 0 && parity == 0)
+		return BTRFS_BLOCK_GROUP_RAID1;
+	else if(copies == 2 && !dup && stripes == -1 && parity == 0)
+		return BTRFS_BLOCK_GROUP_RAID10;
+	else if(copies == 1 && !dup && stripes == -1 && parity == 0)
+		return BTRFS_BLOCK_GROUP_RAID0;
+	else if(copies == 1 && !dup && stripes == -1 && parity == 1)
+		return BTRFS_BLOCK_GROUP_RAID5;
+	else if(copies == 1 && !dup && stripes == -1 && parity == 2)
+		return BTRFS_BLOCK_GROUP_RAID6;
+
+	return (u64)-1;
+}
+
+u64 parse_profile(const char *s)
+{
+	char *pos, *parse_end;
+	int copies = 1;
+	int stripes = 0;
+	int parity = 0;
+	int dup = 0;
+	u64 profile = (u64)-1;
+
+	/* Look for exact match with historical forms first */
+	if (strcmp(s, "raid0") == 0) {
+		return BTRFS_BLOCK_GROUP_RAID0;
+	} else if (strcmp(s, "raid1") == 0) {
+		return BTRFS_BLOCK_GROUP_RAID1;
+	} else if (strcmp(s, "raid5") == 0) {
+		return BTRFS_BLOCK_GROUP_RAID5;
+	} else if (strcmp(s, "raid6") == 0) {
+		return BTRFS_BLOCK_GROUP_RAID6;
+	} else if (strcmp(s, "raid10") == 0) {
+		return BTRFS_BLOCK_GROUP_RAID10;
+	} else if (strcmp(s, "dup") == 0) {
+		return BTRFS_BLOCK_GROUP_DUP;
+	} else if (strcmp(s, "single") == 0) {
+		return 0;
+	}
+
+	/* Attempt to parse new ncmspp form */
+	/* <n>c is required and n must be an unsigned decimal number */
+	copies = strtoul(s, &parse_end, 10);
+	if(parse_end == s || (*parse_end != 'c' && *parse_end != 'C'))
+		goto unknown;
+
+	/* c may be followed by d to indicate non-redundant/DUP */
+	pos = parse_end + 1;
+	if(*pos == 'd' || *pos == 'D') {
+		dup = 1;
+		pos++;
+	}
+	if(*pos == 0)
+		goto done;
+
+	/* <m>s is optional, and <m> may be an integer, or a literal "x" */
+	if(*pos == 'x' || *pos == 'X') {
+		stripes = -1;
+		parse_end = pos+1;
+	} else {
+		stripes = strtoul(pos, &parse_end, 10);
+	}
+	if(parse_end == pos || (*parse_end != 's' && *parse_end != 'S'))
+		goto unknown;
+
+	pos = parse_end + 1;
+	if(*pos == 0)
+		goto done;
+
+	/* <p>p is optional, and p must be an integer */
+	parity = strtoul(pos, &parse_end, 10);
+	if(parse_end == pos || (*parse_end != 'p' && *parse_end != 'P'))
+		goto unknown;
+	pos = parse_end + 1;
+	if(*pos != 0)
+		goto unknown;
+
+done:
+	profile = make_profile(copies, dup, stripes, parity);
+	if(profile == (u64)-1)
+		fprintf(stderr, "Unknown or unavailable profile '%s'\n", s);
+	return profile;
+
+unknown:
+	fprintf(stderr, "Unparseable profile '%s'\n", s);
+	return (u64)-1;
+}
+
 int open_file_or_dir(const char *fname)
 {
 	int ret;
diff --git a/utils.h b/utils.h
index 0b681ed..dcaaa7f 100644
--- a/utils.h
+++ b/utils.h
@@ -47,6 +47,7 @@ char *pretty_sizes(u64 size);
 int get_mountpt(char *dev, char *mntpt, size_t size);
 int btrfs_scan_block_devices(int run_ioctl);
 u64 parse_size(char *s);
+u64 parse_profile(const char* s);
 int open_file_or_dir(const char *fname);
 int get_device_info(int fd, u64 devid,
 		    struct btrfs_ioctl_dev_info_args *di_args);
-- 
1.7.10.4


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

* [PATCH v2 3/5] Convert balance filter parser to use common NcMsPp replication-level parser
  2013-03-11 20:17 [PATCH v2 0/5] RAID-level terminology change Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 1/5] Use NcMsPp format for mkfs Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 2/5] Move parse_profile to utils.c Hugo Mills
@ 2013-03-11 20:17 ` Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 4/5] Change output of btrfs fi df to report new (or old) RAID names Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 5/5] Add man page description for NcMsPp replication levels Hugo Mills
  4 siblings, 0 replies; 6+ messages in thread
From: Hugo Mills @ 2013-03-11 20:17 UTC (permalink / raw)
  To: linux-btrfs, Goffredo Baroncelli, Harald Glatt, Roger Binns,
	Martin Steigerwald, Diego Calleja, sam tygier, David Sterba

Balance filters are the second location which takes user input of
replication levels. Update this to use the common parser so that we can
provide nCmSpP-style names.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
 cmds-balance.c |   23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index f5dc317..6186963 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -42,23 +42,16 @@ static const char balance_cmd_group_info[] =
 
 static int parse_one_profile(const char *profile, u64 *flags)
 {
-	if (!strcmp(profile, "raid0")) {
-		*flags |= BTRFS_BLOCK_GROUP_RAID0;
-	} else if (!strcmp(profile, "raid1")) {
-		*flags |= BTRFS_BLOCK_GROUP_RAID1;
-	} else if (!strcmp(profile, "raid10")) {
-		*flags |= BTRFS_BLOCK_GROUP_RAID10;
-	} else if (!strcmp(profile, "raid5")) {
-		*flags |= BTRFS_BLOCK_GROUP_RAID5;
-	} else if (!strcmp(profile, "raid6")) {
-		*flags |= BTRFS_BLOCK_GROUP_RAID6;
-	} else if (!strcmp(profile, "dup")) {
-		*flags |= BTRFS_BLOCK_GROUP_DUP;
-	} else if (!strcmp(profile, "single")) {
-		*flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
-	} else {
+	u64 result;
+
+	result = parse_profile(profile);
+	if (result == (u64)-1) {
 		fprintf(stderr, "Unknown profile '%s'\n", profile);
 		return 1;
+	} else if (result == 0) {
+		*flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
+	} else {
+		*flags |= result;
 	}
 
 	return 0;
-- 
1.7.10.4


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

* [PATCH v2 4/5] Change output of btrfs fi df to report new (or old) RAID names
  2013-03-11 20:17 [PATCH v2 0/5] RAID-level terminology change Hugo Mills
                   ` (2 preceding siblings ...)
  2013-03-11 20:17 ` [PATCH v2 3/5] Convert balance filter parser to use common NcMsPp replication-level parser Hugo Mills
@ 2013-03-11 20:17 ` Hugo Mills
  2013-03-11 20:17 ` [PATCH v2 5/5] Add man page description for NcMsPp replication levels Hugo Mills
  4 siblings, 0 replies; 6+ messages in thread
From: Hugo Mills @ 2013-03-11 20:17 UTC (permalink / raw)
  To: linux-btrfs, Goffredo Baroncelli, Harald Glatt, Roger Binns,
	Martin Steigerwald, Diego Calleja, sam tygier, David Sterba

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
 cmds-filesystem.c |  173 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 152 insertions(+), 21 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 2210020..3150ff7 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <sys/ioctl.h>
 #include <errno.h>
 #include <uuid/uuid.h>
@@ -39,11 +40,129 @@ static const char * const filesystem_cmd_group_usage[] = {
 };
 
 static const char * const cmd_df_usage[] = {
-	"btrfs filesystem df <path>",
+	"btrfs filesystem df [options] <path>",
 	"Show space usage information for a mount point",
+	"",
+	"-r      Use old-style RAID-n terminology",
+	"-e      Explain new-style NcMsPp terminology",
 	NULL
 };
 
+static const char *cmd_df_short_options = "re";
+static const struct option cmd_df_options[] = {
+	{ "raid",    no_argument, NULL, 'r' },
+	{ "explain", no_argument, NULL, 'e' },
+	{ NULL, 0, NULL, 0 }
+};
+
+#define RAID_NAMES_NEW 0
+#define RAID_NAMES_OLD 1
+#define RAID_NAMES_LONG 2
+
+static int write_raid_name(char* buffer, int size, u64 flags, int raid_format)
+{
+	int copies, stripes, parity;
+	int out;
+	int written = 0;
+
+	if (raid_format == RAID_NAMES_OLD) {
+		if (flags & BTRFS_BLOCK_GROUP_RAID0) {
+			return snprintf(buffer, size, "%s", "RAID0");
+		} else if (flags & BTRFS_BLOCK_GROUP_RAID1) {
+			return snprintf(buffer, size, "%s", "RAID1");
+		} else if (flags & BTRFS_BLOCK_GROUP_DUP) {
+			return snprintf(buffer, size, "%s", "DUP");
+		} else if (flags & BTRFS_BLOCK_GROUP_RAID10) {
+			return snprintf(buffer, size, "%s", "RAID10");
+		} else if (flags & BTRFS_BLOCK_GROUP_RAID5) {
+			return snprintf(buffer, size, "%s", "RAID5");
+		} else if (flags & BTRFS_BLOCK_GROUP_RAID6) {
+			return snprintf(buffer, size, "%s", "RAID6");
+		}
+		return 0;
+	}
+
+	if (flags & (BTRFS_BLOCK_GROUP_RAID1
+				 | BTRFS_BLOCK_GROUP_RAID10
+				 | BTRFS_BLOCK_GROUP_DUP)) {
+		copies = 2;
+	} else {
+		copies = 1;
+	}
+
+	if (raid_format == RAID_NAMES_LONG)
+		out = snprintf(buffer, size, "%d copies", copies);
+	else
+		out = snprintf(buffer, size, "%dc", copies);
+	if (size < out)
+		return written + size;
+	written += out;
+	size -= out;
+
+	if (flags & BTRFS_BLOCK_GROUP_DUP) {
+		if (raid_format == RAID_NAMES_LONG)
+			out = snprintf(buffer+written, size, " low redundancy");
+		else
+			out = snprintf(buffer+written, size, "d");
+		if (size < out)
+			return written + size;
+		written += out;
+		size -= out;
+	}
+
+	if (flags & (BTRFS_BLOCK_GROUP_RAID0
+				 | BTRFS_BLOCK_GROUP_RAID10
+				 | BTRFS_BLOCK_GROUP_RAID5
+				 | BTRFS_BLOCK_GROUP_RAID6)) {
+		stripes = -1;
+	} else {
+		stripes = 0;
+	}
+
+	if (stripes == -1) {
+		if (raid_format == RAID_NAMES_LONG)
+			out = snprintf(buffer+written, size, ", fit stripes");
+		else
+			out = snprintf(buffer+written, size, "Xs");
+	} else if (stripes == 0) {
+		out = 0;
+	} else {
+		if (raid_format == RAID_NAMES_LONG)
+			out = snprintf(buffer+written, size, ", %d stripes", stripes);
+		else
+			out = snprintf(buffer+written, size, "%ds", stripes);
+	}
+
+	if (size < out)
+		return written + size;
+	written += out;
+	size -= out;
+
+	if (flags & BTRFS_BLOCK_GROUP_RAID5) {
+		parity = 1;
+	} else if (flags & BTRFS_BLOCK_GROUP_RAID6) {
+		parity = 2;
+	} else {
+		parity = 0;
+	}
+
+	if (parity == 0) {
+		out = 0;
+	} else {
+		if (raid_format == RAID_NAMES_LONG)
+			out = snprintf(buffer+written, size, ", %d parity", parity);
+		else
+			out = snprintf(buffer+written, size, "%dp", parity);
+	}
+
+	if (size < out)
+		return written + size;
+	written += out;
+	size -= out;
+
+	return written;
+}
+
 static int cmd_df(int argc, char **argv)
 {
 	struct btrfs_ioctl_space_args *sargs, *sargs_orig;
@@ -52,11 +171,32 @@ static int cmd_df(int argc, char **argv)
 	int fd;
 	int e;
 	char *path;
+	int raid_format = RAID_NAMES_NEW;
+
+	while (1) {
+		int option_index = 0;
+		int c = getopt_long(argc, argv,
+							cmd_df_short_options, cmd_df_options,
+							&option_index);
+		if (c == -1)
+			break;
 
-	if (check_argc_exact(argc, 2))
+		switch (c) {
+		case 'r':
+			raid_format = RAID_NAMES_OLD;
+			break;
+		case 'e':
+			raid_format = RAID_NAMES_LONG;
+			break;
+		default:
+			usage(cmd_df_usage);
+		}
+	}
+
+	if (check_argc_exact(argc - optind, 1))
 		usage(cmd_df_usage);
 
-	path = argv[1];
+	path = argv[optind];
 
 	fd = open_file_or_dir(path);
 	if (fd < 0) {
@@ -135,24 +275,15 @@ static int cmd_df(int argc, char **argv)
 			written += 8;
 		}
 
-		if (flags & BTRFS_BLOCK_GROUP_RAID0) {
-			snprintf(description+written, 8, "%s", ", RAID0");
-			written += 7;
-		} else if (flags & BTRFS_BLOCK_GROUP_RAID1) {
-			snprintf(description+written, 8, "%s", ", RAID1");
-			written += 7;
-		} else if (flags & BTRFS_BLOCK_GROUP_DUP) {
-			snprintf(description+written, 6, "%s", ", DUP");
-			written += 5;
-		} else if (flags & BTRFS_BLOCK_GROUP_RAID10) {
-			snprintf(description+written, 9, "%s", ", RAID10");
-			written += 8;
-		} else if (flags & BTRFS_BLOCK_GROUP_RAID5) {
-			snprintf(description+written, 9, "%s", ", RAID5");
-			written += 7;
-		} else if (flags & BTRFS_BLOCK_GROUP_RAID6) {
-			snprintf(description+written, 9, "%s", ", RAID6");
-			written += 7;
+		if ((flags & ~(BTRFS_BLOCK_GROUP_DATA
+					   | BTRFS_BLOCK_GROUP_SYSTEM
+					   | BTRFS_BLOCK_GROUP_METADATA)) != 0) {
+			snprintf(description+written, 3, ", ");
+			written += 2;
+			written += write_raid_name(description+written,
+									   sizeof(description)-written,
+									   flags,
+									   raid_format);
 		}
 
 		total_bytes = pretty_sizes(sargs->spaces[i].total_bytes);
-- 
1.7.10.4


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

* [PATCH v2 5/5] Add man page description for NcMsPp replication levels
  2013-03-11 20:17 [PATCH v2 0/5] RAID-level terminology change Hugo Mills
                   ` (3 preceding siblings ...)
  2013-03-11 20:17 ` [PATCH v2 4/5] Change output of btrfs fi df to report new (or old) RAID names Hugo Mills
@ 2013-03-11 20:17 ` Hugo Mills
  4 siblings, 0 replies; 6+ messages in thread
From: Hugo Mills @ 2013-03-11 20:17 UTC (permalink / raw)
  To: linux-btrfs, Goffredo Baroncelli, Harald Glatt, Roger Binns,
	Martin Steigerwald, Diego Calleja, sam tygier, David Sterba

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
 man/btrfs.8.in      |   16 ++++++++++++++++
 man/mkfs.btrfs.8.in |   24 +++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 94f4ffe..4072510 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -25,6 +25,8 @@ btrfs \- control a btrfs filesystem
 [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> \
 [<\fIfile\fR>|<\fIdir\fR>...]
 .PP
+\fBbtrfs\fP \fBfilesystem df\fP [-r|-e]\fI <path> \fP
+.PP
 \fBbtrfs\fP \fBfilesystem sync\fP\fI <path> \fP
 .PP
 \fBbtrfs\fP \fBfilesystem resize\fP\fI [devid:][+/\-]<size>[gkm]|[devid:]max <filesystem>\fP
@@ -217,6 +219,20 @@ don't use it if you use snapshots, have de-duplicated your data or made
 copies with \fBcp --reflink\fP.
 .TP
 
+\fBfilesystem df\fR [-r|-e] \fI<path>\fR
+Show usage information for the filesystem identified by \fI<path>\fR.
+
+\fB-r, --raid\fP Use old-style "RAID-n" terminology to show replication types
+
+\fB-e, --explain\fP Explain the new-style NcMsPp terminology in more
+detail: Nc shows the number of copies of data; a trailing "d"
+indicates reduced device redundancy (e.g. more than one of the copies
+may live on a single device), Ms shows the number of data stripes per
+copy (with "Xs" indicating as many as will fit across the available
+devices), and Pp shows the number of parity stripes.
+
+.TP
+
 \fBfilesystem sync\fR\fI <path> \fR
 Force a sync for the filesystem identified by \fI<path>\fR.
 .TP
diff --git a/man/mkfs.btrfs.8.in b/man/mkfs.btrfs.8.in
index 41163e0..6d1f5d0 100644
--- a/man/mkfs.btrfs.8.in
+++ b/man/mkfs.btrfs.8.in
@@ -37,7 +37,29 @@ mkfs.btrfs uses all the available storage for the filesystem.
 .TP
 \fB\-d\fR, \fB\-\-data \fItype\fR
 Specify how the data must be spanned across the devices specified. Valid
-values are raid0, raid1, raid10 or single.
+values are of the form <n>c[d][<m>s[<p>p]], where <n> is the number of copies
+of data, <m> is the number of stripes per copy, and <p> is the number of parity
+stripes. The <m> parameter must (currently) be a literal "X", indicating that
+as many stripes as possible will be used. The letter "d" may be added to the
+number of copies, to indicate non-redundant copies (e.g. on the same device).
+
+The following deprecated values may also be used:
+.RS 16
+.P
+single	1c
+.P
+raid0	1cXs
+.P
+raid1	2c
+.P
+dup		2cd
+.P
+raid10	2cXsS
+.P
+raid5	1cXs1p
+.P
+raid6	1cXs2p
+.RS -16
 .TP
 \fB\-f\fR
 Force overwrite when an existing filesystem is detected on the device.
-- 
1.7.10.4


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

end of thread, other threads:[~2013-03-11 20:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-11 20:17 [PATCH v2 0/5] RAID-level terminology change Hugo Mills
2013-03-11 20:17 ` [PATCH v2 1/5] Use NcMsPp format for mkfs Hugo Mills
2013-03-11 20:17 ` [PATCH v2 2/5] Move parse_profile to utils.c Hugo Mills
2013-03-11 20:17 ` [PATCH v2 3/5] Convert balance filter parser to use common NcMsPp replication-level parser Hugo Mills
2013-03-11 20:17 ` [PATCH v2 4/5] Change output of btrfs fi df to report new (or old) RAID names Hugo Mills
2013-03-11 20:17 ` [PATCH v2 5/5] Add man page description for NcMsPp replication levels Hugo Mills

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.