Skip to content

Commit

Permalink
btrfs: dev-replace: move replace members out of fs_info
Browse files Browse the repository at this point in the history
The replace_wait and bio_counter were mistakenly added to fs_info in
commit c404e0d ("Btrfs: fix use-after-free in the finishing
procedure of the device replace"), but they logically belong to
fs_info::dev_replace. Besides, bio_counter is a very generic name and is
confusing in bare fs_info context.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
David Sterba committed Oct 15, 2018
1 parent aa144bf commit 7f8d236
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ struct btrfs_dev_replace {
wait_queue_head_t read_lock_wq;

struct btrfs_scrub_progress scrub_progress;

struct percpu_counter bio_counter;
wait_queue_head_t replace_wait;
};

/* For raid type sysfs entries */
Expand Down Expand Up @@ -1087,9 +1090,6 @@ struct btrfs_fs_info {
/* device replace state */
struct btrfs_dev_replace dev_replace;

struct percpu_counter bio_counter;
wait_queue_head_t replace_wait;

struct semaphore uuid_tree_rescan_sem;

/* Used to reclaim the metadata space in the background. */
Expand Down
16 changes: 8 additions & 8 deletions fs/btrfs/dev-replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info,
static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info)
{
set_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state);
wait_event(fs_info->replace_wait, !percpu_counter_sum(
&fs_info->bio_counter));
wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum(
&fs_info->dev_replace.bio_counter));
}

/*
Expand All @@ -555,7 +555,7 @@ static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info)
static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info)
{
clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state);
wake_up(&fs_info->replace_wait);
wake_up(&fs_info->dev_replace.replace_wait);
}

static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
Expand Down Expand Up @@ -997,25 +997,25 @@ void btrfs_dev_replace_set_lock_blocking(

void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info)
{
percpu_counter_inc(&fs_info->bio_counter);
percpu_counter_inc(&fs_info->dev_replace.bio_counter);
}

void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount)
{
percpu_counter_sub(&fs_info->bio_counter, amount);
cond_wake_up_nomb(&fs_info->replace_wait);
percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount);
cond_wake_up_nomb(&fs_info->dev_replace.replace_wait);
}

void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info)
{
while (1) {
percpu_counter_inc(&fs_info->bio_counter);
percpu_counter_inc(&fs_info->dev_replace.bio_counter);
if (likely(!test_bit(BTRFS_FS_STATE_DEV_REPLACING,
&fs_info->fs_state)))
break;

btrfs_bio_counter_dec(fs_info);
wait_event(fs_info->replace_wait,
wait_event(fs_info->dev_replace.replace_wait,
!test_bit(BTRFS_FS_STATE_DEV_REPLACING,
&fs_info->fs_state));
}
Expand Down
9 changes: 5 additions & 4 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info)
mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
rwlock_init(&fs_info->dev_replace.lock);
atomic_set(&fs_info->dev_replace.blocking_readers, 0);
init_waitqueue_head(&fs_info->replace_wait);
init_waitqueue_head(&fs_info->dev_replace.replace_wait);
init_waitqueue_head(&fs_info->dev_replace.read_lock_wq);
}

Expand Down Expand Up @@ -2646,7 +2646,8 @@ int open_ctree(struct super_block *sb,
goto fail_dirty_metadata_bytes;
}

ret = percpu_counter_init(&fs_info->bio_counter, 0, GFP_KERNEL);
ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0,
GFP_KERNEL);
if (ret) {
err = ret;
goto fail_delalloc_bytes;
Expand Down Expand Up @@ -3307,7 +3308,7 @@ int open_ctree(struct super_block *sb,

iput(fs_info->btree_inode);
fail_bio_counter:
percpu_counter_destroy(&fs_info->bio_counter);
percpu_counter_destroy(&fs_info->dev_replace.bio_counter);
fail_delalloc_bytes:
percpu_counter_destroy(&fs_info->delalloc_bytes);
fail_dirty_metadata_bytes:
Expand Down Expand Up @@ -4016,7 +4017,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)

percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
percpu_counter_destroy(&fs_info->delalloc_bytes);
percpu_counter_destroy(&fs_info->bio_counter);
percpu_counter_destroy(&fs_info->dev_replace.bio_counter);
cleanup_srcu_struct(&fs_info->subvol_srcu);

btrfs_free_stripe_hash_table(fs_info);
Expand Down

0 comments on commit 7f8d236

Please sign in to comment.