On Fri, Apr 17, 2009 at 11:38:23AM +0200, Soren Hansen wrote:
On Fri, Apr 17, 2009 at 10:01:38AM +0100, Daniel P. Berrange wrote:
> The problem with this approach is that the bridge name potentially
> ends up being different every time the virtual network is started. The
> bridge name needs to be stable,
Why? I can't remember ever having to refer to it, and if I did, I can
get that information at runtime by parsing the output from "virsh
net-dumpxml <name of the network>". What am I not thinking of? :)
The non-QEMU drivers I'm afraid. For those, when we connect a guest to
a virtual network, the underlying guest config includes the name of the
bridge associated with that network. So if the network changes its
bridge name, then all your Xen guests loose network connectivity the
next time around :-(
> if (!def->bridge && !(def->bridge = virNetworkAllocateBridge(conn,
> nets)))
>
> To check for %d, as well as NULL, and pass in the template name as your
> patch more or less does
Right, with my patch applied virNetworkAllocateBridge takes the
!def->bridge case into account.
I guess that if this is how you want it, the patch should be good as it
is. Here it is in its entirety:
Index: libvirt-0.6.1/src/network_conf.c
===================================================================
--- libvirt-0.6.1.orig/src/network_conf.c 2009-04-16 20:49:28.851655724 +0200
+++ libvirt-0.6.1/src/network_conf.c 2009-04-17 09:42:33.075084537 +0200
@@ -747,7 +747,7 @@
/* 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 (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge)))
goto error;
I think this would leak memory - the def-bridge string being passed in
is overwritten upon return, if its a non-null string.
if (!(net = virNetworkAssignDef(conn, nets, def)))
@@ -875,16 +875,20 @@
}
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 +913,7 @@
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 +922,7 @@
}
} else {
/* Allocate a bridge name */
- if (!(def->bridge = virNetworkAllocateBridge(conn, nets)))
+ if (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge)))
goto error;
}
Index: libvirt-0.6.1/src/network_conf.h
===================================================================
--- libvirt-0.6.1.orig/src/network_conf.h 2009-04-16 20:49:28.899655820 +0200
+++ libvirt-0.6.1/src/network_conf.h 2009-04-17 09:42:33.075084537 +0200
@@ -174,7 +174,8 @@
const char *skipname);
char *virNetworkAllocateBridge(virConnectPtr conn,
- const virNetworkObjListPtr nets);
+ const virNetworkObjListPtr nets,
+ const char *template);
int virNetworkSetBridgeName(virConnectPtr conn,
const virNetworkObjListPtr nets,
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|