diff options
author | Anand Jain <anand.jain@oracle.com> | 2013-08-07 20:11:25 +0800 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-10-16 08:20:03 -0400 |
commit | 71d6bd3c8d70fb682c7fd50796f587ce1f1cf6f8 (patch) | |
tree | fb05fe333eef75a04c056c8dfa2398e3175e1f19 /utils.c | |
parent | 1bef332a03c19c0142ffd48e061cac7bdd894e70 (diff) |
btrfs-progs: avoid write to the disk before sure to create fs
This patch provides fix for the following bug,
When mkfs.btrfs fails the disks shouldn't be written.
------------
btrfs fi show /dev/sdb
Label: none uuid: 60fb76f4-3b4d-4632-a7da-6a44dea5573d
Total devices 1 FS bytes used 24.00KiB
devid 1 size 2.00GiB used 20.00MiB path /dev/sdb
mkfs.btrfs -dsingle -mraid1 /dev/sdb -f
::
unable to create FS with metadata profile 16 (have 1 devices)
btrfs fi show /dev/sdb
Label: none uuid: 2da2179d-ecb1-4a4e-a44d-e7613a08c18d
Total devices 1 FS bytes used 24.00KiB
devid 1 size 2.00GiB used 20.00MiB path /dev/sdb
-------------
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -1805,6 +1805,47 @@ out: return ret; } +int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile, + u64 dev_cnt, int mixed, char *estr) +{ + size_t sz = 100; + u64 allowed = 0; + + switch (dev_cnt) { + default: + case 4: + allowed |= BTRFS_BLOCK_GROUP_RAID10; + case 3: + allowed |= BTRFS_BLOCK_GROUP_RAID6; + case 2: + allowed |= BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 | + BTRFS_BLOCK_GROUP_RAID5; + break; + case 1: + allowed |= BTRFS_BLOCK_GROUP_DUP; + } + + if (metadata_profile & ~allowed) { + snprintf(estr, sz, "unable to create FS with metadata " + "profile %llu (have %llu devices)\n", + metadata_profile, dev_cnt); + 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); + return 1; + } + + if (!mixed && (data_profile & BTRFS_BLOCK_GROUP_DUP)) { + snprintf(estr, sz, + "dup for data is allowed only in mixed mode"); + return 1; + } + return 0; +} + /* Check if disk is suitable for btrfs * returns: * 1: something is wrong, estr provides the error |