mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-26 14:03:49 +03:00
conf: use virNetDevIPInfo in virDomainHostdevCaps
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.
This commit is contained in:
parent
9911562a22
commit
69e04044dd
@ -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>
|
||||
|
||||
|
@ -2182,8 +2182,6 @@ virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc
|
||||
|
||||
void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!def)
|
||||
return;
|
||||
|
||||
@ -2207,13 +2205,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;
|
||||
@ -6240,10 +6233,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
|
||||
@ -6292,55 +6281,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,
|
||||
@ -6350,8 +6299,6 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
|
||||
}
|
||||
ret = 0;
|
||||
error:
|
||||
VIR_FREE(ipnodes);
|
||||
VIR_FREE(routenodes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -13728,8 +13675,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);
|
||||
}
|
||||
|
||||
|
||||
@ -20522,7 +20469,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,
|
||||
@ -20534,14 +20481,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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user