yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-scsi-disk-Acquire-the-AioContext-in-scsi_-_realize.patch

ae23c9
From f211540f531d850eb336154469d936b87398d877 Mon Sep 17 00:00:00 2001
ae23c9
From: Markus Armbruster <armbru@redhat.com>
ae23c9
Date: Thu, 6 Jun 2019 19:15:23 +0100
ae23c9
Subject: [PATCH 6/8] scsi-disk: Acquire the AioContext in scsi_*_realize()
ae23c9
ae23c9
RH-Author: Markus Armbruster <armbru@redhat.com>
ae23c9
Message-id: <20190606191524.30797-3-armbru@redhat.com>
ae23c9
Patchwork-id: 88605
ae23c9
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 2/3] scsi-disk: Acquire the AioContext in scsi_*_realize()
ae23c9
Bugzilla: 1673396 1673401
ae23c9
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
ae23c9
From: Alberto Garcia <berto@igalia.com>
ae23c9
ae23c9
This fixes a crash when attaching two disks with the same blockdev to
ae23c9
a SCSI device that is using iothreads. Test case included.
ae23c9
ae23c9
Signed-off-by: Alberto Garcia <berto@igalia.com>
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
(cherry picked from commit 3ff35ba391134e4e43ab96152deb38a62e62f858)
ae23c9
[Trivial conflict in hw/scsi/scsi-disk.c due to lack of commit
ae23c9
51f43d5792e resolved]
ae23c9
Signed-off-by: Markus Armbruster <armbru@redhat.com>
ae23c9
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/scsi/scsi-disk.c        | 23 ++++++++++++++++++++---
ae23c9
 tests/qemu-iotests/240     | 18 ++++++++++++++++++
ae23c9
 tests/qemu-iotests/240.out | 16 ++++++++++++++++
ae23c9
 3 files changed, 54 insertions(+), 3 deletions(-)
ae23c9
ae23c9
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
ae23c9
index a20ef91..08da23d 100644
ae23c9
--- a/hw/scsi/scsi-disk.c
ae23c9
+++ b/hw/scsi/scsi-disk.c
ae23c9
@@ -2378,10 +2378,13 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
ae23c9
 static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
ae23c9
 {
ae23c9
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
ae23c9
+    AioContext *ctx = NULL;
ae23c9
     /* can happen for devices without drive. The error message for missing
ae23c9
      * backend will be issued in scsi_realize
ae23c9
      */
ae23c9
     if (s->qdev.conf.blk) {
ae23c9
+        ctx = blk_get_aio_context(s->qdev.conf.blk);
ae23c9
+        aio_context_acquire(ctx);
ae23c9
         blkconf_blocksizes(&s->qdev.conf);
ae23c9
     }
ae23c9
     s->qdev.blocksize = s->qdev.conf.logical_block_size;
ae23c9
@@ -2390,11 +2393,15 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
ae23c9
         s->product = g_strdup("QEMU HARDDISK");
ae23c9
     }
ae23c9
     scsi_realize(&s->qdev, errp);
ae23c9
+    if (ctx) {
ae23c9
+        aio_context_release(ctx);
ae23c9
+    }
ae23c9
 }
ae23c9
 
ae23c9
 static void scsi_cd_realize(SCSIDevice *dev, Error **errp)
ae23c9
 {
ae23c9
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
ae23c9
+    AioContext *ctx;
ae23c9
     int ret;
ae23c9
 
ae23c9
     if (!dev->conf.blk) {
ae23c9
@@ -2405,6 +2412,8 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **errp)
ae23c9
         assert(ret == 0);
ae23c9
     }
ae23c9
 
ae23c9
+    ctx = blk_get_aio_context(dev->conf.blk);
ae23c9
+    aio_context_acquire(ctx);
ae23c9
     s->qdev.blocksize = 2048;
ae23c9
     s->qdev.type = TYPE_ROM;
ae23c9
     s->features |= 1 << SCSI_DISK_F_REMOVABLE;
ae23c9
@@ -2412,6 +2421,7 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **errp)
ae23c9
         s->product = g_strdup("QEMU CD-ROM");
ae23c9
     }
ae23c9
     scsi_realize(&s->qdev, errp);
ae23c9
+    aio_context_release(ctx);
ae23c9
 }
ae23c9
 
ae23c9
 static void scsi_disk_realize(SCSIDevice *dev, Error **errp)
ae23c9
@@ -2550,6 +2560,7 @@ static int get_device_type(SCSIDiskState *s)
ae23c9
 static void scsi_block_realize(SCSIDevice *dev, Error **errp)
ae23c9
 {
ae23c9
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
ae23c9
+    AioContext *ctx;
ae23c9
     int sg_version;
ae23c9
     int rc;
ae23c9
 
ae23c9
@@ -2558,6 +2569,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
+    ctx = blk_get_aio_context(s->qdev.conf.blk);
ae23c9
+    aio_context_acquire(ctx);
ae23c9
+
ae23c9
     /* check we are using a driver managing SG_IO (version 3 and after) */
ae23c9
     rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version);
ae23c9
     if (rc < 0) {
ae23c9
@@ -2565,18 +2579,18 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)
ae23c9
         if (rc != -EPERM) {
ae23c9
             error_append_hint(errp, "Is this a SCSI device?\n");
ae23c9
         }
ae23c9
-        return;
ae23c9
+        goto out;
ae23c9
     }
ae23c9
     if (sg_version < 30000) {
ae23c9
         error_setg(errp, "scsi generic interface too old");
ae23c9
-        return;
ae23c9
+        goto out;
ae23c9
     }
ae23c9
 
ae23c9
     /* get device type from INQUIRY data */
ae23c9
     rc = get_device_type(s);
ae23c9
     if (rc < 0) {
ae23c9
         error_setg(errp, "INQUIRY failed");
ae23c9
-        return;
ae23c9
+        goto out;
ae23c9
     }
ae23c9
 
ae23c9
     /* Make a guess for the block size, we'll fix it when the guest sends.
ae23c9
@@ -2596,6 +2610,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)
ae23c9
 
ae23c9
     scsi_realize(&s->qdev, errp);
ae23c9
     scsi_generic_read_device_inquiry(&s->qdev);
ae23c9
+
ae23c9
+out:
ae23c9
+    aio_context_release(ctx);
ae23c9
 }
ae23c9
 
ae23c9
 typedef struct SCSIBlockReq {
ae23c9
diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240
ae23c9
index ead7ee0..5d499c9 100755
ae23c9
--- a/tests/qemu-iotests/240
ae23c9
+++ b/tests/qemu-iotests/240
ae23c9
@@ -83,6 +83,24 @@ run_qemu <
ae23c9
 { "execute": "quit"}
ae23c9
 EOF
ae23c9
 
ae23c9
+echo
ae23c9
+echo === Attach two SCSI disks using the same block device and the same iothread ===
ae23c9
+echo
ae23c9
+
ae23c9
+run_qemu <
ae23c9
+{ "execute": "qmp_capabilities" }
ae23c9
+{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
ae23c9
+{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
ae23c9
+{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
ae23c9
+{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
ae23c9
+{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0"}}
ae23c9
+{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
ae23c9
+{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
ae23c9
+{ "execute": "device_del", "arguments": {"id": "scsi0"}}
ae23c9
+{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
ae23c9
+{ "execute": "quit"}
ae23c9
+EOF
ae23c9
+
ae23c9
 # success, all done
ae23c9
 echo "*** done"
ae23c9
 rm -f $seq.full
ae23c9
diff --git a/tests/qemu-iotests/240.out b/tests/qemu-iotests/240.out
ae23c9
index 432d981..701cb5c 100644
ae23c9
--- a/tests/qemu-iotests/240.out
ae23c9
+++ b/tests/qemu-iotests/240.out
ae23c9
@@ -15,4 +15,20 @@ QMP_VERSION
ae23c9
 {"return": {}}
ae23c9
 {"return": {}}
ae23c9
 {"return": {}}
ae23c9
+
ae23c9
+=== Attach two SCSI disks using the same block device and the same iothread ===
ae23c9
+
ae23c9
+Testing:
ae23c9
+QMP_VERSION
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
+{"return": {}}
ae23c9
 *** done
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9