[PATCH] Conf: Move validation of Graphics Transport and StorageNetwork Socket out of parser

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

 



I have implemented your corrections successfully. Thank you.
Signed-off-by: K Shiva <shiva_kr@xxxxxxxxxx>
---
 src/conf/domain_conf.c     | 42 +++-------------------------
 src/conf/domain_validate.c | 56 ++++++++++++++++++++++++++++++++++++++
 src/conf/domain_validate.h |  7 +++++
 3 files changed, 67 insertions(+), 38 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 70e4d52ee6..1e0ac737bb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5836,20 +5836,9 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
 
     host->socket = virXMLPropString(hostnode, "socket");
 
-    if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
-        host->socket == NULL) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing socket for unix transport"));
+    // Socket Validation
+    if (virDomainStorageNetHostSocketValidate(host, transport) < 0)
         goto cleanup;
-    }
-
-    if (host->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
-        host->socket != NULL) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("transport '%1$s' does not support socket attribute"),
-                       transport);
-        goto cleanup;
-    }
 
     if (host->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) {
         if (!(host->name = virXMLPropString(hostnode, "name"))) {
@@ -11004,7 +10993,6 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDef *def,
                                    unsigned int flags)
 {
     int ret = -1;
-    const char *graphicsType = virDomainGraphicsTypeToString(graphics->type);
     g_autofree char *address = virXMLPropString(node, "address");
     g_autofree char *network = virXMLPropString(node, "network");
     g_autofree char *socketPath = virXMLPropString(node, "socket");
@@ -11021,30 +11009,8 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDef *def,
                        VIR_XML_PROP_REQUIRED, &def->type) < 0)
         goto error;
 
-    switch (def->type) {
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
-        if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("listen type 'socket' is not available for graphics type '%1$s'"),
-                           graphicsType);
-            goto error;
-        }
-        break;
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
-        if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
-            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("listen type 'none' is not available for graphics type '%1$s'"),
-                           graphicsType);
-            goto error;
-        }
-        break;
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
-        break;
-    }
+    if (virDomainGraphicsListenDefValidate(def, graphics) == -1)
+        goto error;
 
     if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
         if (address && addressCompat && STRNEQ(address, addressCompat)) {
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 9265fef4f9..10f8242c84 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2669,6 +2669,39 @@ virDomainGraphicsDefValidate(const virDomainDef *def,
     return 0;
 }
 
+int
+virDomainGraphicsListenDefValidate(const virDomainGraphicsListenDef *def,
+                                   const virDomainGraphicsDef *graphics)
+{
+    const char *graphicsType = virDomainGraphicsTypeToString(graphics->type);
+
+    switch (def->type) {
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
+        if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("listen type 'socket' is not available for graphics type '%1$s'"),
+                           graphicsType);
+            return -1;
+        }
+        break;
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+        if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
+            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("listen type 'none' is not available for graphics type '%1$s'"),
+                           graphicsType);
+            return -1;
+        }
+        break;
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
+        break;
+    }
+    return 0;
+}
+
 static int
 virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
 {
@@ -2898,3 +2931,26 @@ virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
 
     return 0;
 }
+
+int
+virDomainStorageNetHostSocketValidate(const virStorageNetHostDef *host,
+                                const char* transport)
+{
+    if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
+        host->socket == NULL) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing socket for unix transport"));
+        return -1;
+    }
+
+    if (host->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
+        host->socket != NULL) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("transport '%1$s' does not support socket attribute"),
+                       transport);
+        return -1;
+    }
+
+
+    return 0;
+}
diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h
index fc441cef5b..baeae4b2a3 100644
--- a/src/conf/domain_validate.h
+++ b/src/conf/domain_validate.h
@@ -47,3 +47,10 @@ int virDomainDiskDefSourceLUNValidate(const virStorageSource *src);
 
 int virDomainDefOSValidate(const virDomainDef *def,
                            virDomainXMLOption *xmlopt);
+
+int
+virDomainGraphicsListenDefValidate(const virDomainGraphicsListenDef *def,
+                                   const virDomainGraphicsDef *graphics);
+
+int virDomainStorageNetHostSocketValidate(const virStorageNetHostDef *host,
+                                    const char *transport);
-- 
2.40.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