7a3408
From 8dc583373f79d4b8226eb510c6466759421cf8c7 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <8dc583373f79d4b8226eb510c6466759421cf8c7@dist-git>
7a3408
From: John Ferlan <jferlan@redhat.com>
7a3408
Date: Thu, 9 Jul 2015 08:28:51 -0400
7a3408
Subject: [PATCH] qemu: Introduce qemuIsSharedHostdev
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1072736
7a3408
7a3408
Add a single boolean function to handle whether the hostdev is shared or not.
7a3408
7a3408
Use the new function for the qemu{Add|Remove}SharedHostdev calls as well
7a3408
as qemuSetUnprivSGIO. NB: This third usage fixes a possible bug where
7a3408
if this feature is enabled at some time in the future and the shareable flag
7a3408
wasn't set, the sgio would have been erroneously set.
7a3408
7a3408
Signed-off-by: John Ferlan <jferlan@redhat.com>
7a3408
(cherry picked from commit 8c43258ed5fca8b285400135948300fa6f58f402)
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_conf.c | 28 ++++++++++++++++------------
7a3408
 1 file changed, 16 insertions(+), 12 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
7a3408
index 7c2947c..1467427 100644
7a3408
--- a/src/qemu/qemu_conf.c
7a3408
+++ b/src/qemu/qemu_conf.c
7a3408
@@ -1201,6 +1201,17 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
7a3408
 }
7a3408
 
7a3408
 
7a3408
+static bool
7a3408
+qemuIsSharedHostdev(virDomainHostdevDefPtr hostdev)
7a3408
+{
7a3408
+    return (hostdev->shareable &&
7a3408
+        (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
7a3408
+         hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
7a3408
+         hostdev->source.subsys.u.scsi.protocol !=
7a3408
+         VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI));
7a3408
+}
7a3408
+
7a3408
+
7a3408
 static char *
7a3408
 qemuGetSharedHostdevKey(virDomainHostdevDefPtr hostdev)
7a3408
 {
7a3408
@@ -1238,10 +1249,7 @@ qemuAddSharedHostdev(virQEMUDriverPtr driver,
7a3408
     char *key = NULL;
7a3408
     int ret = -1;
7a3408
 
7a3408
-    if (!hostdev->shareable ||
7a3408
-        !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
7a3408
-          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
7a3408
-          hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI))
7a3408
+    if (!qemuIsSharedHostdev(hostdev))
7a3408
         return 0;
7a3408
 
7a3408
     if (!(key = qemuGetSharedHostdevKey(hostdev)))
7a3408
@@ -1342,10 +1350,7 @@ qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
7a3408
     char *key = NULL;
7a3408
     int ret;
7a3408
 
7a3408
-    if (!hostdev->shareable ||
7a3408
-        !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
7a3408
-          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
7a3408
-          hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI))
7a3408
+    if (!qemuIsSharedHostdev(hostdev))
7a3408
         return 0;
7a3408
 
7a3408
     if (!(key = qemuGetSharedHostdevKey(hostdev)))
7a3408
@@ -1407,11 +1412,10 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
7a3408
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
7a3408
         hostdev = dev->data.hostdev;
7a3408
 
7a3408
+        if (!qemuIsSharedHostdev(hostdev))
7a3408
+            return 0;
7a3408
 
7a3408
-        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
7a3408
-            hostdev->source.subsys.type ==
7a3408
-            VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
7a3408
-            hostdev->source.subsys.u.scsi.sgio) {
7a3408
+        if (hostdev->source.subsys.u.scsi.sgio) {
7a3408
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
7a3408
                            _("'sgio' is not supported for SCSI "
7a3408
                              "generic device yet "));
7a3408
-- 
7a3408
2.5.1
7a3408