[PATCH 5/5] interface: add udevIfaceIsActive() to udev backend

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

 



Add support to check if a specific interface is active by supporting the
following API function in the udev based virInterface backend:
* virConnectInterfaceIsActive()
---
 src/interface/interface_backend_udev.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 2f37bed..82c8681 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -616,6 +616,35 @@ cleanup:
     return xmlstr;
 }
 
+static int
+udevIfaceIsActive(virInterfacePtr ifinfo)
+{
+    struct udev_iface_driver *driverState = ifinfo->conn->interfacePrivateData;
+    struct udev *udev = udev_ref(driverState->udev);
+    struct udev_device *dev;
+    int status;
+
+    dev = udev_device_new_from_subsystem_sysname(udev, "net",
+                                                 ifinfo->name);
+    if (!dev) {
+        virReportError(VIR_ERR_NO_INTERFACE,
+                       _("couldn't find interface named '%s'"),
+                       ifinfo->name);
+        status = -1;
+        goto cleanup;
+    }
+
+    /* Check if its active or not */
+    status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
+
+    udev_device_unref(dev);
+
+cleanup:
+    udev_unref(udev);
+
+    return status;
+}
+
 static virInterfaceDriver udevIfaceDriver = {
     "udev",
     .open = udevIfaceOpenInterface, /* 0.10.3 */
@@ -628,6 +657,7 @@ static virInterfaceDriver udevIfaceDriver = {
     .interfaceLookupByName = udevIfaceLookupByName, /* 0.10.3 */
     .interfaceLookupByMACString = udevIfaceLookupByMACString, /* 0.10.3 */
     .interfaceGetXMLDesc = udevIfaceGetXMLDesc, /* 0.10.3 */
+    .interfaceIsActive = udevIfaceIsActive, /* 0.10.3 */
 };
 
 int
-- 
1.7.8.6

--
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]