Blame SOURCES/kvm-virtio-scsi-Forbid-devices-with-different-iothreads-.patch

7711c0
From f482ed4845d33ce74a990ee935475dfbabf1df70 Mon Sep 17 00:00:00 2001
7711c0
From: Markus Armbruster <armbru@redhat.com>
7711c0
Date: Fri, 10 May 2019 13:28:25 +0200
7711c0
Subject: [PATCH 22/53] virtio-scsi: Forbid devices with different iothreads
7711c0
 sharing a blockdev
7711c0
7711c0
RH-Author: Markus Armbruster <armbru@redhat.com>
7711c0
Message-id: <20190510132825.29833-4-armbru@redhat.com>
7711c0
Patchwork-id: 87266
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 3/3] virtio-scsi: Forbid devices with different iothreads sharing a blockdev
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 patch forbids attaching a disk to a SCSI device if its using a
7711c0
different AioContext. Test case 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 eb97813ff5fd5bdffc8ed9f5be5a3a50eae70a2c)
7711c0
Signed-off-by: Markus Armbruster <armbru@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 hw/scsi/virtio-scsi.c      |  7 +++++++
7711c0
 tests/qemu-iotests/240     | 22 ++++++++++++++++++++++
7711c0
 tests/qemu-iotests/240.out | 20 ++++++++++++++++++++
7711c0
 3 files changed, 49 insertions(+)
7711c0
7711c0
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
7711c0
index 85073f6..391500b 100644
7711c0
--- a/hw/scsi/virtio-scsi.c
7711c0
+++ b/hw/scsi/virtio-scsi.c
7711c0
@@ -800,9 +800,16 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,
7711c0
         return;
7711c0
     }
7711c0
     if (s->ctx && !s->dataplane_fenced) {
7711c0
+        AioContext *ctx;
7711c0
         if (blk_op_is_blocked(sd->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) {
7711c0
             return;
7711c0
         }
7711c0
+        ctx = blk_get_aio_context(sd->conf.blk);
7711c0
+        if (ctx != s->ctx && ctx != qemu_get_aio_context()) {
7711c0
+            error_setg(errp, "Cannot attach a blockdev that is using "
7711c0
+                       "a different iothread");
7711c0
+            return;
7711c0
+        }
7711c0
         virtio_scsi_acquire(s);
7711c0
         blk_set_aio_context(sd->conf.blk, s->ctx);
7711c0
         virtio_scsi_release(s);
7711c0
diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240
7711c0
index 5d499c9..65cc3b3 100755
7711c0
--- a/tests/qemu-iotests/240
7711c0
+++ b/tests/qemu-iotests/240
7711c0
@@ -101,6 +101,28 @@ run_qemu <
7711c0
 { "execute": "quit"}
7711c0
 EOF
7711c0
 
7711c0
+echo
7711c0
+echo === Attach two SCSI disks using the same block device but different iothreads ===
7711c0
+echo
7711c0
+
7711c0
+run_qemu <
7711c0
+{ "execute": "qmp_capabilities" }
7711c0
+{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
7711c0
+{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
7711c0
+{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread1"}}
7711c0
+{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
7711c0
+{ "execute": "device_add", "arguments": {"id": "scsi1", "driver": "${virtio_scsi}", "iothread": "iothread1"}}
7711c0
+{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
7711c0
+{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
7711c0
+{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
7711c0
+{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
7711c0
+{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
7711c0
+{ "execute": "device_del", "arguments": {"id": "scsi0"}}
7711c0
+{ "execute": "device_del", "arguments": {"id": "scsi1"}}
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
diff --git a/tests/qemu-iotests/240.out b/tests/qemu-iotests/240.out
7711c0
index 701cb5c..d763929 100644
7711c0
--- a/tests/qemu-iotests/240.out
7711c0
+++ b/tests/qemu-iotests/240.out
7711c0
@@ -31,4 +31,24 @@ QMP_VERSION
7711c0
 {"return": {}}
7711c0
 {"return": {}}
7711c0
 {"return": {}}
7711c0
+
7711c0
+=== Attach two SCSI disks using the same block device but different iothreads ===
7711c0
+
7711c0
+Testing:
7711c0
+QMP_VERSION
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"error": {"class": "GenericError", "desc": "Cannot attach a blockdev that is using a different iothread"}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
+{"return": {}}
7711c0
 *** done
7711c0
-- 
7711c0
1.8.3.1
7711c0