]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: record a portid against the domain conf
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 1 Feb 2019 18:07:08 +0000 (18:07 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Mon, 17 Jun 2019 14:45:09 +0000 (15:45 +0100)
The portid will be the UUID of the virNetworkPort object associated
with the network interface when a guest is running.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
tests/qemuxml2argvdata/net-virtio-network-portgroup.xml

index 22ddcb71d34579970df5b848ac1365992f7ea206..73a9cb62053c2efad12eaf53fc367319c3d021b3 100644 (file)
       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
index 4bd75e3055274f2174d6e5c0063a39e8301268ba..3661f0a5566c8bd54b38e52cfc12a417b8cf05ff 100644 (file)
         <ref name="deviceName"/>
       </attribute>
     </optional>
+    <optional>
+      <attribute name="portid">
+        <ref name="UUID"/>
+      </attribute>
+    </optional>
   </define>
 
   <define name="interface-bridge-attributes">
index 85b374572c1b8a60875835c5f99930b34feb5ce2..fe8001cb4f4adfb76ff3fdc9197d55432ce412a6 100644 (file)
@@ -11399,6 +11399,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
     VIR_AUTOFREE(char *) type = NULL;
     VIR_AUTOFREE(char *) network = NULL;
     VIR_AUTOFREE(char *) portgroup = NULL;
+    VIR_AUTOFREE(char *) portid = NULL;
     VIR_AUTOFREE(char *) bridge = NULL;
     VIR_AUTOFREE(char *) dev = NULL;
     VIR_AUTOFREE(char *) ifname = NULL;
@@ -11476,6 +11477,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")) {
@@ -11689,6 +11692,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);
@@ -24977,6 +24987,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) {
@@ -25280,6 +25295,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;
 
index 6ba0643cd15d3b317c027aa871bca7fe5579332c..467b72a9778aad1290676e684dc03f3e8ed1c62a 100644 (file)
@@ -968,6 +968,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
@@ -975,6 +976,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;
index 54a0eb7229a52581cbc044438641a40fdd193d6c..3d6cd02a73285711f79980465fe3031f14eb6ab2 100644 (file)
@@ -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>