[PATCH 3/3] Refactoring: Use virHostdevIsSCSIDevice()

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

 



Use the util function virHostdevIsSCSIDevice() to simplify if
statements.

Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxxxxxxx>
---
 src/Makefile.am         | 3 ++-
 src/conf/domain_conf.c  | 8 +++-----
 src/qemu/qemu_command.c | 3 +--
 src/qemu/qemu_conf.c    | 7 +++----
 src/qemu/qemu_domain.c  | 8 ++------
 src/qemu/qemu_process.c | 3 +--
 src/util/virhostdev.c   | 9 +++------
 7 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index aaba9e6..b358e0e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1137,7 +1137,8 @@ libvirt_util_la_LIBADD = $(CAPNG_LIBS) $(YAJL_LIBS) $(LIBNL_LIBS) \
 noinst_LTLIBRARIES += libvirt_conf.la
 libvirt_la_BUILT_LIBADD += libvirt_conf.la
 libvirt_conf_la_SOURCES = $(CONF_SOURCES)
-libvirt_conf_la_CFLAGS = $(AM_CFLAGS)
+libvirt_conf_la_CFLAGS = \
+		-I$(srcdir)/conf $(AM_CFLAGS)
 libvirt_conf_la_LDFLAGS = $(AM_LDFLAGS)
 libvirt_conf_la_LIBADD = $(LIBXML_LIBS)
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6e008e2..e7517d9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -55,6 +55,7 @@
 #include "virtpm.h"
 #include "virstring.h"
 #include "virnetdev.h"
+#include "virhostdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -4247,9 +4248,7 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
     if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
         virDomainHostdevDefPtr hdev = dev->data.hostdev;
 
-        if (hdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-            hdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
-
+        if (virHostdevIsSCSIDevice(hdev)) {
             if (hdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
                 virDomainHostdevAssignAddress(xmlopt, def, hdev) < 0) {
                 virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -15648,8 +15647,7 @@ virDomainDefMaybeAddHostdevSCSIcontroller(virDomainDefPtr def)
 
     for (i = 0; i < def->nhostdevs; i++) {
         hostdev = def->hostdevs[i];
-        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-            hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
+        if (virHostdevIsSCSIDevice(hostdev) &&
             (int)hostdev->info->addr.drive.controller > maxController) {
             maxController = hostdev->info->addr.drive.controller;
         }
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4a5fce3..51b5aaf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5199,8 +5199,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
         }
 
         /* SCSI */
-        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-            subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
+        if (virHostdevIsSCSIDevice(hostdev)) {
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) {
                 char *drvstr;
 
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 0ed88f5..fbac3ea 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1187,10 +1187,9 @@ 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));
+            (virHostdevIsSCSIDevice(hostdev) &&
+             hostdev->source.subsys.u.scsi.protocol !=
+             VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI));
 }
 
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e3c1805..55215ec 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1185,12 +1185,9 @@ qemuDomainSecretHostdevPrepare(virConnectPtr conn,
                                qemuDomainObjPrivatePtr priv,
                                virDomainHostdevDefPtr hostdev)
 {
-    virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
     qemuDomainSecretInfoPtr secinfo = NULL;
 
-    if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-        subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
-
+    if (virHostdevIsSCSIDevice(hostdev)) {
         virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
         virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
 
@@ -4037,8 +4034,7 @@ void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver,
                                     virDomainHostdevDefPtr hostdev,
                                     qemuDomainLogContextPtr logCtxt)
 {
-    if (!(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
+    if (!virHostdevIsSCSIDevice(hostdev))
         return;
 
     if (hostdev->source.subsys.u.scsi.rawio == VIR_TRISTATE_BOOL_YES)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index cca6754..4758c49 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4312,8 +4312,7 @@ qemuProcessSetupRawIO(virQEMUDriverPtr driver,
     /* If rawio not already set, check hostdevs as well */
     if (!rawio) {
         for (i = 0; i < vm->def->nhostdevs; i++) {
-            if (!(vm->def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-                  vm->def->hostdevs[i]->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
+            if (!virHostdevIsSCSIDevice(vm->def->hostdevs[i]))
                 continue;
 
             virDomainHostdevSubsysSCSIPtr scsisrc =
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index d283306..a038e13 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1114,8 +1114,7 @@ virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr,
         hostdev = hostdevs[i];
         scsisrc = &hostdev->source.subsys.u.scsi;
 
-        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-            hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
+        if (!virHostdevIsSCSIDevice(hostdev))
             continue;
 
         if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
@@ -1413,8 +1412,7 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr mgr,
         virDomainHostdevDefPtr hostdev = hostdevs[i];
         virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
 
-        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-            hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
+        if (!virHostdevIsSCSIDevice(hostdev))
             continue;
 
         if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
@@ -1605,8 +1603,7 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr mgr,
         virDomainHostdevDefPtr hostdev = hostdevs[i];
         virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
 
-        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-            hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
+        if (!virHostdevIsSCSIDevice(hostdev))
             continue;
 
         if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
-- 
2.5.5

--
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]
  Powered by Linux