From fbb356632c19c9262231e2062d2f708574f794ad Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Sat, 30 May 2015 15:54:48 +0100 Subject: btrfs-progs: mkfs: check metadata redundancy 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 [make the check more visible in mkfs output] Signed-off-by: David Sterba --- utils.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 4b8a8264..eede72f4 100644 --- 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 -- cgit v1.2.3