summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2014-07-04 15:29:17 +0800
committerDavid Sterba <dsterba@suse.cz>2014-08-22 14:43:11 +0200
commit18e2663db3e18d4506b6fe583ad93fc83235fca9 (patch)
tree29d84e48bd1ce9afaefd78010177f1191dfb5279 /utils.c
parentb5fc0b90144c37532f68839f36be08e05c0767bf (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.c')
-rw-r--r--utils.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 46c3a431..c139eb2e 100644
--- a/utils.c
+++ b/utils.c
@@ -2344,3 +2344,23 @@ int find_mount_root(const char *path, char **mount_root)
free(longest_match);
return ret;
}
+
+int test_minimum_size(const char *file, u32 leafsize)
+{
+ int fd;
+ struct stat statbuf;
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0)
+ return -errno;
+ if (stat(file, &statbuf) < 0) {
+ close(fd);
+ return -errno;
+ }
+ if (btrfs_device_size(fd, &statbuf) < btrfs_min_dev_size(leafsize)) {
+ close(fd);
+ return 1;
+ }
+ close(fd);
+ return 0;
+}