Skip to content

Commit ff09c4c

Browse files
asjkdave
authored andcommitted
btrfs: scrub: convert scrub_workers_refcnt to refcount_t
Use the refcount_t for fs_info::scrub_workers_refcnt instead of int so we get the extra checks. All reference changes are still done under scrub_lock. Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent eb4318e commit ff09c4c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ struct btrfs_fs_info {
10751075
atomic_t scrubs_paused;
10761076
atomic_t scrub_cancel_req;
10771077
wait_queue_head_t scrub_pause_wait;
1078-
int scrub_workers_refcnt;
1078+
refcount_t scrub_workers_refcnt;
10791079
struct btrfs_workqueue *scrub_workers;
10801080
struct btrfs_workqueue *scrub_wr_completion_workers;
10811081
struct btrfs_workqueue *scrub_nocow_workers;

fs/btrfs/disk-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ static void btrfs_init_scrub(struct btrfs_fs_info *fs_info)
21092109
atomic_set(&fs_info->scrubs_paused, 0);
21102110
atomic_set(&fs_info->scrub_cancel_req, 0);
21112111
init_waitqueue_head(&fs_info->scrub_pause_wait);
2112-
fs_info->scrub_workers_refcnt = 0;
2112+
refcount_set(&fs_info->scrub_workers_refcnt, 0);
21132113
}
21142114

21152115
static void btrfs_init_balance(struct btrfs_fs_info *fs_info)

fs/btrfs/scrub.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,7 +3743,7 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
37433743

37443744
lockdep_assert_held(&fs_info->scrub_lock);
37453745

3746-
if (fs_info->scrub_workers_refcnt == 0) {
3746+
if (refcount_read(&fs_info->scrub_workers_refcnt) == 0) {
37473747
fs_info->scrub_workers = btrfs_alloc_workqueue(fs_info, "scrub",
37483748
flags, is_dev_replace ? 1 : max_active, 4);
37493749
if (!fs_info->scrub_workers)
@@ -3760,8 +3760,11 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
37603760
max_active, 2);
37613761
if (!fs_info->scrub_parity_workers)
37623762
goto fail_scrub_parity_workers;
3763+
3764+
refcount_set(&fs_info->scrub_workers_refcnt, 1);
3765+
} else {
3766+
refcount_inc(&fs_info->scrub_workers_refcnt);
37633767
}
3764-
++fs_info->scrub_workers_refcnt;
37653768
return 0;
37663769

37673770
fail_scrub_parity_workers:
@@ -3927,7 +3930,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
39273930

39283931
mutex_lock(&fs_info->scrub_lock);
39293932
dev->scrub_ctx = NULL;
3930-
if (--fs_info->scrub_workers_refcnt == 0) {
3933+
if (refcount_dec_and_test(&fs_info->scrub_workers_refcnt)) {
39313934
scrub_workers = fs_info->scrub_workers;
39323935
scrub_wr_comp = fs_info->scrub_wr_completion_workers;
39333936
scrub_parity = fs_info->scrub_parity_workers;

0 commit comments

Comments
 (0)