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

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