[PATCH] Interface: return appropriate status for bridge device

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

 



In function udevInterfaceIsActive, The current design relies on the sys
attribute 'operstate' to determine whether the interface is active.

For the device node of virtual network(say virbr0), There is already a
dummy tap device to maintain a fixed mac on it, So it's available and
its status should be considered as active. But if no anyelse tap device
connects to it, The value of operstate of virbr0 in sysfs is 'down', So
udevInterfaceIsActive returns 0, It causes 'virsh iface-list --all' to
report the status of virbr0 as 'inactive'.

This patch fixes the issue by counting slave devices for bridge device.

Signed-off-by: Lin Ma <lma@xxxxxxxx>
---
 src/interface/interface_backend_udev.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 5d0fc64..9ac4674 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -1127,6 +1127,11 @@ udevInterfaceIsActive(virInterfacePtr ifinfo)
     struct udev_device *dev;
     virInterfaceDefPtr def = NULL;
     int status = -1;
+    struct dirent **member_list = NULL;
+    const char *devtype;
+    int member_count = 0;
+    char *member_path;
+    size_t i;
 
     dev = udev_device_new_from_subsystem_sysname(udev, "net",
                                                  ifinfo->name);
@@ -1146,6 +1151,23 @@ udevInterfaceIsActive(virInterfacePtr ifinfo)
     /* Check if it's active or not */
     status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
 
+    if (!status) {
+        devtype = udev_device_get_devtype(dev);
+        if (STREQ_NULLABLE(devtype, "bridge")) {
+            if (virAsprintf(&member_path, "%s/%s",
+                        udev_device_get_syspath(dev), "brif") < 0)
+                goto cleanup;
+            member_count = scandir(member_path, &member_list,
+                    udevBridgeScanDirFilter, alphasort);
+            if (member_count > 0)
+                status = 1;
+            for (i = 0; i < member_count; i++)
+                VIR_FREE(member_list[i]);
+            VIR_FREE(member_list);
+            VIR_FREE(member_path);
+        }
+    }
+
     udev_device_unref(dev);
 
  cleanup:
-- 
2.9.2

--
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]
  Powered by Linux