Discussion:
[libvirt] [PATCH 3/3] news: Mention Xen support for openvswitch
Jim Fehlig
2018-11-16 22:26:28 UTC
Permalink
Signed-off-by: Jim Fehlig <***@suse.com>
---
docs/news.xml | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index f52f1ab01a..ffaa49085c 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -55,6 +55,16 @@
guests.
</description>
</change>
+ <change>
+ <summary>
+ Xen: Add support for openvswitch
+ </summary>
+ <description>
+ The libxl driver now supports virtual interfaces that connect to
+ an openvswitch bridge, including interfaces with VLAN tagging and
+ trunking configuration.
+ </description>
+ </change>
</section>
<section title="Improvements">
</section>
--
2.18.0
Jim Fehlig
2018-11-16 22:26:27 UTC
Permalink
Add support for converting openvswitch interface configuration
to/from libvirt domXML and xl.cfg(5). The xl config syntax for
virtual interfaces is described in detail in the
xl-network-configuration(5) man page. The Xen Networking wiki
also contains information and examples for using openvswitch
in xl.cfg config format

https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch

Tests are added to check conversions of openvswitch tagged and
trunked VLAN configuration.

Signed-off-by: Jim Fehlig <***@suse.com>
---
src/xenconfig/xen_common.c | 113 +++++++++++++++++-
.../test-fullvirt-ovswitch-tagged.cfg | 25 ++++
.../test-fullvirt-ovswitch-tagged.xml | 50 ++++++++
.../test-fullvirt-ovswitch-trunked.cfg | 25 ++++
.../test-fullvirt-ovswitch-trunked.xml | 51 ++++++++
tests/xlconfigtest.c | 2 +
6 files changed, 262 insertions(+), 4 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 0a9958711f..5390b933e0 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -856,6 +856,84 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
}


