The portid will be the UUID of the virNetworkPort object associated
with the network interface when a guest is running.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
docs/formatdomain.html.in | 8 +++++++
docs/schemas/domaincommon.rng | 5 +++++
src/conf/domain_conf.c | 22 +++++++++++++++++++
src/conf/domain_conf.h | 4 ++++
.../net-virtio-network-portgroup.xml | 6 ++---
5 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index b848e535e6..8e3a382eeb 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5187,6 +5187,14 @@
information for different classes of network
connections. <span class="since">Since 0.9.4</span>.
</p>
+ <p>
+ When a guest is running and interface of type <code>network</code>
+ may include a <code>portid</code> attribute. This provides the UUID
+ of an associated virNetworkPortPtr object that records the association
+ between the domain interface and the network. This attribute is
+ read-only since port objects are create and deleted automatically
+ during startup and shutdown. <span class="since">Since
5.1.0</span>/
+ </p>
<p>
Also, similar to <code>direct</code> network connections
(described below), a connection of type <code>network</code> may
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 5345e54342..ccf1e7289f 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2536,6 +2536,11 @@
<ref name="deviceName"/>
</attribute>
</optional>
+ <optional>
+ <attribute name="portid">
+ <ref name="UUID"/>
+ </attribute>
+ </optional>
</define>
<define name="interface-bridge-attributes">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d159ddf154..61987e7f51 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11292,6 +11292,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
char *type = NULL;
char *network = NULL;
char *portgroup = NULL;
+ char *portid = NULL;
char *bridge = NULL;
char *dev = NULL;
char *ifname = NULL;
@@ -11374,6 +11375,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
virXMLNodeNameEqual(cur, "source")) {
network = virXMLPropString(cur, "network");
portgroup = virXMLPropString(cur, "portgroup");
+ if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
+ portid = virXMLPropString(cur, "portid");
} else if (!internal &&
def->type == VIR_DOMAIN_NET_TYPE_INTERNAL &&
virXMLNodeNameEqual(cur, "source")) {
@@ -11597,6 +11600,13 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
"specified with <interface
type='network'/>"));
goto error;
}
+ if (portid &&
+ virUUIDParse(portid, def->data.network.portid) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to parse port id '%s'"), portid);
+ goto error;
+ }
+
VIR_STEAL_PTR(def->data.network.name, network);
VIR_STEAL_PTR(def->data.network.portgroup, portgroup);
VIR_STEAL_PTR(def->data.network.actual, actual);
@@ -12077,6 +12087,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
VIR_FREE(macaddr);
VIR_FREE(network);
VIR_FREE(portgroup);
+ VIR_FREE(portid);
VIR_FREE(address);
VIR_FREE(port);
VIR_FREE(vhostuser_type);
@@ -25240,6 +25251,11 @@ virDomainActualNetDefContentsFormat(virBufferPtr buf,
def->data.network.name);
virBufferEscapeString(buf, " portgroup='%s'",
def->data.network.portgroup);
+ if (virUUIDIsValid(def->data.network.portid)) {
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virUUIDFormat(def->data.network.portid, uuidstr);
+ virBufferAsprintf(buf, " portid='%s'", uuidstr);
+ }
}
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
@@ -25543,6 +25559,12 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.network.name);
virBufferEscapeString(buf, " portgroup='%s'",
def->data.network.portgroup);
+ if (virUUIDIsValid(def->data.network.portid) &&
+ !(flags & (VIR_DOMAIN_DEF_FORMAT_INACTIVE))) {
+ char portidstr[VIR_UUID_STRING_BUFLEN];
+ virUUIDFormat(def->data.network.portid, portidstr);
+ virBufferEscapeString(buf, " portid='%s'", portidstr);
+ }
sourceLines++;
break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7f9917ac30..a12bb46ced 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1027,6 +1027,7 @@ struct _virDomainNetDef {
struct {
char *name;
char *portgroup;
+ unsigned char portid[VIR_UUID_BUFLEN];
/* actual has info about the currently used physical
* device (if the network is of type
* bridge/private/vepa/passthrough). This is saved in the
@@ -1034,6 +1035,9 @@ struct _virDomainNetDef {
* since it needs to be re-allocated whenever the domain
* is restarted. It is also never shown to the user, and
* the user cannot specify it in XML documents.
+ *
+ * This information is populated from the virNetworkPort
+ * object associated with the portid UUID above.
*/
virDomainActualNetDefPtr actual;
} network;
diff --git a/tests/qemuxml2argvdata/net-virtio-network-portgroup.xml
b/tests/qemuxml2argvdata/net-virtio-network-portgroup.xml
index 54a0eb7229..3d6cd02a73 100644
--- a/tests/qemuxml2argvdata/net-virtio-network-portgroup.xml
+++ b/tests/qemuxml2argvdata/net-virtio-network-portgroup.xml
@@ -24,7 +24,7 @@
<controller type='pci' index='0' model='pci-root'/>
<interface type='network' trustGuestRxFilters='yes'>
<mac address='00:11:22:33:44:55'/>
- <source network='rednet' portgroup='bob'/>
+ <source network='rednet' portgroup='bob'
portid='873be5a0-6b8a-4a0b-a1df-ef3659cd64bc'/>
<vlan>
<tag id='4095'/>
</vlan>
@@ -35,7 +35,7 @@
</interface>
<interface type='network' trustGuestRxFilters='no'>
<mac address='10:11:22:33:44:55'/>
- <source network='blue' portgroup='sam'/>
+ <source network='blue' portgroup='sam'
portid='b884cc7e-b347-4a17-9e78-4f672a67794e'/>
<virtualport>
<parameters instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'
interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/>
</virtualport>
@@ -43,7 +43,7 @@
</interface>
<interface type='network'>
<mac address='22:11:22:33:44:55'/>
- <source network='blue' portgroup='sam'/>
+ <source network='blue' portgroup='sam'
portid='c5fc8eb4-cb69-4fea-8f8b-65e00e6d1dba'/>
<virtualport type='802.1Qbh'>
<parameters profileid='testhis99'/>
</virtualport>
--
2.20.1