Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Boris Burkov <boris@bur.io>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Filipe Manana and committed by
David Sterba
69e293d2 828ec765

+16 -23
+16 -23
fs/btrfs/relocation.c
··· 3882 3882 struct inode *inode; 3883 3883 struct btrfs_path *path; 3884 3884 int ret; 3885 - int rw = 0; 3886 - int err = 0; 3885 + bool bg_is_ro = false; 3887 3886 3888 3887 /* 3889 3888 * This only gets set if we had a half-deleted snapshot on mount. We ··· 3924 3925 } 3925 3926 3926 3927 ret = reloc_chunk_start(fs_info); 3927 - if (ret < 0) { 3928 - err = ret; 3928 + if (ret < 0) 3929 3929 goto out_put_bg; 3930 - } 3931 3930 3932 3931 rc->extent_root = extent_root; 3933 3932 rc->block_group = bg; 3934 3933 3935 3934 ret = btrfs_inc_block_group_ro(rc->block_group, true); 3936 - if (ret) { 3937 - err = ret; 3935 + if (ret) 3938 3936 goto out; 3939 - } 3940 - rw = 1; 3937 + bg_is_ro = true; 3941 3938 3942 3939 path = btrfs_alloc_path(); 3943 3940 if (!path) { 3944 - err = -ENOMEM; 3941 + ret = -ENOMEM; 3945 3942 goto out; 3946 3943 } 3947 3944 ··· 3949 3954 else 3950 3955 ret = PTR_ERR(inode); 3951 3956 3952 - if (ret && ret != -ENOENT) { 3953 - err = ret; 3957 + if (ret && ret != -ENOENT) 3954 3958 goto out; 3955 - } 3956 3959 3957 3960 rc->data_inode = create_reloc_inode(rc->block_group); 3958 3961 if (IS_ERR(rc->data_inode)) { 3959 - err = PTR_ERR(rc->data_inode); 3962 + ret = PTR_ERR(rc->data_inode); 3960 3963 rc->data_inode = NULL; 3961 3964 goto out; 3962 3965 } ··· 3975 3982 mutex_lock(&fs_info->cleaner_mutex); 3976 3983 ret = relocate_block_group(rc); 3977 3984 mutex_unlock(&fs_info->cleaner_mutex); 3978 - if (ret < 0) 3979 - err = ret; 3980 3985 3981 3986 finishes_stage = rc->stage; 3982 3987 /* ··· 3987 3996 * out of the loop if we hit an error. 3988 3997 */ 3989 3998 if (rc->stage == MOVE_DATA_EXTENTS && rc->found_file_extent) { 3990 - ret = btrfs_wait_ordered_range(BTRFS_I(rc->data_inode), 0, 3991 - (u64)-1); 3992 - if (ret) 3993 - err = ret; 3999 + int wb_ret; 4000 + 4001 + wb_ret = btrfs_wait_ordered_range(BTRFS_I(rc->data_inode), 0, 4002 + (u64)-1); 4003 + if (wb_ret && ret == 0) 4004 + ret = wb_ret; 3994 4005 invalidate_mapping_pages(rc->data_inode->i_mapping, 3995 4006 0, -1); 3996 4007 rc->stage = UPDATE_DATA_PTRS; 3997 4008 } 3998 4009 3999 - if (err < 0) 4010 + if (ret < 0) 4000 4011 goto out; 4001 4012 4002 4013 if (rc->extents_found == 0) ··· 4014 4021 WARN_ON(rc->block_group->reserved > 0); 4015 4022 WARN_ON(rc->block_group->used > 0); 4016 4023 out: 4017 - if (err && rw) 4024 + if (ret && bg_is_ro) 4018 4025 btrfs_dec_block_group_ro(rc->block_group); 4019 4026 iput(rc->data_inode); 4020 4027 reloc_chunk_end(fs_info); 4021 4028 out_put_bg: 4022 4029 btrfs_put_block_group(bg); 4023 4030 free_reloc_control(rc); 4024 - return err; 4031 + return ret; 4025 4032 } 4026 4033 4027 4034 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root)