+static int
+xenParseVifBridge(virDomainNetDefPtr net, char *bridge)
+{
+ char *vlanstr;
+ unsigned int tag;
+
+ /* 'bridge' string contains a bridge name and single vlan tag */
+ vlanstr = strchr(bridge, '.');
+ if (vlanstr) {
+ if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge) < 0)
+ return -1;
+
+ vlanstr++;
+ if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0)
+ return -1;
+
+ if (VIR_ALLOC_N(net->vlan.tag, 1) < 0)
+ return -1;
+
+ net->vlan.tag[0] = tag;
+ net->vlan.nTags = 1;
+
+ if (VIR_ALLOC(net->virtPortProfile) < 0)
+ return -1;
+
+ net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
+ return 0;
+ }
+
+ /* 'bridge' string contains a bridge name and one or more vlan trunks */
+ vlanstr = strchr(bridge, ':');
+ if (vlanstr) {
+ size_t i;
+ size_t nvlans = 0;
+ char **vlanstr_list = virStringSplit(bridge, ":", 0);
+
+ if (!vlanstr_list)
+ return -1;
+
+ if (VIR_STRDUP(net->data.bridge.brname, vlanstr_list[0]) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+
+ for (i = 1; vlanstr_list[i]; i++)
+ nvlans++;
+
+ if (VIR_ALLOC_N(net->vlan.tag, nvlans) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+
+ for (i = 1; i <= nvlans; i++) {
+ if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+ net->vlan.tag[i - 1] = tag;
+ }
+ net->vlan.nTags = nvlans;
+ net->vlan.trunk = true;
+ virStringListFree(vlanstr_list);
+
+ if (VIR_ALLOC(net->virtPortProfile) < 0)
+ return -1;
+
+ net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
+ return 0;
+ }
+
+ /* 'bridge' string only contains the bridge name */
+ if (VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
+ return -1;
+
+ return 0;
+}
+
+
static virDomainNetDefPtr
xenParseVif(char *entry, const char *vif_typename)
{
@@ -974,8 +1052,8 @@ xenParseVif(char *entry, const char *vif_typename)
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
}

- if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE && bridge[0]) {
+ if (xenParseVifBridge(net, bridge) < 0)
goto cleanup;
}
if (ip[0]) {
@@ -1249,14 +1327,41 @@ xenFormatNet(virConnectPtr conn,

switch (net->type) {
case VIR_DOMAIN_NET_TYPE_BRIDGE:
+ {
+ virNetDevVPortProfilePtr port_profile = virDomainNetGetActualVirtPortProfile(net);
+ virNetDevVlanPtr virt_vlan = virDomainNetGetActualVlan(net);
+ const char *script = net->script;
+ size_t i;
+
virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname);
+ if (port_profile &&
+ port_profile->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
+ if (!script)
+ script = "vif-openvswitch";
+ /*
+ * libxl_device_nic->bridge supports an extended format for
+ * specifying VLAN tags and trunks
+ *
+ * BRIDGE_NAME[.VLAN][:TRUNK:TRUNK]
+ */
+ 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 (net->guestIP.nips > 0) {
char *ipStr = xenMakeIPList(&net->guestIP);
virBufferAsprintf(&buf, ",ip=%s", ipStr);
VIR_FREE(ipStr);
}
- virBufferAsprintf(&buf, ",script=%s", DEFAULT_VIF_SCRIPT);
- break;
+ virBufferAsprintf(&buf, ",script=%s", script ? script : DEFAULT_VIF_SCRIPT);
+ }
+ break;

case VIR_DOMAIN_NET_TYPE_ETHERNET:
if (net->script)
diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg
new file mode 100644
index 0000000000..6a3dc3cfeb
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg
@@ -0,0 +1,25 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 8192
+memory = 8192
+vcpus = 8
+pae = 1
+acpi = 1
+apic = 1
+viridian = 0
+rtc_timeoffset = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-system-i386"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+vif = [ "mac=00:16:3e:66:92:9c,bridge=ovsbr0.42,script=vif-openvswitch,model=e1000" ]
+parallel = "none"
+serial = "none"
+builder = "hvm"
+boot = "c"
+disk = [ "format=raw,vdev=hda,access=rw,backendtype=phy,target=/dev/HostVG/XenGuest2" ]
diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml
new file mode 100644
index 0000000000..63f3258b84
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml
@@ -0,0 +1,50 @@
+<domain type='xen'>
+ <name>XenGuest2</name>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>8388608</memory>
+ <currentMemory unit='KiB'>8388608</currentMemory>
+ <vcpu placement='static'>8</vcpu>
+ <os>
+ <type arch='x86_64' machine='xenfv'>hvm</type>
+ <loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='variable' adjustment='0' basis='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/lib/xen/bin/qemu-system-i386</emulator>
+ <disk type='block' device='disk'>
+ <driver name='phy' type='raw'/>
+ <source dev='/dev/HostVG/XenGuest2'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='ide' index='0'/>
+ <interface type='bridge'>
+ <mac address='00:16:3e:66:92:9c'/>
+ <source bridge='ovsbr0'/>
+ <vlan>
+ <tag id='42'/>
+ </vlan>
+ <virtualport type='openvswitch'/>
+ <script path='vif-openvswitch'/>
+ <model type='e1000'/>
+ </interface>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+ <video>
+ <model type='cirrus' vram='8192' heads='1' primary='yes'/>
+ </video>
+ <memballoon model='xen'/>
+ </devices>
+</domain>
diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-trunked.cfg b/tests/xlconfigdata/test-fullvirt-ovswitch-trunked.cfg
new file mode 100644
index 0000000000..29e9d38ae8
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-ovswitch-trunked.cfg
@@ -0,0 +1,25 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 8192
+memory = 8192
+vcpus = 8
+pae = 1
+acpi = 1
+apic = 1
+viridian = 0
+rtc_timeoffset = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-system-i386"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+vif = [ "mac=00:16:3e:66:92:9c,bridge=ovsbr0:42:43,script=vif-openvswitch,model=e1000" ]
+parallel = "none"
+serial = "none"
+builder = "hvm"
+boot = "c"
+disk = [ "format=raw,vdev=hda,access=rw,backendtype=phy,target=/dev/HostVG/XenGuest2" ]
diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-trunked.xml b/tests/xlconfigdata/test-fullvirt-ovswitch-trunked.xml
new file mode 100644
index 0000000000..72d547b2c1
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-ovswitch-trunked.xml
@@ -0,0 +1,51 @@
+<domain type='xen'>
+ <name>XenGuest2</name>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>8388608</memory>
+ <currentMemory unit='KiB'>8388608</currentMemory>
+ <vcpu placement='static'>8</vcpu>
+ <os>
+ <type arch='x86_64' machine='xenfv'>hvm</type>
+ <loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='variable' adjustment='0' basis='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/lib/xen/bin/qemu-system-i386</emulator>
+ <disk type='block' device='disk'>
+ <driver name='phy' type='raw'/>
+ <source dev='/dev/HostVG/XenGuest2'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='ide' index='0'/>
+ <interface type='bridge'>
+ <mac address='00:16:3e:66:92:9c'/>
+ <source bridge='ovsbr0'/>
+ <vlan trunk='yes'>
+ <tag id='42'/>
+ <tag id='43'/>
+ </vlan>
+ <virtualport type='openvswitch'/>
+ <script path='vif-openvswitch'/>
+ <model type='e1000'/>
+ </interface>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+ <video>
+ <model type='cirrus' vram='8192' heads='1' primary='yes'/>
+ </video>
+ <memballoon model='xen'/>
+ </devices>
+</domain>
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index b2e4591c3b..a696ce28b3 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -250,6 +250,8 @@ mymain(void)
DO_TEST_FORMAT(name, true); \
} while (0)

+ DO_TEST("fullvirt-ovswitch-tagged");
+ DO_TEST("fullvirt-ovswitch-trunked");
DO_TEST_REPLACE_VARS("fullvirt-ovmf");
DO_TEST("paravirt-maxvcpus");
DO_TEST("new-disk");
--
2.18.0
Michal Privoznik
2018-12-06 07:44:21 UTC
Permalink
Post by Jim Fehlig
Add support for converting openvswitch interface configuration
to/from libvirt domXML and xl.cfg(5). The xl config syntax for
virtual interfaces is described in detail in the
xl-network-configuration(5) man page. The Xen Networking wiki
also contains information and examples for using openvswitch
in xl.cfg config format
https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch
Tests are added to check conversions of openvswitch tagged and
trunked VLAN configuration.
---
src/xenconfig/xen_common.c | 113 +++++++++++++++++-
.../test-fullvirt-ovswitch-tagged.cfg | 25 ++++
.../test-fullvirt-ovswitch-tagged.xml | 50 ++++++++
.../test-fullvirt-ovswitch-trunked.cfg | 25 ++++
.../test-fullvirt-ovswitch-trunked.xml | 51 ++++++++
tests/xlconfigtest.c | 2 +
6 files changed, 262 insertions(+), 4 deletions(-)
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 0a9958711f..5390b933e0 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -856,6 +856,84 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
}
+static int
+xenParseVifBridge(virDomainNetDefPtr net, char *bridge)
+{
+ char *vlanstr;
+ unsigned int tag;
+
+ /* 'bridge' string contains a bridge name and single vlan tag */
+ vlanstr = strchr(bridge, '.');
+ if (vlanstr) {
+ if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge) < 0)
+ return -1;
+
+ vlanstr++;
+ if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0)
+ return -1;
+
+ if (VIR_ALLOC_N(net->vlan.tag, 1) < 0)
+ return -1;
+
+ net->vlan.tag[0] = tag;
+ net->vlan.nTags = 1;
+
+ if (VIR_ALLOC(net->virtPortProfile) < 0)
+ return -1;
+
+ net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
+ return 0;
+ }
+
+ /* 'bridge' string contains a bridge name and one or more vlan trunks */
+ vlanstr = strchr(bridge, ':');
+ if (vlanstr) {
+ size_t i;
+ size_t nvlans = 0;
+ char **vlanstr_list = virStringSplit(bridge, ":", 0);
+
+ if (!vlanstr_list)
+ return -1;
+
+ if (VIR_STRDUP(net->data.bridge.brname, vlanstr_list[0]) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+
+ for (i = 1; vlanstr_list[i]; i++)
+ nvlans++;
+
+ if (VIR_ALLOC_N(net->vlan.tag, nvlans) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+
+ for (i = 1; i <= nvlans; i++) {
+ if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+ net->vlan.tag[i - 1] = tag;
+ }
+ net->vlan.nTags = nvlans;
+ net->vlan.trunk = true;
+ virStringListFree(vlanstr_list);
+
+ if (VIR_ALLOC(net->virtPortProfile) < 0)
+ return -1;
+
+ net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
+ return 0;
+ }
+
+ /* 'bridge' string only contains the bridge name */
+ if (VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
+ return -1;
+
+ return 0;
Not a show stopper, I just wonder if we should perhaps use:

if ((vlanstr = strchr(bridge, '.'))) {
...
} else if ((vlanstr = strchr(bridge, ':'))) {
...
} else {
...
}

return 0;

To me that looks a bit cleaner, but I'll leave it up to you. Don't want
to be picky.
Post by Jim Fehlig
+}
+
+
static virDomainNetDefPtr
xenParseVif(char *entry, const char *vif_typename)
{
@@ -974,8 +1052,8 @@ xenParseVif(char *entry, const char *vif_typename)
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
}
- if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE && bridge[0]) {
+ if (xenParseVifBridge(net, bridge) < 0)
goto cleanup;
}
if (ip[0]) {
Michal
Jim Fehlig
2018-12-06 22:16:31 UTC
Permalink
Post by Michal Privoznik
Post by Jim Fehlig
Add support for converting openvswitch interface configuration
to/from libvirt domXML and xl.cfg(5). The xl config syntax for
virtual interfaces is described in detail in the
xl-network-configuration(5) man page. The Xen Networking wiki
also contains information and examples for using openvswitch
in xl.cfg config format
https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch
Tests are added to check conversions of openvswitch tagged and
trunked VLAN configuration.
---
src/xenconfig/xen_common.c | 113 +++++++++++++++++-
.../test-fullvirt-ovswitch-tagged.cfg | 25 ++++
.../test-fullvirt-ovswitch-tagged.xml | 50 ++++++++
.../test-fullvirt-ovswitch-trunked.cfg | 25 ++++
.../test-fullvirt-ovswitch-trunked.xml | 51 ++++++++
tests/xlconfigtest.c | 2 +
6 files changed, 262 insertions(+), 4 deletions(-)
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 0a9958711f..5390b933e0 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -856,6 +856,84 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
}
+static int
+xenParseVifBridge(virDomainNetDefPtr net, char *bridge)
+{
+ char *vlanstr;
+ unsigned int tag;
+
+ /* 'bridge' string contains a bridge name and single vlan tag */
+ vlanstr = strchr(bridge, '.');
+ if (vlanstr) {
+ if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge) < 0)
+ return -1;
+
+ vlanstr++;
+ if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0)
+ return -1;
+
+ if (VIR_ALLOC_N(net->vlan.tag, 1) < 0)
+ return -1;
+
+ net->vlan.tag[0] = tag;
+ net->vlan.nTags = 1;
+
+ if (VIR_ALLOC(net->virtPortProfile) < 0)
+ return -1;
+
+ net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
+ return 0;
+ }
+
+ /* 'bridge' string contains a bridge name and one or more vlan trunks */
+ vlanstr = strchr(bridge, ':');
+ if (vlanstr) {
+ size_t i;
+ size_t nvlans = 0;
+ char **vlanstr_list = virStringSplit(bridge, ":", 0);
+
+ if (!vlanstr_list)
+ return -1;
+
+ if (VIR_STRDUP(net->data.bridge.brname, vlanstr_list[0]) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+
+ for (i = 1; vlanstr_list[i]; i++)
+ nvlans++;
+
+ if (VIR_ALLOC_N(net->vlan.tag, nvlans) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+
+ for (i = 1; i <= nvlans; i++) {
+ if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) {
+ virStringListFree(vlanstr_list);
+ return -1;
+ }
+ net->vlan.tag[i - 1] = tag;
+ }
+ net->vlan.nTags = nvlans;
+ net->vlan.trunk = true;
+ virStringListFree(vlanstr_list);
+
+ if (VIR_ALLOC(net->virtPortProfile) < 0)
+ return -1;
+
+ net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
+ return 0;
+ }
+
+ /* 'bridge' string only contains the bridge name */
+ if (VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
+ return -1;
+
+ return 0;
if ((vlanstr = strchr(bridge, '.'))) {
...
} else if ((vlanstr = strchr(bridge, ':'))) {
...
} else {
...
}
return 0;
To me that looks a bit cleaner, but I'll leave it up to you. Don't want
to be picky.
It definitely looks cleaner. I'll squash in the below diff before pushing.
Thanks a lot for reviewing the patches!

Regards,
Jim


diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 83eb28cdc9..60c8d7edc8 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -862,9 +862,8 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge)
char *vlanstr;
unsigned int tag;

- /* 'bridge' string contains a bridge name and single vlan tag */
- vlanstr = strchr(bridge, '.');
- if (vlanstr) {
+ if ((vlanstr = strchr(bridge, '.'))) {
+ /* 'bridge' string contains a bridge name and single vlan tag */
if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge) < 0)
return -1;

@@ -883,11 +882,8 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge)

