diff mbox series

[v4,3/7] btrfs: block-group: Refactor how we delete one block group item

Message ID 20200504235825.4199-4-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: Introduce new incompat feature SKINNY_BG_TREE to hugely reduce mount time | expand

Commit Message

Qu Wenruo May 4, 2020, 11:58 p.m. UTC
When deleting a block group item, it's pretty straight forward, just
delete the item pointed by the key.

However it will not be that straight-forward for incoming skinny block
group item.

So refactor the block group item deletion into a new function,
remove_block_group_item(), also to make the already lengthy
btrfs_remove_block_group() a little shorter.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/block-group.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

Comments

Johannes Thumshirn May 5, 2020, 8:47 a.m. UTC | #1
On 05/05/2020 01:58, Qu Wenruo wrote:
> When deleting a block group item, it's pretty straight forward, just
> delete the item pointed by the key.
> 
> However it will not be that straight-forward for incoming skinny block
> group item.
> 
> So refactor the block group item deletion into a new function,
> remove_block_group_item(), also to make the already lengthy
> btrfs_remove_block_group() a little shorter.

I think this patch is useful even without the skinny_bg feature.

> +static int remove_block_group_item(struct btrfs_trans_handle *trans,
> +				   struct btrfs_path *path,
> +				   struct btrfs_block_group *block_group)
> +{
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
> +	struct btrfs_root *root;

Tiny nitpick, why not:

	struct btrfs_root *root = fs_info->extent_root;

Like it was in brtfs_remove_block_group()?

Anyways looks good to me,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Qu Wenruo May 5, 2020, 8:55 a.m. UTC | #2
On 2020/5/5 下午4:47, Johannes Thumshirn wrote:
> On 05/05/2020 01:58, Qu Wenruo wrote:
>> When deleting a block group item, it's pretty straight forward, just
>> delete the item pointed by the key.
>>
>> However it will not be that straight-forward for incoming skinny block
>> group item.
>>
>> So refactor the block group item deletion into a new function,
>> remove_block_group_item(), also to make the already lengthy
>> btrfs_remove_block_group() a little shorter.
> 
> I think this patch is useful even without the skinny_bg feature.
> 
>> +static int remove_block_group_item(struct btrfs_trans_handle *trans,
>> +				   struct btrfs_path *path,
>> +				   struct btrfs_block_group *block_group)
>> +{
>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>> +	struct btrfs_root *root;
> 
> Tiny nitpick, why not:
> 
> 	struct btrfs_root *root = fs_info->extent_root;
> 
> Like it was in brtfs_remove_block_group()?

That's mostly for the skinny_bg_tree (6th) patch, as in that patch,
skinny_bg_tree feature goes to pick bg_root other than extent root.

So I didn't initialize root here, but leaves it assigned the same timing
as key.

Thanks,
Qu

> 
> Anyways looks good to me,
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>
Johannes Thumshirn May 5, 2020, 8:56 a.m. UTC | #3
On 05/05/2020 10:55, Qu Wenruo wrote:
> That's mostly for the skinny_bg_tree (6th) patch, as in that patch,
> skinny_bg_tree feature goes to pick bg_root other than extent root.
> 
> So I didn't initialize root here, but leaves it assigned the same timing
> as key.


Ah OK I'm not this far in the patchset.
diff mbox series

Patch

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 57483ea07d51..914b1c2064ac 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -865,11 +865,34 @@  static void clear_incompat_bg_bits(struct btrfs_fs_info *fs_info, u64 flags)
 	}
 }
 
+static int remove_block_group_item(struct btrfs_trans_handle *trans,
+				   struct btrfs_path *path,
+				   struct btrfs_block_group *block_group)
+{
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+	struct btrfs_root *root;
+	struct btrfs_key key;
+	int ret;
+
+	root = fs_info->extent_root;
+	key.objectid = block_group->start;
+	key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
+	key.offset = block_group->length;
+
+	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
+	if (ret > 0)
+		ret = -ENOENT;
+	if (ret < 0)
+		return ret;
+
+	ret = btrfs_del_item(trans, root, path);
+	return ret;
+}
+
 int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 			     u64 group_start, struct extent_map *em)
 {
 	struct btrfs_fs_info *fs_info = trans->fs_info;
-	struct btrfs_root *root = fs_info->extent_root;
 	struct btrfs_path *path;
 	struct btrfs_block_group *block_group;
 	struct btrfs_free_cluster *cluster;
@@ -1067,10 +1090,6 @@  int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 
 	spin_unlock(&block_group->space_info->lock);
 
-	key.objectid = block_group->start;
-	key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
-	key.offset = block_group->length;
-
 	mutex_lock(&fs_info->chunk_mutex);
 	spin_lock(&block_group->lock);
 	block_group->removed = 1;
@@ -1109,16 +1128,10 @@  int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 	/* Once for the block groups rbtree */
 	btrfs_put_block_group(block_group);
 
-	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
-	if (ret > 0)
-		ret = -EIO;
+	ret = remove_block_group_item(trans, path, block_group);
 	if (ret < 0)
 		goto out;
 
-	ret = btrfs_del_item(trans, root, path);
-	if (ret)
-		goto out;
-
 	if (remove_em) {
 		struct extent_map_tree *em_tree;