Blame SOURCES/kvm-virtio-scsi-Move-BlockBackend-back-to-the-main-AioCo.patch

b38b0f
From 215a509da9a0a8918ab1bfbd0f6ccfb765578f0f Mon Sep 17 00:00:00 2001
69f3e1
From: Markus Armbruster <armbru@redhat.com>
69f3e1
Date: Thu, 6 Jun 2019 19:15:22 +0100
b38b0f
Subject: [PATCH 5/8] virtio-scsi: Move BlockBackend back to the main
69f3e1
 AioContext on unplug
69f3e1
69f3e1
RH-Author: Markus Armbruster <armbru@redhat.com>
69f3e1
Message-id: <20190606191524.30797-2-armbru@redhat.com>
69f3e1
Patchwork-id: 88607
69f3e1
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 1/3] virtio-scsi: Move BlockBackend back to the main AioContext on unplug
b38b0f
Bugzilla: 1673396 1673401
69f3e1
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
69f3e1
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
69f3e1
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
69f3e1
69f3e1
From: Alberto Garcia <berto@igalia.com>
69f3e1
69f3e1
This fixes a crash when attaching a disk to a SCSI device using
69f3e1
iothreads, then detaching it and reattaching it again. Test case
69f3e1
included.
69f3e1
69f3e1
Signed-off-by: Alberto Garcia <berto@igalia.com>
69f3e1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
69f3e1
(cherry picked from commit a6f230c8d13a7ff3a0c7f1097412f44bfd9eff0b)
69f3e1
[Trivial conflict in tests/qemu-iotests/group resolved]
69f3e1
Signed-off-by: Markus Armbruster <armbru@redhat.com>
69f3e1
69f3e1
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
69f3e1
---
69f3e1
 hw/scsi/virtio-scsi.c      |  6 ++++
69f3e1
 tests/qemu-iotests/240     | 89 ++++++++++++++++++++++++++++++++++++++++++++++
69f3e1
 tests/qemu-iotests/240.out | 18 ++++++++++
69f3e1
 tests/qemu-iotests/group   |  1 +
69f3e1
 4 files changed, 114 insertions(+)
69f3e1
 create mode 100755 tests/qemu-iotests/240
69f3e1
 create mode 100644 tests/qemu-iotests/240.out
69f3e1
69f3e1
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
69f3e1
index 52a3c1d..85073f6 100644
69f3e1
--- a/hw/scsi/virtio-scsi.c
69f3e1
+++ b/hw/scsi/virtio-scsi.c
69f3e1
@@ -841,6 +841,12 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,
69f3e1
         virtio_scsi_release(s);
69f3e1
     }
69f3e1
 
69f3e1
+    if (s->ctx) {
69f3e1
+        virtio_scsi_acquire(s);
69f3e1
+        blk_set_aio_context(sd->conf.blk, qemu_get_aio_context());
69f3e1
+        virtio_scsi_release(s);
69f3e1
+    }
69f3e1
+
69f3e1
     qdev_simple_device_unplug_cb(hotplug_dev, dev, errp);
69f3e1
 }
69f3e1
 
