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 loose 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
V1 -> V2 Downgrade from error to warning as requested by David
Sterba.
Signed-off-by: Sam Tygier <samtygier@xxxxxxxxxxx>
>From fdfcb5f733ff5ed48562366bda6f1a9c740b031a Mon Sep 17 00:00:00 2001
From: Sam Tygier <samtygier@xxxxxxxxxxx>
Date: Sat, 30 May 2015 15:37:37 +0100
Subject: [PATCH] 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
---
mkfs.c | 6 ++++++
utils.c | 18 ++++++++++++++++++
utils.h | 1 +
3 files changed, 25 insertions(+)
diff --git a/mkfs.c b/mkfs.c
index 14e0fed..938840d 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1367,6 +1367,12 @@ int main(int ac, char **av)
exit(1);
}
+ 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");
+ }
+
/* if we are here that means all devs are good to btrfsify */
printf("%s\n", PACKAGE_STRING);
printf("See %s for more information.\n\n", PACKAGE_URL);
diff --git a/utils.c b/utils.c
index 4b8a826..ba35b34 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 flag)
+{
+ switch (flag & 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..98fd812 100644
--- 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 flag);
int is_vol_small(char *file);
int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
int verify);
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html