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

[RFCv2 45/46] conf: Replace virDomainGraphicsDefParseXML(hardcoded) with namesake(generated)



Signed-off-by: Shi Lei <shi_lei massclouds com>
---
 src/conf/domain_conf.c   | 140 ++++++---------------------------------
 src/conf/domain_conf.h   |  21 +++---
 src/qemu/qemu_command.c  |   2 +
 src/qemu/qemu_driver.c   |   2 +
 src/qemu/qemu_hotplug.c  |   1 +
 src/qemu/qemu_process.c  |   4 ++
 src/qemu/qemu_validate.c |   1 +
 src/vmx/vmx.c            |   1 +
 8 files changed, 42 insertions(+), 130 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 60bea6f..61dc7b3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -843,6 +843,7 @@ VIR_ENUM_IMPL(virDomainInputModel,
 
 VIR_ENUM_IMPL(virDomainGraphics,
               VIR_DOMAIN_GRAPHICS_TYPE_LAST,
+              "none",
               "sdl",
               "vnc",
               "rdp",
@@ -1824,6 +1825,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
         VIR_FREE(def->data.egl_headless.rendernode);
         break;
 
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         break;
     }
@@ -14185,47 +14187,6 @@ virDomainGraphicsListenDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
-static int
-virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
-                                 xmlNodePtr node,
-                                 xmlXPathContextPtr ctxt,
-                                 unsigned int flags)
-{
-    int nListens;
-    int ret = -1;
-    g_autofree xmlNodePtr *listenNodes = NULL;
-    VIR_XPATH_NODE_AUTORESTORE(ctxt);
-
-    ctxt->node = node;
-
-    /* parse the <listen> subelements for graphics types that support it */
-    nListens = virXPathNodeSet("./listen", ctxt, &listenNodes);
-    if (nListens < 0)
-        goto cleanup;
-
-    if (nListens > 0) {
-        size_t i;
-
-        if (VIR_ALLOC_N(def->listens, nListens) < 0)
-            goto cleanup;
-
-        for (i = 0; i < nListens; i++) {
-            virDomainGraphicsListenDefPtr listen = &def->listens[i];
-            if (virDomainGraphicsListenDefParseXML(listenNodes[i],
-                                                   listen, NULL,
-                                                   def, &flags) < 0)
-                goto cleanup;
-
-            def->nListens++;
-        }
-    }
-
-    ret = 0;
- cleanup:
-    return ret;
-}
-
-
 int
 virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
                                     virDomainGraphicsVNCDefPtr def,
@@ -14368,7 +14329,7 @@ virDomainNetDefNew(virDomainXMLOptionPtr xmlopt)
 }
 
 
