mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
virNetDevVlanParse: Use virXMLProp* helpers instead of XPath lookups
The loop inside virNetDevVlanParse fetches multiple attributes from the element. Convert it to use the virXMLProp* helpers, which also simplifies error reporting. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
b8e415b467
commit
1de6fd5edb
@ -35,7 +35,6 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlan *def)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
||||||
char *trunk = NULL;
|
char *trunk = NULL;
|
||||||
char *nativeMode = NULL;
|
|
||||||
xmlNodePtr *tagNodes = NULL;
|
xmlNodePtr *tagNodes = NULL;
|
||||||
int nTags;
|
int nTags;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -57,37 +56,34 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlan *def)
|
|||||||
def->nativeMode = 0;
|
def->nativeMode = 0;
|
||||||
def->nativeTag = 0;
|
def->nativeTag = 0;
|
||||||
for (i = 0; i < nTags; i++) {
|
for (i = 0; i < nTags; i++) {
|
||||||
unsigned long id;
|
unsigned int nativeMode = 0;
|
||||||
|
int rc;
|
||||||
|
|
||||||
ctxt->node = tagNodes[i];
|
if (virXMLPropUInt(tagNodes[i], "id", 10, VIR_XML_PROP_REQUIRED,
|
||||||
if (virXPathULong("string(./@id)", ctxt, &id) < 0) {
|
&def->tag[i]) < 0)
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("missing or invalid vlan tag id attribute"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
if (id > 4095) {
|
if (def->tag[i] > 4095) {
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("vlan tag id %lu too large (maximum 4095)"), id);
|
_("vlan tag id %u too large (maximum 4095)"), def->tag[i]);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((nativeMode = virXPathString("string(./@nativeMode)", ctxt))) {
|
|
||||||
|
if ((rc = virXMLPropEnum(tagNodes[i], "nativeMode",
|
||||||
|
virNativeVlanModeTypeFromString,
|
||||||
|
VIR_XML_PROP_NONZERO, &nativeMode)) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (rc == 1) {
|
||||||
if (def->nativeMode != 0) {
|
if (def->nativeMode != 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("duplicate native vlan setting"));
|
_("duplicate native vlan setting"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((def->nativeMode
|
|
||||||
= virNativeVlanModeTypeFromString(nativeMode)) <= 0) {
|
def->nativeMode = nativeMode;
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
def->nativeTag = def->tag[i];
|
||||||
_("Invalid \"nativeMode='%s'\" "
|
|
||||||
"in vlan <tag> element"),
|
|
||||||
nativeMode);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
VIR_FREE(nativeMode);
|
|
||||||
def->nativeTag = id;
|
|
||||||
}
|
|
||||||
def->tag[i] = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def->nTags = nTags;
|
def->nTags = nTags;
|
||||||
@ -128,7 +124,6 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlan *def)
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(tagNodes);
|
VIR_FREE(tagNodes);
|
||||||
VIR_FREE(trunk);
|
VIR_FREE(trunk);
|
||||||
VIR_FREE(nativeMode);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
virNetDevVlanClear(def);
|
virNetDevVlanClear(def);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user