diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3ab7cd2666..2a94566047 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5840,14 +5840,14 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
host->socket = virXMLPropString(hostnode, "socket");
if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
- host->socket == NULL) {
+ virDomainStorageNetHostSocketValidate(host)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing socket for unix transport"));
goto cleanup;
}
if (host->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX &&
- host->socket != NULL) {
+ !virDomainStorageNetHostSocketValidate(host)) {
virReportError(VIR_ERR_XML_ERROR,
_("transport '%1$s' does not support socket attribute"),
transport);
@@ -11024,30 +11024,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, graphicsType))
+ 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..b8b8f941cc 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2669,6 +2669,38 @@ virDomainGraphicsDefValidate(const virDomainDef *def,
return 0;
}
+int
+virDomainGraphicsListenDefValidate(const virDomainGraphicsListenDef *def,
+ const virDomainGraphicsDef *graphics,
+ const char *graphicsType)
+{
+ 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 +2930,13 @@ virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
return 0;
}
+
+int
+virDomainStorageNetHostSocketValidate(const virStorageNetHostDef *host)
+
+{
+ if (host->socket)
+ return 0;
+ else
+ return -1;
+}
diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h
index fc441cef5b..58ee9b7da5 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 virDomainStorageNetHostSocketValidate(const virStorageNetHostDef *host);
+
+int
+virDomainGraphicsListenDefValidate(const virDomainGraphicsListenDef *def,
+ const virDomainGraphicsDef *graphics,
+ const char *graphicsType);
--
2.40.0