c401cc
From ef682705ff82c465fa3789b8715d642fc44d001e Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <ef682705ff82c465fa3789b8715d642fc44d001e@dist-git>
c401cc
From: Osier Yang <jyang@redhat.com>
c401cc
Date: Thu, 13 Mar 2014 18:59:44 +0800
c401cc
Subject: [PATCH] qemu: Forbid "sgio" support for SCSI generic host device
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=957292
c401cc
c401cc
The kernel didn't support the unprivileged SGIO for SCSI generic
c401cc
device finally, and since it's unknow whether the way to support
c401cc
unprivileged SGIO for SCSI generic device will be similar as for
c401cc
SCSI block device or not, even it's simliar (I.e. via sysfs, for
c401cc
SCSI block device, it's /sys/dev/block/8\:0/queue/unpriv_sgio,
c401cc
for example), the file name might be different, So it's better not
c401cc
guess what it should be like currently.
c401cc
c401cc
This patch removes the related code (mainly about the "shareable"
c401cc
checking on the "sgio" setting, it's not supported at all, why
c401cc
we leave checking code there? :-), and error out if "sgio" is
c401cc
specified in the domain config.
c401cc
(cherry picked from commit ce346623c19f82f4b35f3466e2ee4066847b750c)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/qemu/qemu_conf.c | 89 ++++++++++++++--------------------------------------
c401cc
 1 file changed, 23 insertions(+), 66 deletions(-)
c401cc
c401cc
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
c401cc
index 7660e7d..0fa9beb 100644
c401cc
--- a/src/qemu/qemu_conf.c
c401cc
+++ b/src/qemu/qemu_conf.c
c401cc
@@ -704,12 +704,8 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
c401cc
                       virDomainDeviceDefPtr dev)
c401cc
 {
c401cc
     virDomainDiskDefPtr disk = NULL;
c401cc
-    virDomainHostdevDefPtr hostdev = NULL;
c401cc
     char *sysfs_path = NULL;
c401cc
     char *key = NULL;
c401cc
-    char *hostdev_name = NULL;
c401cc
-    char *hostdev_path = NULL;
c401cc
-    char *device_path = NULL;
c401cc
     int val;
c401cc
     int ret = 0;
c401cc
 
c401cc
@@ -721,27 +717,11 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
c401cc
          */
c401cc
         if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
c401cc
             return 0;
c401cc
-
c401cc
-        device_path = disk->src;
c401cc
-    } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
c401cc
-        hostdev = dev->data.hostdev;
c401cc
-
c401cc
-        if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
c401cc
-                                                     hostdev->source.subsys.u.scsi.adapter,
c401cc
-                                                     hostdev->source.subsys.u.scsi.bus,
c401cc
-                                                     hostdev->source.subsys.u.scsi.target,
c401cc
-                                                     hostdev->source.subsys.u.scsi.unit)))
c401cc
-            goto cleanup;
c401cc
-
c401cc
-        if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0)
c401cc
-            goto cleanup;
c401cc
-
c401cc
-        device_path = hostdev_path;
c401cc
     } else {
c401cc
         return 0;
c401cc
     }
c401cc
 
c401cc
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL))) {
c401cc
+    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL))) {
c401cc
         ret = -1;
c401cc
         goto cleanup;
c401cc
     }
c401cc
@@ -752,7 +732,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
c401cc
     if (!virFileExists(sysfs_path))
c401cc
         goto cleanup;
c401cc
 
c401cc
-    if (!(key = qemuGetSharedDeviceKey(device_path))) {
c401cc
+    if (!(key = qemuGetSharedDeviceKey(disk->src))) {
c401cc
         ret = -1;
c401cc
         goto cleanup;
c401cc
     }
c401cc
@@ -763,7 +743,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
c401cc
     if (!(virHashLookup(sharedDevices, key)))
c401cc
         goto cleanup;
c401cc
 
c401cc
-    if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0) {
c401cc
+    if (virGetDeviceUnprivSGIO(disk->src, NULL, &val) < 0) {
c401cc
         ret = -1;
c401cc
         goto cleanup;
c401cc
     }
c401cc
@@ -775,36 +755,25 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
c401cc
          disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))
c401cc
         goto cleanup;
c401cc
 
