btrfs-progs: mkfs: handle block ordering errors in make_btrfs
authorDavid Sterba <dsterba@suse.com>
Tue, 6 Sep 2016 11:52:09 +0000 (13:52 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 21 Sep 2016 12:12:38 +0000 (14:12 +0200)
Signed-off-by: David Sterba <dsterba@suse.com>
utils.c

diff --git a/utils.c b/utils.c
index e164fdd5a8c5b6ddfeaafac130044304d530fca6..8a5c63e7d743d4788aa7c707bf6a2a988e127f41 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1219,8 +1219,21 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg,
                if (!skinny_metadata)
                        item_size += sizeof(struct btrfs_tree_block_info);
 
-               BUG_ON(cfg->blocks[i] < first_free);
-               BUG_ON(cfg->blocks[i] < cfg->blocks[i - 1]);
+               if (cfg->blocks[i] < first_free) {
+                       error("block[%d] below first free: %llu < %llu",
+                                       i, (unsigned long long)cfg->blocks[i],
+                                       (unsigned long long)first_free);
+                       ret = -EINVAL;
+                       goto out;
+               }
+               if (cfg->blocks[i] < cfg->blocks[i - 1]) {
+                       error("blocks %d and %d in reverse order: %llu < %llu",
+                               i, i - 1,
+                               (unsigned long long)cfg->blocks[i],
+                               (unsigned long long)cfg->blocks[i - 1]);
+                       ret = -EINVAL;
+                       goto out;
+               }
 
                /* create extent item */
                itemoff -= item_size;