summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>2014-05-16 17:20:56 +0900
committerDavid Sterba <dsterba@suse.cz>2014-12-04 16:48:12 +0100
commit373110d84f3a1c5bdd305d2e6dcaeb98b5e6dbe7 (patch)
tree651a061d10abd102fcc90a4da6919b9f82aaec2e /utils.c
parent3ab60c6a624b64a3bdd8952d49f0683054fdee10 (diff)
btrfs-progs: provide better error message for raid profile mismatch
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>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/utils.c b/utils.c
index 1fb23776..3fd8092a 100644
--- 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;
}