yeahuh / rpms / qemu-kvm

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