Commit 0339ef2f authored by Qu Wenruo's avatar Qu Wenruo Committed by Josef Bacik

btrfs: Replace fs_info->scrub_* workqueue with btrfs_workqueue.

Replace the fs_info->scrub_* with the newly created
btrfs_workqueue.
Signed-off-by: default avatarQu Wenruo <quwenruo@cn.fujitsu.com>
Tested-by: default avatarDavid Sterba <dsterba@suse.cz>
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
parent fc97fab0
...@@ -1605,9 +1605,9 @@ struct btrfs_fs_info { ...@@ -1605,9 +1605,9 @@ struct btrfs_fs_info {
atomic_t scrub_cancel_req; atomic_t scrub_cancel_req;
wait_queue_head_t scrub_pause_wait; wait_queue_head_t scrub_pause_wait;
int scrub_workers_refcnt; int scrub_workers_refcnt;
struct btrfs_workers scrub_workers; struct btrfs_workqueue_struct *scrub_workers;
struct btrfs_workers scrub_wr_completion_workers; struct btrfs_workqueue_struct *scrub_wr_completion_workers;
struct btrfs_workers scrub_nocow_workers; struct btrfs_workqueue_struct *scrub_nocow_workers;
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
u32 check_integrity_print_mask; u32 check_integrity_print_mask;
......
...@@ -96,7 +96,8 @@ struct scrub_bio { ...@@ -96,7 +96,8 @@ struct scrub_bio {
#endif #endif
int page_count; int page_count;
int next_free; int next_free;
struct btrfs_work work; struct btrfs_work_struct
work;
}; };
struct scrub_block { struct scrub_block {
...@@ -154,7 +155,8 @@ struct scrub_fixup_nodatasum { ...@@ -154,7 +155,8 @@ struct scrub_fixup_nodatasum {
struct btrfs_device *dev; struct btrfs_device *dev;
u64 logical; u64 logical;
struct btrfs_root *root; struct btrfs_root *root;
struct btrfs_work work; struct btrfs_work_struct
work;
int mirror_num; int mirror_num;
}; };
...@@ -172,7 +174,8 @@ struct scrub_copy_nocow_ctx { ...@@ -172,7 +174,8 @@ struct scrub_copy_nocow_ctx {
int mirror_num; int mirror_num;
u64 physical_for_dev_replace; u64 physical_for_dev_replace;
struct list_head inodes; struct list_head inodes;
struct btrfs_work work; struct btrfs_work_struct
work;
}; };
struct scrub_warning { struct scrub_warning {
...@@ -231,7 +234,7 @@ static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len, ...@@ -231,7 +234,7 @@ static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
u64 gen, int mirror_num, u8 *csum, int force, u64 gen, int mirror_num, u8 *csum, int force,
u64 physical_for_dev_replace); u64 physical_for_dev_replace);
static void scrub_bio_end_io(struct bio *bio, int err); static void scrub_bio_end_io(struct bio *bio, int err);
static void scrub_bio_end_io_worker(struct btrfs_work *work); static void scrub_bio_end_io_worker(struct btrfs_work_struct *work);
static void scrub_block_complete(struct scrub_block *sblock); static void scrub_block_complete(struct scrub_block *sblock);
static void scrub_remap_extent(struct btrfs_fs_info *fs_info, static void scrub_remap_extent(struct btrfs_fs_info *fs_info,
u64 extent_logical, u64 extent_len, u64 extent_logical, u64 extent_len,
...@@ -248,14 +251,14 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, ...@@ -248,14 +251,14 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx,
struct scrub_page *spage); struct scrub_page *spage);
static void scrub_wr_submit(struct scrub_ctx *sctx); static void scrub_wr_submit(struct scrub_ctx *sctx);
static void scrub_wr_bio_end_io(struct bio *bio, int err); static void scrub_wr_bio_end_io(struct bio *bio, int err);
static void scrub_wr_bio_end_io_worker(struct btrfs_work *work); static void scrub_wr_bio_end_io_worker(struct btrfs_work_struct *work);
static int write_page_nocow(struct scrub_ctx *sctx, static int write_page_nocow(struct scrub_ctx *sctx,
u64 physical_for_dev_replace, struct page *page); u64 physical_for_dev_replace, struct page *page);
static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root,
struct scrub_copy_nocow_ctx *ctx); struct scrub_copy_nocow_ctx *ctx);
static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len, static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
int mirror_num, u64 physical_for_dev_replace); int mirror_num, u64 physical_for_dev_replace);
static void copy_nocow_pages_worker(struct btrfs_work *work); static void copy_nocow_pages_worker(struct btrfs_work_struct *work);
static void __scrub_blocked_if_needed(struct btrfs_fs_info *fs_info); static void __scrub_blocked_if_needed(struct btrfs_fs_info *fs_info);
static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info); static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info);
...@@ -428,7 +431,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace) ...@@ -428,7 +431,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
sbio->index = i; sbio->index = i;
sbio->sctx = sctx; sbio->sctx = sctx;
sbio->page_count = 0; sbio->page_count = 0;
sbio->work.func = scrub_bio_end_io_worker; btrfs_init_work(&sbio->work, scrub_bio_end_io_worker,
NULL, NULL);
if (i != SCRUB_BIOS_PER_SCTX - 1) if (i != SCRUB_BIOS_PER_SCTX - 1)
sctx->bios[i]->next_free = i + 1; sctx->bios[i]->next_free = i + 1;
...@@ -733,7 +737,7 @@ static int scrub_fixup_readpage(u64 inum, u64 offset, u64 root, void *fixup_ctx) ...@@ -733,7 +737,7 @@ static int scrub_fixup_readpage(u64 inum, u64 offset, u64 root, void *fixup_ctx)
return -EIO; return -EIO;
} }
static void scrub_fixup_nodatasum(struct btrfs_work *work) static void scrub_fixup_nodatasum(struct btrfs_work_struct *work)
{ {
int ret; int ret;
struct scrub_fixup_nodatasum *fixup; struct scrub_fixup_nodatasum *fixup;
...@@ -997,8 +1001,9 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check) ...@@ -997,8 +1001,9 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
fixup_nodatasum->root = fs_info->extent_root; fixup_nodatasum->root = fs_info->extent_root;
fixup_nodatasum->mirror_num = failed_mirror_index + 1; fixup_nodatasum->mirror_num = failed_mirror_index + 1;
scrub_pending_trans_workers_inc(sctx); scrub_pending_trans_workers_inc(sctx);
fixup_nodatasum->work.func = scrub_fixup_nodatasum; btrfs_init_work(&fixup_nodatasum->work, scrub_fixup_nodatasum,
btrfs_queue_worker(&fs_info->scrub_workers, NULL, NULL);
btrfs_queue_work(fs_info->scrub_workers,
&fixup_nodatasum->work); &fixup_nodatasum->work);
goto out; goto out;
} }
...@@ -1613,11 +1618,11 @@ static void scrub_wr_bio_end_io(struct bio *bio, int err) ...@@ -1613,11 +1618,11 @@ static void scrub_wr_bio_end_io(struct bio *bio, int err)
sbio->err = err; sbio->err = err;
sbio->bio = bio; sbio->bio = bio;
sbio->work.func = scrub_wr_bio_end_io_worker; btrfs_init_work(&sbio->work, scrub_wr_bio_end_io_worker, NULL, NULL);
btrfs_queue_worker(&fs_info->scrub_wr_completion_workers, &sbio->work); btrfs_queue_work(fs_info->scrub_wr_completion_workers, &sbio->work);
} }
static void scrub_wr_bio_end_io_worker(struct btrfs_work *work) static void scrub_wr_bio_end_io_worker(struct btrfs_work_struct *work)
{ {
struct scrub_bio *sbio = container_of(work, struct scrub_bio, work); struct scrub_bio *sbio = container_of(work, struct scrub_bio, work);
struct scrub_ctx *sctx = sbio->sctx; struct scrub_ctx *sctx = sbio->sctx;
...@@ -2082,10 +2087,10 @@ static void scrub_bio_end_io(struct bio *bio, int err) ...@@ -2082,10 +2087,10 @@ static void scrub_bio_end_io(struct bio *bio, int err)
sbio->err = err; sbio->err = err;
sbio->bio = bio; sbio->bio = bio;
btrfs_queue_worker(&fs_info->scrub_workers, &sbio->work); btrfs_queue_work(fs_info->scrub_workers, &sbio->work);
} }
static void scrub_bio_end_io_worker(struct btrfs_work *work) static void scrub_bio_end_io_worker(struct btrfs_work_struct *work)
{ {
struct scrub_bio *sbio = container_of(work, struct scrub_bio, work); struct scrub_bio *sbio = container_of(work, struct scrub_bio, work);
struct scrub_ctx *sctx = sbio->sctx; struct scrub_ctx *sctx = sbio->sctx;
...@@ -2780,34 +2785,36 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, ...@@ -2780,34 +2785,36 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
int is_dev_replace) int is_dev_replace)
{ {
int ret = 0; int ret = 0;
int flags = WQ_FREEZABLE | WQ_UNBOUND;
int max_active = fs_info->thread_pool_size;
if (fs_info->scrub_workers_refcnt == 0) { if (fs_info->scrub_workers_refcnt == 0) {
if (is_dev_replace) if (is_dev_replace)
btrfs_init_workers(&fs_info->scrub_workers, "scrub", 1, fs_info->scrub_workers =
&fs_info->generic_worker); btrfs_alloc_workqueue("btrfs-scrub", flags,
1, 4);
else else
btrfs_init_workers(&fs_info->scrub_workers, "scrub", fs_info->scrub_workers =
fs_info->thread_pool_size, btrfs_alloc_workqueue("btrfs-scrub", flags,
&fs_info->generic_worker); max_active, 4);
fs_info->scrub_workers.idle_thresh = 4; if (!fs_info->scrub_workers) {
ret = btrfs_start_workers(&fs_info->scrub_workers); ret = -ENOMEM;
if (ret)
goto out; goto out;
btrfs_init_workers(&fs_info->scrub_wr_completion_workers, }
"scrubwrc", fs_info->scrub_wr_completion_workers =
fs_info->thread_pool_size, btrfs_alloc_workqueue("btrfs-scrubwrc", flags,
&fs_info->generic_worker); max_active, 2);
fs_info->scrub_wr_completion_workers.idle_thresh = 2; if (!fs_info->scrub_wr_completion_workers) {
ret = btrfs_start_workers( ret = -ENOMEM;
&fs_info->scrub_wr_completion_workers);
if (ret)
goto out; goto out;
btrfs_init_workers(&fs_info->scrub_nocow_workers, "scrubnc", 1, }
&fs_info->generic_worker); fs_info->scrub_nocow_workers =
ret = btrfs_start_workers(&fs_info->scrub_nocow_workers); btrfs_alloc_workqueue("btrfs-scrubnc", flags, 1, 0);
if (ret) if (!fs_info->scrub_nocow_workers) {
ret = -ENOMEM;
goto out; goto out;
} }
}
++fs_info->scrub_workers_refcnt; ++fs_info->scrub_workers_refcnt;
out: out:
return ret; return ret;
...@@ -2816,9 +2823,9 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, ...@@ -2816,9 +2823,9 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
static noinline_for_stack void scrub_workers_put(struct btrfs_fs_info *fs_info) static noinline_for_stack void scrub_workers_put(struct btrfs_fs_info *fs_info)
{ {
if (--fs_info->scrub_workers_refcnt == 0) { if (--fs_info->scrub_workers_refcnt == 0) {
btrfs_stop_workers(&fs_info->scrub_workers); btrfs_destroy_workqueue(fs_info->scrub_workers);
btrfs_stop_workers(&fs_info->scrub_wr_completion_workers); btrfs_destroy_workqueue(fs_info->scrub_wr_completion_workers);
btrfs_stop_workers(&fs_info->scrub_nocow_workers); btrfs_destroy_workqueue(fs_info->scrub_nocow_workers);
} }
WARN_ON(fs_info->scrub_workers_refcnt < 0); WARN_ON(fs_info->scrub_workers_refcnt < 0);
} }
...@@ -3129,9 +3136,9 @@ static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len, ...@@ -3129,9 +3136,9 @@ static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
nocow_ctx->len = len; nocow_ctx->len = len;
nocow_ctx->mirror_num = mirror_num; nocow_ctx->mirror_num = mirror_num;
nocow_ctx->physical_for_dev_replace = physical_for_dev_replace; nocow_ctx->physical_for_dev_replace = physical_for_dev_replace;
nocow_ctx->work.func = copy_nocow_pages_worker; btrfs_init_work(&nocow_ctx->work, copy_nocow_pages_worker, NULL, NULL);
INIT_LIST_HEAD(&nocow_ctx->inodes); INIT_LIST_HEAD(&nocow_ctx->inodes);
btrfs_queue_worker(&fs_info->scrub_nocow_workers, btrfs_queue_work(fs_info->scrub_nocow_workers,
&nocow_ctx->work); &nocow_ctx->work);
return 0; return 0;
...@@ -3154,7 +3161,7 @@ static int record_inode_for_nocow(u64 inum, u64 offset, u64 root, void *ctx) ...@@ -3154,7 +3161,7 @@ static int record_inode_for_nocow(u64 inum, u64 offset, u64 root, void *ctx)
#define COPY_COMPLETE 1 #define COPY_COMPLETE 1
static void copy_nocow_pages_worker(struct btrfs_work *work) static void copy_nocow_pages_worker(struct btrfs_work_struct *work)
{ {
struct scrub_copy_nocow_ctx *nocow_ctx = struct scrub_copy_nocow_ctx *nocow_ctx =
container_of(work, struct scrub_copy_nocow_ctx, work); container_of(work, struct scrub_copy_nocow_ctx, work);
......
...@@ -1336,7 +1336,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, ...@@ -1336,7 +1336,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info,
btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size);
btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size);
btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size);
btrfs_set_max_workers(&fs_info->scrub_wr_completion_workers, btrfs_workqueue_set_max(fs_info->scrub_wr_completion_workers,
new_pool_size); new_pool_size);
} }
......
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