btrfs-progs: provide better error message for raid profile mismatch
authorHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Fri, 16 May 2014 08:20:56 +0000 (17:20 +0900)
committerDavid Sterba <dsterba@suse.cz>
Thu, 4 Dec 2014 15:48:12 +0000 (16:48 +0100)
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>
Signed-off-by: David Sterba <dsterba@suse.cz>
utils.c

diff --git a/utils.c b/utils.c
index 1fb2377..3fd8092 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -2084,6 +2084,25 @@ out:
        return ret;
 }
 
+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)
 {
@@ -2104,16 +2123,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 has 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",
+                       btrfs_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",
+                       btrfs_group_profile_str(data_profile), dev_cnt,
+                       group_profile_devs_min(data_profile));
                return 1;
        }