[libvirt] [PATCH v2 4/4] node_device: Expose link state & speed

John Ferlan jferlan at redhat.com
Wed Jun 11 01:15:49 UTC 2014



On 06/05/2014 11:39 AM, Michal Privoznik wrote:
> 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 at redhat.com>
> ---
>  docs/formatnode.html.in              |  6 ++++++
>  docs/schemas/nodedev.rng             |  1 +
>  src/Makefile.am                      |  2 +-
>  src/conf/node_device_conf.c          |  7 ++++++-
>  src/conf/node_device_conf.h          |  2 ++
>  src/node_device/node_device_driver.c | 11 +++++++++--
>  src/node_device/node_device_udev.c   |  5 +++++
>  7 files changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in
> index b424c96..0ef890f 100644
> --- a/docs/formatnode.html.in
> +++ b/docs/formatnode.html.in
> @@ -154,6 +154,12 @@
>                <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 Mbit per

s/Mbit/Mbits

> +                second and <code>state</code> to tell the state of the
> +                link.
> +              </dd>

Should it be noted that reality is this is an output XML setting?
Although possibly set at read time, it's essentially ignored.

The rest seems reasonable.

ACK

John

>                <dt><code>capability</code></dt>
>                <dd>A network protocol exposed by the device, where the
>                  attribute <code>type</code> can be "80203" for IEEE
> diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng
> index 81ab4d4..8c70536 100644
> --- a/docs/schemas/nodedev.rng
> +++ b/docs/schemas/nodedev.rng
> @@ -233,6 +233,7 @@
>          <ref name='mac'/>
>        </element>
>      </optional>
> +    <ref name="link-speed-state"/>
>  
>      <zeroOrMore>
>        <ref name='subcapnet'/>
> diff --git a/src/Makefile.am b/src/Makefile.am
> index a6b8d0b..e7b3318 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -1518,7 +1518,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 =
>  
> diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
> index e65b5e4..8405a25 100644
> --- a/src/conf/node_device_conf.c
> +++ b/src/conf/node_device_conf.c
> @@ -386,6 +386,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);
> @@ -837,7 +838,7 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
>                           xmlNodePtr node,
>                           union _virNodeDevCapData *data)
>  {
> -    xmlNodePtr orignode;
> +    xmlNodePtr orignode, lnk;
>      int ret = -1;
>      char *tmp;
>  
> @@ -869,6 +870,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;
> diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
> index 50e6805..462bfa4 100644
> --- a/src/conf/node_device_conf.h
> +++ b/src/conf/node_device_conf.h
> @@ -29,6 +29,7 @@
>  # include "virutil.h"
>  # include "virthread.h"
>  # include "virpci.h"
> +# include "device_conf.h"
>  
>  # include <libxml/tree.h>
>  
> @@ -135,6 +136,7 @@ struct _virNodeDevCapsDef {
>              char *address;
>              unsigned int address_len;
>              char *ifname;
> +            virInterfaceLink lnk;
>              virNodeDevNetCapType subtype;  /* LAST -> no subtype */
>          } net;
>          struct {
> diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
> index 6906463..92aeb45 100644
> --- a/src/node_device/node_device_driver.c
> +++ b/src/node_device/node_device_driver.c
> @@ -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,15 @@ 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(dev->def->caps->data.net.ifname,
> +                                 &dev->def->caps->data.net.lnk.state,
> +                                 &dev->def->caps->data.net.lnk.speed) < 0)
> +            return -1;
> +
>          cap = cap->next;
>      }
>  
> @@ -315,7 +321,8 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
>          goto cleanup;
>  
>      update_driver_name(obj);
> -    update_caps(obj);
> +    if (update_caps(obj) < 0)
> +        goto cleanup;
>  
>      ret = virNodeDeviceDefFormat(obj->def);
>  
> diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
> index 9a951d9..0d94bba 100644
> --- a/src/node_device/node_device_udev.c
> +++ b/src/node_device/node_device_udev.c
> @@ -40,6 +40,7 @@
>  #include "virfile.h"
>  #include "virpci.h"
>  #include "virstring.h"
> +#include "virnetdev.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_NODEDEV
>  
> @@ -667,6 +668,10 @@ static int udevProcessNetworkInterface(struct udev_device *device,
>          goto out;
>      }
>  
> +    if (virNetDevGetLinkInfo(data->net.ifname, &data->net.lnk.state,
> +                             &data->net.lnk.speed) < 0)
> +        goto out;
> +
>      ret = 0;
>  
>   out:
> 




More information about the libvir-list mailing list