btrfs-progs: mkfs: fix allocation information output of block group types
authorWang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Fri, 1 Jul 2016 05:26:25 +0000 (13:26 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 4 Jul 2016 12:01:04 +0000 (14:01 +0200)
When cleanup_temp_chunks() removes block groups, it forgot to update
mkfs_allocation accordingly, fix this.

Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
[ minor adjustments ]
Signed-off-by: David Sterba <dsterba@suse.com>
mkfs.c

diff --git a/mkfs.c b/mkfs.c
index 697bdc2..9b9fe4c 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -1318,10 +1318,27 @@ static int cleanup_temp_chunks(struct btrfs_fs_info *fs_info,
                if (is_temp_block_group(path->nodes[0], bgi,
                                        data_profile, meta_profile,
                                        sys_profile)) {
+                       u64 flags = btrfs_disk_block_group_flags(path->nodes[0],
+                                                            bgi);
+
                        ret = btrfs_free_block_group(trans, fs_info,
                                        found_key.objectid, found_key.offset);
                        if (ret < 0)
                                goto out;
+
+                       if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+                           BTRFS_BLOCK_GROUP_DATA)
+                               alloc->data -= found_key.offset;
+                       else if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+                                BTRFS_BLOCK_GROUP_METADATA)
+                               alloc->metadata -= found_key.offset;
+                       else if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+                                BTRFS_BLOCK_GROUP_SYSTEM)
+                               alloc->system -= found_key.offset;
+                       else if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+                                (BTRFS_BLOCK_GROUP_METADATA |
+                                 BTRFS_BLOCK_GROUP_DATA))
+                               alloc->mixed -= found_key.offset;
                }
                btrfs_release_path(path);
                key.objectid = found_key.objectid + found_key.offset;