btrfs-progs: convert: Strictly avoid meta or system chunk allocation
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Fri, 29 Jan 2016 05:03:31 +0000 (13:03 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Jun 2016 16:15:19 +0000 (18:15 +0200)
Before this patch, btrfs-convert only rely on large enough initial
system/metadata chunk size to ensure no newer system/meta chunk will be
created.

But that's not safe enough. So add two new members in fs_info,
avoid_sys/meta_chunk_alloc flags to prevent any newer system or meta
chunks to be created before init_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
btrfs-convert.c
ctree.h
extent-tree.c

index c2616ae..7ec6167 100644 (file)
@@ -2349,6 +2349,13 @@ static int init_btrfs_v2(struct btrfs_mkfs_config *cfg, struct btrfs_root *root,
        struct btrfs_fs_info *fs_info = root->fs_info;
        int ret;
 
+       /*
+        * Don't alloc any metadata/system chunk, as we don't want
+        * any meta/sys chunk allcated before all data chunks are inserted.
+        * Or we screw up the chunk layout just like the old implement.
+        */
+       fs_info->avoid_sys_chunk_alloc = 1;
+       fs_info->avoid_meta_chunk_alloc = 1;
        trans = btrfs_start_transaction(root, 1);
        BUG_ON(!trans);
        ret = btrfs_fix_block_accounting(trans, root);
@@ -2386,6 +2393,8 @@ static int init_btrfs_v2(struct btrfs_mkfs_config *cfg, struct btrfs_root *root,
                goto err;
 
        ret = btrfs_commit_transaction(trans, root);
+       fs_info->avoid_sys_chunk_alloc = 0;
+       fs_info->avoid_meta_chunk_alloc = 0;
 err:
        return ret;
 }
diff --git a/ctree.h b/ctree.h
index cccbd5b..c1534fa 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -1032,6 +1032,8 @@ struct btrfs_fs_info {
        unsigned int suppress_check_block_errors:1;
        unsigned int ignore_fsid_mismatch:1;
        unsigned int ignore_chunk_tree_error:1;
+       unsigned int avoid_meta_chunk_alloc:1;
+       unsigned int avoid_sys_chunk_alloc:1;
 
        int (*free_extent_hook)(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
index 45cb439..f9e4bf2 100644 (file)
@@ -1904,6 +1904,16 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,
            thresh)
                return 0;
 
+       /*
+        * Avoid allocating given chunk type
+        */
+       if (extent_root->fs_info->avoid_meta_chunk_alloc &&
+           (flags & BTRFS_BLOCK_GROUP_METADATA))
+               return 0;
+       if (extent_root->fs_info->avoid_sys_chunk_alloc &&
+           (flags & BTRFS_BLOCK_GROUP_SYSTEM))
+               return 0;
+
        ret = btrfs_alloc_chunk(trans, extent_root, &start, &num_bytes,
                                space_info->flags);
        if (ret == -ENOSPC) {