All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: kernel-team@fb.com, linux-btrfs@vger.kernel.org
Subject: [PATCH 42/44] btrfs: make the init of static elements in fs_info separate
Date: Fri, 24 Jan 2020 09:32:59 -0500	[thread overview]
Message-ID: <20200124143301.2186319-43-josef@toxicpanda.com> (raw)
In-Reply-To: <20200124143301.2186319-1-josef@toxicpanda.com>

In adding things like eb leak checking and root leak checking there were
a lot of weird corner cases that come from the fact that

1) We do not init the fs_info until we get to open_ctree time in the
normal case and

2) The test infrastructure half-init's the fs_info for things that it
needs.

This makes it really annoying to make changes because you have to add
init in two different places, have special cases for testing fs_info's
that may not have certain things init'ed, and cases for fs_info's that
didn't make it to open_ctree and thus are not fully init'ed.

Fix this by extracting out the non-allocating init of the fs info into
it's own public function and use that to make sure we're all getting
consistent views of an allocated fs_info.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/disk-io.c           | 19 +++++++++++--------
 fs/btrfs/disk-io.h           |  1 +
 fs/btrfs/super.c             |  7 +++++--
 fs/btrfs/tests/btrfs-tests.c | 28 ++++------------------------
 4 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b7e4313bdc6f..87bad959b1a5 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2649,10 +2649,8 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info)
 	return ret;
 }
 
-static int init_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
+void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
 {
-	int ret;
-
 	INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC);
 	INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC);
 	INIT_LIST_HEAD(&fs_info->trans_list);
@@ -2696,7 +2694,6 @@ static int init_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
 	atomic_set(&fs_info->reada_works_cnt, 0);
 	atomic_set(&fs_info->nr_delayed_iputs, 0);
 	atomic64_set(&fs_info->tree_mod_seq, 0);
-	fs_info->sb = sb;
 	fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE;
 	fs_info->metadata_ratio = 0;
 	fs_info->defrag_inodes = RB_ROOT;
@@ -2722,9 +2719,6 @@ static int init_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
 	btrfs_init_balance(fs_info);
 	btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work);
 
-	sb->s_blocksize = BTRFS_BDEV_BLOCKSIZE;
-	sb->s_blocksize_bits = blksize_bits(BTRFS_BDEV_BLOCKSIZE);
-
 	spin_lock_init(&fs_info->block_group_cache_lock);
 	fs_info->block_group_cache_tree = RB_ROOT;
 	fs_info->first_logical_byte = (u64)-1;
@@ -2769,6 +2763,15 @@ static int init_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
 	fs_info->swapfile_pins = RB_ROOT;
 
 	fs_info->send_in_progress = 0;
+}
+
+static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
+{
+	int ret;
+
+	fs_info->sb = sb;
+	sb->s_blocksize = BTRFS_BDEV_BLOCKSIZE;
+	sb->s_blocksize_bits = blksize_bits(BTRFS_BDEV_BLOCKSIZE);
 
 	ret = init_srcu_struct(&fs_info->subvol_srcu);
 	if (ret)
@@ -2833,7 +2836,7 @@ int __cold open_ctree(struct super_block *sb,
 	int clear_free_space_tree = 0;
 	int level;
 
-	ret = init_fs_info(fs_info, sb);
+	ret = init_mount_fs_info(fs_info, sb);
 	if (ret) {
 		err = ret;
 		goto fail;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 97e7ac474a52..2414d572bc9a 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -39,6 +39,7 @@ static inline u64 btrfs_sb_offset(int mirror)
 struct btrfs_device;
 struct btrfs_fs_devices;
 
+void btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
 int btrfs_verify_level_key(struct extent_buffer *eb, int level,
 			   struct btrfs_key *first_key, u64 parent_transid);
 struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 8ce292a47634..cf8c49d06a77 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1523,14 +1523,17 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
 	/*
 	 * Setup a dummy root and fs_info for test/set super.  This is because
 	 * we don't actually fill this stuff out until open_ctree, but we need
-	 * it for searching for existing supers, so this lets us do that and
-	 * then open_ctree will properly initialize everything later.
+	 * then open_ctree will properly initialize the file system specific
+	 * settings later.  btrfs_init_fs_info initializes the static elements
+	 * of the fs_info (locks and such) to make cleanup easier if we find a
+	 * superblock with our given fs_devices later on at sget() time.
 	 */
 	fs_info = kvzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL);
 	if (!fs_info) {
 		error = -ENOMEM;
 		goto error_sec_opts;
 	}
+	btrfs_init_fs_info(fs_info);
 
 	fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
 	fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index 27f5b662d2cb..683381a692bc 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -120,6 +120,8 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
 		kfree(fs_info);
 		return NULL;
 	}
+	INIT_LIST_HEAD(&fs_info->fs_devices->devices);
+
 	fs_info->super_copy = kzalloc(sizeof(struct btrfs_super_block),
 				      GFP_KERNEL);
 	if (!fs_info->super_copy) {
@@ -128,6 +130,8 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
 		return NULL;
 	}
 
+	btrfs_init_fs_info(fs_info);
+
 	fs_info->nodesize = nodesize;
 	fs_info->sectorsize = sectorsize;
 
@@ -138,30 +142,6 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
 		return NULL;
 	}
 
-	spin_lock_init(&fs_info->buffer_lock);
-	spin_lock_init(&fs_info->qgroup_lock);
-	spin_lock_init(&fs_info->super_lock);
-	spin_lock_init(&fs_info->fs_roots_radix_lock);
-	spin_lock_init(&fs_info->tree_mod_seq_lock);
-	mutex_init(&fs_info->qgroup_ioctl_lock);
-	mutex_init(&fs_info->qgroup_rescan_lock);
-	rwlock_init(&fs_info->tree_mod_log_lock);
-	fs_info->running_transaction = NULL;
-	fs_info->qgroup_tree = RB_ROOT;
-	fs_info->qgroup_ulist = NULL;
-	atomic64_set(&fs_info->tree_mod_seq, 0);
-	INIT_LIST_HEAD(&fs_info->dirty_qgroups);
-	INIT_LIST_HEAD(&fs_info->dead_roots);
-	INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
-	INIT_LIST_HEAD(&fs_info->fs_devices->devices);
-	INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC);
-	INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC);
-	extent_io_tree_init(fs_info, &fs_info->freed_extents[0],
-			    IO_TREE_FS_INFO_FREED_EXTENTS0, NULL);
-	extent_io_tree_init(fs_info, &fs_info->freed_extents[1],
-			    IO_TREE_FS_INFO_FREED_EXTENTS1, NULL);
-	extent_map_tree_init(&fs_info->mapping_tree);
-	fs_info->pinned_extents = &fs_info->freed_extents[0];
 	set_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
 
 	test_mnt->mnt_sb->s_fs_info = fs_info;
-- 
2.24.1


  parent reply	other threads:[~2020-01-24 14:34 UTC|newest]

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

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=20200124143301.2186319-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 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.