]> xenbits.xensource.com Git - libvirt.git/commitdiff
network: add connections counter to networks
authorLaine Stump <laine@laine.org>
Mon, 6 Aug 2012 20:17:58 +0000 (16:17 -0400)
committerLaine Stump <laine@laine.org>
Wed, 15 Aug 2012 03:53:58 +0000 (23:53 -0400)
Just as each physical device used by a network has a connections
counter, now each network has a connections counter which is
incremented once for each guest interface that connects using this
network.

The count is output in the live network XML, like this:

   <network connections='20'>
   ...
   </network>

It is read-only, and for informational purposes only - it isn't used
internally anywhere by libvirt.

docs/formatnetwork.html.in
docs/schemas/network.rng
src/conf/network_conf.c
src/conf/network_conf.h
src/network/bridge_driver.c

index daa6524f0f3b0b4fad19642a0539ed81ff5f7932..a010cbd217f5ee236997a3cce1cea87d53f18278 100644 (file)
 
     <p>
       The root element required for all virtual networks is
-      named <code>network</code> and has no attributes.
-      The network XML format is available <span class="since">since 0.3.0</span>
+      named <code>network</code> and has no configurable attributes
+      (although <span class="since">since 0.10.0</span> there is one
+      optional read-only attribute - when examining the live
+      configuration of a network, the
+      attribute <code>connections</code>, if present, specifies the
+      number of guest interfaces currently connected via this
+      network).  The network XML format is
+      available <span class="since">since 0.3.0</span>
     </p>
 
     <h3><a name="elementsMetadata">General metadata</a></h3>
   &lt;/forward&gt;
 ...
         </pre>
-        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:
+        <p>
+          <span class="since">since 0.10.0</span>,
+          <code>&lt;interface&gt;</code> also has an optional read-only
+          attribute - when examining the live configuration of a
+          network, the attribute <code>connections</code>, if present,
+          specifies the number of guest interfaces currently connected
+          via this physical interface.
+        </p>
+        <p>
+          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:
+        </p>
         <pre>
 ...
   &lt;forward mode='passthrough'&gt;
index 2ae879ec47b48a5b700db71378a11e3c34da5a32..25df26686a76604ddb12535518809c2d251dceb2 100644 (file)
   <define name="network">
 
     <element name="network">
+      <optional>
+        <attribute name="connections">
+          <data type="unsignedInt"/>
+        </attribute>
+      </optional>
       <interleave>
 
         <!-- The name of the network, used to refer to it through the API
                   <attribute name='dev'>
                     <ref name='deviceName'/>
                   </attribute>
+                  <optional>
+                    <attribute name="connections">
+                      <data type="unsignedInt"/>
+                    </attribute>
+                  </optional>
                 </element>
               </zeroOrMore>
               <optional>
index ca5b759c5d648ff18758136624e9efe9161c8c18..45f8e698e525f99ce4829119b3195225d84d918f 100644 (file)
@@ -1463,7 +1463,11 @@ char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags)
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     int ii;
 
-    virBufferAddLit(&buf, "<network>\n");
+    virBufferAddLit(&buf, "<network");
+    if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0)) {
+        virBufferAsprintf(&buf, " connections='%d'", def->connections);
+    }
+    virBufferAddLit(&buf, ">\n");
     virBufferEscapeString(&buf, "  <name>%s</name>\n", def->name);
 
     uuid = def->uuid;
index 23f163202fee19bd53d8859c22a6dfeb0be73abf..32fc765029f682ef2e7d78bac57f5dbf9d5e2cc7 100644 (file)
@@ -156,6 +156,7 @@ struct _virNetworkDef {
     unsigned char uuid[VIR_UUID_BUFLEN];
     bool uuid_specified;
     char *name;
+    int   connections; /* # of guest interfaces connected to this network */
 
     char *bridge;       /* Name of bridge device */
     char *domain;
index c86a157763c75dac5a5a43b0aa8e1a93e1bae0e6..efc79c1ac5f7835c4c41dccb772ece5c54c8eab6 100644 (file)
@@ -3005,6 +3005,10 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
         VIR_DEBUG("Using physical device %s, %d connections",
                   dev->dev, dev->connections);
     }
+
+    netdef->connections++;
+    VIR_DEBUG("Using network %s, %d connections",
+              netdef->name, netdef->connections);
     ret = 0;
 cleanup:
     for (ii = 0; ii < num_virt_fns; ii++)
@@ -3117,6 +3121,9 @@ networkNotifyActualDevice(virDomainNetDefPtr iface)
     }
 
 success:
+    netdef->connections++;
+    VIR_DEBUG("Using network %s, %d connections",
+              netdef->name, netdef->connections);
     ret = 0;
 cleanup:
     if (network)
@@ -3205,6 +3212,9 @@ networkReleaseActualDevice(virDomainNetDefPtr iface)
     }
 
 success:
+    netdef->connections--;
+    VIR_DEBUG("Releasing network %s, %d connections",
+              netdef->name, netdef->connections);
     ret = 0;
 cleanup:
     if (network)