[libvirt] [RFC] [Patch] Support for Linux macvtap device

Stefan Berger stefanb at us.ibm.com
Mon Jan 25 17:47:17 UTC 2010


 The attached patch provides support for the Linux macvtap device for
Qemu by passing a file descriptor to Qemu command line similar to how it
is done with a regular tap device. I have modified the network XML code
to understand a definition as the following one here:

  <extbridge mode='vepa' dev='eth0'/>

This XML indicates the device that links to the external bridge, here
eth0, and the mode this device is supposed to be set into, here 'vepa'.
If 'extbridge' is found in the XML, all other XML elements that have
been used so far, i.e., bridge, ip, dhcp, etc., are ignored.
The above network description can then be referenced from the virtual
machine definition using the typical interface description of type

    <interface type='network'>
      <source network='vepanet'/>
      <model type='virtio'/>

The above network XML holds the necessary parameters to open a macvtap
device. Using command line, one would issue the following command to
achieve the same what now libvirt does internally, using a patched
version of the 'ip' command:

ip link add link eth0 <optional name of if> type macvtap mode vepa

This then creates the network interface, i.e., macvtap12, along with
entries in /sys/class/net/macvtap12/ where the content of the ifindex
file returns the integer necessary to build the /dev/tap%d device to
open the file descriptor of and pass to qemu via command line argument.

Some details:

In libvirt I am first searching for an unused interface name following
the template macvtap%d unless the user has provided a name explicitly
or the previous macvtap%d is now taken by another VM. Once that has
succeeded, I follow the path through the filesystem to open the
corresponding /dev/tap%d.
Unlike the regular tap device, where the network interface disappears
once the corresponding file descriptor is closed, the macvtap device
needs explicit tear-down. So, when a VM terminates, I am deleting all
macvtap type interface with the MAC address as the interface of the
terminating VM.

Some further background on this device was recently given here:

The macvtap patch for Linux was posted here:


I'd be curious about comments on the code.

Signed-off-by: Stefan Berger <stefanb at us.ibm.com>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvirt-macvtap.diff
Type: text/x-patch
Size: 36913 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100125/0fd0ccbf/attachment-0001.bin>

More information about the libvir-list mailing list