From: Michal Privoznik Date: Thu, 5 Jun 2014 15:36:31 +0000 (+0200) Subject: node_device: Expose link state & speed X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=0311ef3d65b6462e405f325f5fdde78de0137005;p=libvirt.git node_device: Expose link state & speed While exposing the info under 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 net_eth0_f0_de_f1_2b_1b_f3 /sys/devices/pci0000:00/0000:00:19.0/net/eth0 pci_0000_00_19_0 eth0
f0:de:f1:2b:1b:f3
Signed-off-by: Michal Privoznik --- diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index 76bf8af1bf..d82bd3eb0e 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -161,6 +161,13 @@
The interface name tied to this device.
address
If present, the MAC address of the device.
+
link
+
Optional to reflect the status of the link. It has + two optional attributes: speed in Mbits per + second and state to tell the state of the + link. So far, the whole element is just for output, + not setting. +
capability
A network protocol exposed by the device, where the attribute type can be "80203" for IEEE diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 02d41063d5..505f913354 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -243,6 +243,7 @@ + diff --git a/src/Makefile.am b/src/Makefile.am index 9ab7c24afb..a72c284f38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 = diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 99fa448e8b..6153aa17c1 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -389,6 +389,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) if (data->net.address) virBufferEscapeString(&buf, "
%s
\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; diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 50ce4b3f70..d1311ddb7b 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 @@ -136,6 +137,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 6906463b81..5d58ca7e46 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,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); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 91fc16f301..a8e74e4577 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 @@ -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: