[PATCH 23/25] qemu: Refactor qemuSetUnprivSGIO to support scsi host device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just like what previous patches do, it refactors qemuSetUnprivSGIO
to take the virDomainDeviceDefPtr as argument instead.
---
 src/qemu/qemu_conf.c    | 67 ++++++++++++++++++++++++++++++++++++++++---------
 src/qemu/qemu_conf.h    |  2 +-
 src/qemu/qemu_driver.c  |  2 +-
 src/qemu/qemu_process.c |  2 +-
 4 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index b7dea57..cf1c7ee 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1309,39 +1309,82 @@ cleanup:
 }
 
 int
-qemuSetUnprivSGIO(virDomainDiskDefPtr disk)
+qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
 {
+    virDomainDiskDefPtr disk = NULL;
+    virDomainHostdevDefPtr hostdev = NULL;
     char *sysfs_path = NULL;
+    char *path = NULL;
+    char *hostdev_name = NULL;
+    char *hostdev_path = NULL;
     int val = -1;
     int ret = 0;
 
     /* "sgio" is only valid for block disk; cdrom
      * and floopy disk can have empty source.
      */
-    if (!disk->src ||
-        disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
-        (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
-         !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
-           disk->srcpool &&
-           disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK)))
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
+        disk = dev->data.disk;
+
+        if (!disk->src ||
+            disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
+            (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
+             !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
+               disk->srcpool &&
+               disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK)))
+            return 0;
+
+        path = disk->src;
+    } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
+        hostdev = dev->data.hostdev;
+
+        if (!hostdev->shareable ||
+            (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+             hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
+            return 0;
+
+        if (!(hostdev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
+                                                     hostdev->source.subsys.u.scsi.bus,
+                                                     hostdev->source.subsys.u.scsi.target,
+                                                     hostdev->source.subsys.u.scsi.unit)))
+            goto cleanup;
+
+        if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        path = hostdev_path;
+    } else {
         return 0;
+    }
 
-    sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL);
-    if (sysfs_path == NULL)
-        return -1;
+    sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL);
+    if (sysfs_path == NULL) {
+        ret = -1;
+        goto cleanup;
+    }
 
     /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0.  */
-    val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
+
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK)
+        val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
+    else
+        val = (hostdev->source.subsys.u.scsi.sgio ==
+               VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
 
     /* Do not do anything if unpriv_sgio is not supported by the kernel and the
      * whitelist is enabled.  But if requesting unfiltered access, always call
      * virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio.
      */
     if ((virFileExists(sysfs_path) || val == 1) &&
-        virSetDeviceUnprivSGIO(disk->src, NULL, val) < 0)
+        virSetDeviceUnprivSGIO(path, NULL, val) < 0)
         ret = -1;
 
+cleanup:
     VIR_FREE(sysfs_path);
+    VIR_FREE(hostdev_name);
+    VIR_FREE(hostdev_path);
     return ret;
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 5e76739..2483fd6 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -299,7 +299,7 @@ int qemuRemoveSharedDevice(virQEMUDriverPtr driver,
                            const char *name)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 
-int qemuSetUnprivSGIO(virDomainDiskDefPtr disk);
+int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
 
 int qemuDriverAllocateID(virQEMUDriverPtr driver);
 virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 991b68b..f523f03 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5651,7 +5651,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
     if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
         goto end;
 
-    if (qemuSetUnprivSGIO(disk) < 0)
+    if (qemuSetUnprivSGIO(dev) < 0)
         goto end;
 
     if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index eb42df1..a6d58cb 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3645,7 +3645,7 @@ int qemuProcessStart(virConnectPtr conn,
         if (qemuAddSharedDevice(driver, &dev, vm->def->name) < 0)
             goto cleanup;
 
-        if (qemuSetUnprivSGIO(disk) < 0)
+        if (qemuSetUnprivSGIO(&dev) < 0)
             goto cleanup;
     }
 
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]