With this patch, the calls to the thread pool functions pass through the new modular thread pool implementation.
Signed-off-by: Matthias Brugger <matthias....@gmail.com> --- async.c | 4 ++-- block/raw-posix.c | 15 +++++++++++---- block/raw-win32.c | 9 +++++++-- include/block/aio.h | 2 +- include/qemu-common.h | 2 ++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/async.c b/async.c index 5fb3fa6..e66f70f 100644 --- a/async.c +++ b/async.c @@ -232,10 +232,10 @@ GSource *aio_get_g_source(AioContext *ctx) return &ctx->source; } -ThreadPool *aio_get_thread_pool(AioContext *ctx) +ThreadPool *aio_get_thread_pool(AioContext *ctx, ThreadPoolFuncArr *tpf) { if (!ctx->thread_pool) { - ctx->thread_pool = thread_pool_new(ctx); + ctx->thread_pool = tpf->thread_pool_new(ctx); } return ctx->thread_pool; } diff --git a/block/raw-posix.c b/block/raw-posix.c index f6d48bb..f747301 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -142,6 +142,7 @@ typedef struct BDRVRawState { bool is_xfs : 1; #endif bool has_discard : 1; + ThreadPoolFuncArr *tpf; } BDRVRawState; typedef struct BDRVRawReopenState { @@ -345,6 +346,9 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, int ret; s->type = FTYPE_FILE; + + s->tpf = thread_pool_probe(); + ret = raw_open_common(bs, options, flags, 0, &local_err); if (error_is_set(&local_err)) { error_propagate(errp, local_err); @@ -792,6 +796,7 @@ static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque, int type) { + BDRVRawState *s = bs->opaque; RawPosixAIOData *acb = g_slice_new(RawPosixAIOData); ThreadPool *pool; @@ -807,8 +812,8 @@ static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd, acb->aio_offset = sector_num * 512; trace_paio_submit(acb, opaque, sector_num, nb_sectors, type); - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); + pool = aio_get_thread_pool(bdrv_get_aio_context(bs), s->tpf); + return s->tpf->thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } static BlockDriverAIOCB *raw_aio_submit(BlockDriverState *bs, @@ -874,6 +879,8 @@ static void raw_close(BlockDriverState *bs) qemu_close(s->fd); s->fd = -1; } + + thread_pool_delete(s->tpf); } static int raw_truncate(BlockDriverState *bs, int64_t offset) @@ -1490,8 +1497,8 @@ static BlockDriverAIOCB *hdev_aio_ioctl(BlockDriverState *bs, acb->aio_offset = 0; acb->aio_ioctl_buf = buf; acb->aio_ioctl_cmd = req; - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); + pool = aio_get_thread_pool(bdrv_get_aio_context(bs), s->tpf); + return s->tpf->thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) diff --git a/block/raw-win32.c b/block/raw-win32.c index 2741e4d..76df266 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -46,6 +46,7 @@ typedef struct RawWin32AIOData { size_t aio_nbytes; off64_t aio_offset; int aio_type; + ThreadPoolFuncArr *tpf; } RawWin32AIOData; typedef struct BDRVRawState { @@ -159,8 +160,8 @@ static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile, acb->aio_offset = sector_num * 512; trace_paio_submit(acb, opaque, sector_num, nb_sectors, type); - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); + pool = aio_get_thread_pool(bdrv_get_aio_context(bs), s->tpf); + return s->tpf->thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } int qemu_ftruncate64(int fd, int64_t length) @@ -248,6 +249,8 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, s->type = FTYPE_FILE; + s->tpf = thread_pool_probe(); + opts = qemu_opts_create_nofail(&raw_runtime_opts); qemu_opts_absorb_qdict(opts, options, &local_err); if (error_is_set(&local_err)) { @@ -339,6 +342,8 @@ static void raw_close(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; CloseHandle(s->hfile); + + thread_pool_delete(s->tpf); } static int raw_truncate(BlockDriverState *bs, int64_t offset) diff --git a/include/block/aio.h b/include/block/aio.h index 2efdf41..22d6fa0 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -231,7 +231,7 @@ void aio_set_event_notifier(AioContext *ctx, GSource *aio_get_g_source(AioContext *ctx); /* Return the ThreadPool bound to this AioContext */ -struct ThreadPool *aio_get_thread_pool(AioContext *ctx); +struct ThreadPool *aio_get_thread_pool(AioContext *ctx, ThreadPoolFuncArr *tpf); /* Functions to operate on the main QEMU AioContext. */ diff --git a/include/qemu-common.h b/include/qemu-common.h index 5054836..594a53b 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -478,4 +478,6 @@ size_t buffer_find_nonzero_offset(const void *buf, size_t len); */ int parse_debug_env(const char *name, int max, int initial); +typedef struct ThreadPoolFuncArr ThreadPoolFuncArr; + #endif -- 1.8.1.2