diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2014-07-04 15:29:17 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2014-08-22 14:43:11 +0200 |
commit | 18e2663db3e18d4506b6fe583ad93fc83235fca9 (patch) | |
tree | 29d84e48bd1ce9afaefd78010177f1191dfb5279 /utils.h | |
parent | b5fc0b90144c37532f68839f36be08e05c0767bf (diff) |
btrfs-progs: Add minimum device size check
Btrfs has global block reservation, so even mkfs.btrfs can execute
without problem, there is still a possibility that the filesystem can't
be mounted.
For example when mkfs.btrfs on a 8M file on x86_64 platform, kernel will
refuse to mount due to ENOSPC, since system block group takes 4M and
mixed block group takes 4M, and global block reservation will takes all
the 4M from mixed block group, which makes btrfs unable to create uuid
tree.
This patch will add minimum device size check before actually mkfs.
The minimum size calculation uses a simplified one:
minimum_size_for_each_dev = 2 * (system block group + global block rsv)
and global block rsv = leafsize << 10
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'utils.h')
-rw-r--r-- | utils.h | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -105,4 +105,26 @@ int get_device_info(int fd, u64 devid, struct btrfs_ioctl_dev_info_args *di_args); int test_uuid_unique(char *fs_uuid); +int test_minimum_size(const char *file, u32 leafsize); + +/* + * Btrfs minimum size calculation is complicated, it should include at least: + * 1. system group size + * 2. minimum global block reserve + * 3. metadata used at mkfs + * 4. space reservation to create uuid for first mount. + * Also, raid factor should also be taken into consideration. + * To avoid the overkill calculation, (system group + global block rsv) * 2 + * for *EACH* device should be good enough. + */ +static inline u64 btrfs_min_global_blk_rsv_size(u32 leafsize) +{ + return leafsize << 10; +} +static inline u64 btrfs_min_dev_size(u32 leafsize) +{ + return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE + + btrfs_min_global_blk_rsv_size(leafsize)); +} + #endif |