Skip to contentSkip to conversation

block: fix bdrv_ioctl called from coroutine

PATCH Applied Paolo Bonzini 3 participants 7 messages Dec 16, 2015 – Dec 18, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: fix bdrv_ioctl called from coroutine

When called from a coroutine, bdrv_ioctl must be asynchronous just like e.g. bdrv_flush. The code was incorrectly making it synchronous, fix it.

---
Fam, any reason why you did it this way? I don't see any coroutine caller, but it doesn't make much sense. :)

 block/io.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
block/io.c +4 -3
index e00fb5d..841f5b5 100644
@@ -2614,10 +2614,11 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
         bdrv_co_ioctl_entry(&data);
     } else {
         Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry);
+
         qemu_coroutine_enter(co, &data);
-    }
-    while (data.ret == -EINPROGRESS) {
-        aio_poll(bdrv_get_aio_context(bs), true);
+        while (data.ret == -EINPROGRESS) {
+            aio_poll(bdrv_get_aio_context(bs), true);
+        }
     }
     return data.ret;
 }
Signature · 1 line
2.5.0
#1 lore raw
Quoted 8 lines · Paolo Bonzini

When called from a coroutine, bdrv_ioctl must be asynchronous just like e.g. bdrv_flush. The code was incorrectly making it synchronous, fix it.

---
Fam, any reason why you did it this way? I don't see any coroutine caller, but it doesn't make much sense. :)

That is a surprising question! From a coroutine, it is bdrv_flush -> bdrv_flush_co_entry -> bdrv_co_flush, which I think is always synchronous, especially, noticing the code around calling bs->bdrv_aio_flush:

        acb = bs->drv->bdrv_aio_flush(bs, bdrv_co_io_em_complete, &co);
        if (acb == NULL) {
            ret = -EIO;
        } else {
            qemu_coroutine_yield();
            ret = co.ret;
        }

Am I missing something?

Fam

Quoted 26 lines
 block/io.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
block/io.c +4 -3
index e00fb5d..841f5b5 100644
@@ -2614,10 +2614,11 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
         bdrv_co_ioctl_entry(&data);
     } else {
         Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry);
+
         qemu_coroutine_enter(co, &data);
-    }
-    while (data.ret == -EINPROGRESS) {
-        aio_poll(bdrv_get_aio_context(bs), true);
+        while (data.ret == -EINPROGRESS) {
+            aio_poll(bdrv_get_aio_context(bs), true);
+        }
     }
     return data.ret;
 }
Signature · 1 line
2.5.0
#2 lore raw
Quoted 22 lines · Fam Zheng
Quoted 8 lines · Paolo Bonzini

When called from a coroutine, bdrv_ioctl must be asynchronous just like e.g. bdrv_flush. The code was incorrectly making it synchronous, fix it.

---
Fam, any reason why you did it this way? I don't see any coroutine caller, but it doesn't make much sense. :)

That is a surprising question! From a coroutine, it is bdrv_flush -> bdrv_flush_co_entry -> bdrv_co_flush, which I think is always synchronous, especially, noticing the code around calling bs->bdrv_aio_flush:

        acb = bs->drv->bdrv_aio_flush(bs, bdrv_co_io_em_complete, &co);
        if (acb == NULL) {
            ret = -EIO;
        } else {
            qemu_coroutine_yield();
            ret = co.ret;
        }
Quoted 1 line

Am I missing something?

In the coroutine case, the yield is hidden in the drivers, and it may or may not happen. For example, qcow2_co_flush_to_os starts with

    qemu_co_mutex_lock(&s->lock);

which can yield.

Paolo

Quoted 30 lines

Fam

Quoted 26 lines
 block/io.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
block/io.c +4 -3
index e00fb5d..841f5b5 100644
@@ -2614,10 +2614,11 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
         bdrv_co_ioctl_entry(&data);
     } else {
         Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry);
+
         qemu_coroutine_enter(co, &data);
-    }
-    while (data.ret == -EINPROGRESS) {
-        aio_poll(bdrv_get_aio_context(bs), true);
+        while (data.ret == -EINPROGRESS) {
+            aio_poll(bdrv_get_aio_context(bs), true);
+        }
     }
     return data.ret;
 }
Signature · 1 line
2.5.0
#3 lore raw
Quoted 25 lines · Paolo Bonzini
Quoted 22 lines · Fam Zheng
Quoted 8 lines · Paolo Bonzini

When called from a coroutine, bdrv_ioctl must be asynchronous just like e.g. bdrv_flush. The code was incorrectly making it synchronous, fix it.

---
Fam, any reason why you did it this way? I don't see any coroutine caller, but it doesn't make much sense. :)

That is a surprising question! From a coroutine, it is bdrv_flush -> bdrv_flush_co_entry -> bdrv_co_flush, which I think is always synchronous, especially, noticing the code around calling bs->bdrv_aio_flush:

        acb = bs->drv->bdrv_aio_flush(bs, bdrv_co_io_em_complete, &co);
        if (acb == NULL) {
            ret = -EIO;
        } else {
            qemu_coroutine_yield();
            ret = co.ret;
        }
Quoted 8 lines
Quoted 1 line

Am I missing something?

In the coroutine case, the yield is hidden in the drivers, and it may or may not happen. For example, qcow2_co_flush_to_os starts with

    qemu_co_mutex_lock(&s->lock);

which can yield.

bdrv_ioctl, on the contrary, is emulated with .bdrv_aio_ioctl, so it always yields (unless -ENOTSUP), that's why I think aio_poll() is necessary in both branches.

Fam

#4 lore raw
Quoted 10 lines · Fam Zheng
Quoted 6 lines

In the coroutine case, the yield is hidden in the drivers, and it may or may not happen. For example, qcow2_co_flush_to_os starts with

    qemu_co_mutex_lock(&s->lock);

which can yield.

bdrv_ioctl, on the contrary, is emulated with .bdrv_aio_ioctl, so it always yields (unless -ENOTSUP), that's why I think aio_poll() is necessary in both branches.

But why should it yield, if called in coroutine context? bdrv_flush doesn't yield if emulated with .bdrv_aio_flush *and* called in coroutine context. bdrv_ioctl should do the same, I think.

Paolo

Reviewed-by
#5 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines · Fam Zheng
Quoted 6 lines

In the coroutine case, the yield is hidden in the drivers, and it may or may not happen. For example, qcow2_co_flush_to_os starts with

    qemu_co_mutex_lock(&s->lock);

which can yield.

Quoted 8 lines
Quoted 3 lines

bdrv_ioctl, on the contrary, is emulated with .bdrv_aio_ioctl, so it always yields (unless -ENOTSUP), that's why I think aio_poll() is necessary in both branches.

But why should it yield, if called in coroutine context? bdrv_flush doesn't yield if emulated with .bdrv_aio_flush *and* called in coroutine context. bdrv_ioctl should do the same, I think.

Looking at bdrv_flush again I see what you mean. Thanks for explaining!

Applied
#6 lore raw
In reply to Paolo Bonzini

[ Cc: qemu-block ]

Am 16.12.2015 um 19:33 hat Paolo Bonzini geschrieben:

Quoted 5 lines

When called from a coroutine, bdrv_ioctl must be asynchronous just like e.g. bdrv_flush. The code was incorrectly making it synchronous, fix it.

Thanks, applied to the block branch.

Kevin