a.k.a. <hostdev mode='capabilities' type='net'>. This replaces the existing nips, ips, nroutes, and routes with a single virNetDevIPInfo, and simplifies the code by calling that object's parse/format/clear functions instead of open coding. --- docs/schemas/domaincommon.rng | 22 +----------- src/conf/domain_conf.c | 80 ++++++------------------------------------- src/conf/domain_conf.h | 7 ++-- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_native.c | 18 +++++----- 5 files changed, 24 insertions(+), 105 deletions(-) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index ab89dab..38590a6 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4034,27 +4034,7 @@ <ref name="deviceName"/> </element> </element> - <zeroOrMore> - <element name="ip"> - <attribute name="address"> - <ref name="ipAddr"/> - </attribute> - <optional> - <attribute name="family"> - <ref name="addr-family"/> - </attribute> - </optional> - <optional> - <attribute name="prefix"> - <ref name="ipPrefix"/> - </attribute> - </optional> - <empty/> - </element> - </zeroOrMore> - <zeroOrMore> - <ref name="route"/> - </zeroOrMore> + <ref name="interface-ip-info"/> </interleave> </define> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 548c750..7072f86 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2184,8 +2184,6 @@ virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc void virDomainHostdevDefClear(virDomainHostdevDefPtr def) { - size_t i; - if (!def) return; @@ -2209,13 +2207,8 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def) VIR_FREE(def->source.caps.u.misc.chardev); break; case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: - VIR_FREE(def->source.caps.u.net.iface); - for (i = 0; i < def->source.caps.u.net.nips; i++) - VIR_FREE(def->source.caps.u.net.ips[i]); - VIR_FREE(def->source.caps.u.net.ips); - for (i = 0; i < def->source.caps.u.net.nroutes; i++) - virNetDevIPRouteFree(def->source.caps.u.net.routes[i]); - VIR_FREE(def->source.caps.u.net.routes); + VIR_FREE(def->source.caps.u.net.ifname); + virNetDevIPInfoClear(&def->source.caps.u.net.ip); break; } break; @@ -6232,10 +6225,6 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED, virDomainHostdevDefPtr def) { xmlNodePtr sourcenode; - xmlNodePtr *ipnodes = NULL; - int nipnodes; - xmlNodePtr *routenodes = NULL; - int nroutenodes; int ret = -1; /* @type is passed in from the caller rather than read from the @@ -6284,55 +6273,15 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED, } break; case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: - if (!(def->source.caps.u.net.iface = + if (!(def->source.caps.u.net.ifname = virXPathString("string(./source/interface[1])", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing <interface> element in hostdev net device")); goto error; } - - /* Parse possible IP addresses */ - if ((nipnodes = virXPathNodeSet("./ip", ctxt, &ipnodes)) < 0) + if (virDomainNetIPInfoParseXML(_("Domain hostdev device"), + ctxt, &def->source.caps.u.net.ip) < 0) goto error; - - if (nipnodes) { - size_t i; - for (i = 0; i < nipnodes; i++) { - virNetDevIPAddrPtr ip = virDomainNetIPParseXML(ipnodes[i]); - - if (!ip) - goto error; - - if (VIR_APPEND_ELEMENT(def->source.caps.u.net.ips, - def->source.caps.u.net.nips, ip) < 0) { - VIR_FREE(ip); - goto error; - } - } - } - - /* Look for possible gateways */ - if ((nroutenodes = virXPathNodeSet("./route", ctxt, &routenodes)) < 0) - goto error; - - if (nroutenodes) { - size_t i; - for (i = 0; i < nroutenodes; i++) { - virNetDevIPRoutePtr route = NULL; - - if (!(route = virNetDevIPRouteParseXML(_("Domain hostdev device"), - routenodes[i], - ctxt))) - goto error; - - - if (VIR_APPEND_ELEMENT(def->source.caps.u.net.routes, - def->source.caps.u.net.nroutes, route) < 0) { - virNetDevIPRouteFree(route); - goto error; - } - } - } break; default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -6342,8 +6291,6 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED, } ret = 0; error: - VIR_FREE(ipnodes); - VIR_FREE(routenodes); return ret; } @@ -13722,8 +13669,8 @@ static int virDomainHostdevMatchCapsNet(virDomainHostdevDefPtr a, virDomainHostdevDefPtr b) { - return STREQ_NULLABLE(a->source.caps.u.net.iface, - b->source.caps.u.net.iface); + return STREQ_NULLABLE(a->source.caps.u.net.ifname, + b->source.caps.u.net.ifname); } @@ -20519,7 +20466,7 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf, break; case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: virBufferEscapeString(buf, "<interface>%s</interface>\n", - def->source.caps.u.net.iface); + def->source.caps.u.net.ifname); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -20531,14 +20478,9 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</source>\n"); - if (def->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) { - if (virDomainNetIPsFormat(buf, def->source.caps.u.net.ips, - def->source.caps.u.net.nips) < 0) - return -1; - if (virDomainNetRoutesFormat(buf, def->source.caps.u.net.routes, - def->source.caps.u.net.nroutes) < 0) - return -1; - } + if (def->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET && + virDomainNetIPInfoFormat(buf, &def->source.caps.u.net.ip) < 0) + return -1; return 0; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c529b09..0c723de 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -395,11 +395,8 @@ struct _virDomainHostdevCaps { char *chardev; } misc; struct { - char *iface; - size_t nips; - virNetDevIPAddrPtr *ips; - size_t nroutes; - virNetDevIPRoutePtr *routes; + char *ifname; + virNetDevIPInfo ip; } net; } u; }; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 2aee41c..e58ff1b 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1984,7 +1984,7 @@ static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl) if (hdcaps.type != VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) continue; - if (virNetDevSetNamespace(hdcaps.u.net.iface, ctrl->initpid) < 0) + if (virNetDevSetNamespace(hdcaps.u.net.ifname, ctrl->initpid) < 0) return -1; } diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 8294d29..f074f03 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -402,7 +402,7 @@ lxcCreateHostdevDef(int mode, int type, const char *data) hostdev->source.caps.type = type; if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET && - VIR_STRDUP(hostdev->source.caps.u.net.iface, data) < 0) { + VIR_STRDUP(hostdev->source.caps.u.net.ifname, data) < 0) { virDomainHostdevDefFree(hostdev); hostdev = NULL; } @@ -492,25 +492,25 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) /* This still requires the user to manually setup the vlan interface * on the host */ if (isVlan && data->vlanid) { - VIR_FREE(hostdev->source.caps.u.net.iface); - if (virAsprintf(&hostdev->source.caps.u.net.iface, + VIR_FREE(hostdev->source.caps.u.net.ifname); + if (virAsprintf(&hostdev->source.caps.u.net.ifname, "%s.%s", data->link, data->vlanid) < 0) goto error; } - hostdev->source.caps.u.net.ips = data->ips; - hostdev->source.caps.u.net.nips = data->nips; + hostdev->source.caps.u.net.ip.ips = data->ips; + hostdev->source.caps.u.net.ip.nips = data->nips; if (data->gateway_ipv4 && lxcAddNetworkRouteDefinition(data->gateway_ipv4, AF_INET, - &hostdev->source.caps.u.net.routes, - &hostdev->source.caps.u.net.nroutes) < 0) + &hostdev->source.caps.u.net.ip.routes, + &hostdev->source.caps.u.net.ip.nroutes) < 0) goto error; if (data->gateway_ipv6 && lxcAddNetworkRouteDefinition(data->gateway_ipv6, AF_INET6, - &hostdev->source.caps.u.net.routes, - &hostdev->source.caps.u.net.nroutes) < 0) + &hostdev->source.caps.u.net.ip.routes, + &hostdev->source.caps.u.net.ip.nroutes) < 0) goto error; if (VIR_EXPAND_N(data->def->hostdevs, data->def->nhostdevs, 1) < 0) -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list