mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
Adding the element pf to network xml.
This element will help the user to just specify the SR-IOV physical function in order to access all the Virtual functions attached to it.
This commit is contained in:
parent
3a0c717b9e
commit
b01b53de3f
@ -226,7 +226,21 @@
|
||||
</forward>
|
||||
...
|
||||
</pre>
|
||||
When a guest interface is being constructed, libvirt will pick
|
||||
Additionally, <span class="since">since 0.9.10</span>, libvirt
|
||||
allows a shorthand for specifying all virtual interfaces
|
||||
associated with a single physical function, by using
|
||||
the <code><pf></code> subelement to call out the
|
||||
corresponding physical interface associated with multiple
|
||||
virtual interfaces:
|
||||
<pre>
|
||||
...
|
||||
<forward mode='passthrough'>
|
||||
<pf dev='eth0'/>
|
||||
</forward>
|
||||
...
|
||||
</pre>
|
||||
|
||||
<p>When a guest interface is being constructed, libvirt will pick
|
||||
an interface from this list to use for the connection. In
|
||||
modes where physical interfaces can be shared by multiple
|
||||
guest interfaces, libvirt will choose the interface that
|
||||
@ -234,7 +248,7 @@
|
||||
that do not allow sharing of the physical device (in
|
||||
particular, 'passthrough' mode, and 'private' mode when using
|
||||
802.1Qbh), libvirt will choose an unused physical interface
|
||||
or, if it can't find an unused interface, fail the operation.
|
||||
or, if it can't find an unused interface, fail the operation.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<h5><a name="elementQoS">Quality of service</a></h5>
|
||||
|
@ -85,13 +85,22 @@
|
||||
</choice>
|
||||
</attribute>
|
||||
</optional>
|
||||
<zeroOrMore>
|
||||
<element name='interface'>
|
||||
<attribute name='dev'>
|
||||
<ref name='deviceName'/>
|
||||
</attribute>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
<interleave>
|
||||
<zeroOrMore>
|
||||
<element name='interface'>
|
||||
<attribute name='dev'>
|
||||
<ref name='deviceName'/>
|
||||
</attribute>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
<optional>
|
||||
<element name='pf'>
|
||||
<attribute name='dev'>
|
||||
<ref name='deviceName'/>
|
||||
</attribute>
|
||||
</element>
|
||||
</optional>
|
||||
</interleave>
|
||||
</element>
|
||||
</optional>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* network_conf.c: network XML handling
|
||||
*
|
||||
* Copyright (C) 2006-2011 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2012 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -162,6 +162,11 @@ void virNetworkDefFree(virNetworkDefPtr def)
|
||||
VIR_FREE(def->bridge);
|
||||
VIR_FREE(def->domain);
|
||||
|
||||
for (ii = 0 ; ii < def->nForwardPfs && def->forwardPfs ; ii++) {
|
||||
virNetworkForwardIfDefClear(&def->forwardPfs[ii]);
|
||||
}
|
||||
VIR_FREE(def->forwardPfs);
|
||||
|
||||
for (ii = 0 ; ii < def->nForwardIfs && def->forwardIfs ; ii++) {
|
||||
virNetworkForwardIfDefClear(&def->forwardIfs[ii]);
|
||||
}
|
||||
@ -929,10 +934,11 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
|
||||
xmlNodePtr *ipNodes = NULL;
|
||||
xmlNodePtr *portGroupNodes = NULL;
|
||||
xmlNodePtr *forwardIfNodes = NULL;
|
||||
xmlNodePtr *forwardPfNodes = NULL;
|
||||
xmlNodePtr dnsNode = NULL;
|
||||
xmlNodePtr virtPortNode = NULL;
|
||||
xmlNodePtr forwardNode = NULL;
|
||||
int nIps, nPortGroups, nForwardIfs;
|
||||
int nIps, nPortGroups, nForwardIfs, nForwardPfs;
|
||||
char *forwardDev = NULL;
|
||||
xmlNodePtr save = ctxt->node;
|
||||
xmlNodePtr bandwidthNode = NULL;
|
||||
@ -1074,10 +1080,44 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
|
||||
|
||||
/* all of these modes can use a pool of physical interfaces */
|
||||
nForwardIfs = virXPathNodeSet("./interface", ctxt, &forwardIfNodes);
|
||||
if (nForwardIfs < 0)
|
||||
goto error;
|
||||
nForwardPfs = virXPathNodeSet("./pf", ctxt, &forwardPfNodes);
|
||||
|
||||
if ((nForwardIfs > 0) || forwardDev) {
|
||||
if (nForwardIfs < 0 || nForwardPfs < 0) {
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("No interface pool or SRIOV physical device given"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (nForwardPfs == 1) {
|
||||
if (VIR_ALLOC_N(def->forwardPfs, nForwardPfs) < 0) {
|
||||
virReportOOMError();
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (forwardDev) {
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("A forward Dev should not be used when using a SRIOV PF"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
forwardDev = virXMLPropString(*forwardPfNodes, "dev");
|
||||
if (!forwardDev) {
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("Missing required dev attribute in network '%s' pf element"),
|
||||
def->name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
def->forwardPfs->usageCount = 0;
|
||||
def->forwardPfs->dev = forwardDev;
|
||||
forwardDev = NULL;
|
||||
def->nForwardPfs++;
|
||||
} else if (nForwardPfs > 1) {
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("Use of more than one physical interface is not allowed"));
|
||||
goto error;
|
||||
}
|
||||
if (nForwardIfs > 0 || forwardDev) {
|
||||
int ii;
|
||||
|
||||
/* allocate array to hold all the portgroups */
|
||||
@ -1123,6 +1163,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
|
||||
def->nForwardIfs++;
|
||||
}
|
||||
}
|
||||
VIR_FREE(forwardDev);
|
||||
VIR_FREE(forwardPfNodes);
|
||||
VIR_FREE(forwardIfNodes);
|
||||
|
||||
switch (def->forwardType) {
|
||||
@ -1178,6 +1220,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
|
||||
VIR_FREE(ipNodes);
|
||||
VIR_FREE(portGroupNodes);
|
||||
VIR_FREE(forwardIfNodes);
|
||||
VIR_FREE(forwardPfNodes);
|
||||
VIR_FREE(forwardDev);
|
||||
ctxt->node = save;
|
||||
return NULL;
|
||||
@ -1420,7 +1463,9 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
|
||||
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", uuidstr);
|
||||
|
||||
if (def->forwardType != VIR_NETWORK_FORWARD_NONE) {
|
||||
const char *dev = virNetworkDefForwardIf(def, 0);
|
||||
const char *dev = NULL;
|
||||
if (!def->nForwardPfs)
|
||||
dev = virNetworkDefForwardIf(def, 0);
|
||||
const char *mode = virNetworkForwardTypeToString(def->forwardType);
|
||||
|
||||
if (!mode) {
|
||||
@ -1430,20 +1475,23 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
|
||||
goto error;
|
||||
}
|
||||
virBufferAddLit(&buf, " <forward");
|
||||
if (dev)
|
||||
virBufferEscapeString(&buf, " dev='%s'", dev);
|
||||
virBufferEscapeString(&buf, " dev='%s'", dev);
|
||||
virBufferAsprintf(&buf, " mode='%s'%s>\n", mode,
|
||||
def->nForwardIfs ? "" : "/");
|
||||
(def->nForwardIfs || def->nForwardPfs) ? "" : "/");
|
||||
|
||||
/* For now, hard-coded to at most 1 forwardPfs */
|
||||
if (def->nForwardPfs)
|
||||
virBufferEscapeString(&buf, " <pf dev='%s'/>\n",
|
||||
def->forwardPfs[0].dev);
|
||||
|
||||
if (def->nForwardIfs) {
|
||||
for (ii = 0; ii < def->nForwardIfs; ii++) {
|
||||
if (def->forwardIfs[ii].dev) {
|
||||
virBufferEscapeString(&buf, " <interface dev='%s'/>\n",
|
||||
def->forwardIfs[ii].dev);
|
||||
}
|
||||
virBufferEscapeString(&buf, " <interface dev='%s'/>\n",
|
||||
def->forwardIfs[ii].dev);
|
||||
}
|
||||
virBufferAddLit(&buf, " </forward>\n");
|
||||
}
|
||||
if (def->nForwardPfs || def->nForwardIfs)
|
||||
virBufferAddLit(&buf, " </forward>\n");
|
||||
}
|
||||
|
||||
if (def->forwardType == VIR_NETWORK_FORWARD_NONE ||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* network_conf.h: network XML handling
|
||||
*
|
||||
* Copyright (C) 2006-2008 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2008, 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -162,6 +162,9 @@ struct _virNetworkDef {
|
||||
/* If there are multiple forward devices (i.e. a pool of
|
||||
* interfaces), they will be listed here.
|
||||
*/
|
||||
size_t nForwardPfs;
|
||||
virNetworkForwardIfDefPtr forwardPfs;
|
||||
|
||||
size_t nForwardIfs;
|
||||
virNetworkForwardIfDefPtr forwardIfs;
|
||||
|
||||
|
10
tests/networkxml2xmlin/passthrough-pf.xml
Normal file
10
tests/networkxml2xmlin/passthrough-pf.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<network>
|
||||
<name>local</name>
|
||||
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||
<forward mode="passthrough">
|
||||
<pf dev='eth0'/>
|
||||
<interface dev='eth10'/>
|
||||
<interface dev='eth11'/>
|
||||
</forward>
|
||||
<ip address="192.168.122.1" netmask="255.255.255.0"/>
|
||||
</network>
|
9
tests/networkxml2xmlout/passthrough-pf.xml
Normal file
9
tests/networkxml2xmlout/passthrough-pf.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<network>
|
||||
<name>local</name>
|
||||
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||
<forward mode='passthrough'>
|
||||
<pf dev='eth0'/>
|
||||
</forward>
|
||||
<ip address='192.168.122.1' netmask='255.255.255.0'>
|
||||
</ip>
|
||||
</network>
|
Loading…
Reference in New Issue
Block a user