diff mbox series

[8/9] block: bdrv_create is never called in non-coroutine context

Message ID 20221103134206.4041928-9-eesposit@redhat.com
State New
Headers show
Series Still more coroutine and various fixes in block layer | expand

Commit Message

Emanuele Giuseppe Esposito Nov. 3, 2022, 1:42 p.m. UTC
Delete the if case and make sure it won't be called again
in coroutines.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 block.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

Comments

Paolo Bonzini Nov. 3, 2022, 5:05 p.m. UTC | #1
On 11/3/22 14:42, Emanuele Giuseppe Esposito wrote:
> Delete the if case and make sure it won't be called again
> in coroutines.
> 
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> ---
>   block.c | 37 ++++++++++++++++---------------------
>   1 file changed, 16 insertions(+), 21 deletions(-)
> 
> diff --git a/block.c b/block.c
> index e5e70acf15..1ee76a8694 100644
> --- a/block.c
> +++ b/block.c
> @@ -557,30 +557,25 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
>   int bdrv_create(BlockDriver *drv, const char* filename,
>                   QemuOpts *opts, Error **errp)
>   {
> +    Coroutine *co;
> +    CreateCo cco = {
> +        .drv = drv,
> +        .filename = g_strdup(filename),
> +        .opts = opts,
> +        .ret = NOT_DONE,
> +        .err = NULL,
> +    };
>       GLOBAL_STATE_CODE();
> +    assert(!qemu_in_coroutine());
>   
> -    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 = g_strdup(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);
> -        g_free(cco.filename);
> -        return cco.ret;
> +    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);
> +    g_free(cco.filename);
> +    return cco.ret;
>   }
>   
>   /**

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox series

Patch

diff --git a/block.c b/block.c
index e5e70acf15..1ee76a8694 100644
--- a/block.c
+++ b/block.c
@@ -557,30 +557,25 @@  static void coroutine_fn bdrv_create_co_entry(void *opaque)
 int bdrv_create(BlockDriver *drv, const char* filename,
                 QemuOpts *opts, Error **errp)
 {
+    Coroutine *co;
+    CreateCo cco = {
+        .drv = drv,
+        .filename = g_strdup(filename),
+        .opts = opts,
+        .ret = NOT_DONE,
+        .err = NULL,
+    };
     GLOBAL_STATE_CODE();
+    assert(!qemu_in_coroutine());
 
-    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 = g_strdup(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);
-        g_free(cco.filename);
-        return cco.ret;
+    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);
+    g_free(cco.filename);
+    return cco.ret;
 }
 
 /**