69f3e1
diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240
69f3e1
new file mode 100755
69f3e1
index 0000000..ead7ee0
69f3e1
--- /dev/null
69f3e1
+++ b/tests/qemu-iotests/240
69f3e1
@@ -0,0 +1,89 @@
69f3e1
+#!/bin/bash
69f3e1
+#
69f3e1
+# Test hot plugging and unplugging with iothreads
69f3e1
+#
69f3e1
+# Copyright (C) 2019 Igalia, S.L.
69f3e1
+# Author: Alberto Garcia <berto@igalia.com>
69f3e1
+#
69f3e1
+# This program is free software; you can redistribute it and/or modify
69f3e1
+# it under the terms of the GNU General Public License as published by
69f3e1
+# the Free Software Foundation; either version 2 of the License, or
69f3e1
+# (at your option) any later version.
69f3e1
+#
69f3e1
+# This program is distributed in the hope that it will be useful,
69f3e1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69f3e1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
69f3e1
+# GNU General Public License for more details.
69f3e1
+#
69f3e1
+# You should have received a copy of the GNU General Public License
69f3e1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
69f3e1
+#
69f3e1
+
69f3e1
+# creator
69f3e1
+owner=berto@igalia.com
69f3e1
+
69f3e1
+seq=`basename $0`
69f3e1
+echo "QA output created by $seq"
69f3e1
+
69f3e1
+status=1	# failure is the default!
69f3e1
+
69f3e1
+# get standard environment, filters and checks
69f3e1
+. ./common.rc
69f3e1
+. ./common.filter
69f3e1
+
69f3e1
+_supported_fmt generic
69f3e1
+_supported_proto generic
69f3e1
+_supported_os Linux
69f3e1
+
69f3e1
+do_run_qemu()
69f3e1
+{
69f3e1
+    echo Testing: "$@"
69f3e1
+    $QEMU -nographic -qmp stdio -serial none "$@"
69f3e1
+    echo
69f3e1
+}
69f3e1
+
69f3e1
+# Remove QMP events from (pretty-printed) output. Doesn't handle
69f3e1
+# nested dicts correctly, but we don't get any of those in this test.
69f3e1
+_filter_qmp_events()
69f3e1
+{
69f3e1
+    tr '\n' '\t' | sed -e \
69f3e1
+	's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \
69f3e1
+	| tr '\t' '\n'
69f3e1
+}
69f3e1
+
69f3e1
+run_qemu()
69f3e1
+{
69f3e1
+    do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events
69f3e1
+}
69f3e1
+
69f3e1
+case "$QEMU_DEFAULT_MACHINE" in
69f3e1
+  s390-ccw-virtio)
69f3e1
+      virtio_scsi=virtio-scsi-ccw
69f3e1
+      ;;
69f3e1
+  *)
69f3e1
+      virtio_scsi=virtio-scsi-pci
69f3e1
+      ;;
69f3e1
+esac
69f3e1
+
69f3e1
+echo
69f3e1
+echo === Unplug a SCSI disk and then plug it again ===
69f3e1
+echo
69f3e1
+
69f3e1
+run_qemu <
69f3e1
+{ "execute": "qmp_capabilities" }
69f3e1
+{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0"}}
69f3e1
+{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
69f3e1
+{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
69f3e1
+{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
69f3e1
+{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
69f3e1
+{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
69f3e1
+{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
69f3e1
+{ "execute": "device_del", "arguments": {"id": "scsi0"}}
69f3e1
+{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
69f3e1
+{ "execute": "quit"}
69f3e1
+EOF
69f3e1
+
69f3e1
+# success, all done
69f3e1
+echo "*** done"
69f3e1
+rm -f $seq.full
69f3e1
+status=0
69f3e1
diff --git a/tests/qemu-iotests/240.out b/tests/qemu-iotests/240.out
69f3e1
new file mode 100644
69f3e1
index 0000000..432d981
69f3e1
--- /dev/null
69f3e1
+++ b/tests/qemu-iotests/240.out
69f3e1
@@ -0,0 +1,18 @@
69f3e1
+QA output created by 240
69f3e1
+
69f3e1
+=== Unplug a SCSI disk and then plug it again ===
69f3e1
+
69f3e1
+Testing:
69f3e1
+QMP_VERSION
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+{"return": {}}
69f3e1
+*** done
69f3e1
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
69f3e1
index 61c0f9c..5cbdc24 100644
69f3e1
--- a/tests/qemu-iotests/group
69f3e1
+++ b/tests/qemu-iotests/group
69f3e1
@@ -226,3 +226,4 @@
69f3e1
 231 auto quick
69f3e1
 232 auto quick
69f3e1
 234 auto quick migration
69f3e1
+240 auto quick
69f3e1
-- 
69f3e1
1.8.3.1
69f3e1