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(a)linux.vnet.ibm.com>
---
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;
}