cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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