1
0
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:
Shradha Shah 2011-12-14 10:50:23 +00:00 committed by Eric Blake
parent 3a0c717b9e
commit b01b53de3f
6 changed files with 117 additions and 24 deletions

View File

@ -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>&lt;pf&gt;</code> subelement to call out the
corresponding physical interface associated with multiple
virtual interfaces:
<pre>
...
&lt;forward mode='passthrough'&gt;
&lt;pf dev='eth0'/&gt;
&lt;/forward&gt;
...
</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>

View File

@ -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>

View File

@ -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 ||

View File

@ -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;

View 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>

View 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>