Skip to content

Commit c835294

Browse files
committed
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: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent ff09c4c commit c835294

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

fs/btrfs/ctree.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,10 @@ struct btrfs_fs_info {
10751075
atomic_t scrubs_paused;
10761076
atomic_t scrub_cancel_req;
10771077
wait_queue_head_t scrub_pause_wait;
1078+
/*
1079+
* The worker pointers are NULL iff the refcount is 0, ie. scrub is not
1080+
* running.
1081+
*/
10781082
refcount_t scrub_workers_refcnt;
10791083
struct btrfs_workqueue *scrub_workers;
10801084
struct btrfs_workqueue *scrub_wr_completion_workers;

fs/btrfs/scrub.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,17 +3744,20 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
37443744
lockdep_assert_held(&fs_info->scrub_lock);
37453745

37463746
if (refcount_read(&fs_info->scrub_workers_refcnt) == 0) {
3747+
ASSERT(fs_info->scrub_workers == NULL);
37473748
fs_info->scrub_workers = btrfs_alloc_workqueue(fs_info, "scrub",
37483749
flags, is_dev_replace ? 1 : max_active, 4);
37493750
if (!fs_info->scrub_workers)
37503751
goto fail_scrub_workers;
37513752

3753+
ASSERT(fs_info->scrub_wr_completion_workers == NULL);
37523754
fs_info->scrub_wr_completion_workers =
37533755
btrfs_alloc_workqueue(fs_info, "scrubwrc", flags,
37543756
max_active, 2);
37553757
if (!fs_info->scrub_wr_completion_workers)
37563758
goto fail_scrub_wr_completion_workers;
37573759

3760+
ASSERT(fs_info->scrub_parity_workers == NULL);
37583761
fs_info->scrub_parity_workers =
37593762
btrfs_alloc_workqueue(fs_info, "scrubparity", flags,
37603763
max_active, 2);
@@ -3934,6 +3937,10 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
39343937
scrub_workers = fs_info->scrub_workers;
39353938
scrub_wr_comp = fs_info->scrub_wr_completion_workers;
39363939
scrub_parity = fs_info->scrub_parity_workers;
3940+
3941+
fs_info->scrub_workers = NULL;
3942+
fs_info->scrub_wr_completion_workers = NULL;
3943+
fs_info->scrub_parity_workers = NULL;
39373944
}
39383945
mutex_unlock(&fs_info->scrub_lock);
39393946

0 commit comments

Comments
 (0)