public inbox for linux-btrfs@vger.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/43] btrfs: free more things in btrfs_free_fs_info
Date: Fri, 17 Jan 2020 08:47:54 -0500	[thread overview]
Message-ID: <20200117134758.41494-40-josef@toxicpanda.com> (raw)
In-Reply-To: <20200117134758.41494-1-josef@toxicpanda.com>

Things like the percpu_counters, the mapping_tree, and the csum hash can
all be free'd at btrfs_free_fs_info time, since the helpers all check if
the structure has been init'ed already.  This significantly cleans up
the error cases in open_ctree.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/disk-io.c | 60 +++++++++++++++++++---------------------------
 1 file changed, 24 insertions(+), 36 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ac306807e5cd..d8adc9c6d8ea 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -98,6 +98,12 @@ void __cold btrfs_end_io_wq_exit(void)
 	kmem_cache_destroy(btrfs_end_io_wq_cache);
 }
 
+static void btrfs_free_csum_hash(struct btrfs_fs_info *fs_info)
+{
+	if (fs_info->csum_shash)
+		crypto_free_shash(fs_info->csum_shash);
+}
+
 /*
  * async submit bios are used to offload expensive checksumming
  * onto the worker threads.  They checksum file and metadata bios
@@ -1527,6 +1533,13 @@ int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info,
 
 void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
 {
+	percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
+	percpu_counter_destroy(&fs_info->delalloc_bytes);
+	percpu_counter_destroy(&fs_info->dio_bytes);
+	percpu_counter_destroy(&fs_info->dev_replace.bio_counter);
+	btrfs_free_csum_hash(fs_info);
+	btrfs_free_stripe_hash_table(fs_info);
+	btrfs_free_ref_cache(fs_info);
 	kfree(fs_info->balance_ctl);
 	kfree(fs_info->delayed_root);
 	btrfs_put_fs_root(fs_info->extent_root);
@@ -2207,11 +2220,6 @@ static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type)
 	return 0;
 }
 
-static void btrfs_free_csum_hash(struct btrfs_fs_info *fs_info)
-{
-	crypto_free_shash(fs_info->csum_shash);
-}
-
 static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
 			    struct btrfs_fs_devices *fs_devices)
 {
@@ -2686,7 +2694,7 @@ int __cold open_ctree(struct super_block *sb,
 	ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL);
 	if (ret) {
 		err = ret;
-		goto fail_dio_bytes;
+		goto fail_srcu;
 	}
 	fs_info->dirty_metadata_batch = PAGE_SIZE *
 					(1 + ilog2(nr_cpu_ids));
@@ -2694,14 +2702,14 @@ int __cold open_ctree(struct super_block *sb,
 	ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL);
 	if (ret) {
 		err = ret;
-		goto fail_dirty_metadata_bytes;
+		goto fail_srcu;
 	}
 
 	ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0,
 			GFP_KERNEL);
 	if (ret) {
 		err = ret;
-		goto fail_delalloc_bytes;
+		goto fail_srcu;
 	}
 
 	INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC);
@@ -2769,7 +2777,7 @@ int __cold open_ctree(struct super_block *sb,
 	fs_info->btree_inode = new_inode(sb);
 	if (!fs_info->btree_inode) {
 		err = -ENOMEM;
-		goto fail_bio_counter;
+		goto fail_srcu;
 	}
 	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
 
@@ -2882,7 +2890,7 @@ int __cold open_ctree(struct super_block *sb,
 		btrfs_err(fs_info, "superblock checksum mismatch");
 		err = -EINVAL;
 		brelse(bh);
-		goto fail_csum;
+		goto fail_alloc;
 	}
 
 	/*
@@ -2919,11 +2927,11 @@ int __cold open_ctree(struct super_block *sb,
 	if (ret) {
 		btrfs_err(fs_info, "superblock contains fatal errors");
 		err = -EINVAL;
-		goto fail_csum;
+		goto fail_alloc;
 	}
 
 	if (!btrfs_super_root(disk_super))
-		goto fail_csum;
+		goto fail_alloc;
 
 	/* check FS state, whether FS is broken. */
 	if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_ERROR)
@@ -2938,7 +2946,7 @@ int __cold open_ctree(struct super_block *sb,
 	ret = btrfs_parse_options(fs_info, options, sb->s_flags);
 	if (ret) {
 		err = ret;
-		goto fail_csum;
+		goto fail_alloc;
 	}
 
 	features = btrfs_super_incompat_flags(disk_super) &
@@ -2948,7 +2956,7 @@ int __cold open_ctree(struct super_block *sb,
 		    "cannot mount because of unsupported optional features (%llx)",
 		    features);
 		err = -EINVAL;
-		goto fail_csum;
+		goto fail_alloc;
 	}
 
 	features = btrfs_super_incompat_flags(disk_super);
@@ -2992,7 +3000,7 @@ int __cold open_ctree(struct super_block *sb,
 		btrfs_err(fs_info,
 "unequal nodesize/sectorsize (%u != %u) are not allowed for mixed block groups",
 			nodesize, sectorsize);
-		goto fail_csum;
+		goto fail_alloc;
 	}
 
 	/*
@@ -3008,7 +3016,7 @@ int __cold open_ctree(struct super_block *sb,
 	"cannot mount read-write because of unsupported optional features (%llx)",
 		       features);
 		err = -EINVAL;
-		goto fail_csum;
+		goto fail_alloc;
 	}
 
 	ret = btrfs_init_workqueues(fs_info, fs_devices);
@@ -3343,25 +3351,14 @@ int __cold open_ctree(struct super_block *sb,
 fail_sb_buffer:
 	btrfs_stop_all_workers(fs_info);
 	btrfs_free_block_groups(fs_info);
-fail_csum:
-	btrfs_free_csum_hash(fs_info);
 fail_alloc:
 fail_iput:
 	btrfs_mapping_tree_free(&fs_info->mapping_tree);
 
 	iput(fs_info->btree_inode);
-fail_bio_counter:
-	percpu_counter_destroy(&fs_info->dev_replace.bio_counter);
-fail_delalloc_bytes:
-	percpu_counter_destroy(&fs_info->delalloc_bytes);
-fail_dirty_metadata_bytes:
-	percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
-fail_dio_bytes:
-	percpu_counter_destroy(&fs_info->dio_bytes);
 fail_srcu:
 	cleanup_srcu_struct(&fs_info->subvol_srcu);
 fail:
-	btrfs_free_stripe_hash_table(fs_info);
 	btrfs_close_devices(fs_info->fs_devices);
 	return err;
 }
@@ -4061,16 +4058,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
 
 	btrfs_mapping_tree_free(&fs_info->mapping_tree);
 	btrfs_close_devices(fs_info->fs_devices);
-
-	percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
-	percpu_counter_destroy(&fs_info->delalloc_bytes);
-	percpu_counter_destroy(&fs_info->dio_bytes);
-	percpu_counter_destroy(&fs_info->dev_replace.bio_counter);
 	cleanup_srcu_struct(&fs_info->subvol_srcu);
-
-	btrfs_free_csum_hash(fs_info);
-	btrfs_free_stripe_hash_table(fs_info);
-	btrfs_free_ref_cache(fs_info);
 }
 
 int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
-- 
2.24.1


  parent reply	other threads:[~2020-01-17 13:49 UTC|newest]

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

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=20200117134758.41494-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox