summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@redhat.com>2009-04-21 19:00:06 +0000
committerDaniel Veillard <veillard@redhat.com>2009-04-21 19:00:06 +0000
commit4c3f3b4d4694e937b9022141eb98cd465f29cc30 (patch)
tree45ab40da267b3c391ca3401f7a3f4c72ea3729da
parent* src/xend_internal.c: let xend try vcpu pinning operation even (diff)
downloadlibvirt-4c3f3b4d4694e937b9022141eb98cd465f29cc30.tar.gz
libvirt-4c3f3b4d4694e937b9022141eb98cd465f29cc30.tar.bz2
libvirt-4c3f3b4d4694e937b9022141eb98cd465f29cc30.zip
* src/network_conf.c src/network_conf.h: add dynamic bridge names
support, patch by Soren Hansen * AUTHORS: add Soren daniel
-rw-r--r--AUTHORS1
-rw-r--r--ChangeLog6
-rw-r--r--src/network_conf.c18
-rw-r--r--src/network_conf.h3
4 files changed, 22 insertions, 6 deletions
diff --git a/AUTHORS b/AUTHORS
index c09232051..02ec005ed 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -69,6 +69,7 @@ Patches have also been contributed by:
Florian Vichot <florian.vichot@diateam.net>
Takahashi Tomohiro <takatom@jp.fujitsu.com>
Serge E. Hallyn <serue@us.ibm.com>
+ Soren Hansen <soren@ubuntu.com>
[....send patches to get your name here....]
diff --git a/ChangeLog b/ChangeLog
index ac56e6729..a28977539 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Apr 21 20:58:50 CEST 2009 Daniel Veillard <veillard@redhat.com>
+
+ * src/network_conf.c src/network_conf.h: add dynamic bridge names
+ support, patch by Soren Hansen
+ * AUTHORS: add Soren
+
Tue Apr 21 17:08:57 CEST 2009 Daniel Veillard <veillard@redhat.com>
* src/xend_internal.c: let xend try vcpu pinning operation even
diff --git a/src/network_conf.c b/src/network_conf.c
index c6a598d0b..e962c1ad4 100644
--- a/src/network_conf.c
+++ b/src/network_conf.c
@@ -724,6 +724,7 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
virNetworkDefPtr def = NULL;
virNetworkObjPtr net;
int autostart;
+ char *tmp;
if ((configFile = virNetworkConfigFile(conn, configDir, name)) == NULL)
goto error;
@@ -747,7 +748,10 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
/* Generate a bridge if none is found, but don't check for collisions
* if a bridge is hardcoded, so the network is at least defined
*/
- if (!def->bridge && !(def->bridge = virNetworkAllocateBridge(conn, nets)))
+ if (tmp = virNetworkAllocateBridge(conn, nets, def->bridge)) {
+ VIR_FREE(def->bridge);
+ def->bridge = tmp;
+ } else
goto error;
if (!(net = virNetworkAssignDef(conn, nets, def)))
@@ -875,16 +879,20 @@ int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
}
char *virNetworkAllocateBridge(virConnectPtr conn,
- const virNetworkObjListPtr nets)
+ const virNetworkObjListPtr nets,
+ const char *template)
{
int id = 0;
char *newname;
+ if (!template)
+ template = "virbr%d";
+
do {
char try[50];
- snprintf(try, sizeof(try), "virbr%d", id);
+ snprintf(try, sizeof(try), template, id);
if (!virNetworkBridgeInUse(nets, try, NULL)) {
if (!(newname = strdup(try))) {
@@ -909,7 +917,7 @@ int virNetworkSetBridgeName(virConnectPtr conn,
int ret = -1;
- if (def->bridge) {
+ if (def->bridge && !strstr(def->bridge, "%d")) {
if (virNetworkBridgeInUse(nets, def->bridge, def->name)) {
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("bridge name '%s' already in use."),
@@ -918,7 +926,7 @@ int virNetworkSetBridgeName(virConnectPtr conn,
}
} else {
/* Allocate a bridge name */
- if (!(def->bridge = virNetworkAllocateBridge(conn, nets)))
+ if (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge)))
goto error;
}
diff --git a/src/network_conf.h b/src/network_conf.h
index 7e36e6872..365d469db 100644
--- a/src/network_conf.h
+++ b/src/network_conf.h
@@ -174,7 +174,8 @@ int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
const char *skipname);
char *virNetworkAllocateBridge(virConnectPtr conn,
- const virNetworkObjListPtr nets);
+ const virNetworkObjListPtr nets,
+ const char *template);
int virNetworkSetBridgeName(virConnectPtr conn,
const virNetworkObjListPtr nets,