[RFCv2 43/46] conf: Generate virDomainGraphicsListenDefFormatBuf

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

 



Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx>
---
 src/conf/domain_conf.c | 114 +++++++++++++++++++++++------------------
 src/conf/domain_conf.h |  12 ++---
 2 files changed, 70 insertions(+), 56 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 507679b..007ee44 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -27614,19 +27614,64 @@ virDomainTimerDefFormat(virBufferPtr buf,
 }
 
 
-static void
-virDomainGraphicsListenDefFormat(virBufferPtr buf,
-                                 virDomainGraphicsListenDefPtr def,
-                                 unsigned int flags)
+static bool
+virDomainGraphicsListenDefValid(const virDomainGraphicsListenDef *def,
+                                const virDomainGraphicsDef *graphics,
+                                unsigned int flags)
 {
-    /* If generating migratable XML, skip listen address
-     * dragged in from config file */
-    if ((flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) && def->fromConfig)
-        return;
+    if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) {
+        /* If the listen is based on config options from qemu.conf we need
+         * to skip it.  It's up to user to properly configure both hosts for
+         * migration. */
+        if (def->fromConfig)
+            return false;
+
+        /* If the socket is provided by user in the XML we need to skip this
+         * listen type to support migration back to old libvirt since old
+         * libvirt supports specifying socket path inside graphics element
+         * as 'socket' attribute.  Auto-generated socket is a new feature
+         * thus we can generate it in the migrateble XML. */
+        if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+            def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET &&
+            def->socket && !def->autoGenerated)
+            return false;
+
+        /* The new listen type none is in the migratable XML represented as
+         * port=0 and autoport=no because old libvirt support this
+         * configuration for spice. */
+        if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
+            def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE)
+            return false;
+    }
+
+    return true;
+}
+
+
+bool
+virDomainGraphicsListenDefCheckHook(const virDomainGraphicsListenDef *def,
+                                    const void *parent,
+                                    void *opaque,
+                                    bool value G_GNUC_UNUSED)
+{
+    virDomainGraphicsDefPtr graphics = (virDomainGraphicsDefPtr) parent;
+    unsigned int flags = 0;
+    if (opaque)
+        flags = *((unsigned int *) opaque);
+    return virDomainGraphicsListenDefValid(def, graphics, flags);
+}
 
-    virBufferAddLit(buf, "<listen");
-    virBufferAsprintf(buf, " type='%s'",
-                      virDomainGraphicsListenTypeToString(def->type));
+
+int
+virDomainGraphicsListenDefFormatHook(const virDomainGraphicsListenDef *def,
+                                     const void *parent G_GNUC_UNUSED,
+                                     const void *opaque,
+                                     virBufferPtr addressBuf,
+                                     virBufferPtr socketBuf)
+{
+    unsigned int flags = 0;
+    if (opaque)
+        flags = *((unsigned int *) opaque);
 
     if (def->address &&
         (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS ||
@@ -27634,28 +27679,17 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf,
           !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)))) {
         /* address may also be set to show current status when type='network',
          * but we don't want to print that if INACTIVE data is requested. */
-        virBufferAsprintf(buf, " address='%s'", def->address);
-    }
-
-    if (def->network &&
-        (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) {
-        virBufferEscapeString(buf, " network='%s'", def->network);
+        virBufferAsprintf(addressBuf, " address='%s'", def->address);
     }
 
     if (def->socket &&
         def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET &&
         !(def->autoGenerated &&
           (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE))) {
-        virBufferEscapeString(buf, " socket='%s'", def->socket);
-    }
-
-    if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS) {
-        virBufferAsprintf(buf, " fromConfig='%d'", def->fromConfig);
-        virBufferAsprintf(buf, " autoGenerated='%s'",
-                          def->autoGenerated ? "yes" : "no");
+        virBufferEscapeString(socketBuf, " socket='%s'", def->socket);
     }
 
-    virBufferAddLit(buf, "/>\n");
+    return 0;
 }
 
 
@@ -27883,37 +27917,17 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
     }
 
     for (i = 0; i < def->nListens; i++) {
-        if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) {
-            /* If the listen is based on config options from qemu.conf we need
-             * to skip it.  It's up to user to properly configure both hosts for
-             * migration. */
-            if (def->listens[i].fromConfig)
-                continue;
-
-            /* If the socket is provided by user in the XML we need to skip this
-             * listen type to support migration back to old libvirt since old
-             * libvirt supports specifying socket path inside graphics element
-             * as 'socket' attribute.  Auto-generated socket is a new feature
-             * thus we can generate it in the migrateble XML. */
-            if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-                def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET &&
-                def->listens[i].socket &&
-                !def->listens[i].autoGenerated)
-                continue;
+        if (!virDomainGraphicsListenDefValid(&def->listens[i], def, flags))
+            continue;
 
-            /* The new listen type none is in the migratable XML represented as
-             * port=0 and autoport=no because old libvirt support this
-             * configuration for spice. */
-            if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
-                def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE)
-                continue;
-        }
         if (!children) {
             virBufferAddLit(buf, ">\n");
             virBufferAdjustIndent(buf, 2);
             children = true;
         }
-        virDomainGraphicsListenDefFormat(buf, &def->listens[i], flags);
+
+        virDomainGraphicsListenDefFormatBuf(buf, "listen",
+                                            &def->listens[i], def, &flags);
     }
 
     if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fc4aae2..d78cdbb 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1668,14 +1668,14 @@ typedef enum {
     VIR_DOMAIN_HUB_TYPE_LAST
 } virDomainHubType;
 
-struct _virDomainGraphicsListenDef {    /* genparse:withhook */
+struct _virDomainGraphicsListenDef {    /* genparse:withhook, genformat */
     virDomainGraphicsListenType type;   /* xmlattr */
-    char *address;                      /* xmlattr */
-    char *network;                      /* xmlattr */
-    char *socket;                       /* xmlattr */
+    char *address;                      /* xmlattr, formathook */
+    char *network;                      /* xmlattr, formatflag:VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK */
+    char *socket;                       /* xmlattr, formathook */
     /* true if the @address is config file originated */
-    int fromConfig;                     /* xmlattr */
-    bool autoGenerated;                 /* xmlattr */
+    int fromConfig;                     /* xmlattr, formatflag:%VIR_DOMAIN_DEF_FORMAT_STATUS */
+    bool autoGenerated;                 /* xmlattr, formatflag:%VIR_DOMAIN_DEF_FORMAT_STATUS */
 };
 
 struct _virDomainGraphicsSDLDef {   /* genparse, genformat:separate */
-- 
2.25.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