[PATCH 10/20] virDomainHostdevDef: Convert 'mode' field to proper enum type

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

 



Convert the field, adjust the XML parser to use
virXMLPropEnumDefault() and fill in missing cases to switch()
statements.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/domain_audit.c         |  2 +-
 src/conf/domain_conf.c          | 23 +++++++++++++----------
 src/conf/domain_conf.h          |  2 +-
 src/lxc/lxc_cgroup.c            |  1 +
 src/lxc/lxc_controller.c        |  1 +
 src/lxc/lxc_driver.c            |  2 ++
 src/lxc/lxc_hostdev.c           |  1 +
 src/qemu/qemu_domain.c          |  2 +-
 src/qemu/qemu_migration.c       |  2 +-
 src/security/security_selinux.c |  2 ++
 10 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index ae875188bd..d4d303a214 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -351,7 +351,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev,
         return;
     }
 
-    switch ((virDomainHostdevMode) hostdev->mode) {
+    switch (hostdev->mode) {
     case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
         switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 65b7b44ccb..c93f89ced6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2648,6 +2648,8 @@ virDomainHostdevDefClear(virDomainHostdevDef *def)
             break;
         }
         break;
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+        break;
     }
 }
 
@@ -12917,7 +12919,6 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
 {
     virDomainHostdevDef *def;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    g_autofree char *mode = virXMLPropString(node, "mode");
     g_autofree char *type = virXMLPropString(node, "type");
 
     ctxt->node = node;
@@ -12925,15 +12926,11 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
     if (!(def = virDomainHostdevDefNew()))
         goto error;
 
-    if (mode) {
-        if ((def->mode = virDomainHostdevModeTypeFromString(mode)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown hostdev mode '%1$s'"), mode);
-            goto error;
-        }
-    } else {
-        def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
-    }
+    if (virXMLPropEnumDefault(node, "mode", virDomainHostdevModeTypeFromString,
+                              VIR_XML_PROP_NONE,
+                              &def->mode,
+                              VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) < 0)
+        goto error;
 
     switch (def->mode) {
     case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
@@ -12947,6 +12944,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
             goto error;
         break;
     default:
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unexpected hostdev mode %1$d"), def->mode);
         goto error;
@@ -14182,6 +14180,8 @@ virDomainHostdevMatch(virDomainHostdevDef *a,
         return virDomainHostdevMatchSubsys(a, b);
     case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
         return virDomainHostdevMatchCaps(a, b);
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+        break;
     }
     return 0;
 }
@@ -26087,6 +26087,7 @@ virDomainHostdevDefFormat(virBuffer *buf,
         }
         break;
     default:
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected hostdev mode %1$d"), def->mode);
         return -1;
@@ -26139,6 +26140,8 @@ virDomainHostdevDefFormat(virBuffer *buf,
         if (virDomainHostdevDefFormatCaps(buf, def) < 0)
             return -1;
         break;
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+        break;
     }
 
     virDomainNetTeamingInfoFormat(def->teaming, buf);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index d6d0799f63..1f977ef1c8 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -371,7 +371,7 @@ struct _virDomainHostdevDef {
      */
     virDomainNetDef *parentnet;
 
-    int mode; /* enum virDomainHostdevMode */
+    virDomainHostdevMode mode;
     virDomainStartupPolicy startupPolicy;
     bool managed;
     bool missing;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index bc39b16928..21d9b456e8 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -313,6 +313,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDef *def,
                 break;
             }
         default:
+        case VIR_DOMAIN_HOSTDEV_MODE_LAST:
             break;
         }
     }
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 6c20429998..e2d67d504d 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1837,6 +1837,7 @@ virLXCControllerSetupAllHostdevs(virLXCController *ctrl)
                 return -1;
             break;
         default:
+        case VIR_DOMAIN_HOSTDEV_MODE_LAST:
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("Unsupported host device mode %1$s"),
                            virDomainHostdevModeTypeToString(def->mode));
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index f3d3e4eb50..fb0301b811 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3905,6 +3905,7 @@ lxcDomainAttachDeviceHostdevLive(virLXCDriver *driver,
         return lxcDomainAttachDeviceHostdevCapsLive(driver, vm, dev);
 
     default:
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported host device mode %1$s"),
                        virDomainHostdevModeTypeToString(dev->data.hostdev->mode));
@@ -4328,6 +4329,7 @@ lxcDomainDetachDeviceHostdevLive(virLXCDriver *driver,
         return lxcDomainDetachDeviceHostdevCapsLive(vm, dev);
 
     default:
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported host device mode %1$s"),
                        virDomainHostdevModeTypeToString(dev->data.hostdev->mode));
diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c
index 8fe02a4276..af3ce3e0ac 100644
--- a/src/lxc/lxc_hostdev.c
+++ b/src/lxc/lxc_hostdev.c
@@ -100,6 +100,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver,
 
 
         default:
+        case VIR_DOMAIN_HOSTDEV_MODE_LAST:
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("Unsupported hostdev mode %1$s"),
                            virDomainHostdevModeTypeToString(dev->mode));
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 069f145d26..818e3822d0 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10678,7 +10678,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDef *dev,
     g_autofree char *tmpPath = NULL;
     int perm = 0;
 
-    switch ((virDomainHostdevMode) dev->mode) {
+    switch (dev->mode) {
     case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
         switch ((virDomainHostdevSubsysType)dev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 801b904a73..9ed5c6e94b 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1280,7 +1280,7 @@ qemuMigrationSrcIsAllowedHostdev(const virDomainDef *def)
      * forbidden. */
     for (i = 0; i < def->nhostdevs; i++) {
         virDomainHostdevDef *hostdev = def->hostdevs[i];
-        switch ((virDomainHostdevMode)hostdev->mode) {
+        switch (hostdev->mode) {
         case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
             virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
                            _("cannot migrate a domain with <hostdev mode='capabilities'>"));
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 7914aba84d..c3c92f3538 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -2345,6 +2345,7 @@ virSecuritySELinuxSetHostdevLabel(virSecurityManager *mgr,
         return virSecuritySELinuxSetHostdevCapsLabel(mgr, def, dev, vroot);
 
     default:
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
         return 0;
     }
 }
@@ -2567,6 +2568,7 @@ virSecuritySELinuxRestoreHostdevLabel(virSecurityManager *mgr,
         return virSecuritySELinuxRestoreHostdevCapsLabel(mgr, dev, vroot);
 
     default:
+    case VIR_DOMAIN_HOSTDEV_MODE_LAST:
         return 0;
     }
 }
-- 
2.41.0




[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