[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 13/14] block: convert bdrv_create to co_wrapper
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH v7 13/14] block: convert bdrv_create to co_wrapper |
Date: |
Mon, 28 Nov 2022 09:23:36 -0500 |
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>
---
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 20a5d7e8cf..8683d24553 100644
--- a/block.c
+++ b/block.c
@@ -528,8 +528,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();
@@ -549,43 +549,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.31.1
- [PATCH v7 01/14] block-io: introduce coroutine_fn duplicates for bdrv_common_block_status_above callers, (continued)
- [PATCH v7 01/14] block-io: introduce coroutine_fn duplicates for bdrv_common_block_status_above callers, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 03/14] nbd/server.c: add coroutine_fn annotations, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 09/14] block: rename generated_co_wrapper in co_wrapper_mixed, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 05/14] block/vmdk: add coroutine_fn annotations, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 07/14] block: distinguish between bdrv_create running in coroutine and not, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 02/14] block-copy: add coroutine_fn annotations, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 10/14] block-coroutine-wrapper.py: introduce co_wrapper, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 08/14] block: bdrv_create_file is a coroutine_fn, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 11/14] block-coroutine-wrapper.py: support functions without bs arg, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 06/14] block: avoid duplicating filename string in bdrv_create, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 13/14] block: convert bdrv_create to co_wrapper,
Emanuele Giuseppe Esposito <=
- [PATCH v7 14/14] block/dirty-bitmap: convert coroutine-only functions to co_wrapper, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 12/14] block-coroutine-wrapper.py: support also basic return types, Emanuele Giuseppe Esposito, 2022/11/28
- [PATCH v7 04/14] block-backend: replace bdrv_*_above with blk_*_above, Emanuele Giuseppe Esposito, 2022/11/28