[PATCH 07/12] interface_backend_udev: Implement link speed & state

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In previous commit the interface XML is prepared for exporting
information on NIC link speed and state. This commit implement
actual logic for getting such info and writing it into XML.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/interface/interface_backend_udev.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index c5353ea..c8940ce 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -1036,6 +1036,8 @@ udevGetIfaceDef(struct udev *udev, const char *name)
     const char *mtu_str;
     char *vlan_parent_dev = NULL;
     const char *devtype;
+    const char *operstate;
+    const char *link_speed;
 
     /* Allocate our interface definition structure */
     if (VIR_ALLOC(ifacedef) < 0)
@@ -1059,6 +1061,23 @@ udevGetIfaceDef(struct udev *udev, const char *name)
                    udev_device_get_sysattr_value(dev, "address")) < 0)
         goto error;
 
+    operstate = udev_device_get_sysattr_value(dev, "operstate");
+    if ((ifacedef->state = virInterfaceStateTypeFromString(operstate)) <= 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse operstate: %s"),
+                       operstate);
+        goto error;
+    }
+
+    link_speed = udev_device_get_sysattr_value(dev, "speed");
+    if (link_speed &&
+        virStrToLong_ul(link_speed, NULL, 10, &ifacedef->speed) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse speed: %s"),
+                       link_speed);
+        goto error;
+    }
+
     /* MTU */
     mtu_str = udev_device_get_sysattr_value(dev, "mtu");
     if (virStrToLong_ui(mtu_str, NULL, 10, &mtu) < 0) {
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]