libvirt/de09ae2f-libxl-support-openvswitch.patch

122 lines
4.4 KiB
Diff

commit de09ae2f4676dd521f558d383d33f4b4c026984c
Author: Jim Fehlig <jfehlig@suse.com>
Date: Tue Jun 28 14:20:02 2016 -0600
libxl: support openvswitch interfaces
It is currently possible to use <interface>s of type openvswitch
with the libxl driver in a non-standard way, e.g.
<interface type='bridge'>
<source bridge='ovsbr0'/>
<mac address='00:16:3e:7a:35:ce'/>
<script path='vif-openvswitch'/>
</interface>
This patch adds support for openvswitch <interface>s specified
in typical libvirt config
<interface type='bridge'>
<source bridge='ovsbr0'/>
<mac address='00:16:3e:7a:35:ce'/>
<virtualport type='openvswitch'/>
</interface>
VLAN tags and trunking are also supported using the extended
syntax for specifying an openvswitch bridge in libxl
BRIDGE_NAME[.VLAN][:TRUNK:TRUNK]
See Xen's networking wiki for more details on openvswitch support
https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Index: libvirt-4.10.0/src/libxl/libxl_conf.c
===================================================================
--- libvirt-4.10.0.orig/src/libxl/libxl_conf.c
+++ libvirt-4.10.0/src/libxl/libxl_conf.c
@@ -51,6 +51,7 @@
#include "cpu/cpu.h"
#include "xen_common.h"
#include "xen_xl.h"
+#include "virnetdevvportprofile.h"
#define VIR_FROM_THIS VIR_FROM_LIBXL
@@ -1229,6 +1230,11 @@ libxlMakeNic(virDomainDefPtr def,
virNetworkPtr network = NULL;
virConnectPtr conn = NULL;
virNetDevBandwidthPtr actual_bw;
+ virNetDevVPortProfilePtr port_profile;
+ virNetDevVlanPtr virt_vlan;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ size_t i;
+ const char *script = NULL;
int ret = -1;
/* TODO: Where is mtu stored?
@@ -1287,14 +1293,50 @@ libxlMakeNic(virDomainDefPtr def,
if (VIR_STRDUP(x_nic->ifname, l_nic->ifname) < 0)
goto cleanup;
+ port_profile = virDomainNetGetActualVirtPortProfile(l_nic);
+ virt_vlan = virDomainNetGetActualVlan(l_nic);
+ script = l_nic->script;
switch (actual_type) {
case VIR_DOMAIN_NET_TYPE_BRIDGE:
+ virBufferAddStr(&buf, virDomainNetGetActualBridgeName(l_nic));
+ /*
+ * A bit of special handling if vif will be connected to an
+ * openvswitch bridge
+ */
+ if (port_profile &&
+ port_profile->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
+ /*
+ * If a custom script is not specified for openvswitch, use
+ * Xen's vif-openvswitch script
+ */
+ if (!script)
+ script = "vif-openvswitch";
+ /*
+ * libxl_device_nic->bridge supports an extended format for
+ * specifying VLAN tags and trunks when using openvswitch
+ *
+ * BRIDGE_NAME[.VLAN][:TRUNK:TRUNK]
+ *
+ * See Xen's networking wiki for more details
+ * https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch
+ */
+ if (virt_vlan && virt_vlan->nTags > 0) {
+ if (virt_vlan->trunk) {
+ for (i = 0; i < virt_vlan->nTags; i++)
+ virBufferAsprintf(&buf, ":%d", virt_vlan->tag[i]);
+ } else {
+ virBufferAsprintf(&buf, ".%d", virt_vlan->tag[0]);
+ }
+ }
+ }
+ if (virBufferCheckError(&buf) < 0)
+ goto cleanup;
if (VIR_STRDUP(x_nic->bridge,
- virDomainNetGetActualBridgeName(l_nic)) < 0)
+ virBufferCurrentContent(&buf)) < 0)
goto cleanup;
ATTRIBUTE_FALLTHROUGH;
case VIR_DOMAIN_NET_TYPE_ETHERNET:
- if (VIR_STRDUP(x_nic->script, l_nic->script) < 0)
+ if (VIR_STRDUP(x_nic->script, script) < 0)
goto cleanup;
if (l_nic->guestIP.nips > 0) {
x_nic->ip = xenMakeIPList(&l_nic->guestIP);
@@ -1391,6 +1433,7 @@ libxlMakeNic(virDomainDefPtr def,
ret = 0;
cleanup:
+ virBufferFreeAndReset(&buf);
virObjectUnref(network);
virObjectUnref(conn);