]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0006-aio-add-missing-aio_notify-to-aio_enable_external.patch
merge various stable fixes
[pve-qemu.git] / debian / patches / extra / 0006-aio-add-missing-aio_notify-to-aio_enable_external.patch
1 From c9d7fd0fd5736afd1f6c508f2b5f1ae0608847bd Mon Sep 17 00:00:00 2001
2 From: Stefan Hajnoczi <stefanha@redhat.com>
3 Date: Mon, 8 May 2017 14:07:05 -0400
4 Subject: [PATCH 06/15] aio: add missing aio_notify() to aio_enable_external()
5
6 The main loop uses aio_disable_external()/aio_enable_external() to
7 temporarily disable processing of external AioContext clients like
8 device emulation.
9
10 This allows monitor commands to quiesce I/O and prevent the guest from
11 submitting new requests while a monitor command is in progress.
12
13 The aio_enable_external() API is currently broken when an IOThread is in
14 aio_poll() waiting for fd activity when the main loop re-enables
15 external clients. Incrementing ctx->external_disable_cnt does not wake
16 the IOThread from ppoll(2) so fd processing remains suspended and leads
17 to unresponsive emulated devices.
18
19 This patch adds an aio_notify() call to aio_enable_external() so the
20 IOThread is kicked out of ppoll(2) and will re-arm the file descriptors.
21
22 The bug can be reproduced as follows:
23
24 $ qemu -M accel=kvm -m 1024 \
25 -object iothread,id=iothread0 \
26 -device virtio-scsi-pci,iothread=iothread0,id=virtio-scsi-pci0 \
27 -drive if=none,id=drive0,aio=native,cache=none,format=raw,file=test.img \
28 -device scsi-hd,id=scsi-hd0,drive=drive0 \
29 -qmp tcp::5555,server,nowait
30
31 $ scripts/qmp/qmp-shell localhost:5555
32 (qemu) blockdev-snapshot-sync device=drive0 snapshot-file=sn1.qcow2
33 mode=absolute-paths format=qcow2
34
35 After blockdev-snapshot-sync completes the SCSI disk will be
36 unresponsive. This leads to request timeouts inside the guest.
37
38 Reported-by: Qianqian Zhu <qizhu@redhat.com>
39 Reviewed-by: Fam Zheng <famz@redhat.com>
40 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
41 Message-id: 20170508180705.20609-1-stefanha@redhat.com
42 Suggested-by: Fam Zheng <famz@redhat.com>
43 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
44 ---
45 include/block/aio.h | 10 ++++++++--
46 1 file changed, 8 insertions(+), 2 deletions(-)
47
48 diff --git a/include/block/aio.h b/include/block/aio.h
49 index 406e32305a..e9aeeaec94 100644
50 --- a/include/block/aio.h
51 +++ b/include/block/aio.h
52 @@ -454,8 +454,14 @@ static inline void aio_disable_external(AioContext *ctx)
53 */
54 static inline void aio_enable_external(AioContext *ctx)
55 {
56 - assert(ctx->external_disable_cnt > 0);
57 - atomic_dec(&ctx->external_disable_cnt);
58 + int old;
59 +
60 + old = atomic_fetch_dec(&ctx->external_disable_cnt);
61 + assert(old > 0);
62 + if (old == 1) {
63 + /* Kick event loop so it re-arms file descriptors */
64 + aio_notify(ctx);
65 + }
66 }
67
68 /**
69 --
70 2.11.0
71