On 5/18/21 11:04 AM, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
src/conf/domain_conf.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 734fa584a4..661fa53206 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6694,28 +6694,23 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
virDomainHostdevDef *def)
{
virDomainHostdevSubsysUSB *usbsrc = &def->source.subsys.u.usb;
- g_autofree char *startupPolicy = NULL;
- g_autofree char *autoAddress = NULL;
xmlNodePtr vendorNode;
xmlNodePtr productNode;
xmlNodePtr addressNode;
+ virTristateBool autoAddress;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
ctxt->node = node;
- if ((startupPolicy = virXMLPropString(node, "startupPolicy"))) {
- int value = virDomainStartupPolicyTypeFromString(startupPolicy);
- if (value <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Unknown startup policy '%s'"),
- startupPolicy);
- return -1;
- }
- def->startupPolicy = value;
- }
+ if (virXMLPropEnum(node, "startupPolicy",
+ virDomainStartupPolicyTypeFromString,
+ VIR_XML_PROP_NONZERO, &def->startupPolicy) < 0)
+ return -1;
- if ((autoAddress = virXMLPropString(node, "autoAddress")))
- ignore_value(virStringParseYesNo(autoAddress, &usbsrc->autoAddress));
+ if (virXMLPropTristateBool(node, "autoAddress", VIR_XML_PROP_NONE,
+ &autoAddress) < 0)
+ return -1;
+ usbsrc->autoAddress = autoAddress == VIR_TRISTATE_BOOL_YES;
(my poor eyesight kept seeing that "==" as "=" and I was confused for
a
second! :-)
Too bad we have to do this rather than having a virTristateBool directly
in the object. But history doesn't permit it (without some *other* extra
code to set it to ..._NO in the case when it isn't specified).
/* Product can validly be 0, so we need some extra help to determine
* if it is uninitialized */