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

[RFCv2 42/46] conf: Replace virDomainGraphicsListenDefParseXML(hardcoded) with namesake(generated)



Signed-off-by: Shi Lei <shi_lei massclouds com>
---
 src/conf/domain_conf.c           | 109 ++++---------------------------
 src/conf/domain_conf.h           |  18 ++---
 src/qemu/qemu_command.c          |   2 +
 src/qemu/qemu_hotplug.c          |   1 +
 src/qemu/qemu_migration_cookie.c |   1 +
 src/qemu/qemu_process.c          |   1 +
 src/qemu/qemu_validate.c         |   1 +
 7 files changed, 27 insertions(+), 106 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d1602ab..507679b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -853,6 +853,7 @@ VIR_ENUM_IMPL(virDomainGraphics,
 
 VIR_ENUM_IMPL(virDomainGraphicsListen,
               VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST,
+              "dummy",
               "none",
               "address",
               "network",
@@ -1789,19 +1790,6 @@ bool virDomainObjTaint(virDomainObjPtr obj,
 }
 
 
-static void
-virDomainGraphicsListenDefClear(virDomainGraphicsListenDefPtr def)
-{
-    if (!def)
-        return;
-
-    VIR_FREE(def->address);
-    VIR_FREE(def->network);
-    VIR_FREE(def->socket);
-    return;
-}
-
-
 void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
 {
     size_t i;
@@ -14119,7 +14107,7 @@ virDomainTimerDefParseXML(xmlNodePtr node,
 }
 
 
-static int
+int
 virDomainGraphicsListenDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
                                        virDomainGraphicsListenDefPtr def,
                                        const char *instname G_GNUC_UNUSED,
@@ -14154,6 +14142,7 @@ virDomainGraphicsListenDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
         break;
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
@@ -14196,87 +14185,6 @@ virDomainGraphicsListenDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
-/**
- * virDomainGraphicsListenDefParseXML:
- * @def: listen def pointer to be filled
- * @graphics: graphics def pointer
- * @node: xml node of <listen/> element
- * @flags: bit-wise or of VIR_DOMAIN_DEF_PARSE_*
- *
- * Parses current <listen/> element from @node to @def.  For backward
- * compatibility the @parent element should contain node of <graphics/> element
- * for the first <listen/> element in order to validate attributes from both
- * elements.
- */
-static int
-virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
-                                   virDomainGraphicsDefPtr graphics,
-                                   xmlNodePtr node,
-                                   unsigned int flags)
-{
-    int ret = -1;
-    int tmp, typeVal;
-    g_autofree char *type = virXMLPropString(node, "type");
-    g_autofree char *address = virXMLPropString(node, "address");
-    g_autofree char *network = virXMLPropString(node, "network");
-    g_autofree char *socketPath = virXMLPropString(node, "socket");
-    g_autofree char *fromConfig = virXMLPropString(node, "fromConfig");
-    g_autofree char *autoGenerated = virXMLPropString(node, "autoGenerated");
-
-    if (!type) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("graphics listen type must be specified"));
-        goto error;
-    }
-
-    if ((typeVal = virDomainGraphicsListenTypeFromString(type)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown graphics listen type '%s'"), type);
-        goto error;
-    }
-    def->type = typeVal;
-
-    if (address && address[0])
-        def->address = g_steal_pointer(&address);
-
-    if (network && network[0])
-        def->network = g_steal_pointer(&network);
-
-    if (socketPath && socketPath[0])
-        def->socket = g_steal_pointer(&socketPath);
-
-    if (fromConfig) {
-        if (virStrToLong_i(fromConfig, NULL, 10, &tmp) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid fromConfig value: %s"),
-                           fromConfig);
-            goto error;
-        }
-        def->fromConfig = tmp != 0;
-    }
-
-    if (autoGenerated) {
-        if (virStringParseYesNo(autoGenerated, &def->autoGenerated) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid autoGenerated value: %s"),
-                           autoGenerated);
-            goto error;
-        }
-    }
-
-    if (virDomainGraphicsListenDefParseXMLHook(node, def, NULL,
-                                               graphics, &flags, type,
-                                               fromConfig, autoGenerated) < 0)
-        goto error;
-
-    ret = 0;
- error:
-    if (ret < 0)
-        virDomainGraphicsListenDefClear(def);
-    return ret;
-}
-
-
 static int
 virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
                                  xmlNodePtr node,
