[libvirt] Supporting dynamic bridge names

Daniel P. Berrange berrange at redhat.com
Fri Apr 17 09:01:38 UTC 2009


On Fri, Apr 17, 2009 at 10:46:47AM +0200, Soren Hansen wrote:
> I'm fairly sure we've discussed this before, but I couldn't find it in
> my archives..
> 
> A rather long time ago (0.4.0 timeframe, I think) we switched the
> default network in Ubuntu to use a bridge whose name was defined as
> "virbr%d". This was done to be able to actually supply a default,
> enabled network without the risk of interfering with an existing bridge
> called "virbr0" (ignoring the possible implications of unconditionally
> using 192.168.122.0/24 (about which, I might add, I've never had /any/
> complaints)).
> 
> Now, since 0.5.0 (or thereabouts, I think), libvirt doesn't support
> this, which
> 
> a) makes it rather difficult to achieve our goal of not clashing with
> existing bridges named "virbr0", and
> b) causes some amount of grief for updates.

[snip]

> This is far from perfect, though.
> 
> a) As used to be the case for the VNC port, "virsh net-dumpxml" will
> give you /current/ bridge name, so e.g. "virsh net-edit" will cause you
> to hardcode the bridge name if you're not careful to replace the current
> name with one that says '%d' somewhere. This can be fixed by e.g. either
> adding a "template" or "current" attribute on the bridge element in the
> network XML (depending on whether you want the "name" attribute to be
> set to the current value or the template value).
> 
> b) Even if you /do/ remember to put '%d' in place of the assigned number
> during editing, the bridge number will be increased, because
> virNetworkBridgeInUse thinks the bridge name is in use. This should be
> easy to fix, though.

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, once allocated at time the virtual network is
defined in libvirt. So if we're to accept 'virbr%d' in a XML for a network
then at the time it is define, it should be converted into a real bridge
name and remain fixed thereafter. This is almost possible already
Just need to change the couple of places 

    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

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 :|




More information about the libvir-list mailing list