Commit c8352942 authored by David Sterba's avatar David Sterba

btrfs: scrub: add assertions for worker pointers

The scrub worker pointers are not NULL iff the scrub is running, so
reset them back once the last reference is dropped. Add assertions to
the initial phase of scrub to verify that.
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ff09c4ca
...@@ -1075,6 +1075,10 @@ struct btrfs_fs_info { ...@@ -1075,6 +1075,10 @@ struct btrfs_fs_info {
atomic_t scrubs_paused; atomic_t scrubs_paused;
atomic_t scrub_cancel_req; atomic_t scrub_cancel_req;
wait_queue_head_t scrub_pause_wait; wait_queue_head_t scrub_pause_wait;
/*
* The worker pointers are NULL iff the refcount is 0, ie. scrub is not
* running.
*/
refcount_t scrub_workers_refcnt; refcount_t scrub_workers_refcnt;
struct btrfs_workqueue *scrub_workers; struct btrfs_workqueue *scrub_workers;
struct btrfs_workqueue *scrub_wr_completion_workers; struct btrfs_workqueue *scrub_wr_completion_workers;
......
...@@ -3744,17 +3744,20 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, ...@@ -3744,17 +3744,20 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
lockdep_assert_held(&fs_info->scrub_lock); lockdep_assert_held(&fs_info->scrub_lock);
if (refcount_read(&fs_info->scrub_workers_refcnt) == 0) { if (refcount_read(&fs_info->scrub_workers_refcnt) == 0) {
ASSERT(fs_info->scrub_workers == NULL);
fs_info->scrub_workers = btrfs_alloc_workqueue(fs_info, "scrub", fs_info->scrub_workers = btrfs_alloc_workqueue(fs_info, "scrub",
flags, is_dev_replace ? 1 : max_active, 4); flags, is_dev_replace ? 1 : max_active, 4);
if (!fs_info->scrub_workers) if (!fs_info->scrub_workers)
goto fail_scrub_workers; goto fail_scrub_workers;
ASSERT(fs_info->scrub_wr_completion_workers == NULL);
fs_info->scrub_wr_completion_workers = fs_info->scrub_wr_completion_workers =
btrfs_alloc_workqueue(fs_info, "scrubwrc", flags, btrfs_alloc_workqueue(fs_info, "scrubwrc", flags,
max_active, 2); max_active, 2);
if (!fs_info->scrub_wr_completion_workers) if (!fs_info->scrub_wr_completion_workers)
goto fail_scrub_wr_completion_workers; goto fail_scrub_wr_completion_workers;
ASSERT(fs_info->scrub_parity_workers == NULL);
fs_info->scrub_parity_workers = fs_info->scrub_parity_workers =
btrfs_alloc_workqueue(fs_info, "scrubparity", flags, btrfs_alloc_workqueue(fs_info, "scrubparity", flags,
max_active, 2); max_active, 2);
...@@ -3934,6 +3937,10 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, ...@@ -3934,6 +3937,10 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
scrub_workers = fs_info->scrub_workers; scrub_workers = fs_info->scrub_workers;
scrub_wr_comp = fs_info->scrub_wr_completion_workers; scrub_wr_comp = fs_info->scrub_wr_completion_workers;
scrub_parity = fs_info->scrub_parity_workers; scrub_parity = fs_info->scrub_parity_workers;
fs_info->scrub_workers = NULL;
fs_info->scrub_wr_completion_workers = NULL;
fs_info->scrub_parity_workers = NULL;
} }
mutex_unlock(&fs_info->scrub_lock); mutex_unlock(&fs_info->scrub_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment