[libvirt] [PATCH 1/2] libxl: add support for multiple IP addresses
vif-* scripts support it for a long time, and expect addresses to be separated by spaces. Add appropriate support to libxl driver. --- src/libxl/libxl_conf.c | 29 +++++++++++++++++++++++++++-- src/libxl/libxl_domain.c | 12 ------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 2a9be69..f84ffc6 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1067,6 +1067,31 @@ libxlUpdateDiskDef(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk) ignore_value(virDomainDiskSetDriver(l_disk, driver)); } +static char * +libxlMakeIPList(virNetDevIPInfoPtr guestIP) +{ + size_t i; + char **address_array; + char *ret = NULL; + + if (VIR_ALLOC_N(address_array, guestIP->nips + 1) < 0) + return NULL; + + for (i = 0; i < guestIP->nips; i++) { + address_array[i] = virSocketAddrFormat(&guestIP->ips[i]->address); + if (!address_array[i]) + goto cleanup; + } + address_array[guestIP->nips] = NULL; + + ret = virStringListJoin((const char**)address_array, " "); + + cleanup: + while (i > 0) + VIR_FREE(address_array[--i]); + return ret; +} + int libxlMakeNic(virDomainDefPtr def, virDomainNetDefPtr l_nic, @@ -1144,7 +1169,7 @@ libxlMakeNic(virDomainDefPtr def, if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) goto cleanup; if (l_nic->guestIP.nips > 0) { - x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address); + x_nic->ip = libxlMakeIPList(&l_nic->guestIP); if (!x_nic->ip) goto cleanup; } @@ -1160,7 +1185,7 @@ libxlMakeNic(virDomainDefPtr def, } if (l_nic->guestIP.nips > 0) { - x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address); + x_nic->ip = libxlMakeIPList(&l_nic->guestIP); if (!x_nic->ip) goto cleanup; } diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index d054b07..395c8a9 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -294,18 +294,6 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, def->os.type != VIR_DOMAIN_OSTYPE_HVM) dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN; - if (dev->type == VIR_DOMAIN_DEVICE_NET && - (dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE || - dev->data.net->type == VIR_DOMAIN_NET_TYPE_ETHERNET || - dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK)) { - if (dev->data.net->guestIP.nips > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("multiple IP addresses not supported on device type %s"), - virDomainNetTypeToString(dev->data.net->type)); - return -1; - } - } - if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV || (dev->type == VIR_DOMAIN_DEVICE_NET && dev->data.net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)) { base-commit: 9f0ccc717ba9026c30ce38951a354dd66fa12e3b -- git-series 0.9.1
--- tests/libxlxml2domconfigdata/multiple-ip.json | 37 ++++++++++++++++++++- tests/libxlxml2domconfigdata/multiple-ip.xml | 22 ++++++++++++- tests/libxlxml2domconfigtest.c | 1 +- 3 files changed, 60 insertions(+) create mode 100644 tests/libxlxml2domconfigdata/multiple-ip.json create mode 100644 tests/libxlxml2domconfigdata/multiple-ip.xml diff --git a/tests/libxlxml2domconfigdata/multiple-ip.json b/tests/libxlxml2domconfigdata/multiple-ip.json new file mode 100644 index 0000000..4aff61d --- /dev/null +++ b/tests/libxlxml2domconfigdata/multiple-ip.json @@ -0,0 +1,37 @@ +{ + "c_info": { + "type": "pv", + "name": "test-pv", + "uuid": "039e9ee6-4a84-3055-4c81-8ba426ae2656" + }, + "b_info": { + "max_vcpus": 4, + "avail_vcpus": [ + 0, + 1, + 2, + 3 + ], + "max_memkb": 524288, + "target_memkb": 524288, + "sched_params": { + "weight": 1000 + }, + "type.pv": { + "bootloader": "pygrub" + }, + "arch_arm": { + + } + }, + "nics": [ + { + "devid": 0, + "mac": "00:16:3e:3e:86:60", + "ip": "10.0.0.1 2000:abcd::1", + "script": "/etc/xen/scripts/vif-bridge", + "nictype": "vif" + } + ], + "on_reboot": "restart" +} diff --git a/tests/libxlxml2domconfigdata/multiple-ip.xml b/tests/libxlxml2domconfigdata/multiple-ip.xml new file mode 100644 index 0000000..5188935 --- /dev/null +++ b/tests/libxlxml2domconfigdata/multiple-ip.xml @@ -0,0 +1,22 @@ +<domain type='xen'> + <name>test-pv</name> + <uuid>039e9ee6-4a84-3055-4c81-8ba426ae2656</uuid> + <memory>524288</memory> + <currentMemory>524288</currentMemory> + <vcpu>4</vcpu> + <os> + <type arch='x86_64' machine='xenpv'>linux</type> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <interface type='ethernet'> + <ip address='10.0.0.1' family='ipv4'/> + <ip address='2000:abcd::1' family='ipv6'/> + <mac address='00:16:3e:3e:86:60'/> + <script path='/etc/xen/scripts/vif-bridge'/> + </interface> + </devices> +</domain> diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index c8379f1..bd4c3af 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -190,6 +190,7 @@ mymain(void) DO_TEST("basic-hvm"); DO_TEST("moredevs-hvm"); DO_TEST("vnuma-hvm"); + DO_TEST("multiple-ip"); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- git-series 0.9.1
On 12/02/2017 07:35 PM, Marek Marczykowski-Górecki wrote:
--- tests/libxlxml2domconfigdata/multiple-ip.json | 37 ++++++++++++++++++++- tests/libxlxml2domconfigdata/multiple-ip.xml | 22 ++++++++++++- tests/libxlxml2domconfigtest.c | 1 +- 3 files changed, 60 insertions(+) create mode 100644 tests/libxlxml2domconfigdata/multiple-ip.json create mode 100644 tests/libxlxml2domconfigdata/multiple-ip.xml
Reviewed-by: Jim Fehlig <jfehlig@suse.com> Regards, Jim
diff --git a/tests/libxlxml2domconfigdata/multiple-ip.json b/tests/libxlxml2domconfigdata/multiple-ip.json new file mode 100644 index 0000000..4aff61d --- /dev/null +++ b/tests/libxlxml2domconfigdata/multiple-ip.json @@ -0,0 +1,37 @@ +{ + "c_info": { + "type": "pv", + "name": "test-pv", + "uuid": "039e9ee6-4a84-3055-4c81-8ba426ae2656" + }, + "b_info": { + "max_vcpus": 4, + "avail_vcpus": [ + 0, + 1, + 2, + 3 + ], + "max_memkb": 524288, + "target_memkb": 524288, + "sched_params": { + "weight": 1000 + }, + "type.pv": { + "bootloader": "pygrub" + }, + "arch_arm": { + + } + }, + "nics": [ + { + "devid": 0, + "mac": "00:16:3e:3e:86:60", + "ip": "10.0.0.1 2000:abcd::1", + "script": "/etc/xen/scripts/vif-bridge", + "nictype": "vif" + } + ], + "on_reboot": "restart" +} diff --git a/tests/libxlxml2domconfigdata/multiple-ip.xml b/tests/libxlxml2domconfigdata/multiple-ip.xml new file mode 100644 index 0000000..5188935 --- /dev/null +++ b/tests/libxlxml2domconfigdata/multiple-ip.xml @@ -0,0 +1,22 @@ +<domain type='xen'> + <name>test-pv</name> + <uuid>039e9ee6-4a84-3055-4c81-8ba426ae2656</uuid> + <memory>524288</memory> + <currentMemory>524288</currentMemory> + <vcpu>4</vcpu> + <os> + <type arch='x86_64' machine='xenpv'>linux</type> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <interface type='ethernet'> + <ip address='10.0.0.1' family='ipv4'/> + <ip address='2000:abcd::1' family='ipv6'/> + <mac address='00:16:3e:3e:86:60'/> + <script path='/etc/xen/scripts/vif-bridge'/> + </interface> + </devices> +</domain> diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index c8379f1..bd4c3af 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -190,6 +190,7 @@ mymain(void) DO_TEST("basic-hvm"); DO_TEST("moredevs-hvm"); DO_TEST("vnuma-hvm"); + DO_TEST("multiple-ip");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
On 12/02/2017 07:35 PM, Marek Marczykowski-Górecki wrote:
vif-* scripts support it for a long time, and expect addresses to be separated by spaces. Add appropriate support to libxl driver. --- src/libxl/libxl_conf.c | 29 +++++++++++++++++++++++++++-- src/libxl/libxl_domain.c | 12 ------------ 2 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 2a9be69..f84ffc6 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1067,6 +1067,31 @@ libxlUpdateDiskDef(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk) ignore_value(virDomainDiskSetDriver(l_disk, driver)); }
+static char * +libxlMakeIPList(virNetDevIPInfoPtr guestIP) +{ + size_t i; + char **address_array; + char *ret = NULL; + + if (VIR_ALLOC_N(address_array, guestIP->nips + 1) < 0) + return NULL; + + for (i = 0; i < guestIP->nips; i++) { + address_array[i] = virSocketAddrFormat(&guestIP->ips[i]->address); + if (!address_array[i]) + goto cleanup; + } + address_array[guestIP->nips] = NULL; + + ret = virStringListJoin((const char**)address_array, " "); + + cleanup: + while (i > 0) + VIR_FREE(address_array[--i]); + return ret; +} + int libxlMakeNic(virDomainDefPtr def, virDomainNetDefPtr l_nic, @@ -1144,7 +1169,7 @@ libxlMakeNic(virDomainDefPtr def, if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) goto cleanup; if (l_nic->guestIP.nips > 0) { - x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address); + x_nic->ip = libxlMakeIPList(&l_nic->guestIP); if (!x_nic->ip) goto cleanup; } @@ -1160,7 +1185,7 @@ libxlMakeNic(virDomainDefPtr def, }
if (l_nic->guestIP.nips > 0) { - x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address); + x_nic->ip = libxlMakeIPList(&l_nic->guestIP); if (!x_nic->ip) goto cleanup; } diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index d054b07..395c8a9 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -294,18 +294,6 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, def->os.type != VIR_DOMAIN_OSTYPE_HVM) dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
- if (dev->type == VIR_DOMAIN_DEVICE_NET && - (dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE || - dev->data.net->type == VIR_DOMAIN_NET_TYPE_ETHERNET || - dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK)) { - if (dev->data.net->guestIP.nips > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("multiple IP addresses not supported on device type %s"), - virDomainNetTypeToString(dev->data.net->type)); - return -1; - } - } -
There's another instance of this check in xenFormatNet() in src/xenconfig/xen_common.c. I suppose multiple IP addrs are not supported in xml <-> xl.cfg conversions. Do you have time to fix the config converter too? Reviewed-by: Jim Fehlig <jfehlig@suse.com> Regards, Jim
On Mon, Dec 04, 2017 at 02:46:58PM -0700, Jim Fehlig wrote:
There's another instance of this check in xenFormatNet() in src/xenconfig/xen_common.c. I suppose multiple IP addrs are not supported in xml <-> xl.cfg conversions. Do you have time to fix the config converter too?
Where should I put helper function to not duplicate it across those two drivers? -- Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
On 12/04/2017 02:53 PM, Marek Marczykowski-Górecki wrote:
On Mon, Dec 04, 2017 at 02:46:58PM -0700, Jim Fehlig wrote:
There's another instance of this check in xenFormatNet() in src/xenconfig/xen_common.c. I suppose multiple IP addrs are not supported in xml <-> xl.cfg conversions. Do you have time to fix the config converter too?
Where should I put helper function to not duplicate it across those two drivers?
Would there be duplicate code? The two serve different purposes. xenconfig converts libvirt domXML to/from the various Xen config formats (xl, xm, sexpr). The libxl driver maps virDomainDef to libxl_domain_config. Regards, Jim
On Mon, Dec 04, 2017 at 03:14:33PM -0700, Jim Fehlig wrote:
On 12/04/2017 02:53 PM, Marek Marczykowski-Górecki wrote:
On Mon, Dec 04, 2017 at 02:46:58PM -0700, Jim Fehlig wrote:
There's another instance of this check in xenFormatNet() in src/xenconfig/xen_common.c. I suppose multiple IP addrs are not supported in xml <-> xl.cfg conversions. Do you have time to fix the config converter too?
Where should I put helper function to not duplicate it across those two drivers?
Would there be duplicate code? The two serve different purposes. xenconfig converts libvirt domXML to/from the various Xen config formats (xl, xm, sexpr). The libxl driver maps virDomainDef to libxl_domain_config.
In both cases I need a function that makes a space-separated list of IP addresses, out of virNetDevIPInfo struct. But the same question applies also to a loong waiting cpuid patch series (there: preparing libxl cpuid features string)... -- Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
On 12/04/2017 03:27 PM, Marek Marczykowski-Górecki wrote:
On Mon, Dec 04, 2017 at 03:14:33PM -0700, Jim Fehlig wrote:
On 12/04/2017 02:53 PM, Marek Marczykowski-Górecki wrote:
On Mon, Dec 04, 2017 at 02:46:58PM -0700, Jim Fehlig wrote:
There's another instance of this check in xenFormatNet() in src/xenconfig/xen_common.c. I suppose multiple IP addrs are not supported in xml <-> xl.cfg conversions. Do you have time to fix the config converter too?
Where should I put helper function to not duplicate it across those two drivers?
Would there be duplicate code? The two serve different purposes. xenconfig converts libvirt domXML to/from the various Xen config formats (xl, xm, sexpr). The libxl driver maps virDomainDef to libxl_domain_config.
In both cases I need a function that makes a space-separated list of IP addresses, out of virNetDevIPInfo struct.
Given the current contents of src/xenconfig/xen_common.{ch}, I suppose it is the best fit. The contents of src/xenconfig can be folded into src/libxl once the old xend driver is removed, making this a bit cleaner.
But the same question applies also to a loong waiting cpuid patch series (there: preparing libxl cpuid features string)...
Heh, I was going to ask you about that series :-). Sorry, I didn't realize you were waiting on me. At any rate, same answer as above. Will you be rebasing and resubmitting it? Regards, Jim
participants (2)
-
Jim Fehlig -
Marek Marczykowski-Górecki