76daa3
From 988413c0fb5eed4d0f11d218e2d2a883d713e777 Mon Sep 17 00:00:00 2001
76daa3
From: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
Date: Mon, 15 May 2017 14:25:31 +0200
76daa3
Subject: [PATCH 4/5] aio: add missing aio_notify() to aio_enable_external()
76daa3
76daa3
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
Message-id: <20170515142531.15830-2-stefanha@redhat.com>
76daa3
Patchwork-id: 75165
76daa3
O-Subject: [RHV-7.4 qemu-kvm-rhev PATCH 1/1] aio: add missing aio_notify() to aio_enable_external()
76daa3
Bugzilla: 1446498
76daa3
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
76daa3
RH-Acked-by: Fam Zheng <famz@redhat.com>
76daa3
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
76daa3
76daa3
The main loop uses aio_disable_external()/aio_enable_external() to
76daa3
temporarily disable processing of external AioContext clients like
76daa3
device emulation.
76daa3
76daa3
This allows monitor commands to quiesce I/O and prevent the guest from
76daa3
submitting new requests while a monitor command is in progress.
76daa3
76daa3
The aio_enable_external() API is currently broken when an IOThread is in
76daa3
aio_poll() waiting for fd activity when the main loop re-enables
76daa3
external clients.  Incrementing ctx->external_disable_cnt does not wake
76daa3
the IOThread from ppoll(2) so fd processing remains suspended and leads
76daa3
to unresponsive emulated devices.
76daa3
76daa3
This patch adds an aio_notify() call to aio_enable_external() so the
76daa3
IOThread is kicked out of ppoll(2) and will re-arm the file descriptors.
76daa3
76daa3
The bug can be reproduced as follows:
76daa3
76daa3
  $ qemu -M accel=kvm -m 1024 \
76daa3
         -object iothread,id=iothread0 \
76daa3
         -device virtio-scsi-pci,iothread=iothread0,id=virtio-scsi-pci0 \
76daa3
         -drive if=none,id=drive0,aio=native,cache=none,format=raw,file=test.img \
76daa3
         -device scsi-hd,id=scsi-hd0,drive=drive0 \
76daa3
         -qmp tcp::5555,server,nowait
76daa3
76daa3
  $ scripts/qmp/qmp-shell localhost:5555
76daa3
  (qemu) blockdev-snapshot-sync device=drive0 snapshot-file=sn1.qcow2
76daa3
         mode=absolute-paths format=qcow2
76daa3
76daa3
After blockdev-snapshot-sync completes the SCSI disk will be
76daa3
unresponsive.  This leads to request timeouts inside the guest.
76daa3
76daa3
Reported-by: Qianqian Zhu <qizhu@redhat.com>
76daa3
Reviewed-by: Fam Zheng <famz@redhat.com>
76daa3
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
Message-id: 20170508180705.20609-1-stefanha@redhat.com
76daa3
Suggested-by: Fam Zheng <famz@redhat.com>
76daa3
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
(cherry picked from commit 321d1dba8bef9676a77e9399484e3cd8bf2cf16a)
76daa3
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 include/block/aio.h | 10 ++++++++--
76daa3
 1 file changed, 8 insertions(+), 2 deletions(-)
76daa3
76daa3
diff --git a/include/block/aio.h b/include/block/aio.h
76daa3
index 406e323..e9aeeae 100644
76daa3
--- a/include/block/aio.h
76daa3
+++ b/include/block/aio.h
76daa3
@@ -454,8 +454,14 @@ static inline void aio_disable_external(AioContext *ctx)
76daa3
  */
76daa3
 static inline void aio_enable_external(AioContext *ctx)
76daa3
 {
76daa3
-    assert(ctx->external_disable_cnt > 0);
76daa3
-    atomic_dec(&ctx->external_disable_cnt);
76daa3
+    int old;
76daa3
+
76daa3
+    old = atomic_fetch_dec(&ctx->external_disable_cnt);
76daa3
+    assert(old > 0);
76daa3
+    if (old == 1) {
76daa3
+        /* Kick event loop so it re-arms file descriptors */
76daa3
+        aio_notify(ctx);
76daa3
+    }
76daa3
 }
76daa3
 
76daa3
 /**
76daa3
-- 
76daa3
1.8.3.1
76daa3