thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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