Commit 69e293d2 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba
Browse files

btrfs: use single return value variable in btrfs_relocate_block_group()



We are using 'ret' and 'err' variables to track return values and errors,
which is pattern that is error prone and we had quite some bugs due to
this pattern in the past.

Simplify this and use a single variable, named 'ret', to track errors and
the return value.

Also rename the variable 'rw' to 'bg_is_ro' which is more meaningful name,
and change its type from int to bool.

Reviewed-by: default avatarBoris Burkov <boris@bur.io>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 828ec765
Loading
Loading
Loading
Loading
+16 −23
Original line number Diff line number Diff line
@@ -3882,8 +3882,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start,
	struct inode *inode;
	struct btrfs_path *path;
	int ret;
	int rw = 0;
	int err = 0;
	bool bg_is_ro = false;

	/*
	 * This only gets set if we had a half-deleted snapshot on mount.  We
@@ -3925,24 +3924,20 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start,
	}

	ret = reloc_chunk_start(fs_info);
	if (ret < 0) {
		err = ret;
	if (ret < 0)
		goto out_put_bg;
	}

	rc->extent_root = extent_root;
	rc->block_group = bg;

	ret = btrfs_inc_block_group_ro(rc->block_group, true);
	if (ret) {
		err = ret;
	if (ret)
		goto out;
	}
	rw = 1;
	bg_is_ro = true;

	path = btrfs_alloc_path();
	if (!path) {
		err = -ENOMEM;
		ret = -ENOMEM;
		goto out;
	}

@@ -3954,14 +3949,12 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start,
	else
		ret = PTR_ERR(inode);

	if (ret && ret != -ENOENT) {
		err = ret;
	if (ret && ret != -ENOENT)
		goto out;
	}

	rc->data_inode = create_reloc_inode(rc->block_group);
	if (IS_ERR(rc->data_inode)) {
		err = PTR_ERR(rc->data_inode);
		ret = PTR_ERR(rc->data_inode);
		rc->data_inode = NULL;
		goto out;
	}
@@ -3982,8 +3975,6 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start,
		mutex_lock(&fs_info->cleaner_mutex);
		ret = relocate_block_group(rc);
		mutex_unlock(&fs_info->cleaner_mutex);
		if (ret < 0)
			err = ret;

		finishes_stage = rc->stage;
		/*
@@ -3996,16 +3987,18 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start,
		 * out of the loop if we hit an error.
		 */
		if (rc->stage == MOVE_DATA_EXTENTS && rc->found_file_extent) {
			ret = btrfs_wait_ordered_range(BTRFS_I(rc->data_inode), 0,
			int wb_ret;

			wb_ret = btrfs_wait_ordered_range(BTRFS_I(rc->data_inode), 0,
							  (u64)-1);
			if (ret)
				err = ret;
			if (wb_ret && ret == 0)
				ret = wb_ret;
			invalidate_mapping_pages(rc->data_inode->i_mapping,
						 0, -1);
			rc->stage = UPDATE_DATA_PTRS;
		}

		if (err < 0)
		if (ret < 0)
			goto out;

		if (rc->extents_found == 0)
@@ -4021,14 +4014,14 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start,
	WARN_ON(rc->block_group->reserved > 0);
	WARN_ON(rc->block_group->used > 0);
out:
	if (err && rw)
	if (ret && bg_is_ro)
		btrfs_dec_block_group_ro(rc->block_group);
	iput(rc->data_inode);
	reloc_chunk_end(fs_info);
out_put_bg:
	btrfs_put_block_group(bg);
	free_reloc_control(rc);
	return err;
	return ret;
}

static noinline_for_stack int mark_garbage_root(struct btrfs_root *root)