btrfs-progs: mkfs: check metadata redundancy
authorSam Tygier <samtygier@yahoo.co.uk>
Sat, 30 May 2015 14:54:48 +0000 (15:54 +0100)
committerDavid Sterba <dsterba@suse.cz>
Tue, 2 Jun 2015 15:02:19 +0000 (17:02 +0200)
Currently BTRFS allows you to make bad choices of data and
metadata levels. For example -d raid1 -m raid0 means you can
only use half your total disk space, but will lose everything
if 1 disk fails. It should give a warning in these cases.

When making a filesystem, check that metadata mode is at least
as redundant as the data mode. For example give warning when:

-d raid1 -m raid0

Signed-off-by: Sam Tygier <samtygier@yahoo.co.uk>
[make the check more visible in mkfs output]
Signed-off-by: David Sterba <dsterba@suse.cz>
mkfs.c
utils.c
utils.h

diff --git a/mkfs.c b/mkfs.c
index c16aeb9..83c4a6a 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -1429,6 +1429,12 @@ int main(int ac, char **av)
                        nodesize * i;
        }
 
+       if (group_profile_max_safe_loss(metadata_profile) <
+               group_profile_max_safe_loss(data_profile)){
+               fprintf(stderr,
+                       "WARNING: metatdata has lower redundancy than data!\n\n");
+       }
+
        /*
         * FS features that can be set by other means than -O
         * just set the bit here
diff --git a/utils.c b/utils.c
index 4b8a826..eede72f 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -2354,6 +2354,24 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
        return 0;
 }
 
+int group_profile_max_safe_loss(u64 flags)
+{
+       switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
+       case 0: /* single */
+       case BTRFS_BLOCK_GROUP_DUP:
+       case BTRFS_BLOCK_GROUP_RAID0:
+               return 0;
+       case BTRFS_BLOCK_GROUP_RAID1:
+       case BTRFS_BLOCK_GROUP_RAID5:
+       case BTRFS_BLOCK_GROUP_RAID10:
+               return 1;
+       case BTRFS_BLOCK_GROUP_RAID6:
+               return 2;
+       default:
+               return -1;
+       }
+}
+
 /* Check if disk is suitable for btrfs
  * returns:
  *  1: something is wrong, estr provides the error
diff --git a/utils.h b/utils.h
index 5657c74..a0057de 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -144,6 +144,7 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr);
 int get_label_mounted(const char *mount_path, char *labelp);
 int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
        u64 dev_cnt, int mixed, char *estr);
+int group_profile_max_safe_loss(u64 flags);
 int is_vol_small(char *file);
 int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
                           int verify);