-static int
+int
 virDomainGraphicsDefParseXMLHook(xmlNodePtr node,
                                  virDomainGraphicsDefPtr def,
                                  const char *instname G_GNUC_UNUSED,
@@ -14464,78 +14425,6 @@ virDomainGraphicsDefParseXMLHook(xmlNodePtr node,
 }
 
 
-/* Parse the XML definition for a graphics device */
-static virDomainGraphicsDefPtr
-virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt,
-                             xmlNodePtr node,
-                             xmlXPathContextPtr ctxt,
-                             unsigned int flags)
-{
-    virDomainGraphicsDefPtr def;
-    int typeVal;
-    g_autofree char *type = NULL;
-
-    if (!(def = virDomainGraphicsDefNew(xmlopt)))
-        return NULL;
-
-    type = virXMLPropString(node, "type");
-    if (!type) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("missing graphics device type"));
-        goto error;
-    }
-
-    if ((typeVal = virDomainGraphicsTypeFromString(type)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown graphics device type '%s'"), type);
-        goto error;
-    }
-    def->type = typeVal;
-
-    if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0)
-        goto error;
-
-    switch (def->type) {
-    case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
-        if (virDomainGraphicsVNCDefParseXML(node, &def->data.vnc, NULL, def, &flags) < 0)
-            goto error;
-        break;
-    case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
-        if (virDomainGraphicsSDLDefParseXML(node, &def->data.sdl, NULL, def, NULL) < 0)
-            goto error;
-        break;
-    case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
-        if (virDomainGraphicsRDPDefParseXML(node, &def->data.rdp, NULL, def, &flags) < 0)
-            goto error;
-        break;
-    case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
-        if (virDomainGraphicsDesktopDefParseXML(node, &def->data.desktop, NULL, def, NULL) < 0)
-            goto error;
-        break;
-    case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
-        if (virDomainGraphicsSpiceDefParseXML(node, &def->data.spice, NULL, def, &flags) < 0)
-            goto error;
-        break;
-    case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
-        if (virDomainGraphicsEGLHeadlessDefParseXML(node, &def->data.egl_headless, NULL, def, NULL) < 0)
-            goto error;
-        break;
-    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
-        break;
-    }
-
-    if (virDomainGraphicsDefParseXMLHook(node, def, NULL, NULL, &flags) < 0)
-        goto error;
-
-    return def;
-
- error:
-    virDomainGraphicsDefFree(def);
-    def = NULL;
-    return NULL;
-}
-
-
 static virDomainSoundCodecDefPtr
 virDomainSoundCodecDefParseXML(xmlNodePtr node)
 {
@@ -16714,9 +16603,14 @@ virDomainDeviceDefParse(const char *xmlStr,
             return NULL;
         break;
     case VIR_DOMAIN_DEVICE_GRAPHICS:
-        if (!(dev->data.graphics = virDomainGraphicsDefParseXML(xmlopt, node,
-                                                                ctxt, flags)))
+        if (!(dev->data.graphics = virDomainGraphicsDefNew(xmlopt)))
             return NULL;
+        if (virDomainGraphicsDefParseXML(node, dev->data.graphics, NULL,
+                                         dev, &flags) < 0) {
+            virDomainGraphicsDefFree(dev->data.graphics);
+            dev->data.graphics = NULL;
+            return NULL;
+        }
         break;
     case VIR_DOMAIN_DEVICE_HUB:
         if (!(dev->data.hub = virDomainHubDefParseXML(xmlopt, node, flags)))
@@ -21572,13 +21466,16 @@ virDomainDefParseXML(xmlDocPtr xml,
     if (n && VIR_ALLOC_N(def->graphics, n) < 0)
         goto error;
     for (i = 0; i < n; i++) {
-        virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(xmlopt,
-                                                                        nodes[i],
-                                                                        ctxt,
-                                                                        flags);
+        virDomainGraphicsDefPtr graphics = virDomainGraphicsDefNew(xmlopt);
         if (!graphics)
             goto error;
 
+        if (virDomainGraphicsDefParseXML(nodes[i], graphics, NULL,
+                                         def, &flags) < 0) {
+            virDomainGraphicsDefFree(graphics);
+            goto error;
+        }
+
         def->graphics[def->ngraphics++] = graphics;
     }
     VIR_FREE(nodes);
@@ -27934,6 +27831,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
             return -1;
 
         break;
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         break;
     }
@@ -32343,6 +32241,7 @@ virDomainGraphicsDefHasOpenGL(const virDomainDef *def)
         case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
             return true;
 
+        case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
         case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
             break;
         }
@@ -32381,6 +32280,7 @@ virDomainGraphicsGetRenderNode(const virDomainGraphicsDef *graphics)
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
     case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
     case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         break;
     }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index d78cdbb..b6d69fa 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1545,6 +1545,7 @@ struct _virDomainVideoDef {
 
 /* graphics console modes */
 typedef enum {
+    VIR_DOMAIN_GRAPHICS_TYPE_NONE = 0,
     VIR_DOMAIN_GRAPHICS_TYPE_SDL,
     VIR_DOMAIN_GRAPHICS_TYPE_VNC,
     VIR_DOMAIN_GRAPHICS_TYPE_RDP,
@@ -1750,7 +1751,7 @@ struct _virDomainGraphicsEGLHeadlessDef {   /* genparse, genformat:separate */
     char *rendernode;                       /* xmlattr:gl/rendernode */
 };
 
-struct _virDomainGraphicsDef {
+struct _virDomainGraphicsDef {      /* genparse:concisehook */
     virObjectPtr privateData;
 
     /* Port value discipline:
@@ -1758,20 +1759,20 @@ struct _virDomainGraphicsDef {
      * Value 0 means port wasn't specified in XML at all.
      * Positive value is actual port number given in XML.
      */
-    virDomainGraphicsType type;
+    virDomainGraphicsType type;     /* xmlattr */
     union {
-        virDomainGraphicsSDLDef sdl;
-        virDomainGraphicsVNCDef vnc;
-        virDomainGraphicsRDPDef rdp;
-        virDomainGraphicsDesktopDef desktop;
-        virDomainGraphicsSpiceDef spice;
-        virDomainGraphicsEGLHeadlessDef egl_headless;
-    } data;
+        virDomainGraphicsSDLDef sdl;                    /* xmlgroup */
+        virDomainGraphicsVNCDef vnc;                    /* xmlgroup */
+        virDomainGraphicsRDPDef rdp;                    /* xmlgroup */
+        virDomainGraphicsDesktopDef desktop;            /* xmlgroup */
+        virDomainGraphicsSpiceDef spice;                /* xmlgroup */
+        virDomainGraphicsEGLHeadlessDef egl_headless;   /* xmlgroup */
+    } data;                         /* xmlswitch:type */
     /* nListens, listens, and *port are only useful if type is vnc,
      * rdp, or spice. They've been extracted from the union only to
      * simplify parsing code.*/
     size_t nListens;
-    virDomainGraphicsListenDefPtr listens;
+    virDomainGraphicsListenDefPtr listens;  /* xmlelem, array:nListens */
 };
 
 typedef enum {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f60f1e8..272be28 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7938,6 +7938,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
         case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
         case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
             return -1;
+        case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
         case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         default:
             virReportEnumRangeError(virDomainGraphicsType, graphics->type);
@@ -9772,6 +9773,7 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver,
             break;
         case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
         case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
+        case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
         case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
             break;
         }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0d06812..922b9bb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15681,6 +15681,7 @@ qemuDomainOpenGraphics(virDomainPtr dom,
                        _("Can only open VNC or SPICE graphics backends, not %s"),
                        virDomainGraphicsTypeToString(vm->def->graphics[idx]->type));
         goto endjob;
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
     default:
         virReportEnumRangeError(virDomainGraphicsType,
@@ -15750,6 +15751,7 @@ qemuDomainOpenGraphicsFD(virDomainPtr dom,
                        _("Can only open VNC or SPICE graphics backends, not %s"),
                        virDomainGraphicsTypeToString(vm->def->graphics[idx]->type));
         goto cleanup;
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
     default:
         virReportEnumRangeError(virDomainGraphicsType,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0588745..d008035 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4191,6 +4191,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unable to change config on '%s' graphics type"), type);
         break;
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
     default:
         virReportEnumRangeError(virDomainGraphicsType, dev->type);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index db1b47e..c20988f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4687,6 +4687,7 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
     case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
     case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
     case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         break;
     }
@@ -4726,6 +4727,7 @@ qemuProcessGraphicsAllocatePorts(virQEMUDriverPtr driver,
     case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
     case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
     case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         break;
     }
@@ -4882,6 +4884,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
     case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
     case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
     case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         break;
     }
@@ -5188,6 +5191,7 @@ qemuProcessStartValidateGraphics(virDomainObjPtr vm)
         case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
         case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
         case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
+        case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
         case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
             break;
         }
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 167cdc2..1d7a492 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -3416,6 +3416,7 @@ qemuValidateDomainDeviceDefGraphics(const virDomainGraphicsDef *graphics,
                        _("unsupported graphics type '%s'"),
                        virDomainGraphicsTypeToString(graphics->type));
         return -1;
+    case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
     case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
     default:
         return -1;
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 4b1b04c..cfc88aa 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -3314,6 +3314,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
                            virDomainGraphicsTypeToString(def->graphics[i]->type));
             goto cleanup;
 
+          case VIR_DOMAIN_GRAPHICS_TYPE_NONE:
           case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
           default:
               virReportEnumRangeError(virDomainGraphicsType, def->graphics[i]->type);
-- 
2.25.1



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