[libvirt] [PATCH v2 2/2] network_conf: check if bridge exists on host for user created bridges

Shivaprasad G Bhat shivaprasadbhat at gmail.com
Wed Mar 11 09:11:34 UTC 2015


virNetworkBridgeInUse() doesn't check if the bridge is manually created
outside of libvirt. Check if the bridge actually exist on host using the
virNetDevExists().

Signed-off-by: Shivaprasad G Bhat <sbhat at linux.vnet.ibm.com>
---
 src/conf/network_conf.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index d0e7e1b..3ab087c 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3074,16 +3074,23 @@ int virNetworkBridgeInUse(virNetworkObjListPtr nets,
 {
     size_t i;
     unsigned int ret = 0;
+    int defined_bridge = 0;
 
     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)
+        ret = virNetDevExists(bridge) ? 1 : 0;
+
     return ret;
 }
 




More information about the libvir-list mailing list