[libvirt PATCH v2 07/51] conf: Use virTristateXXX in virDomainChrSourceDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 15dc416384..6619b9f006 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1232,7 +1232,7 @@ struct _virDomainChrSourceDef { /* no for null, vc, stdio */ struct { char *path; -int append; /* enum virTristateSwitch */ +virTristateSwitch append; } file; /* pty, file, pipe, or device */ struct { char *master; @@ -1244,7 +1244,7 @@ struct _virDomainChrSourceDef { bool listen; int protocol; bool tlscreds; -int haveTLS; /* enum virTristateBool */ +virTristateBool haveTLS; bool tlsFromConfig; virDomainChrSourceReconnectDef reconnect; } tcp; @@ -1265,7 +1265,7 @@ struct _virDomainChrSourceDef { } spiceport; } data; char *logfile; -int logappend; +virTristateSwitch logappend; size_t nseclabels; virSecurityDeviceLabelDefPtr *seclabels; -- 2.26.2
[libvirt PATCH v2 16/51] virxml: Add virXMLPropTristateSwitch
Convenience function to return value of an on / off attribute. Signed-off-by: Tim Wiederhake --- src/libvirt_private.syms | 1 + src/util/virxml.c| 41 src/util/virxml.h| 6 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 70525cef8c..9aed890c58 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3546,6 +3546,7 @@ virXMLPickShellSafeComment; virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; +virXMLPropTristateSwitch; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 81b7bb1386..aaad6453d2 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -599,6 +599,47 @@ virXMLPropTristateBool(xmlNodePtr node, const char* name, bool required, } +/** + * virXMLPropTristateSwitch: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @required: Change the return value to -1 if the attribute is not present + * @result: The returned virTristateSwitch value + * + * Convenience function to return value of an on / off attribute. + * + * Returns 1 in case of success in which case @value is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropTristateSwitch(xmlNodePtr node, const char* name, bool required, + virTristateSwitch *result) +{ +g_autofree char *tmp = virXMLPropString(node, name); +int val; + +if (!tmp) { +if (!required) +return 0; +virReportError(VIR_ERR_XML_ERROR, + _("Missing required attribute '%s' in element '%s'"), + name, node->name); +return -1; +} + +if ((val = virTristateSwitchTypeFromString(tmp)) <= 0) { +virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s': '%s'. Expected 'on' or 'off'"), + name, node->name, tmp); +return -1; +} + +*result = val; +return 1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index 3041c37df3..e844cb0713 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -80,8 +80,12 @@ char * virXMLPropStringLimit(xmlNodePtr node, char * virXMLNodeContentString(xmlNodePtr node); int virXMLPropTristateBool(xmlNodePtr node, const char *name, - bool mandatory, + bool required, virTristateBool *result); +int virXMLPropTristateSwitch(xmlNodePtr node, + const char *name, + bool required, + virTristateSwitch *result); /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, -- 2.26.2
[libvirt PATCH v2 25/51] domain_conf: Use virXMLPropTristateXXX in virDomainNetDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 177 +++-- 1 file changed, 48 insertions(+), 129 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fef0b7235a..329f42d6dd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10720,7 +10720,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, g_autofree char *queues = NULL; g_autofree char *rx_queue_size = NULL; g_autofree char *tx_queue_size = NULL; -g_autofree char *str = NULL; g_autofree char *filter = NULL; g_autofree char *internal = NULL; g_autofree char *mode = NULL; @@ -10730,7 +10729,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, g_autofree char *vhostuser_mode = NULL; g_autofree char *vhostuser_path = NULL; g_autofree char *vhostuser_type = NULL; -g_autofree char *trustGuestRxFilters = NULL; g_autofree char *vhost_path = NULL; const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; @@ -10750,15 +10748,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, def->type = VIR_DOMAIN_NET_TYPE_USER; } -trustGuestRxFilters = virXMLPropString(node, "trustGuestRxFilters"); -if (trustGuestRxFilters && -((def->trustGuestRxFilters - = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown trustGuestRxFilters value '%s'"), - trustGuestRxFilters); +if (virXMLPropTristateBool(node, "trustGuestRxFilters", false, + >trustGuestRxFilters) < 0) goto error; -} cur = node->children; while (cur != NULL) { @@ -11328,128 +11320,55 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, } if ((tmpNode = virXPathNode("./driver/host", ctxt))) { -if ((str = virXMLPropString(tmpNode, "csum"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host csum mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.csum = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "gso"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host gso mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.gso = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "tso4"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host tso4 mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.tso4 = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "tso6"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host tso6 mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.tso6 = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "ecn"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host ecn mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.ecn = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "ufo"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host ufo mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.ufo = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "mrg_rxbuf"))) { -
[libvirt PATCH v2 23/51] domain_conf: Use virXMLPropTristateXXX in virDomainActualNetDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 11 ++- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ef7eed5682..bcc89c0afc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10436,7 +10436,6 @@ virDomainActualNetDefParseXML(xmlNodePtr node, g_autofree char *type = NULL; g_autofree char *mode = NULL; g_autofree char *addrtype = NULL; -g_autofree char *trustGuestRxFilters = NULL; g_autofree char *macTableManager = NULL; actual = g_new0(virDomainActualNetDef, 1); @@ -10464,15 +10463,9 @@ virDomainActualNetDefParseXML(xmlNodePtr node, goto error; } -trustGuestRxFilters = virXMLPropString(node, "trustGuestRxFilters"); -if (trustGuestRxFilters && -((actual->trustGuestRxFilters - = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown trustGuestRxFilters value '%s'"), - trustGuestRxFilters); +if (virXMLPropTristateBool(node, "trustGuestRxFilters", false, + >trustGuestRxFilters) < 0) goto error; -} virtPortNode = virXPathNode("./virtualport", ctxt); if (virtPortNode) { -- 2.26.2
[libvirt PATCH v2 13/51] conf: Use virTristateXXX in virStoragePoolSourceDevice
Signed-off-by: Tim Wiederhake --- src/conf/storage_conf.c | 2 +- src/conf/storage_conf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 2e07c81f8a..fa8bcfb8ce 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1097,7 +1097,7 @@ virStoragePoolSourceFormat(virBufferPtr buf, virBufferEscapeString(buf, "devices[i].path); if (src->devices[i].part_separator != -VIR_TRISTATE_SWITCH_ABSENT) { +VIR_TRISTATE_BOOL_ABSENT) { virBufferAsprintf(buf, " part_separator='%s'", virTristateBoolTypeToString(src->devices[i].part_separator)); } diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 647eb847bf..8d417af7bb 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -168,7 +168,7 @@ struct _virStoragePoolSourceDevice { virStoragePoolSourceDeviceExtentPtr freeExtents; char *path; int format; /* Pool specific source format */ -int part_separator; /* enum virTristateSwitch */ +virTristateBool part_separator; /* When the source device is a physical disk, * the geometry data is needed -- 2.26.2
[libvirt PATCH v2 18/51] domain_conf: Use virXMLPropTristateXXX in virDomainVirtioOptionsParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 34 ++ 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3ac041e3d2..c8411bdf40 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1591,9 +1591,7 @@ static int virDomainVirtioOptionsParseXML(xmlNodePtr driver, virDomainVirtioOptionsPtr *virtio) { -int val; virDomainVirtioOptionsPtr res; -g_autofree char *str = NULL; if (*virtio || !driver) return 0; @@ -1602,34 +1600,14 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, res = *virtio; -if ((str = virXMLPropString(driver, "iommu"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid iommu value")); -return -1; -} -res->iommu = val; -} -VIR_FREE(str); +if (virXMLPropTristateSwitch(driver, "iommu", false, >iommu) < 0) +return -1; -if ((str = virXMLPropString(driver, "ats"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid ats value")); -return -1; -} -res->ats = val; -} -VIR_FREE(str); +if (virXMLPropTristateSwitch(driver, "ats", false, >ats) < 0) +return -1; -if ((str = virXMLPropString(driver, "packed"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid packed value")); -return -1; -} -res->packed = val; -} +if (virXMLPropTristateSwitch(driver, "packed", false, >packed) < 0) +return -1; return 0; } -- 2.26.2
[libvirt PATCH v2 17/51] domain_conf: Use virXMLPropTristateXXX in virDomainKeyWrapCipherDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 14 ++ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7671050134..3ac041e3d2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1447,10 +1447,9 @@ static int virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, xmlNodePtr node) { -int state_type; +virTristateSwitch state_type = VIR_TRISTATE_SWITCH_ABSENT; int name_type; g_autofree char *name = NULL; -g_autofree char *state = NULL; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", @@ -1464,17 +1463,8 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, return -1; } -if (!(state = virXMLPropString(node, "state"))) { -virReportError(VIR_ERR_CONF_SYNTAX, - _("missing state for cipher named %s"), name); -return -1; -} - -if ((state_type = virTristateSwitchTypeFromString(state)) < 0) { -virReportError(VIR_ERR_CONF_SYNTAX, - _("%s is not a supported cipher state"), state); +if (virXMLPropTristateSwitch(node, "state", true, _type) < 0) return -1; -} switch ((virDomainKeyWrapCipherName) name_type) { case VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_AES: -- 2.26.2
[libvirt PATCH v2 12/51] conf: Use virTristateXXX in virStorageAdapterFCHost
Signed-off-by: Tim Wiederhake --- src/conf/storage_adapter_conf.c | 4 +++- src/conf/storage_adapter_conf.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/conf/storage_adapter_conf.c b/src/conf/storage_adapter_conf.c index 77ecb8d5f2..69062b4b58 100644 --- a/src/conf/storage_adapter_conf.c +++ b/src/conf/storage_adapter_conf.c @@ -68,13 +68,15 @@ virStorageAdapterParseXMLFCHost(xmlNodePtr node, fchost->parent = virXMLPropString(node, "parent"); if ((managed = virXMLPropString(node, "managed"))) { -if ((fchost->managed = virTristateBoolTypeFromString(managed)) < 0) { +int value; +if ((value = virTristateBoolTypeFromString(managed)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown fc_host managed setting '%s'"), managed); VIR_FREE(managed); return -1; } +fchost->managed = value; } fchost->parent_wwnn = virXMLPropString(node, "parent_wwnn"); diff --git a/src/conf/storage_adapter_conf.h b/src/conf/storage_adapter_conf.h index 4c7da7c8d9..3f64cda9af 100644 --- a/src/conf/storage_adapter_conf.h +++ b/src/conf/storage_adapter_conf.h @@ -51,7 +51,7 @@ struct _virStorageAdapterFCHost { char *parent_fabric_wwn; char *wwnn; char *wwpn; -int managed;/* enum virTristateSwitch */ +virTristateBool managed; }; typedef struct _virStorageAdapter virStorageAdapter; -- 2.26.2
[libvirt PATCH v2 20/51] domain_conf: Use virXMLPropTristateXXX in virDomainDiskSourceNetworkParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 9 ++--- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 91dc00edad..0e9106b061 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8275,7 +8275,6 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, { int tlsCfgVal; g_autofree char *protocol = NULL; -g_autofree char *haveTLS = NULL; g_autofree char *tlsCfg = NULL; g_autofree char *sslverifystr = NULL; xmlNodePtr tmpnode; @@ -8299,12 +8298,8 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, return -1; } -if ((haveTLS = virXMLPropString(node, "tls")) && -(src->haveTLS = virTristateBoolTypeFromString(haveTLS)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown disk source 'tls' setting '%s'"), haveTLS); -return -1; -} +if (virXMLPropTristateBool(node, "tls", false, >haveTLS) < 0) +return -1; if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && (tlsCfg = virXMLPropString(node, "tlsFromConfig"))) { -- 2.26.2
[libvirt PATCH v2 15/51] virxml: Add virXMLPropTristateBool
Convenience function to return value of a yes / no attribute. Signed-off-by: Tim Wiederhake --- src/libvirt_private.syms | 1 + src/util/virxml.c| 41 src/util/virxml.h| 5 + 3 files changed, 47 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 526dcee11a..70525cef8c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3545,6 +3545,7 @@ virXMLParseHelper; virXMLPickShellSafeComment; virXMLPropString; virXMLPropStringLimit; +virXMLPropTristateBool; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 4a6fe09468..81b7bb1386 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -558,6 +558,47 @@ virXMLNodeContentString(xmlNodePtr node) } +/** + * virXMLPropTristateBool: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @required: Change the return value to -1 if the attribute is not present + * @result: The returned virTristateBool value + * + * Convenience function to return value of a yes / no attribute. + * + * Returns 1 in case of success in which case @value is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropTristateBool(xmlNodePtr node, const char* name, bool required, + virTristateBool *result) +{ +g_autofree char *tmp = virXMLPropString(node, name); +int val; + +if (!tmp) { +if (!required) +return 0; +virReportError(VIR_ERR_XML_ERROR, + _("Missing required attribute '%s' in element '%s'"), + name, node->name); +return -1; +} + +if ((val = virTristateBoolTypeFromString(tmp)) <= 0) { +virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s': '%s'. Expected 'yes' or 'no'"), + name, node->name, tmp); +return -1; +} + +*result = val; +return 1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index d32f77b867..3041c37df3 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -28,6 +28,7 @@ #include #include "virbuffer.h" +#include "virenum.h" xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) G_GNUC_WARN_UNUSED_RESULT; @@ -77,6 +78,10 @@ char * virXMLPropStringLimit(xmlNodePtr node, const char *name, size_t maxlen); char * virXMLNodeContentString(xmlNodePtr node); +int virXMLPropTristateBool(xmlNodePtr node, + const char *name, + bool mandatory, + virTristateBool *result); /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, -- 2.26.2
[libvirt PATCH v2 24/51] domain_conf: Use virXMLPropTristateXXX in virDomainChrSourceReconnectDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bcc89c0afc..fef0b7235a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10619,7 +10619,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def, xmlNodePtr node, xmlXPathContextPtr ctxt) { -int tmpVal; VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr cur; g_autofree char *tmp = NULL; @@ -10627,16 +10626,8 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def, ctxt->node = node; if ((cur = virXPathNode("./reconnect", ctxt))) { -if ((tmp = virXMLPropString(cur, "enabled"))) { -if ((tmpVal = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid reconnect enabled value: '%s'"), - tmp); -return -1; -} -def->enabled = tmpVal; -VIR_FREE(tmp); -} +if (virXMLPropTristateBool(cur, "enabled", false, >enabled) < 0) +return -1; if (def->enabled == VIR_TRISTATE_BOOL_YES) { if ((tmp = virXMLPropString(cur, "timeout"))) { -- 2.26.2
[libvirt PATCH v2 04/51] conf: Use virTristateXXX in virDomainDiskDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 87bc7e8625..853cab96b5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -568,9 +568,9 @@ struct _virDomainDiskDef { int error_policy; /* enum virDomainDiskErrorPolicy */ int rerror_policy; /* enum virDomainDiskErrorPolicy */ int iomode; /* enum virDomainDiskIo */ -int ioeventfd; /* enum virTristateSwitch */ -int event_idx; /* enum virTristateSwitch */ -int copy_on_read; /* enum virTristateSwitch */ +virTristateSwitch ioeventfd; +virTristateSwitch event_idx; +virTristateSwitch copy_on_read; int snapshot; /* virDomainSnapshotLocation, snapshot_conf.h */ int startupPolicy; /* enum virDomainStartupPolicy */ bool transient; -- 2.26.2
[libvirt PATCH v2 10/51] conf: Use virTristateXXX in virDomainLoaderDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2d342effb1..d6ca5e9725 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2152,9 +2152,9 @@ VIR_ENUM_DECL(virDomainLoader); struct _virDomainLoaderDef { char *path; -int readonly; /* enum virTristateBool */ +virTristateBool readonly; virDomainLoader type; -int secure; /* enum virTristateBool */ +virTristateBool secure; char *nvram;/* path to non-volatile RAM */ char *templt; /* user override of path to master nvram */ }; -- 2.26.2
[libvirt PATCH v2 06/51] conf: Use virTristateXXX in virDomainNetDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 90079d7e64..15dc416384 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1102,7 +1102,7 @@ struct _virDomainNetDef { GHashTable *filterparams; virNetDevBandwidthPtr bandwidth; virNetDevVlan vlan; -int trustGuestRxFilters; /* enum virTristateBool */ +virTristateBool trustGuestRxFilters; virTristateBool isolatedPort; int linkstate; unsigned int mtu; -- 2.26.2
[libvirt PATCH v2 14/51] conf: Use virTristateXXX in virPCIDeviceAddress
Signed-off-by: Tim Wiederhake --- src/util/virpci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virpci.h b/src/util/virpci.h index 9b37a12883..2c86642ea7 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -65,7 +65,7 @@ struct _virPCIDeviceAddress { unsigned int bus; unsigned int slot; unsigned int function; -int multi; /* virTristateSwitch */ +virTristateSwitch multi; int extFlags; /* enum virPCIDeviceAddressExtensionFlags */ virZPCIDeviceAddress zpci; /* Don't forget to update virPCIDeviceAddressCopy if needed. */ -- 2.26.2
[libvirt PATCH v2 46/51] backup_conf: Use virXMLPropTristateXXX in virDomainBackupDefParse
Signed-off-by: Tim Wiederhake --- src/conf/backup_conf.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index ce85ed8bad..d3ea9ce4a3 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -234,8 +234,6 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt, def->incremental = virXPathString("string(./incremental)", ctxt); if ((node = virXPathNode("./server", ctxt))) { -g_autofree char *tls = NULL; - if (def->type != VIR_DOMAIN_BACKUP_TYPE_PULL) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("use of requires pull mode backup")); @@ -261,18 +259,8 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt, return NULL; } -if ((tls = virXMLPropString(node, "tls"))) { -int tmp; - -if ((tmp = virTristateBoolTypeFromString(tls)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown value '%s' of 'tls' attribute"),\ - tls); -return NULL; -} - -def->tls = tmp; -} +if (virXMLPropTristateBool(node, "tls", false, >tls) < 0) +return NULL; } if ((n = virXPathNodeSet("./disks/*", ctxt, )) < 0) -- 2.26.2
[libvirt PATCH v2 48/51] network_conf: Use virXMLPropTristateXXX in virNetworkForwardNatDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/network_conf.c | 15 ++- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 4cf4aa4840..bbd18ba163 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1321,7 +1321,6 @@ virNetworkForwardNatDefParseXML(const char *networkName, g_autofree xmlNodePtr *natPortNodes = NULL; g_autofree char *addrStart = NULL; g_autofree char *addrEnd = NULL; -g_autofree char *ipv6 = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) ctxt->node = node; @@ -1333,18 +1332,8 @@ virNetworkForwardNatDefParseXML(const char *networkName, return -1; } -ipv6 = virXMLPropString(node, "ipv6"); -if (ipv6) { -int natIPv6; -if ((natIPv6 = virTristateBoolTypeFromString(ipv6)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("Invalid ipv6 setting '%s' " - "in network '%s' NAT"), - ipv6, networkName); -return -1; -} -def->natIPv6 = natIPv6; -} +if (virXMLPropTristateBool(node, "ipv6", false, >natIPv6) < 0) +return -1; /* addresses for SNAT */ nNatAddrs = virXPathNodeSet("./address", ctxt, ); -- 2.26.2
[libvirt PATCH v2 21/51] domain_conf: Use virXMLPropTristateXXX in virDomainDiskSourceNVMeParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 11 ++- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0e9106b061..39b1e237f5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8398,7 +8398,6 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node, g_autoptr(virStorageSourceNVMeDef) nvme = NULL; g_autofree char *type = NULL; g_autofree char *namespc = NULL; -g_autofree char *managed = NULL; xmlNodePtr address; nvme = g_new0(virStorageSourceNVMeDef, 1); @@ -8429,14 +8428,8 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node, return -1; } -if ((managed = virXMLPropString(node, "managed"))) { -if ((nvme->managed = virTristateBoolTypeFromString(managed)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("malformed managed value '%s'"), - managed); -return -1; -} -} +if (virXMLPropTristateBool(node, "managed", false, >managed) < 0) +return -1; if (!(address = virXPathNode("./address", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", -- 2.26.2
[libvirt PATCH v2 22/51] domain_conf: Use virXMLPropTristateXXX in virDomainDiskDefDriverParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 21 +++-- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 39b1e237f5..ef7eed5682 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9133,29 +9133,14 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, } VIR_FREE(tmp); -if ((tmp = virXMLPropString(cur, "ioeventfd")) && -(def->ioeventfd = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk ioeventfd mode '%s'"), tmp); +if (virXMLPropTristateSwitch(cur, "ioeventfd", false, >ioeventfd) < 0) return -1; -} -VIR_FREE(tmp); -if ((tmp = virXMLPropString(cur, "event_idx")) && -(def->event_idx = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk event_idx mode '%s'"), tmp); +if (virXMLPropTristateSwitch(cur, "event_idx", false, >event_idx) < 0) return -1; -} -VIR_FREE(tmp); -if ((tmp = virXMLPropString(cur, "copy_on_read")) && -(def->copy_on_read = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk copy_on_read mode '%s'"), tmp); +if (virXMLPropTristateSwitch(cur, "copy_on_read", false, >copy_on_read) < 0) return -1; -} -VIR_FREE(tmp); if ((tmp = virXMLPropString(cur, "discard")) && (def->discard = virDomainDiskDiscardTypeFromString(tmp)) <= 0) { -- 2.26.2
[libvirt PATCH v2 50/51] storage_adapter_conf: Use virXMLPropTristateXXX in virStorageAdapterParseXMLFCHost
Signed-off-by: Tim Wiederhake --- src/conf/storage_adapter_conf.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/conf/storage_adapter_conf.c b/src/conf/storage_adapter_conf.c index 69062b4b58..a19920c8b2 100644 --- a/src/conf/storage_adapter_conf.c +++ b/src/conf/storage_adapter_conf.c @@ -64,28 +64,16 @@ static int virStorageAdapterParseXMLFCHost(xmlNodePtr node, virStorageAdapterFCHostPtr fchost) { -char *managed = NULL; +if (virXMLPropTristateBool(node, "managed", false, >managed) < 0) +return -1; fchost->parent = virXMLPropString(node, "parent"); -if ((managed = virXMLPropString(node, "managed"))) { -int value; -if ((value = virTristateBoolTypeFromString(managed)) < 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown fc_host managed setting '%s'"), - managed); -VIR_FREE(managed); -return -1; -} -fchost->managed = value; -} - fchost->parent_wwnn = virXMLPropString(node, "parent_wwnn"); fchost->parent_wwpn = virXMLPropString(node, "parent_wwpn"); fchost->parent_fabric_wwn = virXMLPropString(node, "parent_fabric_wwn"); fchost->wwpn = virXMLPropString(node, "wwpn"); fchost->wwnn = virXMLPropString(node, "wwnn"); -VIR_FREE(managed); return 0; } -- 2.26.2
[libvirt PATCH v2 43/51] domain_conf: Use virXMLPropTristateXXX in virDomainLoaderDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 21 - 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 83fc12c41b..6c4595fd20 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18713,14 +18713,12 @@ virDomainLoaderDefParseXML(xmlNodePtr node, virDomainLoaderDefPtr loader, bool fwAutoSelect) { -g_autofree char *readonly_str = NULL; -g_autofree char *secure_str = NULL; g_autofree char *type_str = NULL; -secure_str = virXMLPropString(node, "secure"); - if (!fwAutoSelect) { -readonly_str = virXMLPropString(node, "readonly"); +if (virXMLPropTristateBool(node, "readonly", false, >readonly) < 0) +return -1; + type_str = virXMLPropString(node, "type"); if (!(loader->path = virXMLNodeContentString(node))) return -1; @@ -18729,19 +18727,8 @@ virDomainLoaderDefParseXML(xmlNodePtr node, VIR_FREE(loader->path); } -if (readonly_str && -(loader->readonly = virTristateBoolTypeFromString(readonly_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown readonly value: %s"), readonly_str); +if (virXMLPropTristateBool(node, "secure", false, >secure) < 0) return -1; -} - -if (secure_str && -(loader->secure = virTristateBoolTypeFromString(secure_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown secure value: %s"), secure_str); -return -1; -} if (type_str) { int type; -- 2.26.2
[libvirt PATCH v2 42/51] domain_conf: Use virXMLPropTristateXXX in virDomainFeaturesDefParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 146 ++--- 1 file changed, 33 insertions(+), 113 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 418e86ebcb..83fc12c41b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18237,6 +18237,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def, for (i = 0; i < n; i++) { g_autofree char *tmp = NULL; +virTristateSwitch triSwitch = VIR_TRISTATE_SWITCH_ABSENT; int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name); if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18246,16 +18247,8 @@ virDomainFeaturesDefParse(virDomainDefPtr def, switch ((virDomainFeature) val) { case VIR_DOMAIN_FEATURE_APIC: -if ((tmp = virXPathString("string(./features/apic/@eoi)", ctxt))) { -int eoi; -if ((eoi = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown value for attribute eoi: '%s'"), - tmp); -return -1; -} -def->apic_eoi = eoi; -} +if (virXMLPropTristateSwitch(nodes[i], "eoi", false, >apic_eoi) < 0) +return -1; G_GNUC_FALLTHROUGH; case VIR_DOMAIN_FEATURE_ACPI: case VIR_DOMAIN_FEATURE_PAE: @@ -18287,16 +18280,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def, case VIR_DOMAIN_FEATURE_PVSPINLOCK: case VIR_DOMAIN_FEATURE_VMPORT: case VIR_DOMAIN_FEATURE_SMM: -if ((tmp = virXMLPropString(nodes[i], "state"))) { -if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) == -1) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); -return -1; -} -} else { +if (virXMLPropTristateSwitch(nodes[i], "state", false, ) < 0) +return -1; +if ((def->features[val] = triSwitch) == VIR_TRISTATE_SWITCH_ABSENT) def->features[val] = VIR_TRISTATE_SWITCH_ON; -} break; case VIR_DOMAIN_FEATURE_GIC: @@ -18404,18 +18391,9 @@ virDomainFeaturesDefParse(virDomainDefPtr def, case VIR_DOMAIN_FEATURE_HTM: case VIR_DOMAIN_FEATURE_NESTED_HV: case VIR_DOMAIN_FEATURE_CCF_ASSIST: -if (!(tmp = virXMLPropString(nodes[i], "state"))) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("missing state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); -return -1; -} -if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); +if (virXMLPropTristateSwitch(nodes[i], "state", true, ) < 0) return -1; -} +def->features[val] = triSwitch; break; /* coverity[dead_error_begin] */ @@ -18427,13 +18405,12 @@ virDomainFeaturesDefParse(virDomainDefPtr def, if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { int feature; -int value; +virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT; xmlNodePtr node = ctxt->node; if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, )) < 0) return -1; for (i = 0; i < n; i++) { -g_autofree char *tmp = NULL; feature = virDomainHypervTypeFromString((const char *)nodes[i]->name); if (feature < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18444,23 +18421,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def, ctxt->node = nodes[i]; -if (!(tmp = virXMLPropString(nodes[i], "state"))) { -virReportError(VIR_ERR_XML_ERROR, - _("missing 'state' attribute for " - "HyperV Enlightenment feature '%s'"), - nodes[i]->name); +if (virXMLPropTristateSwitch(nodes[i], "state", true, ) < 0) return -1; -} -if ((value
[libvirt PATCH v2 44/51] domain_conf: Use virXMLPropTristateXXX in virDomainVcpuParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 28 +--- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6c4595fd20..6b9a5f26e6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18999,7 +18999,7 @@ virDomainVcpuParse(virDomainDefPtr def, for (i = 0; i < n; i++) { virDomainVcpuDefPtr vcpu; -int state; +virTristateBool state; unsigned int id; unsigned int order; @@ -19021,31 +19021,13 @@ virDomainVcpuParse(virDomainDefPtr def, vcpu = virDomainDefGetVcpu(def, id); -if (!(tmp = virXMLPropString(nodes[i], "enabled"))) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing vcpu enabled state")); +if (virXMLPropTristateBool(nodes[i], "enabled", true, ) < 0) return -1; -} - -if ((state = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid vcpu 'enabled' value '%s'"), tmp); -return -1; -} -VIR_FREE(tmp); - vcpu->online = state == VIR_TRISTATE_BOOL_YES; -if ((tmp = virXMLPropString(nodes[i], "hotpluggable"))) { -int hotpluggable; -if ((hotpluggable = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid vcpu 'hotpluggable' value '%s'"), tmp); -return -1; -} -vcpu->hotpluggable = hotpluggable; -VIR_FREE(tmp); -} +if (virXMLPropTristateBool(nodes[i], "hotpluggable", false, + >hotpluggable) < 0) +return -1; if ((tmp = virXMLPropString(nodes[i], "order"))) { if (virStrToLong_uip(tmp, NULL, 10, ) < 0) { -- 2.26.2
[libvirt PATCH v2 30/51] domain_conf: Use virXMLPropTristateXXX in virDomainGraphicsDefParseXMLSDL
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 16 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3409355722..c6c78abb84 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13140,10 +13140,8 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt) { VIR_XPATH_NODE_AUTORESTORE(ctxt) -int enableVal; xmlNodePtr glNode; g_autofree char *fullscreen = virXMLPropString(node, "fullscreen"); -g_autofree char *enable = NULL; ctxt->node = node; @@ -13162,20 +13160,14 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def, glNode = virXPathNode("./gl", ctxt); if (glNode) { -enable = virXMLPropString(glNode, "enable"); -if (!enable) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("sdl gl element missing enable")); +if (virXMLPropTristateBool(glNode, "enable", false, >data.sdl.gl) < 0) return -1; -} -enableVal = virTristateBoolTypeFromString(enable); -if (enableVal < 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); +if (def->data.sdl.gl == VIR_TRISTATE_BOOL_ABSENT) { +virReportError(VIR_ERR_XML_ERROR, "%s", + _("sdl gl element missing enable")); return -1; } -def->data.sdl.gl = enableVal; } return 0; -- 2.26.2
[libvirt PATCH v2 28/51] domain_conf: Use virXMLPropTristateXXX in virDomainChrSourceDefParseLog
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 9 + 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fd7613a479..619a4306f6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11813,17 +11813,10 @@ static int virDomainChrSourceDefParseLog(virDomainChrSourceDefPtr def, xmlNodePtr log) { -g_autofree char *append = NULL; - def->logfile = virXMLPropString(log, "file"); -if ((append = virXMLPropString(log, "append")) && -(def->logappend = virTristateSwitchTypeFromString(append)) <= 0) { -virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid append attribute value '%s'"), - append); +if (virXMLPropTristateSwitch(log, "append", false, >logappend) < 0) return -1; -} return 0; } -- 2.26.2
[libvirt PATCH v2 51/51] storage_conf: Use virXMLPropTristateXXX in virStoragePoolDefParseSource
Signed-off-by: Tim Wiederhake --- src/conf/storage_conf.c | 15 --- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index fa8bcfb8ce..286cdf105d 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -605,7 +605,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, goto cleanup; for (i = 0; i < nsource; i++) { -g_autofree char *partsep = NULL; virStoragePoolSourceDevice dev = { .path = NULL }; dev.path = virXMLPropString(nodeset[i], "path"); @@ -615,16 +614,10 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, goto cleanup; } -partsep = virXMLPropString(nodeset[i], "part_separator"); -if (partsep) { -dev.part_separator = virTristateBoolTypeFromString(partsep); -if (dev.part_separator <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid part_separator setting '%s'"), - partsep); -virStoragePoolSourceDeviceClear(); -goto cleanup; -} +if (virXMLPropTristateBool(nodeset[i], "part_separator", false, + _separator) < 0) { +virStoragePoolSourceDeviceClear(); +goto cleanup; } if (VIR_APPEND_ELEMENT(source->devices, source->ndevice, dev) < 0) { -- 2.26.2
[libvirt PATCH v3 49/51] numa_conf: Use virXMLPropTristateXXX in virDomainNumaDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/numa_conf.c | 14 +++--- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 64b93fd7d1..2555eeaef9 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -1079,17 +1079,9 @@ virDomainNumaDefParseXML(virDomainNumaPtr def, VIR_FREE(tmp); } -if ((tmp = virXMLPropString(nodes[i], "discard"))) { -if ((rc = virTristateBoolTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid 'discard' attribute value '%s'"), - tmp); -goto cleanup; -} - -def->mem_nodes[cur_cell].discard = rc; -VIR_FREE(tmp); -} +if (virXMLPropTristateBool(nodes[i], "discard", false, + >mem_nodes[cur_cell].discard) < 0) +goto cleanup; /* Parse NUMA distances info */ if (virDomainNumaDefNodeDistanceParseXML(def, ctxt, cur_cell) < 0) -- 2.26.2
[libvirt PATCH v2 35/51] domain_conf: Use virXMLPropTristateXXX in virDomainAudioDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 16 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 17b8cab707..976bdb0172 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13970,23 +13970,15 @@ virDomainAudioDefParseXML(virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED, break; case VIR_DOMAIN_AUDIO_TYPE_OSS: { -g_autofree char *tryMMap = virXMLPropString(node, "tryMMap"); -g_autofree char *exclusive = virXMLPropString(node, "exclusive"); g_autofree char *dspPolicy = virXMLPropString(node, "dspPolicy"); -if (tryMMap && ((def->backend.oss.tryMMap = - virTristateBoolTypeFromString(tryMMap)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'tryMMap' value '%s'"), tryMMap); +if (virXMLPropTristateBool(node, "tryMMap", false, + >backend.oss.tryMMap) < 0) goto error; -} -if (exclusive && ((def->backend.oss.exclusive = - virTristateBoolTypeFromString(exclusive)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'exclusive' value '%s'"), exclusive); +if (virXMLPropTristateBool(node, "exclusive", false, + >backend.oss.exclusive) < 0) goto error; -} if (dspPolicy) { if (virStrToLong_i(dspPolicy, NULL, 10, -- 2.26.2
[libvirt PATCH v2 36/51] domain_conf: Use virXMLPropTristateXXX in virDomainMemballoonDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 15 +++ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 976bdb0172..72c98cc5a2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14212,8 +14212,6 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPtr xmlopt, VIR_XPATH_NODE_AUTORESTORE(ctxt) unsigned int period = 0; g_autofree char *model = NULL; -g_autofree char *freepage_reporting = NULL; -g_autofree char *deflate = NULL; def = g_new0(virDomainMemballoonDef, 1); @@ -14230,19 +14228,12 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } -if ((deflate = virXMLPropString(node, "autodeflate")) && -(def->autodeflate = virTristateSwitchTypeFromString(deflate)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid autodeflate attribute value '%s'"), deflate); +if (virXMLPropTristateSwitch(node, "autodeflate", false, >autodeflate) < 0) goto error; -} -if ((freepage_reporting = virXMLPropString(node, "freePageReporting")) && -(def->free_page_reporting = virTristateSwitchTypeFromString(freepage_reporting)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid freePageReporting attribute value '%s'"), freepage_reporting); +if (virXMLPropTristateSwitch(node, "freePageReporting", false, + >free_page_reporting) < 0) goto error; -} ctxt->node = node; if (virXPathUInt("string(./stats/@period)", ctxt, ) < -1) { -- 2.26.2
[libvirt PATCH v2 40/51] domain_conf: Use virXMLPropTristateXXX in virDomainIOMMUDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 41 + 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3c69f3913a..4bcae93c37 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15777,40 +15777,17 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, iommu->model = val; if ((driver = virXPathNode("./driver", ctxt))) { -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "intremap"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown intremap value: %s"), tmp); -return NULL; -} -iommu->intremap = val; -} +if (virXMLPropTristateSwitch(driver, "intremap", false, >intremap) < 0) +return NULL; -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "caching_mode"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown caching_mode value: %s"), tmp); -return NULL; -} -iommu->caching_mode = val; -} -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "iotlb"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown iotlb value: %s"), tmp); -return NULL; -} -iommu->iotlb = val; -} +if (virXMLPropTristateSwitch(driver, "caching_mode", false, >caching_mode) < 0) +return NULL; -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "eim"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown eim value: %s"), tmp); -return NULL; -} -iommu->eim = val; -} +if (virXMLPropTristateSwitch(driver, "iotlb", false, >iotlb) < 0) +return NULL; + +if (virXMLPropTristateSwitch(driver, "eim", false, >eim) < 0) +return NULL; VIR_FREE(tmp); if ((tmp = virXMLPropString(driver, "aw_bits"))) { -- 2.26.2
[libvirt PATCH v2 49/51] numa_conf: Use virXMLPropTristateXXX in virDomainNumaDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/numa_conf.c | 14 +++--- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 64b93fd7d1..2555eeaef9 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -1079,17 +1079,9 @@ virDomainNumaDefParseXML(virDomainNumaPtr def, VIR_FREE(tmp); } -if ((tmp = virXMLPropString(nodes[i], "discard"))) { -if ((rc = virTristateBoolTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid 'discard' attribute value '%s'"), - tmp); -goto cleanup; -} - -def->mem_nodes[cur_cell].discard = rc; -VIR_FREE(tmp); -} +if (virXMLPropTristateBool(nodes[i], "discard", false, + >mem_nodes[cur_cell].discard) < 0) +goto cleanup; /* Parse NUMA distances info */ if (virDomainNumaDefNodeDistanceParseXML(def, ctxt, cur_cell) < 0) -- 2.26.2
[libvirt PATCH v2 38/51] domain_conf: Use virXMLPropTristateXXX in virDomainPerfEventDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 15 +++ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8ca6cd2e44..ef1f930a96 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15443,7 +15443,7 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, { int event; g_autofree char *name = NULL; -g_autofree char *enabled = NULL; +virTristateBool enabled = VIR_TRISTATE_BOOL_ABSENT; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing perf event name")); @@ -15462,18 +15462,9 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, return -1; } -if (!(enabled = virXMLPropString(node, "enabled"))) { -virReportError(VIR_ERR_XML_ERROR, - _("missing state of perf event '%s'"), name); -return -1; -} - -if ((perf->events[event] = virTristateBoolTypeFromString(enabled)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid state '%s' of perf event '%s'"), - enabled, name); +if (virXMLPropTristateBool(node, "enabled", true, ) < 0) return -1; -} +perf->events[event] = enabled; return 0; } -- 2.26.2
[libvirt PATCH v2 27/51] domain_conf: Use virXMLPropTristateXXX in virDomainChrSourceDefParseFile
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 10 ++ 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9822f4f451..fd7613a479 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11778,17 +11778,11 @@ static int virDomainChrSourceDefParseFile(virDomainChrSourceDefPtr def, xmlNodePtr source) { -g_autofree char *append = NULL; - def->data.file.path = virXMLPropString(source, "path"); -if ((append = virXMLPropString(source, "append")) && -(def->data.file.append = virTristateSwitchTypeFromString(append)) <= 0) { -virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid append attribute value '%s'"), - append); +if (virXMLPropTristateSwitch(source, "append", false, + >data.file.append) < 0) return -1; -} return 0; } -- 2.26.2
[libvirt PATCH v2 31/51] domain_conf: Use virXMLPropTristateXXX in virDomainGraphicsDefParseXMLSpice
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 75 ++ 1 file changed, 10 insertions(+), 65 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c6c78abb84..8f906e455d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13397,23 +13397,10 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, def->data.spice.zlib = compressionVal; } else if (virXMLNodeNameEqual(cur, "playback")) { -int compressionVal; -g_autofree char *compression = virXMLPropString(cur, "compression"); - -if (!compression) { -virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice playback missing compression")); -return -1; -} - -if ((compressionVal = - virTristateSwitchTypeFromString(compression)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice playback compression")); +if (virXMLPropTristateSwitch(cur, "compression", true, + >data.spice.playback) < 0) return -1; -} -def->data.spice.playback = compressionVal; } else if (virXMLNodeNameEqual(cur, "streaming")) { int modeVal; g_autofree char *mode = virXMLPropString(cur, "mode"); @@ -13432,62 +13419,20 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, def->data.spice.streaming = modeVal; } else if (virXMLNodeNameEqual(cur, "clipboard")) { -int copypasteVal; -g_autofree char *copypaste = virXMLPropString(cur, "copypaste"); - -if (!copypaste) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice clipboard missing copypaste")); +if (virXMLPropTristateBool(cur, "copypaste", true, + >data.spice.copypaste) < 0) return -1; -} - -if ((copypasteVal = - virTristateBoolTypeFromString(copypaste)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown copypaste value '%s'"), copypaste); -return -1; -} - -def->data.spice.copypaste = copypasteVal; } else if (virXMLNodeNameEqual(cur, "filetransfer")) { -int enableVal; -g_autofree char *enable = virXMLPropString(cur, "enable"); - -if (!enable) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice filetransfer missing enable")); +if (virXMLPropTristateBool(cur, "enable", true, + >data.spice.filetransfer) < 0) return -1; -} - -if ((enableVal = - virTristateBoolTypeFromString(enable)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); -return -1; -} - -def->data.spice.filetransfer = enableVal; } else if (virXMLNodeNameEqual(cur, "gl")) { -int enableVal; -g_autofree char *enable = virXMLPropString(cur, "enable"); -g_autofree char *rendernode = virXMLPropString(cur, "rendernode"); +def->data.spice.rendernode = virXMLPropString(cur, + "rendernode"); -if (!enable) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice gl element missing enable")); -return -1; -} - -if ((enableVal = - virTristateBoolTypeFromString(enable)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); +if (virXMLPropTristateBool(cur, "enable", true, + >data.spice.gl) < 0) return -1; -} - -def->data.spice.gl = enableVal; -def->data.spice.rendernode = g_steal_pointer(); - } else if (virXMLNodeNameEqual(cur, "mouse")) { int modeVal; g_autofree char *mode = virXMLPropString(cur, "mode"); -- 2.26.2
[libvirt PATCH v2 32/51] domain_conf: Use virXMLPropTristateXXX in virDomainAudioCommonParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8f906e455d..f8793237d4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13717,8 +13717,6 @@ virDomainAudioCommonParse(virDomainAudioIOCommonPtr def, xmlNodePtr node, xmlXPathContextPtr ctxt) { -g_autofree char *mixingEngine = virXMLPropString(node, "mixingEngine"); -g_autofree char *fixedSettings = virXMLPropString(node, "fixedSettings"); g_autofree char *voices = virXMLPropString(node, "voices"); g_autofree char *bufferLength = virXMLPropString(node, "bufferLength"); xmlNodePtr settings; @@ -13727,21 +13725,11 @@ virDomainAudioCommonParse(virDomainAudioIOCommonPtr def, ctxt->node = node; settings = virXPathNode("./settings", ctxt); -if (mixingEngine && -((def->mixingEngine = - virTristateBoolTypeFromString(mixingEngine)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'mixingEngine' value '%s'"), mixingEngine); +if (virXMLPropTristateBool(node, "mixingEngine", false, >mixingEngine) < 0) return -1; -} -if (fixedSettings && -((def->fixedSettings = - virTristateBoolTypeFromString(fixedSettings)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'fixedSettings' value '%s'"), fixedSettings); +if (virXMLPropTristateBool(node, "fixedSettings", false, >fixedSettings) < 0) return -1; -} if (def->fixedSettings == VIR_TRISTATE_BOOL_YES && def->mixingEngine != VIR_TRISTATE_BOOL_YES) { -- 2.26.2
[libvirt PATCH v2 33/51] domain_conf: Use virXMLPropTristateXXX in virDomainAudioJackParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 9 + 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f8793237d4..7714b58a6a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13823,19 +13823,12 @@ static int virDomainAudioJackParse(virDomainAudioIOJackPtr def, xmlNodePtr node) { -g_autofree char *exactName = virXMLPropString(node, "exactName"); - def->serverName = virXMLPropString(node, "serverName"); def->clientName = virXMLPropString(node, "clientName"); def->connectPorts = virXMLPropString(node, "connectPorts"); -if (exactName && -((def->exactName = - virTristateBoolTypeFromString(exactName)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'exactName' value '%s'"), exactName); +if (virXMLPropTristateBool(node, "exactName", false, >exactName) < 0) return -1; -} return 0; } -- 2.26.2
[libvirt PATCH v2 39/51] domain_conf: Use virXMLPropTristateXXX in virDomainMemoryDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 12 ++-- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ef1f930a96..3c69f3913a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15706,16 +15706,8 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt, } VIR_FREE(tmp); -if ((tmp = virXMLPropString(memdevNode, "discard"))) { -if ((val = virTristateBoolTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid discard value '%s'"), tmp); -goto error; -} - -def->discard = val; -} -VIR_FREE(tmp); +if (virXMLPropTristateBool(memdevNode, "discard", false, >discard) < 0) +goto error; /* Extract NVDIMM UUID. */ if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM && -- 2.26.2
[libvirt PATCH v2 41/51] domain_conf: Use virXMLPropTristateXXX in virDomainVsockDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4bcae93c37..418e86ebcb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15842,17 +15842,8 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt, } } -VIR_FREE(tmp); -if ((tmp = virXMLPropString(cid, "auto"))) { -val = virTristateBoolTypeFromString(tmp); -if (val <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("'auto' attribute can be 'yes' or 'no': %s"), - tmp); -return NULL; -} -vsock->auto_cid = val; -} +if (virXMLPropTristateBool(cid, "auto", false, >auto_cid) < 0) +return NULL; } if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, >info, flags) < 0) -- 2.26.2
[libvirt PATCH v2 47/51] device_conf: Use virXMLPropTristateXXX in virPCIDeviceAddressParseXML
Signed-off-by: Tim Wiederhake --- src/conf/device_conf.c | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 714ac50762..8d0540bb02 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -214,7 +214,6 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, g_autofree char *bus = virXMLPropString(node, "bus"); g_autofree char *slot = virXMLPropString(node, "slot"); g_autofree char *function = virXMLPropString(node, "function"); -g_autofree char *multi= virXMLPropString(node, "multifunction"); memset(addr, 0, sizeof(*addr)); @@ -246,14 +245,9 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, return -1; } -if (multi && -((addr->multi = virTristateSwitchTypeFromString(multi)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown value '%s' for 'multifunction' attribute"), - multi); +if (virXMLPropTristateSwitch(node, "multifunction", false, >multi) < 0) return -1; -} if (!virPCIDeviceAddressIsEmpty(addr) && !virPCIDeviceAddressIsValid(addr, true)) return -1; -- 2.26.2
[libvirt PATCH v2 08/51] conf: Use virTristateXXX in virDomainGraphicsDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6619b9f006..09b697432d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1862,7 +1862,7 @@ struct _virDomainGraphicsDef { int image; int jpeg; int zlib; -int playback; +virTristateSwitch playback; int streaming; virTristateBool copypaste; virTristateBool filetransfer; -- 2.26.2
[libvirt PATCH v2 45/51] backup_conf: Use virXMLPropTristateXXX in virDomainBackupDiskDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/backup_conf.c | 16 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index ba58b2e322..ce85ed8bad 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -106,7 +106,6 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, g_autofree char *type = NULL; g_autofree char *format = NULL; g_autofree char *idx = NULL; -g_autofree char *backup = NULL; g_autofree char *state = NULL; g_autofree char *backupmode = NULL; int tmp; @@ -125,17 +124,10 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, return -1; } -def->backup = VIR_TRISTATE_BOOL_YES; - -if ((backup = virXMLPropString(node, "backup"))) { -if ((tmp = virTristateBoolTypeFromString(backup)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid disk 'backup' state '%s'"), backup); -return -1; -} - -def->backup = tmp; -} +if (virXMLPropTristateBool(node, "backup", false, >backup) < 0) +return -1; +if (def->backup == VIR_TRISTATE_BOOL_ABSENT) +def->backup = VIR_TRISTATE_BOOL_YES; /* don't parse anything else if backup is disabled */ if (def->backup == VIR_TRISTATE_BOOL_NO) -- 2.26.2
[libvirt PATCH v2 26/51] domain_conf: Use virXMLPropTristateXXX in virDomainChrSourceDefParseTCP
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 11 ++- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 329f42d6dd..9822f4f451 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11704,15 +11704,8 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, def->data.tcp.host = virXMLPropString(source, "host"); def->data.tcp.service = virXMLPropString(source, "service"); -if ((tmp = virXMLPropString(source, "tls"))) { -if ((def->data.tcp.haveTLS = virTristateBoolTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown chardev 'tls' setting '%s'"), - tmp); -return -1; -} -VIR_FREE(tmp); -} +if (virXMLPropTristateBool(source, "tls", false, >data.tcp.haveTLS) < 0) +return -1; if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && (tmp = virXMLPropString(source, "tlsFromConfig"))) { -- 2.26.2
[libvirt PATCH v2 34/51] domain_conf: Use virXMLPropTristateXXX in virDomainAudioOSSParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7714b58a6a..17b8cab707 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13838,18 +13838,12 @@ static int virDomainAudioOSSParse(virDomainAudioIOOSSPtr def, xmlNodePtr node) { -g_autofree char *tryPoll = virXMLPropString(node, "tryPoll"); g_autofree char *bufferCount = virXMLPropString(node, "bufferCount"); def->dev = virXMLPropString(node, "dev"); -if (tryPoll && -((def->tryPoll = - virTristateBoolTypeFromString(tryPoll)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'tryPoll' value '%s'"), tryPoll); +if (virXMLPropTristateBool(node, "tryPoll", false, >tryPoll) < 0) return -1; -} if (bufferCount && virStrToLong_ui(bufferCount, NULL, 10, -- 2.26.2
[libvirt PATCH v2 37/51] domain_conf: Use virXMLPropTristateXXX in virDomainShmemDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 14 +++--- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 72c98cc5a2..8ca6cd2e44 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14359,17 +14359,9 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt, } VIR_FREE(tmp); -if ((tmp = virXMLPropString(msi, "ioeventfd"))) { -int val; - -if ((val = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid msi ioeventfd setting for shmem: '%s'"), - tmp); -goto cleanup; -} -def->msi.ioeventfd = val; -} +if (virXMLPropTristateSwitch(msi, "ioeventfd", false, + >msi.ioeventfd) < 0) +goto cleanup; } /* msi option is only relevant with a server */ -- 2.26.2
[libvirt PATCH v2 29/51] domain_conf: Use virXMLPropTristateXXX in virDomainGraphicsDefParseXMLVNC
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 +++-- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 619a4306f6..3409355722 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13044,7 +13044,6 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, g_autofree char *websocketGenerated = virXMLPropString(node, "websocketGenerated"); g_autofree char *sharePolicy = virXMLPropString(node, "sharePolicy"); g_autofree char *autoport = virXMLPropString(node, "autoport"); -g_autofree char *powerControl = virXMLPropString(node, "powerControl"); xmlNodePtr audioNode; VIR_XPATH_NODE_AUTORESTORE(ctxt) @@ -13103,15 +13102,9 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, } } -if (powerControl) { -int powerControlVal = virTristateBoolTypeFromString(powerControl); -if (powerControlVal < 0) { -virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse vnc power control '%s'"), powerControl); -return -1; -} -def->data.vnc.powerControl = powerControlVal; -} +if ((virXMLPropTristateBool(node, "powerControl", false, +>data.vnc.powerControl)) < 0) +return -1; def->data.vnc.keymap = virXMLPropString(node, "keymap"); -- 2.26.2
[libvirt PATCH v2 11/51] conf: Use virTristateXXX in virDomainDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index d6ca5e9725..25af058241 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2755,7 +2755,7 @@ struct _virDomainDef { virDomainHPTResizing hpt_resizing; unsigned long long hpt_maxpagesize; /* Stored in KiB */ char *hyperv_vendor_id; -int apic_eoi; +virTristateSwitch apic_eoi; bool tseg_specified; unsigned long long tseg_size; -- 2.26.2
[libvirt PATCH v2 05/51] conf: Use virTristateXXX in virDomainActualNetDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 853cab96b5..90079d7e64 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -994,7 +994,7 @@ struct _virDomainActualNetDef { virNetDevVPortProfilePtr virtPortProfile; virNetDevBandwidthPtr bandwidth; virNetDevVlan vlan; -int trustGuestRxFilters; /* enum virTristateBool */ +virTristateBool trustGuestRxFilters; virTristateBool isolatedPort; unsigned int class_id; /* class ID for bandwidth 'floor' */ }; -- 2.26.2
[libvirt PATCH v3 44/51] domain_conf: Use virXMLPropTristateXXX in virDomainVcpuParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 28 +--- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 55405d129b..97c7a3ec28 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18998,7 +18998,7 @@ virDomainVcpuParse(virDomainDefPtr def, for (i = 0; i < n; i++) { virDomainVcpuDefPtr vcpu; -int state; +virTristateBool state; unsigned int id; unsigned int order; @@ -19020,31 +19020,13 @@ virDomainVcpuParse(virDomainDefPtr def, vcpu = virDomainDefGetVcpu(def, id); -if (!(tmp = virXMLPropString(nodes[i], "enabled"))) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing vcpu enabled state")); +if (virXMLPropTristateBool(nodes[i], "enabled", true, ) < 0) return -1; -} - -if ((state = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid vcpu 'enabled' value '%s'"), tmp); -return -1; -} -VIR_FREE(tmp); - vcpu->online = state == VIR_TRISTATE_BOOL_YES; -if ((tmp = virXMLPropString(nodes[i], "hotpluggable"))) { -int hotpluggable; -if ((hotpluggable = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid vcpu 'hotpluggable' value '%s'"), tmp); -return -1; -} -vcpu->hotpluggable = hotpluggable; -VIR_FREE(tmp); -} +if (virXMLPropTristateBool(nodes[i], "hotpluggable", false, + >hotpluggable) < 0) +return -1; if ((tmp = virXMLPropString(nodes[i], "order"))) { if (virStrToLong_uip(tmp, NULL, 10, ) < 0) { -- 2.26.2
[libvirt PATCH v3 45/51] backup_conf: Use virXMLPropTristateXXX in virDomainBackupDiskDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/backup_conf.c | 16 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index ba58b2e322..ce85ed8bad 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -106,7 +106,6 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, g_autofree char *type = NULL; g_autofree char *format = NULL; g_autofree char *idx = NULL; -g_autofree char *backup = NULL; g_autofree char *state = NULL; g_autofree char *backupmode = NULL; int tmp; @@ -125,17 +124,10 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, return -1; } -def->backup = VIR_TRISTATE_BOOL_YES; - -if ((backup = virXMLPropString(node, "backup"))) { -if ((tmp = virTristateBoolTypeFromString(backup)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid disk 'backup' state '%s'"), backup); -return -1; -} - -def->backup = tmp; -} +if (virXMLPropTristateBool(node, "backup", false, >backup) < 0) +return -1; +if (def->backup == VIR_TRISTATE_BOOL_ABSENT) +def->backup = VIR_TRISTATE_BOOL_YES; /* don't parse anything else if backup is disabled */ if (def->backup == VIR_TRISTATE_BOOL_NO) -- 2.26.2
[libvirt PATCH v3 43/51] domain_conf: Use virXMLPropTristateXXX in virDomainLoaderDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 29 + 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index dfa8b98aae..55405d129b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18712,14 +18712,12 @@ virDomainLoaderDefParseXML(xmlNodePtr node, virDomainLoaderDefPtr loader, bool fwAutoSelect) { -g_autofree char *readonly_str = NULL; -g_autofree char *secure_str = NULL; g_autofree char *type_str = NULL; -secure_str = virXMLPropString(node, "secure"); - if (!fwAutoSelect) { -readonly_str = virXMLPropString(node, "readonly"); +if (virXMLPropTristateBool(node, "readonly", false, >readonly) < 0) +return -1; + type_str = virXMLPropString(node, "type"); if (!(loader->path = virXMLNodeContentString(node))) return -1; @@ -18728,25 +18726,8 @@ virDomainLoaderDefParseXML(xmlNodePtr node, VIR_FREE(loader->path); } -if (readonly_str) { -int value; -if ((value = virTristateBoolTypeFromString(readonly_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown readonly value: %s"), readonly_str); -return -1; -} -loader->readonly = value; -} - -if (secure_str) { -int value; -if ((value = virTristateBoolTypeFromString(secure_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown secure value: %s"), secure_str); -return -1; -} -loader->secure = value; -} +if (virXMLPropTristateBool(node, "secure", false, >secure) < 0) +return -1; if (type_str) { int type; -- 2.26.2
[libvirt PATCH v3 47/51] device_conf: Use virXMLPropTristateXXX in virPCIDeviceAddressParseXML
Signed-off-by: Tim Wiederhake --- src/conf/device_conf.c | 14 +++--- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 0dd60985e9..8d0540bb02 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -214,7 +214,6 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, g_autofree char *bus = virXMLPropString(node, "bus"); g_autofree char *slot = virXMLPropString(node, "slot"); g_autofree char *function = virXMLPropString(node, "function"); -g_autofree char *multi= virXMLPropString(node, "multifunction"); memset(addr, 0, sizeof(*addr)); @@ -246,16 +245,9 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, return -1; } -if (multi) { -int value; -if ((value = virTristateSwitchTypeFromString(multi)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown value '%s' for 'multifunction' attribute"), - multi); -return -1; -} -addr->multi = value; -} +if (virXMLPropTristateSwitch(node, "multifunction", false, >multi) < 0) +return -1; + if (!virPCIDeviceAddressIsEmpty(addr) && !virPCIDeviceAddressIsValid(addr, true)) return -1; -- 2.26.2
[libvirt PATCH v3 10/51] conf: Use virTristateXXX in virDomainLoaderDef
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 26 -- src/conf/domain_conf.h | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0480fc610d..9e106b8846 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19198,18 +19198,24 @@ virDomainLoaderDefParseXML(xmlNodePtr node, VIR_FREE(loader->path); } -if (readonly_str && -(loader->readonly = virTristateBoolTypeFromString(readonly_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown readonly value: %s"), readonly_str); -return -1; +if (readonly_str) { +int value; +if ((value = virTristateBoolTypeFromString(readonly_str)) <= 0) { +virReportError(VIR_ERR_XML_DETAIL, + _("unknown readonly value: %s"), readonly_str); +return -1; +} +loader->readonly = value; } -if (secure_str && -(loader->secure = virTristateBoolTypeFromString(secure_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown secure value: %s"), secure_str); -return -1; +if (secure_str) { +int value; +if ((value = virTristateBoolTypeFromString(secure_str)) <= 0) { +virReportError(VIR_ERR_XML_DETAIL, + _("unknown secure value: %s"), secure_str); +return -1; +} +loader->secure = value; } if (type_str) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2d342effb1..d6ca5e9725 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2152,9 +2152,9 @@ VIR_ENUM_DECL(virDomainLoader); struct _virDomainLoaderDef { char *path; -int readonly; /* enum virTristateBool */ +virTristateBool readonly; virDomainLoader type; -int secure; /* enum virTristateBool */ +virTristateBool secure; char *nvram;/* path to non-volatile RAM */ char *templt; /* user override of path to master nvram */ }; -- 2.26.2
[libvirt PATCH v3 42/51] domain_conf: Use virXMLPropTristateXXX in virDomainFeaturesDefParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 146 ++--- 1 file changed, 33 insertions(+), 113 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3289c9fa12..dfa8b98aae 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18236,6 +18236,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def, for (i = 0; i < n; i++) { g_autofree char *tmp = NULL; +virTristateSwitch triSwitch = VIR_TRISTATE_SWITCH_ABSENT; int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name); if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18245,16 +18246,8 @@ virDomainFeaturesDefParse(virDomainDefPtr def, switch ((virDomainFeature) val) { case VIR_DOMAIN_FEATURE_APIC: -if ((tmp = virXPathString("string(./features/apic/@eoi)", ctxt))) { -int eoi; -if ((eoi = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown value for attribute eoi: '%s'"), - tmp); -return -1; -} -def->apic_eoi = eoi; -} +if (virXMLPropTristateSwitch(nodes[i], "eoi", false, >apic_eoi) < 0) +return -1; G_GNUC_FALLTHROUGH; case VIR_DOMAIN_FEATURE_ACPI: case VIR_DOMAIN_FEATURE_PAE: @@ -18286,16 +18279,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def, case VIR_DOMAIN_FEATURE_PVSPINLOCK: case VIR_DOMAIN_FEATURE_VMPORT: case VIR_DOMAIN_FEATURE_SMM: -if ((tmp = virXMLPropString(nodes[i], "state"))) { -if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) == -1) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); -return -1; -} -} else { +if (virXMLPropTristateSwitch(nodes[i], "state", false, ) < 0) +return -1; +if ((def->features[val] = triSwitch) == VIR_TRISTATE_SWITCH_ABSENT) def->features[val] = VIR_TRISTATE_SWITCH_ON; -} break; case VIR_DOMAIN_FEATURE_GIC: @@ -18403,18 +18390,9 @@ virDomainFeaturesDefParse(virDomainDefPtr def, case VIR_DOMAIN_FEATURE_HTM: case VIR_DOMAIN_FEATURE_NESTED_HV: case VIR_DOMAIN_FEATURE_CCF_ASSIST: -if (!(tmp = virXMLPropString(nodes[i], "state"))) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("missing state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); -return -1; -} -if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); +if (virXMLPropTristateSwitch(nodes[i], "state", true, ) < 0) return -1; -} +def->features[val] = triSwitch; break; /* coverity[dead_error_begin] */ @@ -18426,13 +18404,12 @@ virDomainFeaturesDefParse(virDomainDefPtr def, if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { int feature; -int value; +virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT; xmlNodePtr node = ctxt->node; if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, )) < 0) return -1; for (i = 0; i < n; i++) { -g_autofree char *tmp = NULL; feature = virDomainHypervTypeFromString((const char *)nodes[i]->name); if (feature < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18443,23 +18420,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def, ctxt->node = nodes[i]; -if (!(tmp = virXMLPropString(nodes[i], "state"))) { -virReportError(VIR_ERR_XML_ERROR, - _("missing 'state' attribute for " - "HyperV Enlightenment feature '%s'"), - nodes[i]->name); -return -1; -} - -if ((value = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR
[libvirt PATCH v3 46/51] backup_conf: Use virXMLPropTristateXXX in virDomainBackupDefParse
Signed-off-by: Tim Wiederhake --- src/conf/backup_conf.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index ce85ed8bad..d3ea9ce4a3 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -234,8 +234,6 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt, def->incremental = virXPathString("string(./incremental)", ctxt); if ((node = virXPathNode("./server", ctxt))) { -g_autofree char *tls = NULL; - if (def->type != VIR_DOMAIN_BACKUP_TYPE_PULL) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("use of requires pull mode backup")); @@ -261,18 +259,8 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt, return NULL; } -if ((tls = virXMLPropString(node, "tls"))) { -int tmp; - -if ((tmp = virTristateBoolTypeFromString(tls)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown value '%s' of 'tls' attribute"),\ - tls); -return NULL; -} - -def->tls = tmp; -} +if (virXMLPropTristateBool(node, "tls", false, >tls) < 0) +return NULL; } if ((n = virXPathNodeSet("./disks/*", ctxt, )) < 0) -- 2.26.2
Re: [libvirt PATCH v3 16/51] virxml: Add virXMLPropTristateSwitch
On Mon, 2021-03-22 at 12:31 +, Daniel P. Berrangé wrote: > On Mon, Mar 22, 2021 at 01:23:28PM +0100, Michal Privoznik wrote: > > On 3/19/21 4:57 PM, Tim Wiederhake wrote: > > > Convenience function to return value of an on / off attribute. > > > > > > Signed-off-by: Tim Wiederhake > > > --- > > > src/libvirt_private.syms | 1 + > > > src/util/virxml.c| 41 > > > > > > src/util/virxml.h| 6 +- > > > 3 files changed, 47 insertions(+), 1 deletion(-) > > > > > > diff --git a/src/util/virxml.h b/src/util/virxml.h > > > index 3041c37df3..e844cb0713 100644 > > > --- a/src/util/virxml.h > > > +++ b/src/util/virxml.h > > > @@ -80,8 +80,12 @@ char * virXMLPropStringLimit(xmlNodePtr > > > node, > > > char * virXMLNodeContentString(xmlNodePtr node); > > > int virXMLPropTristateBool(xmlNodePtr node, > > >const char *name, > > > - bool mandatory, > > > + bool required, > > >virTristateBool *result); > > > > I guess this doesn't belong here. I'll squash it into the previous > > patch. > > I wonder if we should avoid the boolean arg entirely though. > Looking at a call > > if (virXMLPropTristateBool(node, "foo", true, ) < 0) > > you have no idea whether "true" means mandatory or optional unless > you're very familiar with the code. In GTK/GNOME they generally > discourage use of bool parameters in favour of enums for this reason. > eg they would have a VIR_XML_TRISTATE_REQUIRED enum flag. > > This is quite verbose though, so perhaps we can just use trivial > wrapper methods: > >virXMLPropTristateRequiredBool >virXMLPropTristateOptionalBool > > Regards, > Daniel I agree that having a couple of bool arguments is not perfect, and my first (unpublished and proof-of-concept) version had one function per variant. The problem with this approach becomes apparent in the yet-to-be- published series that refactors reading integer attributes. In addition to the "required or optional" variant, these also have "allow two's complement wraparound for unsigned int or not" variants and "zero is a valid number or not" variants. Having dedicated enums for this might be an option, especially as I believe I will be able to reuse e.g. the enum for "attribute is required or not". What is your opinion on using bools for the time being, see how the refactoring for "int attributes" and "enum attributes" turns out, and then revisiting this issue? Regards, Tim
[libvirt PATCH 4/5] vsh: setmaxmem: Mark '--kilobytes' as deprecated
Signed-off-by: Tim Wiederhake --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 32bd048d26..9f0e3e1a5e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9065,6 +9065,7 @@ static const vshCmdOptDef opts_setmaxmem[] = { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "kilobytes", .type = VSH_OT_ALIAS, + .flags = VSH_OFLAG_DEPRECATED, .help = "size" }, {.name = "size", -- 2.26.2
[libvirt PATCH 5/5] vsh: secret-set-value: Mark '--base64' as deprecated
Signed-off-by: Tim Wiederhake --- tools/virsh-secret.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 7ca3e864da..5a1c4d7bf6 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -192,6 +192,7 @@ static const vshCmdOptDef opts_secret_set_value[] = { }, {.name = "base64", .type = VSH_OT_STRING, + .flags = VSH_OFLAG_DEPRECATED, .help = N_("base64-encoded secret value") }, {.name = NULL} @@ -225,8 +226,6 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) return false; if (base64) { -/* warn users that the --base64 option passed from command line is wrong */ -vshError(ctl, _("Passing secret value as command-line argument is insecure!")); secret_val = g_strdup(base64); secret_len = strlen(secret_val); } else if (filename) { -- 2.26.2
[libvirt PATCH 3/5] vsh: setmem: Mark '--kilobytes' as deprecated
Signed-off-by: Tim Wiederhake --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7db88f700a..32bd048d26 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8986,6 +8986,7 @@ static const vshCmdOptDef opts_setmem[] = { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "kilobytes", .type = VSH_OT_ALIAS, + .flags = VSH_OFLAG_DEPRECATED, .help = "size" }, {.name = "size", -- 2.26.2
[libvirt PATCH 0/5] Formalize the deprecation of arguments in virsh
virsh has several arguments that are better not used. This series introduces a formal way of marking them as deprecated. Tim Wiederhake (5): vsh: Set default log level to "warning" vsh: Introduce flag for deprecated options vsh: setmem: Mark '--kilobytes' as deprecated vsh: setmaxmem: Mark '--kilobytes' as deprecated vsh: secret-set-value: Mark '--base64' as deprecated tools/virsh-domain.c | 2 ++ tools/virsh-secret.c | 3 +-- tools/vsh.c | 11 +-- tools/vsh.h | 11 ++- 4 files changed, 18 insertions(+), 9 deletions(-) -- 2.26.2
[libvirt PATCH 2/5] vsh: Introduce flag for deprecated options
Signed-off-by: Tim Wiederhake --- tools/vsh.c | 11 +-- tools/vsh.h | 9 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 8fb033249e..8b58db8896 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -321,7 +321,8 @@ vshCmddefCheckInternals(vshControl *ctl, char *name = (char *)opt->help; /* cast away const */ char *p; -if (opt->flags || !opt->help) { +if ((opt->flags != 0 && opt->flags != VSH_OFLAG_DEPRECATED) || +!opt->help) { vshError(ctl, _("parameter '%s' of command '%s' has incorrect alias option"), opt->name, cmd->name); return -1; /* alias options are tracked by the original name */ @@ -442,6 +443,11 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, const vshCmdOptDef *opt = >opts[i]; if (STREQ(opt->name, name)) { +if (report && (opt->flags & VSH_OFLAG_DEPRECATED)) { +vshDebug(ctl, VSH_ERR_WARNING, + _("Warning: Option '%s' is deprecated\n"), name); +} + if (opt->type == VSH_OT_ALIAS) { char *value; @@ -697,7 +703,8 @@ vshCmddefHelp(const vshCmdDef *def) continue; } -fprintf(stdout, "%-15s %s\n", buf, _(opt->help)); +fprintf(stdout, "%-15s %s%s\n", buf, _(opt->help), +opt->flags & VSH_OFLAG_DEPRECATED ? " (deprecated)" : ""); } } fputc('\n', stdout); diff --git a/tools/vsh.h b/tools/vsh.h index e83e0eca9e..e85206b726 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -98,10 +98,11 @@ typedef enum { * Command Option Flags */ enum { -VSH_OFLAG_NONE = 0,/* without flags */ -VSH_OFLAG_REQ = (1 << 0), /* option required */ -VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */ -VSH_OFLAG_REQ_OPT = (1 << 2), /* --optionname required */ +VSH_OFLAG_NONE = 0,/* without flags */ +VSH_OFLAG_REQ= (1 << 0), /* option required */ +VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */ +VSH_OFLAG_REQ_OPT= (1 << 2), /* --optionname required */ +VSH_OFLAG_DEPRECATED = (1 << 3), /* option is deprecated */ }; /* forward declarations */ -- 2.26.2
[libvirt PATCH 1/5] vsh: Set default log level to "warning"
Signed-off-by: Tim Wiederhake --- tools/vsh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/vsh.h b/tools/vsh.h index 39f70913fe..e83e0eca9e 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -60,7 +60,7 @@ typedef enum { VSH_ERR_ERROR } vshErrorLevel; -#define VSH_DEBUG_DEFAULT VSH_ERR_ERROR +#define VSH_DEBUG_DEFAULT VSH_ERR_WARNING /* * virsh command line grammar: -- 2.26.2
[libvirt PATCH 14/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceDefParseFile
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 14 +- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1cec2edde7..d9330f9ee7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11808,17 +11808,13 @@ static int virDomainChrSourceDefParseFile(virDomainChrSourceDefPtr def, xmlNodePtr source) { -g_autofree char *append = NULL; - -def->data.file.path = virXMLPropString(source, "path"); +virTristateSwitch append = VIR_TRISTATE_SWITCH_ABSENT; -if ((append = virXMLPropString(source, "append")) && -(def->data.file.append = virTristateSwitchTypeFromString(append)) <= 0) { -virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid append attribute value '%s'"), - append); +if (virXMLPropOnOff(source, "append", ) < 0) return -1; -} + +def->data.file.path = virXMLPropString(source, "path"); +def->data.file.append = append; return 0; } -- 2.26.2
[libvirt PATCH 19/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioCommonParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 360528ef1e..4e7f5031e7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13772,8 +13772,6 @@ virDomainAudioCommonParse(virDomainAudioIOCommonPtr def, xmlNodePtr node, xmlXPathContextPtr ctxt) { -g_autofree char *mixingEngine = virXMLPropString(node, "mixingEngine"); -g_autofree char *fixedSettings = virXMLPropString(node, "fixedSettings"); g_autofree char *voices = virXMLPropString(node, "voices"); g_autofree char *bufferLength = virXMLPropString(node, "bufferLength"); xmlNodePtr settings; @@ -13782,21 +13780,11 @@ virDomainAudioCommonParse(virDomainAudioIOCommonPtr def, ctxt->node = node; settings = virXPathNode("./settings", ctxt); -if (mixingEngine && -((def->mixingEngine = - virTristateBoolTypeFromString(mixingEngine)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'mixingEngine' value '%s'"), mixingEngine); +if (virXMLPropYesNo(node, "mixingEngine", >mixingEngine) < 0) return -1; -} -if (fixedSettings && -((def->fixedSettings = - virTristateBoolTypeFromString(fixedSettings)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'fixedSettings' value '%s'"), fixedSettings); +if (virXMLPropYesNo(node, "fixedSettings", >fixedSettings) < 0) return -1; -} if (def->fixedSettings == VIR_TRISTATE_BOOL_YES && def->mixingEngine != VIR_TRISTATE_BOOL_YES) { -- 2.26.2
[libvirt PATCH 20/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioJackParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 9 + 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4e7f5031e7..b9ee1e2de7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13878,19 +13878,12 @@ static int virDomainAudioJackParse(virDomainAudioIOJackPtr def, xmlNodePtr node) { -g_autofree char *exactName = virXMLPropString(node, "exactName"); - def->serverName = virXMLPropString(node, "serverName"); def->clientName = virXMLPropString(node, "clientName"); def->connectPorts = virXMLPropString(node, "connectPorts"); -if (exactName && -((def->exactName = - virTristateBoolTypeFromString(exactName)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'exactName' value '%s'"), exactName); +if (virXMLPropYesNo(node, "exactName", >exactName) < 0) return -1; -} return 0; } -- 2.26.2
[libvirt PATCH 11/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceReconnectDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b8dfc77cfc..52e1668010 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10658,7 +10658,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def, xmlNodePtr node, xmlXPathContextPtr ctxt) { -int tmpVal; VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr cur; g_autofree char *tmp = NULL; @@ -10666,16 +10665,8 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def, ctxt->node = node; if ((cur = virXPathNode("./reconnect", ctxt))) { -if ((tmp = virXMLPropString(cur, "enabled"))) { -if ((tmpVal = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid reconnect enabled value: '%s'"), - tmp); -return -1; -} -def->enabled = tmpVal; -VIR_FREE(tmp); -} +if (virXMLPropYesNo(cur, "enabled", >enabled) < 0) +return -1; if (def->enabled == VIR_TRISTATE_BOOL_YES) { if ((tmp = virXMLPropString(cur, "timeout"))) { -- 2.26.2
[libvirt PATCH 21/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioOSSParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b9ee1e2de7..6559c3d2f8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13893,18 +13893,12 @@ static int virDomainAudioOSSParse(virDomainAudioIOOSSPtr def, xmlNodePtr node) { -g_autofree char *tryPoll = virXMLPropString(node, "tryPoll"); g_autofree char *bufferCount = virXMLPropString(node, "bufferCount"); def->dev = virXMLPropString(node, "dev"); -if (tryPoll && -((def->tryPoll = - virTristateBoolTypeFromString(tryPoll)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'tryPoll' value '%s'"), tryPoll); +if (virXMLPropYesNo(node, "tryPoll", >tryPoll) < 0) return -1; -} if (bufferCount && virStrToLong_ui(bufferCount, NULL, 10, -- 2.26.2
[libvirt PATCH 12/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainNetDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 166 + 1 file changed, 37 insertions(+), 129 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 52e1668010..54c647bfd5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10759,7 +10759,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, g_autofree char *queues = NULL; g_autofree char *rx_queue_size = NULL; g_autofree char *tx_queue_size = NULL; -g_autofree char *str = NULL; g_autofree char *filter = NULL; g_autofree char *internal = NULL; g_autofree char *mode = NULL; @@ -10769,8 +10768,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, g_autofree char *vhostuser_mode = NULL; g_autofree char *vhostuser_path = NULL; g_autofree char *vhostuser_type = NULL; -g_autofree char *trustGuestRxFilters = NULL; g_autofree char *vhost_path = NULL; +virTristateBool trustGuestRxFilters = VIR_TRISTATE_BOOL_ABSENT; const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; if (!(def = virDomainNetDefNew(xmlopt))) @@ -10789,15 +10788,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, def->type = VIR_DOMAIN_NET_TYPE_USER; } -trustGuestRxFilters = virXMLPropString(node, "trustGuestRxFilters"); -if (trustGuestRxFilters && -((def->trustGuestRxFilters - = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown trustGuestRxFilters value '%s'"), - trustGuestRxFilters); +if (virXMLPropYesNo(node, "trustGuestRxFilters", ) < 0) goto error; -} +def->trustGuestRxFilters = trustGuestRxFilters; cur = node->children; while (cur != NULL) { @@ -11367,128 +11360,43 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, } if ((tmpNode = virXPathNode("./driver/host", ctxt))) { -if ((str = virXMLPropString(tmpNode, "csum"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host csum mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.csum = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "gso"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host gso mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.gso = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "tso4"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host tso4 mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.tso4 = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "tso6"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host tso6 mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.tso6 = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "ecn"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host ecn mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.ecn = val; -} -VIR_FREE(str); -if ((str = virXMLPropString(tmpNode, "ufo"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host ufo mode '%s'"), - str); -goto error; -} -def->driver.virtio.host.ufo = val; -} -
[libvirt PATCH 10/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainActualNetDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 12 +++- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8dbf371e81..b8dfc77cfc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10474,8 +10474,8 @@ virDomainActualNetDefParseXML(xmlNodePtr node, g_autofree char *type = NULL; g_autofree char *mode = NULL; g_autofree char *addrtype = NULL; -g_autofree char *trustGuestRxFilters = NULL; g_autofree char *macTableManager = NULL; +virTristateBool trustGuestRxFilters = VIR_TRISTATE_BOOL_ABSENT; actual = g_new0(virDomainActualNetDef, 1); @@ -10502,15 +10502,9 @@ virDomainActualNetDefParseXML(xmlNodePtr node, goto error; } -trustGuestRxFilters = virXMLPropString(node, "trustGuestRxFilters"); -if (trustGuestRxFilters && -((actual->trustGuestRxFilters - = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown trustGuestRxFilters value '%s'"), - trustGuestRxFilters); +if (virXMLPropYesNo(node, "trustGuestRxFilters", ) < 0) goto error; -} +actual->trustGuestRxFilters = trustGuestRxFilters; virtPortNode = virXPathNode("./virtualport", ctxt); if (virtPortNode) { -- 2.26.2
[libvirt PATCH 02/38] virxml: Add virXMLPropYesNo
Convenience function to return value of a yes / no attribute. Does not use virTristateBoolTypeFromString to disallow "default". Signed-off-by: Tim Wiederhake --- src/util/virxml.c | 37 + src/util/virxml.h | 4 2 files changed, 41 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 060b7530fc..47e8414bd5 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -556,6 +556,43 @@ virXMLNodeContentString(xmlNodePtr node) } +/** + * virXMLPropYesNo: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @value: The returned virTristateBool value + * + * Convenience function to return value of a yes / no attribute. + * + * Returns 1 in case of success in which case @value is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropYesNo(xmlNodePtr node, const char* name, virTristateBool *value) +{ +g_autofree char *tmp = virXMLPropString(node, name); + +if (!tmp) +return 0; + +if (STREQ("yes", tmp)) { +*value = VIR_TRISTATE_BOOL_YES; +return 1; +} + +if (STREQ("no", tmp)) { +*value = VIR_TRISTATE_BOOL_NO; +return 1; +} + +virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in node '%s': '%s'. Expected 'yes' or 'no'"), + name, node->name, tmp); +return -1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index d32f77b867..072948b3e2 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -28,6 +28,7 @@ #include #include "virbuffer.h" +#include "virenum.h" xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) G_GNUC_WARN_UNUSED_RESULT; @@ -77,6 +78,9 @@ char * virXMLPropStringLimit(xmlNodePtr node, const char *name, size_t maxlen); char * virXMLNodeContentString(xmlNodePtr node); +int virXMLPropYesNo(xmlNodePtr node, + const char *name, + virTristateBool *value); /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, -- 2.26.2
[libvirt PATCH 09/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDiskDefDriverParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 27 +-- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e3e38ae30d..8dbf371e81 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9126,6 +9126,9 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, xmlXPathContextPtr ctxt) { g_autofree char *tmp = NULL; +virTristateSwitch ioeventfd = VIR_TRISTATE_SWITCH_ABSENT; +virTristateSwitch event_idx = VIR_TRISTATE_SWITCH_ABSENT; +virTristateSwitch copy_on_read = VIR_TRISTATE_SWITCH_ABSENT; VIR_XPATH_NODE_AUTORESTORE(ctxt) ctxt->node = cur; @@ -9165,29 +9168,17 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, } VIR_FREE(tmp); -if ((tmp = virXMLPropString(cur, "ioeventfd")) && -(def->ioeventfd = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk ioeventfd mode '%s'"), tmp); +if (virXMLPropOnOff(cur, "ioeventfd", ) < 0) return -1; -} -VIR_FREE(tmp); +def->ioeventfd = ioeventfd; -if ((tmp = virXMLPropString(cur, "event_idx")) && -(def->event_idx = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk event_idx mode '%s'"), tmp); +if (virXMLPropOnOff(cur, "event_idx", _idx) < 0) return -1; -} -VIR_FREE(tmp); +def->event_idx = event_idx; -if ((tmp = virXMLPropString(cur, "copy_on_read")) && -(def->copy_on_read = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk copy_on_read mode '%s'"), tmp); +if (virXMLPropOnOff(cur, "copy_on_read", _on_read) < 0) return -1; -} -VIR_FREE(tmp); +def->copy_on_read = copy_on_read; if ((tmp = virXMLPropString(cur, "discard")) && (def->discard = virDomainDiskDiscardTypeFromString(tmp)) <= 0) { -- 2.26.2
[libvirt PATCH 13/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceDefParseTCP
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 15 +-- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 54c647bfd5..1cec2edde7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11724,23 +11724,18 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, int mode; int tmpVal; g_autofree char *tmp = NULL; +virTristateBool haveTLS = VIR_TRISTATE_BOOL_ABSENT; if ((mode = virDomainChrSourceDefParseMode(source)) < 0) return -1; +if (virXMLPropYesNo(source, "tls", ) < 0) +return -1; + def->data.tcp.listen = mode == VIR_DOMAIN_CHR_SOURCE_MODE_BIND; def->data.tcp.host = virXMLPropString(source, "host"); def->data.tcp.service = virXMLPropString(source, "service"); - -if ((tmp = virXMLPropString(source, "tls"))) { -if ((def->data.tcp.haveTLS = virTristateBoolTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown chardev 'tls' setting '%s'"), - tmp); -return -1; -} -VIR_FREE(tmp); -} +def->data.tcp.haveTLS = haveTLS; if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && (tmp = virXMLPropString(source, "tlsFromConfig"))) { -- 2.26.2
[libvirt PATCH 15/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceDefParseLog
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 14 +- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d9330f9ee7..b4928a94c2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11845,17 +11845,13 @@ static int virDomainChrSourceDefParseLog(virDomainChrSourceDefPtr def, xmlNodePtr log) { -g_autofree char *append = NULL; +virTristateSwitch logappend = VIR_TRISTATE_SWITCH_ABSENT; -def->logfile = virXMLPropString(log, "file"); - -if ((append = virXMLPropString(log, "append")) && -(def->logappend = virTristateSwitchTypeFromString(append)) <= 0) { -virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid append attribute value '%s'"), - append); +if (virXMLPropOnOff(log, "append", ) < 0) return -1; -} + +def->logfile = virXMLPropString(log, "file"); +def->logappend = logappend; return 0; } -- 2.26.2
[libvirt PATCH 05/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainVirtioOptionsParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 34 ++ 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b6e505b384..3a4b01ad1e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1590,9 +1590,7 @@ static int virDomainVirtioOptionsParseXML(xmlNodePtr driver, virDomainVirtioOptionsPtr *virtio) { -int val; virDomainVirtioOptionsPtr res; -g_autofree char *str = NULL; if (*virtio || !driver) return 0; @@ -1601,34 +1599,14 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, res = *virtio; -if ((str = virXMLPropString(driver, "iommu"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid iommu value")); -return -1; -} -res->iommu = val; -} -VIR_FREE(str); +if (virXMLPropOnOff(driver, "iommu", >iommu) < 0) +return -1; -if ((str = virXMLPropString(driver, "ats"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid ats value")); -return -1; -} -res->ats = val; -} -VIR_FREE(str); +if (virXMLPropOnOff(driver, "ats", >ats) < 0) +return -1; -if ((str = virXMLPropString(driver, "packed"))) { -if ((val = virTristateSwitchTypeFromString(str)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid packed value")); -return -1; -} -res->packed = val; -} +if (virXMLPropOnOff(driver, "packed", >packed) < 0) +return -1; return 0; } -- 2.26.2
[libvirt PATCH 01/38] virStorageAdapterFCHost: Fix comment
Signed-off-by: Tim Wiederhake --- src/conf/storage_adapter_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/storage_adapter_conf.h b/src/conf/storage_adapter_conf.h index 4c7da7c8d9..93879acb6e 100644 --- a/src/conf/storage_adapter_conf.h +++ b/src/conf/storage_adapter_conf.h @@ -51,7 +51,7 @@ struct _virStorageAdapterFCHost { char *parent_fabric_wwn; char *wwnn; char *wwpn; -int managed;/* enum virTristateSwitch */ +int managed;/* enum virTristateBool */ }; typedef struct _virStorageAdapter virStorageAdapter; -- 2.26.2
[libvirt PATCH 06/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDeviceInfoParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 21 + 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3a4b01ad1e..e1b2baf621 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6620,8 +6620,6 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr boot = NULL; xmlNodePtr rom = NULL; int ret = -1; -g_autofree char *romenabled = NULL; -g_autofree char *rombar = NULL; g_autofree char *aliasStr = NULL; virDomainDeviceInfoClear(info); @@ -6673,18 +6671,17 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt, } if (rom) { -if ((romenabled = virXMLPropString(rom, "enabled")) && -((info->romenabled = virTristateBoolTypeFromString(romenabled)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown rom enabled value '%s'"), romenabled); +virTristateBool romenabled = VIR_TRISTATE_BOOL_ABSENT; +virTristateSwitch rombar = VIR_TRISTATE_SWITCH_ABSENT; + +if (virXMLPropYesNo(rom, "enabled", ) < 0) goto cleanup; -} -if ((rombar = virXMLPropString(rom, "bar")) && -((info->rombar = virTristateSwitchTypeFromString(rombar)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown rom bar value '%s'"), rombar); + +if (virXMLPropOnOff(rom, "bar", ) < 0) goto cleanup; -} + +info->romenabled = romenabled; +info->rombar = rombar; info->romfile = virXMLPropString(rom, "file"); if (info->romenabled == VIR_TRISTATE_BOOL_NO && -- 2.26.2
[libvirt PATCH 03/38] virxml: Add virXMLPropOnOff
Convenience function to return value of an on / off attribute. Does not use virTristateSwitchTypeFromString to disallow "default". Signed-off-by: Tim Wiederhake --- src/util/virxml.c | 37 + src/util/virxml.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 47e8414bd5..7c06530d25 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -593,6 +593,43 @@ virXMLPropYesNo(xmlNodePtr node, const char* name, virTristateBool *value) } +/** + * virXMLPropOnOff: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @value: The returned virTristateSwitch value + * + * Convenience function to return value of an on / off attribute. + * + * Returns 1 in case of success in which case @value is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropOnOff(xmlNodePtr node, const char* name, virTristateSwitch *value) +{ +g_autofree char *tmp = virXMLPropString(node, name); + +if (!tmp) +return 0; + +if (STREQ("on", tmp)) { +*value = VIR_TRISTATE_SWITCH_ON; +return 1; +} + +if (STREQ("off", tmp)) { +*value = VIR_TRISTATE_SWITCH_OFF; +return 1; +} + +virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in node '%s': '%s'. Expected 'on' or 'off'"), + name, node->name, tmp); +return -1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index 072948b3e2..d0577723ef 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -81,6 +81,9 @@ char * virXMLNodeContentString(xmlNodePtr node); int virXMLPropYesNo(xmlNodePtr node, const char *name, virTristateBool *value); +int virXMLPropOnOff(xmlNodePtr node, + const char *name, + virTristateSwitch *value); /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, -- 2.26.2
[libvirt PATCH 00/38] Refactor XML parsing boilerplate code
This series replaces some recurring boilerplate code in src/conf/ regarding the extraction of a virTristate(Switch|Bool) XML attribute. The boilerplate code looks roughly like this, g_autofree char *str = NULL; if (str = virXMLPropString(node, ...)) { int val; if ((val = virTristateBoolTypeFromString(str)) <= 0) { virReportError(...) return -1; } def->... = val; } with some variations regarding how `str` is free'd in case of later re-use, the exact error message for invalid values, whether or not `VIR_TRISTATE_(SWITCH|BOOL)_ABSENT` is explicitly checked for (`val < 0` vs. `val <= 0`), whether an intermediate variable is used or the value is assigned directly, and in some cases the conditions in the two if-blocks are merged. As a side effect, this makes the error messages for invalid values in these attributes much more consistent and catches some instances where e.g. `` would incorrectly be accepted. Patch #11 (virDomainChrSourceReconnectDefParseXML) is a good example of what this refactoring is about. Tim Wiederhake (38): virStorageAdapterFCHost: Fix comment virxml: Add virXMLPropYesNo virxml: Add virXMLPropOnOff domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainKeyWrapCipherDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainVirtioOptionsParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDeviceInfoParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDiskSourceNetworkParse domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDiskSourceNVMeParse domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDiskDefDriverParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainActualNetDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceReconnectDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainNetDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceDefParseTCP domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceDefParseFile domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainChrSourceDefParseLog domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainGraphicsDefParseXMLVNC domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainGraphicsDefParseXMLSDL domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainGraphicsDefParseXMLSpice domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioCommonParse domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioJackParse domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioOSSParse domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainMemballoonDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainShmemDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainPerfEventDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainMemoryDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainIOMMUDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainVsockDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainFeaturesDefParse domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainLoaderDefParseXML domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainVcpuParse backup_conf: Use virXMLProp(OnOff|YesNo) in virDomainBackupDiskDefParseXML backup_conf: Use virXMLProp(OnOff|YesNo) in virDomainBackupDefParse device_conf: Use virXMLProp(OnOff|YesNo) in virPCIDeviceAddressParseXML network_conf: Use virXMLProp(OnOff|YesNo) in virNetworkForwardNatDefParseXML numa_conf: Use virXMLProp(OnOff|YesNo) in virDomainNumaDefParseXML storage_adapter_conf: Use virXMLProp(OnOff|YesNo) in virStorageAdapterParseXMLFCHost storage_conf: Use virXMLProp(OnOff|YesNo) in virStoragePoolDefParseSource src/conf/backup_conf.c | 32 +- src/conf/device_conf.c | 10 +- src/conf/domain_conf.c | 791 +--- src/conf/network_conf.c | 15 +- src/conf/numa_conf.c| 13 +- src/conf/storage_adapter_conf.c | 17 +- src/conf/storage_adapter_conf.h | 2 +- src/conf/storage_conf.c | 16 +- src/util/virxml.c | 74 +++ src/util/virxml.h | 7 + 10 files changed, 314 insertions(+), 663 deletions(-) -- 2.26.2
[libvirt PATCH 04/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainKeyWrapCipherDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 - 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 47756ff0be..b6e505b384 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1441,10 +1441,9 @@ static int virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, xmlNodePtr node) { -int state_type; +virTristateSwitch state_type = VIR_TRISTATE_SWITCH_ABSENT; int name_type; g_autofree char *name = NULL; -g_autofree char *state = NULL; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", @@ -1458,15 +1457,11 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, return -1; } -if (!(state = virXMLPropString(node, "state"))) { -virReportError(VIR_ERR_CONF_SYNTAX, - _("missing state for cipher named %s"), name); +if (virXMLPropOnOff(node, "state", _type) < 0) return -1; -} - -if ((state_type = virTristateSwitchTypeFromString(state)) < 0) { +if (state_type == VIR_TRISTATE_SWITCH_ABSENT) { virReportError(VIR_ERR_CONF_SYNTAX, - _("%s is not a supported cipher state"), state); + _("missing state for cipher named %s"), name); return -1; } -- 2.26.2
[libvirt PATCH 16/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainGraphicsDefParseXMLVNC
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 12 ++-- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b4928a94c2..756a35f33b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13077,7 +13077,6 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, g_autofree char *websocketGenerated = virXMLPropString(node, "websocketGenerated"); g_autofree char *sharePolicy = virXMLPropString(node, "sharePolicy"); g_autofree char *autoport = virXMLPropString(node, "autoport"); -g_autofree char *powerControl = virXMLPropString(node, "powerControl"); xmlNodePtr audioNode; VIR_XPATH_NODE_AUTORESTORE(ctxt) @@ -13136,15 +13135,8 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, } } -if (powerControl) { -int powerControlVal = virTristateBoolTypeFromString(powerControl); -if (powerControlVal < 0) { -virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse vnc power control '%s'"), powerControl); -return -1; -} -def->data.vnc.powerControl = powerControlVal; -} +if ((virXMLPropYesNo(node, "powerControl", >data.vnc.powerControl)) < 0) +return -1; def->data.vnc.keymap = virXMLPropString(node, "keymap"); -- 2.26.2
[libvirt PATCH 17/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainGraphicsDefParseXMLSDL
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 16 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 756a35f33b..011745e73a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13172,10 +13172,8 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt) { VIR_XPATH_NODE_AUTORESTORE(ctxt) -int enableVal; xmlNodePtr glNode; g_autofree char *fullscreen = virXMLPropString(node, "fullscreen"); -g_autofree char *enable = NULL; ctxt->node = node; @@ -13194,20 +13192,14 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def, glNode = virXPathNode("./gl", ctxt); if (glNode) { -enable = virXMLPropString(glNode, "enable"); -if (!enable) { -virReportError(VIR_ERR_XML_ERROR, "%s", - _("sdl gl element missing enable")); +if (virXMLPropYesNo(glNode, "enable", >data.sdl.gl) < 0) return -1; -} -enableVal = virTristateBoolTypeFromString(enable); -if (enableVal < 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); +if (def->data.sdl.gl == VIR_TRISTATE_BOOL_ABSENT) { +virReportError(VIR_ERR_XML_ERROR, "%s", + _("sdl gl element missing enable")); return -1; } -def->data.sdl.gl = enableVal; } return 0; -- 2.26.2
[libvirt PATCH 07/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDiskSourceNetworkParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 11 --- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e1b2baf621..55920e7a7d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8303,9 +8303,9 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, { int tlsCfgVal; g_autofree char *protocol = NULL; -g_autofree char *haveTLS = NULL; g_autofree char *tlsCfg = NULL; g_autofree char *sslverifystr = NULL; +virTristateBool haveTLS = VIR_TRISTATE_BOOL_ABSENT; xmlNodePtr tmpnode; if (!(protocol = virXMLPropString(node, "protocol"))) { @@ -8327,12 +8327,9 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, return -1; } -if ((haveTLS = virXMLPropString(node, "tls")) && -(src->haveTLS = virTristateBoolTypeFromString(haveTLS)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown disk source 'tls' setting '%s'"), haveTLS); -return -1; -} +if (virXMLPropYesNo(node, "tls", ) < 0) +return -1; +src->haveTLS = haveTLS; if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && (tlsCfg = virXMLPropString(node, "tlsFromConfig"))) { -- 2.26.2
[libvirt PATCH 18/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainGraphicsDefParseXMLSpice
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 66 +++--- 1 file changed, 17 insertions(+), 49 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 011745e73a..360528ef1e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13429,23 +13429,18 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, def->data.spice.zlib = compressionVal; } else if (virXMLNodeNameEqual(cur, "playback")) { -int compressionVal; -g_autofree char *compression = virXMLPropString(cur, "compression"); +virTristateSwitch compression = VIR_TRISTATE_SWITCH_ABSENT; -if (!compression) { -virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice playback missing compression")); +if (virXMLPropOnOff(cur, "compression", ) < 0) return -1; -} -if ((compressionVal = - virTristateSwitchTypeFromString(compression)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice playback compression")); +if (compression == VIR_TRISTATE_SWITCH_ABSENT) { +virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("spice playback missing compression")); return -1; } -def->data.spice.playback = compressionVal; +def->data.spice.playback = compression; } else if (virXMLNodeNameEqual(cur, "streaming")) { int modeVal; g_autofree char *mode = virXMLPropString(cur, "mode"); @@ -13464,62 +13459,35 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, def->data.spice.streaming = modeVal; } else if (virXMLNodeNameEqual(cur, "clipboard")) { -int copypasteVal; -g_autofree char *copypaste = virXMLPropString(cur, "copypaste"); +if (virXMLPropYesNo(cur, "copypaste", >data.spice.copypaste) < 0) +return -1; -if (!copypaste) { +if (def->data.spice.copypaste == VIR_TRISTATE_BOOL_ABSENT) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice clipboard missing copypaste")); return -1; } - -if ((copypasteVal = - virTristateBoolTypeFromString(copypaste)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown copypaste value '%s'"), copypaste); -return -1; -} - -def->data.spice.copypaste = copypasteVal; } else if (virXMLNodeNameEqual(cur, "filetransfer")) { -int enableVal; -g_autofree char *enable = virXMLPropString(cur, "enable"); +if (virXMLPropYesNo(cur, "enable", >data.spice.filetransfer) < 0) +return -1; -if (!enable) { +if (def->data.spice.filetransfer == VIR_TRISTATE_BOOL_ABSENT) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice filetransfer missing enable")); return -1; } +} else if (virXMLNodeNameEqual(cur, "gl")) { +def->data.spice.rendernode = virXMLPropString(cur, + "rendernode"); -if ((enableVal = - virTristateBoolTypeFromString(enable)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); +if (virXMLPropYesNo(cur, "enable", >data.spice.gl) < 0) return -1; -} - -def->data.spice.filetransfer = enableVal; -} else if (virXMLNodeNameEqual(cur, "gl")) { -int enableVal; -g_autofree char *enable = virXMLPropString(cur, "enable"); -g_autofree char *rendernode = virXMLPropString(cur, "rendernode"); -if (!enable) { +if (def->data.spice.gl == VIR_TRISTATE_BOOL_ABSENT) { virReportError(VIR_ERR_XML_ERROR, "%s",
[libvirt PATCH 34/38] device_conf: Use virXMLProp(OnOff|YesNo) in virPCIDeviceAddressParseXML
Signed-off-by: Tim Wiederhake --- src/conf/device_conf.c | 10 +++--- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 714ac50762..ee248648bd 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -214,7 +214,7 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, g_autofree char *bus = virXMLPropString(node, "bus"); g_autofree char *slot = virXMLPropString(node, "slot"); g_autofree char *function = virXMLPropString(node, "function"); -g_autofree char *multi= virXMLPropString(node, "multifunction"); +virTristateSwitch multifunction = VIR_TRISTATE_SWITCH_ABSENT; memset(addr, 0, sizeof(*addr)); @@ -246,14 +246,10 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, return -1; } -if (multi && -((addr->multi = virTristateSwitchTypeFromString(multi)) <= 0)) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown value '%s' for 'multifunction' attribute"), - multi); +if (virXMLPropOnOff(node, "multifunction", ) < 0) return -1; +addr->multi = multifunction; -} if (!virPCIDeviceAddressIsEmpty(addr) && !virPCIDeviceAddressIsValid(addr, true)) return -1; -- 2.26.2
[libvirt PATCH 08/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainDiskSourceNVMeParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 - 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 55920e7a7d..e3e38ae30d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8428,7 +8428,7 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node, g_autoptr(virStorageSourceNVMeDef) nvme = NULL; g_autofree char *type = NULL; g_autofree char *namespc = NULL; -g_autofree char *managed = NULL; +virTristateBool managed = VIR_TRISTATE_BOOL_ABSENT; xmlNodePtr address; nvme = g_new0(virStorageSourceNVMeDef, 1); @@ -8459,14 +8459,9 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node, return -1; } -if ((managed = virXMLPropString(node, "managed"))) { -if ((nvme->managed = virTristateBoolTypeFromString(managed)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("malformed managed value '%s'"), - managed); -return -1; -} -} +if (virXMLPropYesNo(node, "managed", ) < 0) +return -1; +nvme->managed = managed; if (!(address = virXPathNode("./address", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", -- 2.26.2
[libvirt PATCH 30/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainLoaderDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 25 - 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4f020714bc..9b4c083801 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18806,14 +18806,15 @@ virDomainLoaderDefParseXML(xmlNodePtr node, virDomainLoaderDefPtr loader, bool fwAutoSelect) { -g_autofree char *readonly_str = NULL; -g_autofree char *secure_str = NULL; g_autofree char *type_str = NULL; - -secure_str = virXMLPropString(node, "secure"); +virTristateBool readonly = VIR_TRISTATE_BOOL_ABSENT; +virTristateBool secure = VIR_TRISTATE_BOOL_ABSENT; if (!fwAutoSelect) { -readonly_str = virXMLPropString(node, "readonly"); +if (virXMLPropYesNo(node, "readonly", ) < 0) +return -1; +loader->readonly = readonly; + type_str = virXMLPropString(node, "type"); if (!(loader->path = virXMLNodeContentString(node))) return -1; @@ -18822,19 +18823,9 @@ virDomainLoaderDefParseXML(xmlNodePtr node, VIR_FREE(loader->path); } -if (readonly_str && -(loader->readonly = virTristateBoolTypeFromString(readonly_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown readonly value: %s"), readonly_str); +if (virXMLPropYesNo(node, "secure", ) < 0) return -1; -} - -if (secure_str && -(loader->secure = virTristateBoolTypeFromString(secure_str)) <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("unknown secure value: %s"), secure_str); -return -1; -} +loader->secure = secure; if (type_str) { int type; -- 2.26.2
[libvirt PATCH 31/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainVcpuParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 25 ++--- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9b4c083801..66d3080744 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19096,7 +19096,7 @@ virDomainVcpuParse(virDomainDefPtr def, for (i = 0; i < n; i++) { virDomainVcpuDefPtr vcpu; -int state; +virTristateBool state = VIR_TRISTATE_BOOL_ABSENT; unsigned int id; unsigned int order; @@ -19118,31 +19118,18 @@ virDomainVcpuParse(virDomainDefPtr def, vcpu = virDomainDefGetVcpu(def, id); -if (!(tmp = virXMLPropString(nodes[i], "enabled"))) { +if (virXMLPropYesNo(nodes[i], "enabled", ) < 0) +return -1; +if (state == VIR_TRISTATE_BOOL_ABSENT) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vcpu enabled state")); return -1; } -if ((state = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid vcpu 'enabled' value '%s'"), tmp); -return -1; -} -VIR_FREE(tmp); - vcpu->online = state == VIR_TRISTATE_BOOL_YES; -if ((tmp = virXMLPropString(nodes[i], "hotpluggable"))) { -int hotpluggable; -if ((hotpluggable = virTristateBoolTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid vcpu 'hotpluggable' value '%s'"), tmp); -return -1; -} -vcpu->hotpluggable = hotpluggable; -VIR_FREE(tmp); -} +if (virXMLPropYesNo(nodes[i], "hotpluggable", >hotpluggable) < 0) +return -1; if ((tmp = virXMLPropString(nodes[i], "order"))) { if (virStrToLong_uip(tmp, NULL, 10, ) < 0) { -- 2.26.2
[libvirt PATCH 26/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainMemoryDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 12 ++-- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c020bf9124..d4ca60f98c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15764,16 +15764,8 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt, } VIR_FREE(tmp); -if ((tmp = virXMLPropString(memdevNode, "discard"))) { -if ((val = virTristateBoolTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid discard value '%s'"), tmp); -goto error; -} - -def->discard = val; -} -VIR_FREE(tmp); +if (virXMLPropYesNo(memdevNode, "discard", >discard) < 0) +goto error; /* Extract NVDIMM UUID. */ if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM && -- 2.26.2
[libvirt PATCH 27/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainIOMMUDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 41 + 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d4ca60f98c..2969cf0d88 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15835,40 +15835,17 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, iommu->model = val; if ((driver = virXPathNode("./driver", ctxt))) { -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "intremap"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown intremap value: %s"), tmp); -return NULL; -} -iommu->intremap = val; -} +if (virXMLPropOnOff(driver, "intremap", >intremap) < 0) +return NULL; -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "caching_mode"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown caching_mode value: %s"), tmp); -return NULL; -} -iommu->caching_mode = val; -} -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "iotlb"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown iotlb value: %s"), tmp); -return NULL; -} -iommu->iotlb = val; -} +if (virXMLPropOnOff(driver, "caching_mode", >caching_mode) < 0) +return NULL; -VIR_FREE(tmp); -if ((tmp = virXMLPropString(driver, "eim"))) { -if ((val = virTristateSwitchTypeFromString(tmp)) < 0) { -virReportError(VIR_ERR_XML_ERROR, _("unknown eim value: %s"), tmp); -return NULL; -} -iommu->eim = val; -} +if (virXMLPropOnOff(driver, "iotlb", >iotlb) < 0) +return NULL; + +if (virXMLPropOnOff(driver, "eim", >eim) < 0) +return NULL; VIR_FREE(tmp); if ((tmp = virXMLPropString(driver, "aw_bits"))) { -- 2.26.2
[libvirt PATCH 28/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainVsockDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2969cf0d88..39f171ba74 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15900,17 +15900,8 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt, } } -VIR_FREE(tmp); -if ((tmp = virXMLPropString(cid, "auto"))) { -val = virTristateBoolTypeFromString(tmp); -if (val <= 0) { -virReportError(VIR_ERR_XML_DETAIL, - _("'auto' attribute can be 'yes' or 'no': %s"), - tmp); -return NULL; -} -vsock->auto_cid = val; -} +if (virXMLPropYesNo(cid, "auto", >auto_cid) < 0) +return NULL; } if (virDomainDeviceInfoParseXML(xmlopt, node, >info, flags) < 0) -- 2.26.2
[libvirt PATCH 25/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainPerfEventDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a1aefdf0bf..c020bf9124 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15496,7 +15496,7 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, { int event; g_autofree char *name = NULL; -g_autofree char *enabled = NULL; +virTristateBool enabled = VIR_TRISTATE_BOOL_ABSENT; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing perf event name")); @@ -15515,16 +15515,12 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, return -1; } -if (!(enabled = virXMLPropString(node, "enabled"))) { -virReportError(VIR_ERR_XML_ERROR, - _("missing state of perf event '%s'"), name); +if (virXMLPropYesNo(node, "enabled", ) < 0) return -1; -} -if ((perf->events[event] = virTristateBoolTypeFromString(enabled)) < 0) { +if ((perf->events[event] = enabled) == VIR_TRISTATE_BOOL_ABSENT) { virReportError(VIR_ERR_XML_ERROR, - _("invalid state '%s' of perf event '%s'"), - enabled, name); + _("missing state of perf event '%s'"), name); return -1; } -- 2.26.2
[libvirt PATCH 33/38] backup_conf: Use virXMLProp(OnOff|YesNo) in virDomainBackupDefParse
Signed-off-by: Tim Wiederhake --- src/conf/backup_conf.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 8560f3bf2e..3a1863d2c3 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -234,8 +234,6 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt, def->incremental = virXPathString("string(./incremental)", ctxt); if ((node = virXPathNode("./server", ctxt))) { -g_autofree char *tls = NULL; - if (def->type != VIR_DOMAIN_BACKUP_TYPE_PULL) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("use of requires pull mode backup")); @@ -261,18 +259,8 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt, return NULL; } -if ((tls = virXMLPropString(node, "tls"))) { -int tmp; - -if ((tmp = virTristateBoolTypeFromString(tls)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown value '%s' of 'tls' attribute"),\ - tls); -return NULL; -} - -def->tls = tmp; -} +if (virXMLPropYesNo(node, "tls", >tls) < 0) +return NULL; } if ((n = virXPathNodeSet("./disks/*", ctxt, )) < 0) -- 2.26.2
[libvirt PATCH 22/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainAudioDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 14 ++ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6559c3d2f8..fe35a3960e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14025,23 +14025,13 @@ virDomainAudioDefParseXML(virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED, break; case VIR_DOMAIN_AUDIO_TYPE_OSS: { -g_autofree char *tryMMap = virXMLPropString(node, "tryMMap"); -g_autofree char *exclusive = virXMLPropString(node, "exclusive"); g_autofree char *dspPolicy = virXMLPropString(node, "dspPolicy"); -if (tryMMap && ((def->backend.oss.tryMMap = - virTristateBoolTypeFromString(tryMMap)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'tryMMap' value '%s'"), tryMMap); +if (virXMLPropYesNo(node, "tryMMap", >backend.oss.tryMMap) < 0) goto error; -} -if (exclusive && ((def->backend.oss.exclusive = - virTristateBoolTypeFromString(exclusive)) <= 0)) { -virReportError(VIR_ERR_XML_ERROR, - _("unknown 'exclusive' value '%s'"), exclusive); +if (virXMLPropYesNo(node, "exclusive", >backend.oss.exclusive) < 0) goto error; -} if (dspPolicy) { if (virStrToLong_i(dspPolicy, NULL, 10, -- 2.26.2
[libvirt PATCH 32/38] backup_conf: Use virXMLProp(OnOff|YesNo) in virDomainBackupDiskDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/backup_conf.c | 16 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index ba58b2e322..8560f3bf2e 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -106,7 +106,6 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, g_autofree char *type = NULL; g_autofree char *format = NULL; g_autofree char *idx = NULL; -g_autofree char *backup = NULL; g_autofree char *state = NULL; g_autofree char *backupmode = NULL; int tmp; @@ -125,17 +124,10 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, return -1; } -def->backup = VIR_TRISTATE_BOOL_YES; - -if ((backup = virXMLPropString(node, "backup"))) { -if ((tmp = virTristateBoolTypeFromString(backup)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid disk 'backup' state '%s'"), backup); -return -1; -} - -def->backup = tmp; -} +if (virXMLPropYesNo(node, "backup", >backup) < 0) +return -1; +if (def->backup == VIR_TRISTATE_BOOL_ABSENT) +def->backup = VIR_TRISTATE_BOOL_YES; /* don't parse anything else if backup is disabled */ if (def->backup == VIR_TRISTATE_BOOL_NO) -- 2.26.2
[libvirt PATCH 24/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainShmemDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0c4f7ab879..a1aefdf0bf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14413,17 +14413,8 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt, } VIR_FREE(tmp); -if ((tmp = virXMLPropString(msi, "ioeventfd"))) { -int val; - -if ((val = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("invalid msi ioeventfd setting for shmem: '%s'"), - tmp); -goto cleanup; -} -def->msi.ioeventfd = val; -} +if (virXMLPropOnOff(msi, "ioeventfd", >msi.ioeventfd) < 0) +goto cleanup; } /* msi option is only relevant with a server */ -- 2.26.2
[libvirt PATCH 29/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainFeaturesDefParse
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 138 ++--- 1 file changed, 48 insertions(+), 90 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 39f171ba74..4f020714bc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18292,6 +18292,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def, for (i = 0; i < n; i++) { g_autofree char *tmp = NULL; +virTristateSwitch triSwitch = VIR_TRISTATE_SWITCH_ABSENT; int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name); if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18301,16 +18302,9 @@ virDomainFeaturesDefParse(virDomainDefPtr def, switch ((virDomainFeature) val) { case VIR_DOMAIN_FEATURE_APIC: -if ((tmp = virXPathString("string(./features/apic/@eoi)", ctxt))) { -int eoi; -if ((eoi = virTristateSwitchTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown value for attribute eoi: '%s'"), - tmp); -return -1; -} -def->apic_eoi = eoi; -} +if (virXMLPropOnOff(nodes[i], "eoi", ) < 0) +return -1; +def->apic_eoi = triSwitch; G_GNUC_FALLTHROUGH; case VIR_DOMAIN_FEATURE_ACPI: case VIR_DOMAIN_FEATURE_PAE: @@ -18342,16 +18336,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def, case VIR_DOMAIN_FEATURE_PVSPINLOCK: case VIR_DOMAIN_FEATURE_VMPORT: case VIR_DOMAIN_FEATURE_SMM: -if ((tmp = virXMLPropString(nodes[i], "state"))) { -if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) == -1) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); -return -1; -} -} else { +if (virXMLPropOnOff(nodes[i], "state", ) < 0) +return -1; +if ((def->features[val] = triSwitch) == VIR_TRISTATE_SWITCH_ABSENT) def->features[val] = VIR_TRISTATE_SWITCH_ON; -} break; case VIR_DOMAIN_FEATURE_GIC: @@ -18459,15 +18447,11 @@ virDomainFeaturesDefParse(virDomainDefPtr def, case VIR_DOMAIN_FEATURE_HTM: case VIR_DOMAIN_FEATURE_NESTED_HV: case VIR_DOMAIN_FEATURE_CCF_ASSIST: -if (!(tmp = virXMLPropString(nodes[i], "state"))) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("missing state attribute '%s' of feature '%s'"), - tmp, virDomainFeatureTypeToString(val)); +if (virXMLPropOnOff(nodes[i], "state", ) < 0) return -1; -} -if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) < 0) { +if ((def->features[val] = triSwitch) == VIR_TRISTATE_SWITCH_ABSENT) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature '%s'"), + _("missing state attribute '%s' of feature '%s'"), tmp, virDomainFeatureTypeToString(val)); return -1; } @@ -18482,13 +18466,12 @@ virDomainFeaturesDefParse(virDomainDefPtr def, if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { int feature; -int value; +virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT; xmlNodePtr node = ctxt->node; if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, )) < 0) return -1; for (i = 0; i < n; i++) { -g_autofree char *tmp = NULL; feature = virDomainHypervTypeFromString((const char *)nodes[i]->name); if (feature < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18499,7 +18482,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def, ctxt->node = nodes[i]; -if (!(tmp = virXMLPropString(nodes[i], "state"))) { +if (virXMLPropOnOff(nodes[i], "state", ) < 0) +return -1; + +if (state == VIR_TRISTATE_SWITCH_ABSENT) { virReportError(VIR_ERR_XML_ERROR, _("missing 'state' attribute for " "HyperV Enlightenment feature '%s
[libvirt PATCH 38/38] storage_conf: Use virXMLProp(OnOff|YesNo) in virStoragePoolDefParseSource
Signed-off-by: Tim Wiederhake --- src/conf/storage_conf.c | 16 +--- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 2e07c81f8a..7dc528b103 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -605,7 +605,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, goto cleanup; for (i = 0; i < nsource; i++) { -g_autofree char *partsep = NULL; +virTristateBool partsep = VIR_TRISTATE_BOOL_ABSENT; virStoragePoolSourceDevice dev = { .path = NULL }; dev.path = virXMLPropString(nodeset[i], "path"); @@ -615,17 +615,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, goto cleanup; } -partsep = virXMLPropString(nodeset[i], "part_separator"); -if (partsep) { -dev.part_separator = virTristateBoolTypeFromString(partsep); -if (dev.part_separator <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid part_separator setting '%s'"), - partsep); -virStoragePoolSourceDeviceClear(); -goto cleanup; -} +if (virXMLPropYesNo(nodeset[i], "part_separator", ) < 0) { +virStoragePoolSourceDeviceClear(); +goto cleanup; } +dev.part_separator = partsep; if (VIR_APPEND_ELEMENT(source->devices, source->ndevice, dev) < 0) { virStoragePoolSourceDeviceClear(); -- 2.26.2
[libvirt PATCH 37/38] storage_adapter_conf: Use virXMLProp(OnOff|YesNo) in virStorageAdapterParseXMLFCHost
Signed-off-by: Tim Wiederhake --- src/conf/storage_adapter_conf.c | 17 + 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/conf/storage_adapter_conf.c b/src/conf/storage_adapter_conf.c index 77ecb8d5f2..96e6c733d0 100644 --- a/src/conf/storage_adapter_conf.c +++ b/src/conf/storage_adapter_conf.c @@ -64,26 +64,19 @@ static int virStorageAdapterParseXMLFCHost(xmlNodePtr node, virStorageAdapterFCHostPtr fchost) { -char *managed = NULL; +virTristateBool managed = VIR_TRISTATE_BOOL_ABSENT; -fchost->parent = virXMLPropString(node, "parent"); -if ((managed = virXMLPropString(node, "managed"))) { -if ((fchost->managed = virTristateBoolTypeFromString(managed)) < 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown fc_host managed setting '%s'"), - managed); -VIR_FREE(managed); -return -1; -} -} +if (virXMLPropYesNo(node, "managed", ) < 0) +return -1; +fchost->parent = virXMLPropString(node, "parent"); +fchost->managed = managed; fchost->parent_wwnn = virXMLPropString(node, "parent_wwnn"); fchost->parent_wwpn = virXMLPropString(node, "parent_wwpn"); fchost->parent_fabric_wwn = virXMLPropString(node, "parent_fabric_wwn"); fchost->wwpn = virXMLPropString(node, "wwpn"); fchost->wwnn = virXMLPropString(node, "wwnn"); -VIR_FREE(managed); return 0; } -- 2.26.2
[libvirt PATCH 23/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainMemballoonDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 18 ++ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fe35a3960e..0c4f7ab879 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14264,8 +14264,8 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPtr xmlopt, VIR_XPATH_NODE_AUTORESTORE(ctxt) unsigned int period = 0; g_autofree char *model = NULL; -g_autofree char *freepage_reporting = NULL; -g_autofree char *deflate = NULL; +virTristateSwitch autodeflate = VIR_TRISTATE_SWITCH_ABSENT; +virTristateSwitch free_page_reporting = VIR_TRISTATE_SWITCH_ABSENT; def = g_new0(virDomainMemballoonDef, 1); @@ -14282,19 +14282,13 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } -if ((deflate = virXMLPropString(node, "autodeflate")) && -(def->autodeflate = virTristateSwitchTypeFromString(deflate)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid autodeflate attribute value '%s'"), deflate); +if (virXMLPropOnOff(node, "autodeflate", ) < 0) goto error; -} +def->autodeflate = autodeflate; -if ((freepage_reporting = virXMLPropString(node, "freePageReporting")) && -(def->free_page_reporting = virTristateSwitchTypeFromString(freepage_reporting)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid freePageReporting attribute value '%s'"), freepage_reporting); +if (virXMLPropOnOff(node, "freePageReporting", _page_reporting) < 0) goto error; -} +def->free_page_reporting = free_page_reporting; ctxt->node = node; if (virXPathUInt("string(./stats/@period)", ctxt, ) < -1) { -- 2.26.2
[libvirt PATCH 36/38] numa_conf: Use virXMLProp(OnOff|YesNo) in virDomainNumaDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/numa_conf.c | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 64b93fd7d1..d16a44c955 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -1079,17 +1079,8 @@ virDomainNumaDefParseXML(virDomainNumaPtr def, VIR_FREE(tmp); } -if ((tmp = virXMLPropString(nodes[i], "discard"))) { -if ((rc = virTristateBoolTypeFromString(tmp)) <= 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid 'discard' attribute value '%s'"), - tmp); -goto cleanup; -} - -def->mem_nodes[cur_cell].discard = rc; -VIR_FREE(tmp); -} +if (virXMLPropYesNo(nodes[i], "discard", >mem_nodes[cur_cell].discard) < 0) +goto cleanup; /* Parse NUMA distances info */ if (virDomainNumaDefNodeDistanceParseXML(def, ctxt, cur_cell) < 0) -- 2.26.2
[libvirt PATCH 35/38] network_conf: Use virXMLProp(OnOff|YesNo) in virNetworkForwardNatDefParseXML
Signed-off-by: Tim Wiederhake --- src/conf/network_conf.c | 15 ++- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 4cf4aa4840..93972a544a 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1321,7 +1321,6 @@ virNetworkForwardNatDefParseXML(const char *networkName, g_autofree xmlNodePtr *natPortNodes = NULL; g_autofree char *addrStart = NULL; g_autofree char *addrEnd = NULL; -g_autofree char *ipv6 = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) ctxt->node = node; @@ -1333,18 +1332,8 @@ virNetworkForwardNatDefParseXML(const char *networkName, return -1; } -ipv6 = virXMLPropString(node, "ipv6"); -if (ipv6) { -int natIPv6; -if ((natIPv6 = virTristateBoolTypeFromString(ipv6)) <= 0) { -virReportError(VIR_ERR_XML_ERROR, - _("Invalid ipv6 setting '%s' " - "in network '%s' NAT"), - ipv6, networkName); -return -1; -} -def->natIPv6 = natIPv6; -} +if (virXMLPropYesNo(node, "ipv6", >natIPv6) < 0) +return -1; /* addresses for SNAT */ nNatAddrs = virXPathNodeSet("./address", ctxt, ); -- 2.26.2