linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: provide better error message for raid profile mismatch
@ 2014-05-16  8:20 Hidetoshi Seto
  2014-05-28 16:53 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Hidetoshi Seto @ 2014-05-16  8:20 UTC (permalink / raw)
  To: linux-btrfs

Current error messages are like following:
  Error: unable to create FS with metadata profile 32 (have 2 devices)
  Error: unable to create FS with metadata profile 256 (have 2 devices)

Obviously it is hard for users to interpret "profile XX" to proper
meaning, such as "raidN". So use recongizable string instead of
internal numerical value. In case of "dup", use an explicit message.

Plus this patch fix a bug that message mistake metadata profile
for data profile.

After applying this patch, messages will be like:
  Error: dup is not allowed when FS have multiple devices
  Error: unable to create FS with metadata profile RAID6 (have 2
  devices but 3 devices are required)

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
---
 cmds-filesystem.c |   22 ------------------
 utils.c           |   63 +++++++++++++++++++++++++++++++++++++++++++++++-----
 utils.h           |    1 +
 3 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index bd9ba66..400e8d9 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -134,28 +134,6 @@ static char *group_type_str(u64 flag)
 	}
 }
 
-static char *group_profile_str(u64 flag)
-{
-	switch (flag & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
-	case 0:
-		return "single";
-	case BTRFS_BLOCK_GROUP_RAID0:
-		return "RAID0";
-	case BTRFS_BLOCK_GROUP_RAID1:
-		return "RAID1";
-	case BTRFS_BLOCK_GROUP_RAID5:
-		return "RAID5";
-	case BTRFS_BLOCK_GROUP_RAID6:
-		return "RAID6";
-	case BTRFS_BLOCK_GROUP_DUP:
-		return "DUP";
-	case BTRFS_BLOCK_GROUP_RAID10:
-		return "RAID10";
-	default:
-		return "unknown";
-	}
-}
-
 static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
 {
 	u64 count = 0;
diff --git a/utils.c b/utils.c
index 3e9c527..3f5d328 100644
--- a/utils.c
+++ b/utils.c
@@ -1943,6 +1943,47 @@ out:
 	return ret;
 }
 
+char *group_profile_str(u64 flag)
+{
+	switch (flag & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
+	case 0:
+		return "single";
+	case BTRFS_BLOCK_GROUP_RAID0:
+		return "RAID0";
+	case BTRFS_BLOCK_GROUP_RAID1:
+		return "RAID1";
+	case BTRFS_BLOCK_GROUP_RAID5:
+		return "RAID5";
+	case BTRFS_BLOCK_GROUP_RAID6:
+		return "RAID6";
+	case BTRFS_BLOCK_GROUP_DUP:
+		return "DUP";
+	case BTRFS_BLOCK_GROUP_RAID10:
+		return "RAID10";
+	default:
+		return "unknown";
+	}
+}
+
+static int group_profile_devs_min(u64 flag)
+{
+	switch (flag & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
+	case 0: /* single */
+	case BTRFS_BLOCK_GROUP_DUP:
+		return 1;
+	case BTRFS_BLOCK_GROUP_RAID0:
+	case BTRFS_BLOCK_GROUP_RAID1:
+	case BTRFS_BLOCK_GROUP_RAID5:
+		return 2;
+	case BTRFS_BLOCK_GROUP_RAID6:
+		return 3;
+	case BTRFS_BLOCK_GROUP_RAID10:
+		return 4;
+	default:
+		return -1;
+	}
+}
+
 int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
 	u64 dev_cnt, int mixed, char *estr)
 {
@@ -1963,16 +2004,26 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
 		allowed |= BTRFS_BLOCK_GROUP_DUP;
 	}
 
+	if (dev_cnt > 1 &&
+	    ((metadata_profile | data_profile) & BTRFS_BLOCK_GROUP_DUP)) {
+		snprintf(estr, sz,
+			"dup is not allowed when FS have multiple devices\n");
+		return 1;
+	}
 	if (metadata_profile & ~allowed) {
-		snprintf(estr, sz, "unable to create FS with metadata "
-			"profile %llu (have %llu devices)\n",
-			metadata_profile, dev_cnt);
+		snprintf(estr, sz,
+			"unable to create FS with metadata profile %s "
+			"(have %llu devices but %d devices are required)\n",
+			group_profile_str(metadata_profile), dev_cnt,
+			group_profile_devs_min(metadata_profile));
 		return 1;
 	}
 	if (data_profile & ~allowed) {
-		snprintf(estr, sz, "unable to create FS with data "
-			"profile %llu (have %llu devices)\n",
-			metadata_profile, dev_cnt);
+		snprintf(estr, sz,
+			"unable to create FS with data profile %s "
+			"(have %llu devices but %d devices are required)\n",
+			group_profile_str(data_profile), dev_cnt,
+			group_profile_devs_min(data_profile));
 		return 1;
 	}
 
diff --git a/utils.h b/utils.h
index 3c62066..af5dd84 100644
--- a/utils.h
+++ b/utils.h
@@ -88,6 +88,7 @@ u64 btrfs_device_size(int fd, struct stat *st);
 int test_dev_for_mkfs(char *file, int force_overwrite, char *estr);
 int scan_for_btrfs(int where, int update_kernel);
 int get_label_mounted(const char *mount_path, char *labelp);
+char *group_profile_str(u64 flag);
 int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
 	u64 dev_cnt, int mixed, char *estr);
 int is_vol_small(char *file);
-- 
1.7.1



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

* Re: [PATCH] btrfs-progs: provide better error message for raid profile mismatch
  2014-05-16  8:20 [PATCH] btrfs-progs: provide better error message for raid profile mismatch Hidetoshi Seto
@ 2014-05-28 16:53 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2014-05-28 16:53 UTC (permalink / raw)
  To: Hidetoshi Seto; +Cc: linux-btrfs

On Fri, May 16, 2014 at 05:20:56PM +0900, Hidetoshi Seto wrote:
> Current error messages are like following:
>   Error: unable to create FS with metadata profile 32 (have 2 devices)
>   Error: unable to create FS with metadata profile 256 (have 2 devices)
> 
> Obviously it is hard for users to interpret "profile XX" to proper
> meaning, such as "raidN". So use recongizable string instead of
> internal numerical value. In case of "dup", use an explicit message.
> 
> Plus this patch fix a bug that message mistake metadata profile
> for data profile.
> 
> After applying this patch, messages will be like:
>   Error: dup is not allowed when FS have multiple devices
>   Error: unable to create FS with metadata profile RAID6 (have 2
>   devices but 3 devices are required)

Nice, thanks.

Moving the group_profile_* functions to utils.c was done in "Enhance
the command btrfs filesystem df", so your patch ends up a bit shorter.

I've modified the 'dup' to be 'DUP' in the error message and changelog
so it's consistent with spelling of the RAIDx names.

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

end of thread, other threads:[~2014-05-28 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-16  8:20 [PATCH] btrfs-progs: provide better error message for raid profile mismatch Hidetoshi Seto
2014-05-28 16:53 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).