]> xenbits.xensource.com Git - libvirt.git/commitdiff
node_device: Expose link state & speed
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 5 Jun 2014 15:36:31 +0000 (17:36 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 11 Jun 2014 08:59:39 +0000 (10:59 +0200)
While exposing the info under <interface/> in previous patch works, it
may work only in cases where interface is configured on the host.
However, orchestrating application may want to know the link state and
speed even in that case. That's why we ought to expose this in nodedev
XML too:

virsh # nodedev-dumpxml net_eth0_f0_de_f1_2b_1b_f3
<device>
  <name>net_eth0_f0_de_f1_2b_1b_f3</name>
  <path>/sys/devices/pci0000:00/0000:00:19.0/net/eth0</path>
  <parent>pci_0000_00_19_0</parent>
  <capability type='net'>
    <interface>eth0</interface>
    <address>f0:de:f1:2b:1b:f3</address>
    <link speed='1000' state='up'/>
    <capability type='80203'/>
  </capability>
</device>

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
docs/formatnode.html.in
docs/schemas/nodedev.rng
src/Makefile.am
src/conf/node_device_conf.c
src/conf/node_device_conf.h
src/node_device/node_device_driver.c
src/node_device/node_device_udev.c

index 76bf8af1bf158f0bd9afb76a33c17e08402a259d..d82bd3eb0e8d67e99873224245448bcca6895cb2 100644 (file)
               <dd>The interface name tied to this device.</dd>
               <dt><code>address</code></dt>
               <dd>If present, the MAC address of the device.</dd>
+              <dt><code>link</code></dt>
+              <dd>Optional to reflect the status of the link. It has
+                two optional attributes: <code>speed</code> in Mbits per
+                second and <code>state</code> to tell the state of the
+                link. So far, the whole element is just for output,
+                not setting.
+              </dd>
               <dt><code>capability</code></dt>
               <dd>A network protocol exposed by the device, where the
                 attribute <code>type</code> can be "80203" for IEEE
index 02d41063d5d5f9f607f6ae7cddee4bacd4f6f097..505f913354e9ea0cb6cde468aa03e5a2ba8a7368 100644 (file)
         <ref name='mac'/>
       </element>
     </optional>
+    <ref name="link-speed-state"/>
 
     <zeroOrMore>
       <ref name='subcapnet'/>
index 9ab7c24afb7d6e3ed823bf46fda6662898122a09..a72c284f38c2eb5db0a224f3c4419a06fe8d756e 100644 (file)
@@ -1519,7 +1519,7 @@ libvirt_driver_nodedev_la_SOURCES = $(NODE_DEVICE_DRIVER_SOURCES)
 libvirt_driver_nodedev_la_CFLAGS = \
                -I$(top_srcdir)/src/access \
                -I$(top_srcdir)/src/conf \
-               $(AM_CFLAGS)
+               $(AM_CFLAGS) $(LIBNL_CFLAGS)
 libvirt_driver_nodedev_la_LDFLAGS = $(AM_LDFLAGS)
 libvirt_driver_nodedev_la_LIBADD =
 
index 99fa448e8b820faa5b7d62e30679e762e886515a..6153aa17c1441522c3639d2603f7af300d5fa14a 100644 (file)
@@ -389,6 +389,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
             if (data->net.address)
                 virBufferEscapeString(&buf, "<address>%s</address>\n",
                                   data->net.address);
+            virInterfaceLinkFormat(&buf, &data->net.lnk);
             if (data->net.subtype != VIR_NODE_DEV_CAP_NET_LAST) {
                 const char *subtyp =
                     virNodeDevNetCapTypeToString(data->net.subtype);
@@ -875,7 +876,7 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
                          xmlNodePtr node,
                          union _virNodeDevCapData *data)
 {
-    xmlNodePtr orignode;
+    xmlNodePtr orignode, lnk;
     int ret = -1;
     char *tmp;
 
@@ -907,6 +908,10 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
         data->net.subtype = val;
     }
 
+    lnk = virXPathNode("./link", ctxt);
+    if (lnk && virInterfaceLinkParseXML(lnk, &data->net.lnk) < 0)
+        goto out;
+
     ret = 0;
  out:
     ctxt->node = orignode;
index 50ce4b3f705f714cb0680750d54fa0db40a934a8..d1311ddb7b32fc4f8516a79b9589da86318f13fb 100644 (file)
@@ -29,6 +29,7 @@
 # include "virutil.h"
 # include "virthread.h"
 # include "virpci.h"
+# include "device_conf.h"
 
 # include <libxml/tree.h>
 
@@ -136,6 +137,7 @@ struct _virNodeDevCapsDef {
             char *address;
             unsigned int address_len;
             char *ifname;
+            virInterfaceLink lnk;
             virNodeDevNetCapType subtype;  /* LAST -> no subtype */
         } net;
         struct {
index 6906463b8194d7c72decef8fdc29576e233828f1..5d58ca7e46bb3780b652be6637a6da650a5b49dc 100644 (file)
@@ -39,6 +39,7 @@
 #include "node_device_driver.h"
 #include "virutil.h"
 #include "viraccessapicheck.h"
+#include "virnetdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_NODEDEV
 
@@ -47,10 +48,13 @@ static int update_caps(virNodeDeviceObjPtr dev)
     virNodeDevCapsDefPtr cap = dev->def->caps;
 
     while (cap) {
-        /* The only caps that currently need updating are FC related. */
         if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) {
             detect_scsi_host_caps(&dev->def->caps->data);
         }
+        if (cap->type == VIR_NODE_DEV_CAP_NET &&
+            virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.lnk) < 0)
+            return -1;
+
         cap = cap->next;
     }
 
@@ -315,7 +319,8 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
         goto cleanup;
 
     update_driver_name(obj);
-    update_caps(obj);
+    if (update_caps(obj) < 0)
+        goto cleanup;
 
     ret = virNodeDeviceDefFormat(obj->def);
 
index 91fc16f301eac06e36a10479767ed651d1680146..a8e74e457765158b5b04480b068e42b9ea457330 100644 (file)
@@ -40,6 +40,7 @@
 #include "virfile.h"
 #include "virpci.h"
 #include "virstring.h"
+#include "virnetdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_NODEDEV
 
@@ -679,6 +680,9 @@ static int udevProcessNetworkInterface(struct udev_device *device,
         goto out;
     }
 
+    if (virNetDevGetLinkInfo(data->net.ifname, &data->net.lnk) < 0)
+        goto out;
+
     ret = 0;
 
  out: