[PATCH] network_conf: check sysfs if the bridge exists on host for user created bridges

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

 



virNetworkBridgeInUse() doesn't check if the bridge is manually created
outside of libvirt. Check the bridge name file in the sysfs to see if the
bridge is in use.

Signed-off-by: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxxxxxxx>
---
 src/conf/network_conf.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index d0e7e1b..4f90425 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3074,16 +3074,28 @@ int virNetworkBridgeInUse(virNetworkObjListPtr nets,
 {
     size_t i;
     unsigned int ret = 0;
+    int defined_bridge = 0;
+    char *path = NULL;
 
     for (i = 0; i < nets->count; i++) {
         virNetworkObjLock(nets->objs[i]);
         if (nets->objs[i]->def->bridge &&
-            STREQ(nets->objs[i]->def->bridge, bridge) &&
-            !(skipname && STREQ(nets->objs[i]->def->name, skipname)))
+            STREQ(nets->objs[i]->def->bridge, bridge)) {
+            defined_bridge = 1;
+            if (!(skipname && STREQ(nets->objs[i]->def->name, skipname)))
                 ret = 1;
+        }
         virNetworkObjUnlock(nets->objs[i]);
     }
 
+    /* Bridge might have been created by a user manually outside libvirt */
+    if (!defined_bridge && !ret) {
+        if (virAsprintf(&path, "/sys/class/net/%s/", bridge) < 0)
+            return -1;
+        ret = virFileExists(path) ? 1 : 0;
+        VIR_FREE(path);
+    }
+
     return ret;
 }
 

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