net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
return 0;
- }
-
- /* 'bridge' string contains a bridge name and one or more vlan trunks */
- vlanstr = strchr(bridge, ':');
- if (vlanstr) {
+ } else if ((vlanstr = strchr(bridge, ':'))) {
+ /* 'bridge' string contains a bridge name and one or more vlan trunks */
size_t i;
size_t nvlans = 0;
char **vlanstr_list = virStringSplit(bridge, ":", 0);
@@ -924,12 +920,12 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge)

net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH;
return 0;
+ } else {
+ /* 'bridge' string only contains the bridge name */
+ if (VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
+ return -1;
}

- /* 'bridge' string only contains the bridge name */
- if (VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
- return -1;
-
return 0;
}

Jim Fehlig
2018-11-16 22:26:26 UTC
Permalink
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 <***@suse.com>
---
src/libxl/libxl_conf.c | 47 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index e2bfa2f5c3..39c969e482 100644
--- a/src/libxl/libxl_conf.c
+++ b/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
@@ -1190,6 +1191,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?
@@ -1247,14 +1253,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:
+ virBufferAsprintf(&buf, "%s", 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);
@@ -1351,6 +1393,7 @@ libxlMakeNic(virDomainDefPtr def,
ret = 0;

cleanup:
+ virBufferFreeAndReset(&buf);
virObjectUnref(network);
virObjectUnref(conn);
--
2.18.0
Michal Privoznik
2018-12-06 07:44:19 UTC
Permalink
Post by Jim Fehlig
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
---
src/libxl/libxl_conf.c | 47 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index e2bfa2f5c3..39c969e482 100644
--- a/src/libxl/libxl_conf.c
+++ b/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
@@ -1190,6 +1191,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?
@@ -1247,14 +1253,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) {
+ virBufferAsprintf(&buf, "%s", virDomainNetGetActualBridgeName(l_nic));
Or virBufferAddStr() or virBufferAdd(,,-1);
Post by Jim Fehlig
+ /*
+ * 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;
- 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);
@@ -1351,6 +1393,7 @@ libxlMakeNic(virDomainDefPtr def,
ret = 0;
+ virBufferFreeAndReset(&buf);
virObjectUnref(network);
virObjectUnref(conn);
Michal
Jim Fehlig
2018-12-06 22:13:55 UTC
Permalink
Post by Michal Privoznik
Post by Jim Fehlig
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
---
src/libxl/libxl_conf.c | 47 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index e2bfa2f5c3..39c969e482 100644
--- a/src/libxl/libxl_conf.c
+++ b/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
@@ -1190,6 +1191,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?
@@ -1247,14 +1253,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) {
+ virBufferAsprintf(&buf, "%s", virDomainNetGetActualBridgeName(l_nic));
Or virBufferAddStr() or virBufferAdd(,,-1);
I recall liking virBufferAddStr() that last time it was recommended :-).

Regards,
Jim
Michal Privoznik
2018-12-06 07:44:20 UTC
Permalink
Patch1 adds support in the driver, patch2 adds support in the
config converter, and it ends with some news...
libxl: support openvswitch interfaces
xenconfig: add support for openvswitch configuration
news: Mention Xen support for openvswitch
docs/news.xml | 10 ++
src/libxl/libxl_conf.c | 47 +++++++-
src/xenconfig/xen_common.c | 113 +++++++++++++++++-
.../test-fullvirt-ovswitch-tagged.cfg | 25 ++++
.../test-fullvirt-ovswitch-tagged.xml | 50 ++++++++
.../test-fullvirt-ovswitch-trunked.cfg | 25 ++++
.../test-fullvirt-ovswitch-trunked.xml | 51 ++++++++
tests/xlconfigtest.c | 2 +
8 files changed, 317 insertions(+), 6 deletions(-)
create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg
create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml
create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-trunked.cfg
create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-trunked.xml
ACK

Michal
Michal Privoznik
2018-12-06 07:44:43 UTC
Permalink
Post by Jim Fehlig
---
docs/news.xml | 10 ++++++++++
1 file changed, 10 insertions(+)
This will need to be rebased, but I guess you already know that.

Michal
Loading...