linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 42/44] btrfs: move fs_info init work into it's own helper function
Date: Fri,  6 Dec 2019 09:45:36 -0500	[thread overview]
Message-ID: <20191206144538.168112-43-josef@toxicpanda.com> (raw)
In-Reply-To: <20191206144538.168112-1-josef@toxicpanda.com>

open_ctree mixes initialization of fs stuff and fs_info stuff, which
makes it confusing when doing things like adding the root leak
detection.  Make a separate function that init's all the static
structures inside of the fs_info needed for the fs to operate, and then
call that before we start setting up the fs_info to be mounted.

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

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index c7163229effc..6151c828a311 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2649,68 +2649,9 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info)
 	return ret;
 }
 
-int __cold open_ctree(struct super_block *sb,
-	       struct btrfs_fs_devices *fs_devices,
-	       char *options)
+static int init_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
 {
-	u32 sectorsize;
-	u32 nodesize;
-	u32 stripesize;
-	u64 generation;
-	u64 features;
-	u16 csum_type;
-	struct btrfs_key location;
-	struct buffer_head *bh;
-	struct btrfs_super_block *disk_super;
-	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
-	struct btrfs_root *tree_root;
-	struct btrfs_root *chunk_root;
 	int ret;
-	int err = -EINVAL;
-	int clear_free_space_tree = 0;
-	int level;
-
-	tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info,
-					BTRFS_ROOT_TREE_OBJECTID, GFP_KERNEL);
-	chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info,
-					BTRFS_CHUNK_TREE_OBJECTID, GFP_KERNEL);
-	if (!tree_root || !chunk_root) {
-		err = -ENOMEM;
-		goto fail;
-	}
-
-	ret = init_srcu_struct(&fs_info->subvol_srcu);
-	if (ret) {
-		err = ret;
-		goto fail;
-	}
-
-	ret = percpu_counter_init(&fs_info->dio_bytes, 0, GFP_KERNEL);
-	if (ret) {
-		err = ret;
-		goto fail_srcu;
-	}
-
-	ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL);
-	if (ret) {
-		err = ret;
-		goto fail_srcu;
-	}
-	fs_info->dirty_metadata_batch = PAGE_SIZE *
-					(1 + ilog2(nr_cpu_ids));
-
-	ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL);
-	if (ret) {
-		err = ret;
-		goto fail_srcu;
-	}
-
-	ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0,
-			GFP_KERNEL);
-	if (ret) {
-		err = ret;
-		goto fail_srcu;
-	}
 
 	INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC);
 	INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC);
@@ -2774,21 +2715,6 @@ int __cold open_ctree(struct super_block *sb,
 	INIT_LIST_HEAD(&fs_info->ordered_roots);
 	spin_lock_init(&fs_info->ordered_root_lock);
 
-	fs_info->btree_inode = new_inode(sb);
-	if (!fs_info->btree_inode) {
-		err = -ENOMEM;
-		goto fail_srcu;
-	}
-	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
-
-	fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root),
-					GFP_KERNEL);
-	if (!fs_info->delayed_root) {
-		err = -ENOMEM;
-		goto fail_iput;
-	}
-	btrfs_init_delayed_root(fs_info->delayed_root);
-
 	btrfs_init_scrub(fs_info);
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
 	fs_info->check_integrity_print_mask = 0;
@@ -2799,8 +2725,6 @@ int __cold open_ctree(struct super_block *sb,
 	sb->s_blocksize = BTRFS_BDEV_BLOCKSIZE;
 	sb->s_blocksize_bits = blksize_bits(BTRFS_BDEV_BLOCKSIZE);
 
-	btrfs_init_btree_inode(fs_info);
-
 	spin_lock_init(&fs_info->block_group_cache_lock);
 	fs_info->block_group_cache_tree = RB_ROOT;
 	fs_info->first_logical_byte = (u64)-1;
@@ -2845,12 +2769,91 @@ int __cold open_ctree(struct super_block *sb,
 
 	fs_info->send_in_progress = 0;
 
+	ret = init_srcu_struct(&fs_info->subvol_srcu);
+	if (ret)
+		return ret;
+
+	ret = percpu_counter_init(&fs_info->dio_bytes, 0, GFP_KERNEL);
+	if (ret)
+		goto fail;
+
+	ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL);
+	if (ret)
+		goto fail;
+
+	fs_info->dirty_metadata_batch = PAGE_SIZE *
+					(1 + ilog2(nr_cpu_ids));
+
+	ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL);
+	if (ret)
+		goto fail;
+
+	ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0,
+			GFP_KERNEL);
+	if (ret)
+		goto fail;
+
+	fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root),
+					GFP_KERNEL);
+	if (!fs_info->delayed_root) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+	btrfs_init_delayed_root(fs_info->delayed_root);
+
 	ret = btrfs_alloc_stripe_hash_table(fs_info);
-	if (ret) {
-		err = ret;
-		goto fail_alloc;
+	if (ret)
+		goto fail;
+
+	return 0;
+fail:
+	cleanup_srcu_struct(&fs_info->subvol_srcu);
+	return ret;
+}
+
+int __cold open_ctree(struct super_block *sb,
+	       struct btrfs_fs_devices *fs_devices,
+	       char *options)
+{
+	u32 sectorsize;
+	u32 nodesize;
+	u32 stripesize;
+	u64 generation;
+	u64 features;
+	u16 csum_type;
+	struct btrfs_key location;
+	struct buffer_head *bh;
+	struct btrfs_super_block *disk_super;
+	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+	struct btrfs_root *tree_root;
+	struct btrfs_root *chunk_root;
+	int ret;
+	int err = -EINVAL;
+	int clear_free_space_tree = 0;
+	int level;
+
+	err = init_fs_info(fs_info, sb);
+	if (err)
+		goto fail;
+
+	/* These need to be init'ed before we start creating inodes and such. */
+	tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info,
+					BTRFS_ROOT_TREE_OBJECTID, GFP_KERNEL);
+	chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info,
+					BTRFS_CHUNK_TREE_OBJECTID, GFP_KERNEL);
+	if (!tree_root || !chunk_root) {
+		err = -ENOMEM;
+		goto fail_srcu;
 	}
 
+	fs_info->btree_inode = new_inode(sb);
+	if (!fs_info->btree_inode) {
+		err = -ENOMEM;
+		goto fail_srcu;
+	}
+	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
+	btrfs_init_btree_inode(fs_info);
+
 	invalidate_bdev(fs_devices->latest_bdev);
 
 	/*
@@ -3357,7 +3360,6 @@ int __cold open_ctree(struct super_block *sb,
 	btrfs_stop_all_workers(fs_info);
 	btrfs_free_block_groups(fs_info);
 fail_alloc:
-fail_iput:
 	btrfs_mapping_tree_free(&fs_info->mapping_tree);
 
 	iput(fs_info->btree_inode);
-- 
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 ` [PATCH 39/44] btrfs: use btrfs_put_fs_root to free roots always Josef Bacik
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 ` Josef Bacik [this message]
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-43-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;
as well as URLs for NNTP newsgroup(s).