c401cc
-    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
c401cc
-        if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
c401cc
-            virReportError(VIR_ERR_OPERATION_INVALID,
c401cc
-                           _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
c401cc
-                             "with other active domains"),
c401cc
-                           disk->srcpool->pool,
c401cc
-                           disk->srcpool->volume);
c401cc
-        } else {
c401cc
-            virReportError(VIR_ERR_OPERATION_INVALID,
c401cc
-                           _("sgio of shared disk '%s' conflicts with other "
c401cc
-                             "active domains"), disk->src);
c401cc
-        }
c401cc
+    if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
c401cc
+        virReportError(VIR_ERR_OPERATION_INVALID,
c401cc
+                       _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
c401cc
+                         "with other active domains"),
c401cc
+                       disk->srcpool->pool,
c401cc
+                       disk->srcpool->volume);
c401cc
     } else {
c401cc
         virReportError(VIR_ERR_OPERATION_INVALID,
c401cc
-                       _("sgio of shared scsi host device '%s-%d-%d-%d' conflicts "
c401cc
-                          "with other active domains"),
c401cc
-                       hostdev->source.subsys.u.scsi.adapter,
c401cc
-                       hostdev->source.subsys.u.scsi.bus,
c401cc
-                       hostdev->source.subsys.u.scsi.target,
c401cc
-                       hostdev->source.subsys.u.scsi.unit);
c401cc
+                       _("sgio of shared disk '%s' conflicts with other "
c401cc
+                         "active domains"), disk->src);
c401cc
     }
c401cc
 
c401cc
     ret = -1;
c401cc
 cleanup:
c401cc
-    VIR_FREE(hostdev_name);
c401cc
-    VIR_FREE(hostdev_path);
c401cc
     VIR_FREE(sysfs_path);
c401cc
     VIR_FREE(key);
c401cc
     return ret;
c401cc
 }
c401cc
+
c401cc
 bool
c401cc
 qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
c401cc
                                   const char *name,
c401cc
@@ -1081,8 +1050,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
c401cc
     virDomainHostdevDefPtr hostdev = NULL;
c401cc
     char *sysfs_path = NULL;
c401cc
     char *path = NULL;
c401cc
-    char *hostdev_name = NULL;
c401cc
-    char *hostdev_path = NULL;
c401cc
     int val = -1;
c401cc
     int ret = 0;
c401cc
 
c401cc
@@ -1100,22 +1067,19 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
c401cc
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
c401cc
         hostdev = dev->data.hostdev;
c401cc
 
c401cc
-        if (!hostdev->shareable ||
c401cc
-            !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
c401cc
-              hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
c401cc
-            return 0;
c401cc
-
c401cc
-        if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
c401cc
-                                                     hostdev->source.subsys.u.scsi.adapter,
c401cc
-                                                     hostdev->source.subsys.u.scsi.bus,
c401cc
-                                                     hostdev->source.subsys.u.scsi.target,
c401cc
-                                                     hostdev->source.subsys.u.scsi.unit)))
c401cc
-            goto cleanup;
c401cc
 
c401cc
-        if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0)
c401cc
+        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
c401cc
+            hostdev->source.subsys.type ==
c401cc
+            VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
c401cc
+            hostdev->source.subsys.u.scsi.sgio) {
c401cc
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
c401cc
+                           _("'sgio' is not supported for SCSI "
c401cc
+                             "generic device yet "));
c401cc
+            ret = -1;
c401cc
             goto cleanup;
c401cc
+        }
c401cc
 
c401cc
-        path = hostdev_path;
c401cc
+        return 0;
c401cc
     } else {
c401cc
         return 0;
c401cc
     }
c401cc
@@ -1127,12 +1091,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
c401cc
     }
c401cc
 
c401cc
     /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0.  */
c401cc
-
c401cc
-    if (dev->type == VIR_DOMAIN_DEVICE_DISK)
c401cc
-        val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
c401cc
-    else
c401cc
-        val = (hostdev->source.subsys.u.scsi.sgio ==
c401cc
-               VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
c401cc
+    val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
c401cc
 
c401cc
     /* Do not do anything if unpriv_sgio is not supported by the kernel and the
c401cc
      * whitelist is enabled.  But if requesting unfiltered access, always call
c401cc
@@ -1144,8 +1103,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
c401cc
 
c401cc
 cleanup:
c401cc
     VIR_FREE(sysfs_path);
c401cc
-    VIR_FREE(hostdev_name);
c401cc
-    VIR_FREE(hostdev_path);
c401cc
     return ret;
c401cc
 }
c401cc
 
c401cc
-- 
c401cc
1.9.0
c401cc