aio: add missing aio_notify() to aio_enable_external()
A message that is not in the archive (sent off-list or not yet received): [email protected]
Paolo Bonzini
Reviewed-byQuoted 25 lines · Stefan Hajnoczi
The main loop uses aio_disable_external()/aio_enable_external() to temporarily disable processing of external AioContext clients like device emulation.
This allows monitor commands to quiesce I/O and prevent the guest from submitting new requests while a monitor command is in progress.
The
aio_enable_external()API is currently broken when an IOThread is inaio_poll()waiting for fd activity when the main loop re-enables external clients. Incrementingctx->external_disable_cntdoes not wake the IOThread from ppoll(2) so fd processing remains suspended and leads to unresponsive emulated devices.This patch adds an
aio_notify()call toaio_enable_external()so the IOThread is kicked out of ppoll(2) and will re-arm the file descriptors.The bug can be reproduced as follows:
$ qemu -M accel=kvm -m 1024 \ -object iothread,id=iothread0 \ -device virtio-scsi-pci,iothread=iothread0,id=virtio-scsi-pci0 \ -drive if=none,id=drive0,aio=native,cache=none,format=raw,file=test.img \ -device scsi-hd,id=scsi-hd0,drive=drive0 \ -qmp tcp::5555,server,nowait
Quoted 6 lines
$ scripts/qmp/qmp-shell localhost:5555 (qemu) blockdev-snapshot-sync device=drive0 snapshot-file=sn1.qcow2 mode=absolute-paths format=qcow2After blockdev-snapshot-sync completes the SCSI disk will be unresponsive. This leads to request timeouts inside the guest.
I agree this is the minimal fix and is the right thing to do. The bdrv_drained_begin/end device callbacks would also make it possible to remove disable/enable external altogether, but that's more invasive.
Quoted 20 lines
Reported-by Qianqian Zhu <[email protected]>Suggested-by Fam Zheng <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- include/block/aio.h | 1 + 1 file changed, 1 insertion(+)include/block/aio.h +1
-0@@ -456,6 +456,7 @@ static inline void aio_enable_external(AioContext *ctx) {assert (ctx->external_disable_cnt >0 );atomic_dec (&ctx->external_disable_cnt); +aio_notify (ctx); }/**
Quoted 49 lines · Paolo Bonzini
Quoted 25 lines · Stefan Hajnoczi
The main loop uses aio_disable_external()/aio_enable_external() to temporarily disable processing of external AioContext clients like device emulation.
This allows monitor commands to quiesce I/O and prevent the guest from submitting new requests while a monitor command is in progress.
The
aio_enable_external()API is currently broken when an IOThread is inaio_poll()waiting for fd activity when the main loop re-enables external clients. Incrementingctx->external_disable_cntdoes not wake the IOThread from ppoll(2) so fd processing remains suspended and leads to unresponsive emulated devices.This patch adds an
aio_notify()call toaio_enable_external()so the IOThread is kicked out of ppoll(2) and will re-arm the file descriptors.The bug can be reproduced as follows:
$ qemu -M accel=kvm -m 1024 \ -object iothread,id=iothread0 \ -device virtio-scsi-pci,iothread=iothread0,id=virtio-scsi-pci0 \ -drive if=none,id=drive0,aio=native,cache=none,format=raw,file=test.img \ -device scsi-hd,id=scsi-hd0,drive=drive0 \ -qmp tcp::5555,server,nowaitQuoted 6 lines
$ scripts/qmp/qmp-shell localhost:5555 (qemu) blockdev-snapshot-sync device=drive0 snapshot-file=sn1.qcow2 mode=absolute-paths format=qcow2After blockdev-snapshot-sync completes the SCSI disk will be unresponsive. This leads to request timeouts inside the guest.
I agree this is the minimal fix and is the right thing to do. The bdrv_drained_begin/end device callbacks would also make it possible to remove disable/enable external altogether, but that's more invasive.
Reviewed-by Paolo Bonzini <[email protected]>Quoted 7 lines
Reported-by Qianqian Zhu <[email protected]>Suggested-by Fam Zheng <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- include/block/aio.h | 1 + 1 file changed, 1 insertion(+)
Quoted 8 lines
include/block/aio.h static inline void aio_enable_external(AioContext *ctx) · line 458
Quoted 8 lines
include/block/aio.h +0
-0@@ -456,6 +456,7 @@ static inline void aio_enable_external(AioContext *ctx) {assert (ctx->external_disable_cnt >0 );atomic_dec (&ctx->external_disable_cnt);
This can be changed to atomic_fetch_dec and only call aio_notify if it returned 1, which is cleaner.
Quoted 5 lines
Quoted 5 lines
include/block/aio.h +1
-0+aio_notify (ctx); }/**
Quoted 13 lines · Fam Zheng
Quoted 9 lines · Paolo Bonzini
include/block/aio.h static inline void aio_enable_external(AioContext *ctx) · line 458
Quoted 8 lines · Stefan Hajnoczi
include/block/aio.h +0
-0@@ -456,6 +456,7 @@ static inline void aio_enable_external(AioContext *ctx) {assert (ctx->external_disable_cnt >0 );atomic_dec (&ctx->external_disable_cnt);This can be changed to
atomic_fetch_decand only callaio_notifyif it returned 1, which is cleaner.
Nice idea. Will send v2.
Stefan