[PATCH 1/2] virDomainDeviceDefParse: Separate code for parsing type

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

 



Move the code into a new function named virDomainDeviceDefParseType. The
separation will make it easier to change the type of the 'type' field in
side of virDomainDeviceDef.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 43 +++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6e33a4472f..2744a3370e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13730,6 +13730,32 @@ virDomainCryptoDefParseXML(virDomainXMLOption *xmlopt,
 }


+static int
+virDomainDeviceDefParseType(const char *typestr,
+                            int *type)
+{
+    int tmp;
+
+    /* Mapping of serial, parallel, console and channel to VIR_DOMAIN_DEVICE_CHR. */
+    if (STREQ(typestr, "channel") ||
+        STREQ(typestr, "console") ||
+        STREQ(typestr, "parallel") ||
+        STREQ(typestr, "serial")) {
+        *type = VIR_DOMAIN_DEVICE_CHR;
+        return 0;
+    }
+
+    if ((tmp = virDomainDeviceTypeFromString(typestr)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown device type '%s'"), typestr);
+        return -1;
+    }
+
+    *type = tmp;
+    return 0;
+}
+
+
 virDomainDeviceDef *
 virDomainDeviceDefParse(const char *xmlStr,
                         const virDomainDef *def,
@@ -13749,21 +13775,8 @@ virDomainDeviceDefParse(const char *xmlStr,

     dev = g_new0(virDomainDeviceDef, 1);

-    if ((dev->type = virDomainDeviceTypeFromString((const char *) node->name)) < 0) {
-        /* Some crazy mapping of serial, parallel, console and channel to
-         * VIR_DOMAIN_DEVICE_CHR. */
-        if (virXMLNodeNameEqual(node, "channel") ||
-            virXMLNodeNameEqual(node, "console") ||
-            virXMLNodeNameEqual(node, "parallel") ||
-            virXMLNodeNameEqual(node, "serial")) {
-            dev->type = VIR_DOMAIN_DEVICE_CHR;
-        } else {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown device type '%s'"),
-                           node->name);
-            return NULL;
-        }
-    }
+    if (virDomainDeviceDefParseType((const char *)node->name, &dev->type) < 0)
+        return NULL;

     switch ((virDomainDeviceType) dev->type) {
     case VIR_DOMAIN_DEVICE_DISK:
-- 
2.39.1




[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