]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
network: check for bridge name conflict with existing devices
authorLaine Stump <laine@laine.org>
Thu, 23 Apr 2015 18:29:08 +0000 (14:29 -0400)
committerLaine Stump <laine@laine.org>
Tue, 28 Apr 2015 05:21:41 +0000 (01:21 -0400)
Since some people use the same naming convention as libvirt for bridge
devices they create outside the context of libvirt, it is much nicer
if we check for those devices when looking for a bridge device name to
auto-assign to a new network.

src/network/bridge_driver.c

index 48b9d0fadec64fe7d405abc725dbe648891f4385..3b879cd42b460b44747d93bf628f1c5ccd457604 100644 (file)
@@ -2764,8 +2764,9 @@ static int networkIsPersistent(virNetworkPtr net)
 
 /*
  * networkFindUnusedBridgeName() - try to find a bridge name that is
- * unused by the currently configured libvirt networks, and set this
- * network's name to that new name.
+ * unused by the currently configured libvirt networks, as well as by
+ * the host system itself (possibly created by someone/something other
+ * than libvirt). Set this network's name to that new name.
  */
 static int
 networkFindUnusedBridgeName(virNetworkObjListPtr nets,
@@ -2779,7 +2780,13 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets,
     do {
         if (virAsprintf(&newname, templ, id) < 0)
             goto cleanup;
-        if (!virNetworkBridgeInUse(nets, newname, def->name)) {
+        /* check if this name is used in another libvirt network or
+         * there is an existing device with that name. ignore errors
+         * from virNetDevExists(), just in case it isn't implemented
+         * on this platform (probably impossible).
+         */
+        if (!(virNetworkBridgeInUse(nets, newname, def->name) ||
+              virNetDevExists(newname) == 1)) {
             VIR_FREE(def->bridge); /*could contain template */
             def->bridge = newname;
             ret = 0;