[libvirt PATCH 06/10] virDomainActualNetDefParseXML: Use virXMLProp*
Ján Tomko
jtomko at redhat.com
Fri Apr 23 13:35:57 UTC 2021
On a Friday in 2021, Tim Wiederhake wrote:
>Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
>---
> src/conf/domain_conf.c | 57 ++++++++++++++----------------------------
> 1 file changed, 19 insertions(+), 38 deletions(-)
>
>diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>index 554efe0aea..3051a5d56d 100644
>--- a/src/conf/domain_conf.c
>+++ b/src/conf/domain_conf.c
>@@ -10066,49 +10066,30 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
> xmlNodePtr bandwidth_node = NULL;
> xmlNodePtr vlanNode;
> xmlNodePtr virtPortNode;
>- 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;
>- int type_value;
>
> actual = g_new0(virDomainActualNetDef, 1);
>
> ctxt->node = node;
>
>- type = virXMLPropString(node, "type");
>- if (!type) {
>- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
>- _("missing type attribute in interface's <actual> element"));
>+ if (virXMLPropEnum(node, "type", virDomainNetTypeFromString,
>+ VIR_XML_PROP_REQUIRED, &actual->type) < 0)
> goto error;
>- }
>- if ((type_value = virDomainNetTypeFromString(type)) < 0) {
>- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>- _("unknown type '%s' in interface's <actual> element"), type);
>- goto error;
>- }
>- actual->type = type_value;
>+
> if (actual->type != VIR_DOMAIN_NET_TYPE_BRIDGE &&
> actual->type != VIR_DOMAIN_NET_TYPE_DIRECT &&
> actual->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
> actual->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
> virReportError(VIR_ERR_INTERNAL_ERROR,
> _("unsupported type '%s' in interface's <actual> element"),
>- type);
>+ virDomainNetTypeToString(actual->type));
> goto error;
> }
>
>- if ((trustGuestRxFilters = virXMLPropString(node, "trustGuestRxFilters"))) {
>- int value;
>- if ((value = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0) {
>- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>- _("unknown trustGuestRxFilters value '%s'"),
>- trustGuestRxFilters);
>- goto error;
>- }
>- actual->trustGuestRxFilters = value;
>- }
>+ if (virXMLPropTristateBool(node, "trustGuestRxFilters", VIR_XML_PROP_NONE,
>+ &actual->trustGuestRxFilters) < 0)
>+ goto error;
>
> virtPortNode = virXPathNode("./virtualport", ctxt);
> if (virtPortNode) {
>@@ -10127,7 +10108,8 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
> } else {
> virReportError(VIR_ERR_INTERNAL_ERROR,
> _("<virtualport> element unsupported for type='%s'"
>- " in interface's <actual> element"), type);
>+ " in interface's <actual> element"),
>+ virDomainNetTypeToString(actual->type));
> goto error;
> }
> }
>@@ -10136,19 +10118,18 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
> xmlNodePtr sourceNode = virXPathNode("./source[1]", ctxt);
>
> if (sourceNode) {
>+ int rc;
>+ virNetDevMacVLanMode mode;
>+
> actual->data.direct.linkdev = virXMLPropString(sourceNode, "dev");
>
>- mode = virXMLPropString(sourceNode, "mode");
>- if (mode) {
>- int m;
>- if ((m = virNetDevMacVLanModeTypeFromString(mode)) < 0) {
>- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>- _("Unknown mode '%s' in interface <actual> element"),
>- mode);
>- goto error;
>- }
>- actual->data.direct.mode = m;
>- }
>+ if ((rc = virXMLPropEnum(sourceNode, "mode",
>+ virNetDevMacVLanModeTypeFromString,
>+ VIR_XML_PROP_NONE, &mode)) < 0)
Indentation is off.
>+ goto error;
>+
>+ if (rc)
>+ actual->data.direct.mode = mode;
You can just pass actual->data.direct.mode as an argument to the
virXMLPropEnum call, eliminating the need for this if and both of the
local variables, unless I'm missing something.
> }
> } else if (actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
> virDomainHostdevDef *hostdev = &actual->data.hostdev.def;
With that addressed:
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210423/7abcf107/attachment-0001.sig>
More information about the libvir-list
mailing list