btrfs: use btrfs_put_fs_root to free roots always
authorJosef Bacik <josef@toxicpanda.com>
Fri, 24 Jan 2020 14:32:55 +0000 (09:32 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Mar 2020 16:01:32 +0000 (17:01 +0100)
If we are going to track leaked roots we need to free them all the same
way, so don't kfree() roots directly, use btrfs_put_fs_root.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/free-space-tree.c
fs/btrfs/qgroup.c
fs/btrfs/tests/btrfs-tests.c
fs/btrfs/tree-log.c

index 76b8887285403442e5c25027c28a149892272473..5be61619c71b8a8f5bfce4cdf37da5ef6a31be5c 100644 (file)
@@ -1297,7 +1297,7 @@ fail:
                free_extent_buffer(root->commit_root);
                free_extent_buffer(leaf);
        }
-       kfree(root);
+       btrfs_put_fs_root(root);
 
        return ERR_PTR(ret);
 }
@@ -1328,7 +1328,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
        leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID,
                        NULL, 0, 0, 0);
        if (IS_ERR(leaf)) {
-               kfree(root);
+               btrfs_put_fs_root(root);
                return ERR_CAST(leaf);
        }
 
@@ -1431,7 +1431,7 @@ out:
        return root;
 
 find_fail:
-       kfree(root);
+       btrfs_put_fs_root(root);
 alloc_fail:
        root = ERR_PTR(ret);
        goto out;
@@ -1527,17 +1527,17 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
 {
        kfree(fs_info->balance_ctl);
        kfree(fs_info->delayed_root);
-       kfree(fs_info->extent_root);
-       kfree(fs_info->tree_root);
-       kfree(fs_info->chunk_root);
-       kfree(fs_info->dev_root);
-       kfree(fs_info->csum_root);
-       kfree(fs_info->quota_root);
-       kfree(fs_info->uuid_root);
-       kfree(fs_info->free_space_root);
+       btrfs_put_fs_root(fs_info->extent_root);
+       btrfs_put_fs_root(fs_info->tree_root);
+       btrfs_put_fs_root(fs_info->chunk_root);
+       btrfs_put_fs_root(fs_info->dev_root);
+       btrfs_put_fs_root(fs_info->csum_root);
+       btrfs_put_fs_root(fs_info->quota_root);
+       btrfs_put_fs_root(fs_info->uuid_root);
+       btrfs_put_fs_root(fs_info->free_space_root);
+       btrfs_put_fs_root(fs_info->fs_root);
        kfree(fs_info->super_copy);
        kfree(fs_info->super_for_commit);
-       btrfs_put_fs_root(fs_info->fs_root);
        kvfree(fs_info);
 }
 
@@ -2223,12 +2223,12 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
        if (IS_ERR(log_tree_root->node)) {
                btrfs_warn(fs_info, "failed to read log tree");
                ret = PTR_ERR(log_tree_root->node);
-               kfree(log_tree_root);
+               btrfs_put_fs_root(log_tree_root);
                return ret;
        } else if (!extent_buffer_uptodate(log_tree_root->node)) {
                btrfs_err(fs_info, "failed to read log tree");
                free_extent_buffer(log_tree_root->node);
-               kfree(log_tree_root);
+               btrfs_put_fs_root(log_tree_root);
                return -EIO;
        }
        /* returns with log_tree_root freed on success */
@@ -2237,7 +2237,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
                btrfs_handle_fs_error(fs_info, ret,
                                      "Failed to recover log tree");
                free_extent_buffer(log_tree_root->node);
-               kfree(log_tree_root);
+               btrfs_put_fs_root(log_tree_root);
                return ret;
        }
 
index 258cb3fae17ab10a3814595979f794021b3a4ddb..c79804c30b1738c1d6e4a528e88ca323d4a924b6 100644 (file)
@@ -1253,7 +1253,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
 
        free_extent_buffer(free_space_root->node);
        free_extent_buffer(free_space_root->commit_root);
-       kfree(free_space_root);
+       btrfs_put_fs_root(free_space_root);
 
        return btrfs_commit_transaction(trans);
 
index ff1870ff3474a71f1fada625e17effa09917a074..09fc588ab4bf7c9471989071fb78c57b068d7446 100644 (file)
@@ -1040,7 +1040,7 @@ out_free_root:
        if (ret) {
                free_extent_buffer(quota_root->node);
                free_extent_buffer(quota_root->commit_root);
-               kfree(quota_root);
+               btrfs_put_fs_root(quota_root);
        }
 out:
        if (ret) {
@@ -1106,7 +1106,7 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
 
        free_extent_buffer(quota_root->node);
        free_extent_buffer(quota_root->commit_root);
-       kfree(quota_root);
+       btrfs_put_fs_root(quota_root);
 
 end_trans:
        ret = btrfs_end_transaction(trans);
index 84fb3fa940a6bd749af941fcd87ab852fff3ae56..5efd8000e65bd6a7d38980067b58b87d2c9d200c 100644 (file)
@@ -227,7 +227,7 @@ void btrfs_free_dummy_root(struct btrfs_root *root)
                /* One for allocate_extent_buffer */
                free_extent_buffer(root->node);
        }
-       kfree(root);
+       btrfs_put_fs_root(root);
 }
 
 struct btrfs_block_group *
index 169270c931a9f7ae19a159f076592c5ab37d2784..1776ac466f02ba39f18228268afef0137db0841c 100644 (file)
@@ -3289,7 +3289,7 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
        clear_extent_bits(&log->dirty_log_pages, 0, (u64)-1,
                          EXTENT_DIRTY | EXTENT_NEW | EXTENT_NEED_WAIT);
        free_extent_buffer(log->node);
-       kfree(log);
+       btrfs_put_fs_root(log);
 }
 
 /*
@@ -6187,7 +6187,7 @@ again:
                                                        log->node->len);
                        free_extent_buffer(log->node);
                        free_extent_buffer(log->commit_root);
-                       kfree(log);
+                       btrfs_put_fs_root(log);
 
                        if (!ret)
                                goto next;
@@ -6226,7 +6226,7 @@ again:
                btrfs_put_fs_root(wc.replay_dest);
                free_extent_buffer(log->node);
                free_extent_buffer(log->commit_root);
-               kfree(log);
+               btrfs_put_fs_root(log);
 
                if (ret)
                        goto error;
@@ -6260,7 +6260,7 @@ next:
        free_extent_buffer(log_root_tree->node);
        log_root_tree->log_root = NULL;
        clear_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags);
-       kfree(log_root_tree);
+       btrfs_put_fs_root(log_root_tree);
 
        return 0;
 error: