[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 32/51] block: convert bdrv_create to co_wrapper
From: |
Kevin Wolf |
Subject: |
[PULL 32/51] block: convert bdrv_create to co_wrapper |
Date: |
Wed, 14 Dec 2022 14:44:34 +0100 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
This function is never called in coroutine context, therefore
instead of manually creating a new coroutine, delegate it to the
block-coroutine-wrapper script, defining it as co_wrapper.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-14-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block-global-state.h | 8 ++++--
block.c | 41 ++----------------------------
2 files changed, 8 insertions(+), 41 deletions(-)
diff --git a/include/block/block-global-state.h
b/include/block/block-global-state.h
index 387a7cbb2e..1f8b54f2df 100644
--- a/include/block/block-global-state.h
+++ b/include/block/block-global-state.h
@@ -55,8 +55,12 @@ BlockDriver *bdrv_find_protocol(const char *filename,
bool allow_protocol_prefix,
Error **errp);
BlockDriver *bdrv_find_format(const char *format_name);
-int bdrv_create(BlockDriver *drv, const char* filename,
- QemuOpts *opts, Error **errp);
+
+int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
+ QemuOpts *opts, Error **errp);
+int co_wrapper bdrv_create(BlockDriver *drv, const char *filename,
+ QemuOpts *opts, Error **errp);
+
int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts,
Error **errp);
diff --git a/block.c b/block.c
index c8ac91eb63..6191ac1f44 100644
--- a/block.c
+++ b/block.c
@@ -526,8 +526,8 @@ typedef struct CreateCo {
Error *err;
} CreateCo;
-static int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
- QemuOpts *opts, Error **errp)
+int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
+ QemuOpts *opts, Error **errp)
{
int ret;
GLOBAL_STATE_CODE();
@@ -547,43 +547,6 @@ static int coroutine_fn bdrv_co_create(BlockDriver *drv,
const char *filename,
return ret;
}
-static void coroutine_fn bdrv_create_co_entry(void *opaque)
-{
- CreateCo *cco = opaque;
- GLOBAL_STATE_CODE();
-
- cco->ret = bdrv_co_create(cco->drv, cco->filename, cco->opts, &cco->err);
- aio_wait_kick();
-}
-
-int bdrv_create(BlockDriver *drv, const char* filename,
- QemuOpts *opts, Error **errp)
-{
- GLOBAL_STATE_CODE();
-
- if (qemu_in_coroutine()) {
- /* Fast-path if already in coroutine context */
- return bdrv_co_create(drv, filename, opts, errp);
- } else {
- Coroutine *co;
- CreateCo cco = {
- .drv = drv,
- .filename = filename,
- .opts = opts,
- .ret = NOT_DONE,
- .err = NULL,
- };
-
- co = qemu_coroutine_create(bdrv_create_co_entry, &cco);
- qemu_coroutine_enter(co);
- while (cco.ret == NOT_DONE) {
- aio_poll(qemu_get_aio_context(), true);
- }
- error_propagate(errp, cco.err);
- return cco.ret;
- }
-}
-
/**
* Helper function for bdrv_create_file_fallback(): Resize @blk to at
* least the given @minimum_size.
--
2.38.1
- [PULL 21/51] block-copy: add coroutine_fn annotations, (continued)
- [PULL 21/51] block-copy: add coroutine_fn annotations, Kevin Wolf, 2022/12/14
- [PULL 17/51] block: Drop out of coroutine in bdrv_do_drained_begin_quiesce(), Kevin Wolf, 2022/12/14
- [PULL 29/51] block-coroutine-wrapper.py: introduce co_wrapper, Kevin Wolf, 2022/12/14
- [PULL 31/51] block-coroutine-wrapper.py: support also basic return types, Kevin Wolf, 2022/12/14
- [PULL 36/51] graph-lock: Implement guard macros, Kevin Wolf, 2022/12/14
- [PULL 26/51] block: distinguish between bdrv_create running in coroutine and not, Kevin Wolf, 2022/12/14
- [PULL 25/51] block: avoid duplicating filename string in bdrv_create, Kevin Wolf, 2022/12/14
- [PULL 24/51] block/vmdk: add coroutine_fn annotations, Kevin Wolf, 2022/12/14
- [PULL 28/51] block: rename generated_co_wrapper in co_wrapper_mixed, Kevin Wolf, 2022/12/14
- [PULL 27/51] block: bdrv_create_file is a coroutine_fn, Kevin Wolf, 2022/12/14
- [PULL 32/51] block: convert bdrv_create to co_wrapper,
Kevin Wolf <=
- [PULL 35/51] graph-lock: Introduce a lock to protect block graph operations, Kevin Wolf, 2022/12/14
- [PULL 38/51] Import clang-tsa.h, Kevin Wolf, 2022/12/14
- [PULL 33/51] block/dirty-bitmap: convert coroutine-only functions to co_wrapper, Kevin Wolf, 2022/12/14
- [PULL 40/51] clang-tsa: Add macros for shared locks, Kevin Wolf, 2022/12/14
- [PULL 41/51] configure: Enable -Wthread-safety if present, Kevin Wolf, 2022/12/14
- [PULL 42/51] test-bdrv-drain: Fix incorrrect drain assumptions, Kevin Wolf, 2022/12/14
- [PULL 37/51] async: Register/unregister aiocontext in graph lock list, Kevin Wolf, 2022/12/14
- [PULL 50/51] block: use co_wrapper_mixed_bdrv_rdlock in functions taking the rdlock, Kevin Wolf, 2022/12/14
- [PULL 47/51] graph-lock: TSA annotations for lock/unlock functions, Kevin Wolf, 2022/12/14
- [PULL 48/51] Mark assert_bdrv_graph_readable/writable() GRAPH_RD/WRLOCK, Kevin Wolf, 2022/12/14