All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 39/44] btrfs: use btrfs_put_fs_root to free roots always
Date: Fri,  6 Dec 2019 09:45:33 -0500	[thread overview]
Message-ID: <20191206144538.168112-40-josef@toxicpanda.com> (raw)
In-Reply-To: <20191206144538.168112-1-josef@toxicpanda.com>

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.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/disk-io.c         | 30 +++++++++++++++---------------
 fs/btrfs/free-space-tree.c |  2 +-
 fs/btrfs/qgroup.c          |  4 ++--
 fs/btrfs/tree-log.c        |  8 ++++----
 4 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 9435d4aa1668..b7a2c570c438 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1299,7 +1299,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
 		free_extent_buffer(root->commit_root);
 		free_extent_buffer(leaf);
 	}
-	kfree(root);
+	btrfs_put_fs_root(root);
 
 	return ERR_PTR(ret);
 }
@@ -1330,7 +1330,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);
 	}
 
@@ -1433,7 +1433,7 @@ struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
 	return root;
 
 find_fail:
-	kfree(root);
+	btrfs_put_fs_root(root);
 alloc_fail:
 	root = ERR_PTR(ret);
 	goto out;
@@ -1529,17 +1529,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);
 }
 
@@ -2220,12 +2220,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 */
@@ -2234,7 +2234,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;
 	}
 
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 258cb3fae17a..c79804c30b17 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -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);
 
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 93aeb2e539a4..762f254b4b38 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1040,7 +1040,7 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info)
 	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);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 07e7fd508213..f2c26e07eedb 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -3296,7 +3296,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);
 }
 
 /*
@@ -6316,7 +6316,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
 							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;
@@ -6355,7 +6355,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
 		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;
@@ -6389,7 +6389,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
 	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:
-- 
2.23.0


  parent reply	other threads:[~2019-12-06 14:46 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 14:44 [PATCH 0/44] Cleanup how we handle root refs, part 1 Josef Bacik
2019-12-06 14:44 ` [PATCH 01/44] btrfs: push __setup_root into btrfs_alloc_root Josef Bacik
2019-12-06 14:44 ` [PATCH 02/44] btrfs: move fs root init stuff into btrfs_init_fs_root Josef Bacik
2019-12-06 14:44 ` [PATCH 03/44] btrfs: make btrfs_find_orphan_roots use btrfs_get_fs_root Josef Bacik
2019-12-06 14:44 ` [PATCH 04/44] btrfs: export and use btrfs_read_tree_root Josef Bacik
2019-12-06 14:44 ` [PATCH 05/44] btrfs: make relocation use btrfs_read_tree_root() Josef Bacik
2019-12-06 14:45 ` [PATCH 06/44] btrfs: kill btrfs_read_fs_root Josef Bacik
2019-12-06 14:45 ` [PATCH 07/44] btrfs: kill the btrfs_read_fs_root_no_name helper Josef Bacik
2019-12-06 14:45 ` [PATCH 08/44] btrfs: make the fs root init functions static Josef Bacik
2019-12-06 14:45 ` [PATCH 09/44] btrfs: handle NULL roots in btrfs_put_fs_root() Josef Bacik
2019-12-06 14:45 ` [PATCH 10/44] btrfs: hold a ref on fs roots while they're in the radix tree Josef Bacik
2019-12-06 14:45 ` [PATCH 11/44] btrfs: hold a ref on the root in resolve_indirect_ref Josef Bacik
2019-12-06 14:45 ` [PATCH 12/44] btrfs: hold a root ref in btrfs_get_dentry Josef Bacik
2019-12-06 14:45 ` [PATCH 13/44] btrfs: hold a ref on the root in __btrfs_run_defrag_inode Josef Bacik
2019-12-06 14:45 ` [PATCH 14/44] btrfs: hold a ref for the root in record_one_backref Josef Bacik
2019-12-06 14:45 ` [PATCH 15/44] btrfs: grab a ref on the root in relink_extent_backref Josef Bacik
2019-12-06 14:45 ` [PATCH 16/44] btrfs: hold a ref on the root in fixup_tree_root_location Josef Bacik
2019-12-06 14:45 ` [PATCH 17/44] btrfs: hold a ref on the root in create_subvol Josef Bacik
2019-12-06 14:45 ` [PATCH 18/44] btrfs: hold a ref on the root in search_ioctl Josef Bacik
2019-12-06 14:45 ` [PATCH 19/44] btrfs: hold a ref on the root in btrfs_search_path_in_tree Josef Bacik
2019-12-06 14:45 ` [PATCH 20/44] btrfs: hold a ref on the root in btrfs_search_path_in_tree_user Josef Bacik
2019-12-06 14:45 ` [PATCH 21/44] btrfs: hold a ref on the root in btrfs_ioctl_get_subvol_info Josef Bacik
2019-12-06 14:45 ` [PATCH 22/44] btrfs: hold ref on root in btrfs_ioctl_default_subvol Josef Bacik
2019-12-06 14:45 ` [PATCH 23/44] btrfs: hold a ref on the root in build_backref_tree Josef Bacik
2019-12-06 14:45 ` [PATCH 24/44] btrfs: hold a ref on the root in prepare_to_merge Josef Bacik
2019-12-06 14:45 ` [PATCH 25/44] btrfs: hold a ref on the root in merge_reloc_roots Josef Bacik
2019-12-06 14:45 ` [PATCH 26/44] btrfs: hold a ref on the root in record_reloc_root_in_trans Josef Bacik
2019-12-06 14:45 ` [PATCH 27/44] btrfs: hold a ref on the root in find_data_references Josef Bacik
2019-12-06 14:45 ` [PATCH 28/44] btrfs: hold a ref on the root in create_reloc_inode Josef Bacik
2019-12-06 14:45 ` [PATCH 29/44] btrfs: hold a ref on the root in btrfs_recover_relocation Josef Bacik
2019-12-06 14:45 ` [PATCH 30/44] btrfs: push grab_fs_root into read_fs_root Josef Bacik
2019-12-06 14:45 ` [PATCH 31/44] btrfs: hold a ref for the root in btrfs_find_orphan_roots Josef Bacik
2019-12-06 14:45 ` [PATCH 32/44] btrfs: hold a ref on the root in scrub_print_warning_inode Josef Bacik
2019-12-06 14:45 ` [PATCH 33/44] btrfs: hold a ref on the root in btrfs_ioctl_send Josef Bacik
2019-12-06 14:45 ` [PATCH 34/44] btrfs: hold a ref on the root in get_subvol_name_from_objectid Josef Bacik
2019-12-06 14:45 ` [PATCH 35/44] btrfs: hold a ref on the root in create_pending_snapshot Josef Bacik
2019-12-06 14:45 ` [PATCH 36/44] btrfs: hold a ref on the root in btrfs_recover_log_trees Josef Bacik
2019-12-06 14:45 ` [PATCH 37/44] btrfs: hold a ref on the root in btrfs_check_uuid_tree_entry Josef Bacik
2019-12-06 14:45 ` [PATCH 38/44] btrfs: hold a ref on the root in open_ctree Josef Bacik
2019-12-06 14:45 ` Josef Bacik [this message]
2019-12-06 14:45 ` [PATCH 40/44] btrfs: push btrfs_grab_fs_root into btrfs_get_fs_root Josef Bacik
2019-12-06 14:45 ` [PATCH 41/44] btrfs: free more things in btrfs_free_fs_info Josef Bacik
2019-12-06 14:45 ` [PATCH 42/44] btrfs: move fs_info init work into it's own helper function Josef Bacik
2019-12-06 14:45 ` [PATCH 43/44] btrfs: add a leak check for roots Josef Bacik
2019-12-06 14:45 ` [PATCH 44/44] btrfs: rename btrfs_put_fs_root and btrfs_grab_fs_root Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191206144538.168112-40-josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.