@@ -14305,9 +14213,9 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
 
         for (i = 0; i < nListens; i++) {
             virDomainGraphicsListenDefPtr listen = &def->listens[i];
-            if (virDomainGraphicsListenDefParseXML(listen, def,
-                                                   listenNodes[i],
-                                                   flags) < 0)
+            if (virDomainGraphicsListenDefParseXML(listenNodes[i],
+                                                   listen, NULL,
+                                                   def, &flags) < 0)
                 goto cleanup;
 
             if (i == 0) {
@@ -27827,6 +27735,7 @@ virDomainGraphicsVNCDefCheckAttrHook(const virDomainGraphicsVNCDef *def G_GNUC_U
         ret = true;
         break;
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
@@ -27890,6 +27799,7 @@ virDomainGraphicsVNCDefFormatAttrHook(const virDomainGraphicsVNCDef *def,
         virDomainGraphicsListenDefFormatAddr(listenBuf, glisten, flags);
         break;
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
@@ -27918,6 +27828,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
         if (virDomainGraphicsVNCDefFormatAttr(buf, &def->data.vnc, def, &flags) < 0)
             return -1;
+
         break;
 
     case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
@@ -32630,6 +32541,7 @@ virDomainGraphicsSpiceDefCheckAttrHook(const virDomainGraphicsSpiceDef *def G_GN
         }
         break;
 
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
@@ -32696,6 +32608,7 @@ virDomainGraphicsSpiceDefFormatAttrHook(const virDomainGraphicsSpiceDef *def,
         }
         break;
 
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6273c40..fc4aae2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1653,7 +1653,8 @@ typedef enum {
 } virDomainGraphicsSpiceStreamingMode;
 
 typedef enum {
-    VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE = 0,
+    VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY = 0,
+    VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE,
     VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS,
     VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK,
     VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET,
@@ -1667,13 +1668,14 @@ typedef enum {
     VIR_DOMAIN_HUB_TYPE_LAST
 } virDomainHubType;
 
-struct _virDomainGraphicsListenDef {
-    virDomainGraphicsListenType type;
-    char *address;
-    char *network;
-    char *socket;
-    bool fromConfig;    /* true if the @address is config file originated */
-    bool autoGenerated;
+struct _virDomainGraphicsListenDef {    /* genparse:withhook */
+    virDomainGraphicsListenType type;   /* xmlattr */
+    char *address;                      /* xmlattr */
+    char *network;                      /* xmlattr */
+    char *socket;                       /* xmlattr */
+    /* true if the @address is config file originated */
+    int fromConfig;                     /* xmlattr */
+    bool autoGenerated;                 /* xmlattr */
 };
 
 struct _virDomainGraphicsSDLDef {   /* genparse, genformat:separate */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index bd98b0a..f60f1e8 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7592,6 +7592,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
         virBufferAddLit(&opt, "none");
         break;
 
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
@@ -7718,6 +7719,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
         virBufferAddLit(&opt, "port=0,");
         hasInsecure = true;
         break;
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e2c6e14..0588745 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4085,6 +4085,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver,
             break;
 
         case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+        case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
         case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
             /* nada */
             break;
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index cef2555..9a8e7ab 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -349,6 +349,7 @@ qemuMigrationCookieAddGraphics(qemuMigrationCookiePtr mig,
 
             case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
             case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+            case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
             case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
                 break;
             }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index cfe09d6..db1b47e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4926,6 +4926,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
             break;
 
         case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+        case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
         case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
             break;
         }
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 070f1c9..167cdc2 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -3293,6 +3293,7 @@ qemuValidateDomainDeviceDefSPICEGraphics(const virDomainGraphicsDef *graphics,
 
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
         break;
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY:
     case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
         break;
     }
-- 
2.25.1



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