]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Introduce qemuIsSharedHostdev
authorJohn Ferlan <jferlan@redhat.com>
Tue, 16 Jun 2015 17:33:37 +0000 (13:33 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 8 Jul 2015 19:07:22 +0000 (15:07 -0400)
Add a single boolean function to handle whether the hostdev is shared or not.

Use the new function for the qemu{Add|Remove}SharedHostdev calls as well
as qemuSetUnprivSGIO. NB: This third usage fixes a possible bug where
if this feature is enabled at some time in the future and the shareable flag
wasn't set, the sgio would have been erroneously set.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_conf.c

index d521886d7d285d8fa069474044450ee36c374853..679e11b579deced5b166ef46028ac0a90b582aa0 100644 (file)
@@ -1201,6 +1201,17 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
 }
 
 
+static bool
+qemuIsSharedHostdev(virDomainHostdevDefPtr hostdev)
+{
+    return (hostdev->shareable &&
+        (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+         hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
+         hostdev->source.subsys.u.scsi.protocol !=
+         VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI));
+}
+
+
 static char *
 qemuGetSharedHostdevKey(virDomainHostdevDefPtr hostdev)
 {
@@ -1238,10 +1249,7 @@ qemuAddSharedHostdev(virQEMUDriverPtr driver,
     char *key = NULL;
     int ret = -1;
 
-    if (!hostdev->shareable ||
-        !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
-          hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI))
+    if (!qemuIsSharedHostdev(hostdev))
         return 0;
 
     if (!(key = qemuGetSharedHostdevKey(hostdev)))
@@ -1342,10 +1350,7 @@ qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
     char *key = NULL;
     int ret;
 
-    if (!hostdev->shareable ||
-        !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
-          hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI))
+    if (!qemuIsSharedHostdev(hostdev))
         return 0;
 
     if (!(key = qemuGetSharedHostdevKey(hostdev)))
@@ -1407,11 +1412,10 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
         hostdev = dev->data.hostdev;
 
+        if (!qemuIsSharedHostdev(hostdev))
+            return 0;
 
-        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-            hostdev->source.subsys.type ==
-            VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
-            hostdev->source.subsys.u.scsi.sgio) {
+        if (hostdev->source.subsys.u.scsi.sgio) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("'sgio' is not supported for SCSI "
                              "generic device yet "));