[PATCH v1 00/12] libxl: bump LIBXL_API_VERSION

Various changes to handle libxl API variants. Olaf Olaf Hering (12): libxl: add API wrapper for libxl_domain_create_restore libxl: add API wrapper for libxl_retrieve_domain_configuration libxl: add API wrapper for libxl_domain_shutdown libxl: add API wrapper for libxl_domain_reboot libxl: add API wrapper for libxl_domain_pause libxl: add API wrapper for libxl_domain_unpause libxl: add API wrapper for libxl_domain_need_memory libxl: add API wrapper for libxl_get_free_memory libxl: add API wrapper for libxl_set_vcpuonline libxl: add API wrapper for libxl_send_trigger libxl: add API wrapper for libxl_set_memory_target libxl: use API 4.13 to support domUs with more than 4TB meson.build | 7 +- src/libxl/libxl_api.h | 219 ++++++++++++++++++++++++++++++++++++ src/libxl/libxl_conf.c | 5 +- src/libxl/libxl_domain.c | 23 ++-- src/libxl/libxl_driver.c | 21 ++-- src/libxl/libxl_migration.c | 3 +- tests/libxlmock.c | 7 +- 7 files changed, 259 insertions(+), 26 deletions(-) create mode 100644 src/libxl/libxl_api.h

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_domain_create_restore, which got a new parameter "send_back_fd" in Xen 4.7. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 44 ++++++++++++++++++++++++++++++++++++++++ src/libxl/libxl_domain.c | 5 +++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/libxl/libxl_api.h diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h new file mode 100644 index 0000000000..64ccd7a428 --- /dev/null +++ b/src/libxl/libxl_api.h @@ -0,0 +1,44 @@ +/* + * libxl_api.h: handle various libxl API variants + * + * Copyright (C) 2021 SUSE LLC + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <libxl.h> + +static inline int +Libxl_Domain_Create_Restore(libxl_ctx *ctx, + libxl_domain_config *d_config, + uint32_t *domid, + int restore_fd, + const libxl_domain_restore_params *params, + const libxl_asyncprogress_how *aop_console_how) +{ + int ret; + +#if LIBXL_API_VERSION < 0x040700 + ret = libxl_domain_create_restore(ctx, d_config, domid, restore_fd, params, + NULL, aop_console_how); +#else + ret = libxl_domain_create_restore(ctx, d_config, domid, restore_fd, -1, + params, NULL, aop_console_how); +#endif + + return ret; +} diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 014f6aceca..2fe1d34e19 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -22,6 +22,7 @@ #include <fcntl.h> +#include "libxl_api.h" #include "libxl_domain.h" #include "libxl_capabilities.h" @@ -1396,8 +1397,8 @@ libxlDomainStart(libxlDriverPrivatePtr driver, #ifdef LIBXL_HAVE_SRM_V2 params.stream_version = restore_ver; #endif - ret = libxl_domain_create_restore(cfg->ctx, &d_config, &domid, - restore_fd, ¶ms, NULL, + ret = Libxl_Domain_Create_Restore(cfg->ctx, &d_config, &domid, + restore_fd, ¶ms, &aop_console_how); libxl_domain_restore_params_dispose(¶ms); }

On 3/17/21 4:57 AM, Olaf Hering wrote:
Upcoming changes will use different LIBXL_API_VERSION variants.
Prepare libxl_domain_create_restore, which got a new parameter "send_back_fd" in Xen 4.7. libvirt does not use this parameter.
No functional change intended.
Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 44 ++++++++++++++++++++++++++++++++++++++++ src/libxl/libxl_domain.c | 5 +++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/libxl/libxl_api.h
diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h new file mode 100644 index 0000000000..64ccd7a428 --- /dev/null +++ b/src/libxl/libxl_api.h
What do you think of a more descriptive name for this file? E.g. libxl_api_quirks.h or libxl_api_wrap.h?
@@ -0,0 +1,44 @@ +/* + * libxl_api.h: handle various libxl API variants
Or maybe libxl_api_variants.h?
+ * + * Copyright (C) 2021 SUSE LLC + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <libxl.h> + +static inline int +Libxl_Domain_Create_Restore(libxl_ctx *ctx,
libvirt doesn't use this format for function names. See 'Function names' under naming conventions https://libvirt.org/coding-style.html#naming-conventions I struggled with naming when toying with this in the past. Maybe libxlDomainCreateRestoreWrap? The 'Wrap' suffix compliments the libxl_api_wrap.h name suggestion. Regards, Jim
+ libxl_domain_config *d_config, + uint32_t *domid, + int restore_fd, + const libxl_domain_restore_params *params, + const libxl_asyncprogress_how *aop_console_how) +{ + int ret; + +#if LIBXL_API_VERSION < 0x040700 + ret = libxl_domain_create_restore(ctx, d_config, domid, restore_fd, params, + NULL, aop_console_how); +#else + ret = libxl_domain_create_restore(ctx, d_config, domid, restore_fd, -1, + params, NULL, aop_console_how); +#endif + + return ret; +} diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 014f6aceca..2fe1d34e19 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -22,6 +22,7 @@
#include <fcntl.h>
+#include "libxl_api.h" #include "libxl_domain.h" #include "libxl_capabilities.h"
@@ -1396,8 +1397,8 @@ libxlDomainStart(libxlDriverPrivatePtr driver, #ifdef LIBXL_HAVE_SRM_V2 params.stream_version = restore_ver; #endif - ret = libxl_domain_create_restore(cfg->ctx, &d_config, &domid, - restore_fd, ¶ms, NULL, + ret = Libxl_Domain_Create_Restore(cfg->ctx, &d_config, &domid, + restore_fd, ¶ms, &aop_console_how); libxl_domain_restore_params_dispose(¶ms); }

Am Thu, 18 Mar 2021 16:26:14 -0600 schrieb Jim Fehlig <jfehlig@suse.com>:
Maybe libxlDomainCreateRestoreWrap? The 'Wrap' suffix compliments the libxl_api_wrap.h name suggestion.
"Naming conventions" does not cover API wrapping. Some of the names are already taken, like libxl_domain_shutdown/libxlDomainShutdown. This is the reason why I just used uppercase for the first letter of the libxl function. I assume virLibxlDomainShutdown may work, because in the end the wrappers are a libvirt thing. Olaf

On 3/18/21 5:00 PM, Olaf Hering wrote:
Am Thu, 18 Mar 2021 16:26:14 -0600 schrieb Jim Fehlig <jfehlig@suse.com>:
Maybe libxlDomainCreateRestoreWrap? The 'Wrap' suffix compliments the libxl_api_wrap.h name suggestion.
"Naming conventions" does not cover API wrapping.
I was referring to the use of '_' in the names. From the coding style doc: "Underscores should not be used in function names". The style doc doesn't dictate the words used to form function names, but does suggest a vir$object$verb$subject pattern.
Some of the names are already taken, like libxl_domain_shutdown/libxlDomainShutdown.
In hindsight I would have probably used the 'vir' prefix in the driver entry points, e.g. virlibxlDomainShutdown (libxl_driver.c), giving some flexibility for driver-internal function naming. There is nothing preventing such change now, other than the future annoyance of backport conflicts.
This is the reason why I just used uppercase for the first letter of the libxl function.
I assume virLibxlDomainShutdown may work, because in the end the wrappers are a libvirt thing.
Unless someone listening has a better idea, I lean towards libxl_api_wrapper.h with function names libxl*Wrapper. Jim

Am Thu, 18 Mar 2021 21:51:18 -0600 schrieb Jim Fehlig <jfehlig@suse.com>:
Unless someone listening has a better idea, I lean towards libxl_api_wrapper.h with function names libxl*Wrapper.
I will rename the header, adjust the two style issues, and use these function names: libxlDomainCreateRestoreWrapper libxlRetrieveDomainConfigurationWrapper libxlDomainShutdownWrapper libxlDomainRebootWrapper libxlDomainPauseWrapper libxlDomainUnpauseWrapper libxlDomainNeedMemoryWrapper libxlGetFreeMemoryWrapper libxlSetVcpuonlineWrapper libxlSendTriggerWrapper libxlSetMemoryTargetWrapper Olaf

On Thu, Mar 18, 2021 at 09:51:18PM -0600, Jim Fehlig wrote:
On 3/18/21 5:00 PM, Olaf Hering wrote:
Am Thu, 18 Mar 2021 16:26:14 -0600 schrieb Jim Fehlig <jfehlig@suse.com>:
Maybe libxlDomainCreateRestoreWrap? The 'Wrap' suffix compliments the libxl_api_wrap.h name suggestion.
"Naming conventions" does not cover API wrapping.
I was referring to the use of '_' in the names. From the coding style doc: "Underscores should not be used in function names". The style doc doesn't dictate the words used to form function names, but does suggest a vir$object$verb$subject pattern.
Some of the names are already taken, like libxl_domain_shutdown/libxlDomainShutdown.
In hindsight I would have probably used the 'vir' prefix in the driver entry points, e.g. virlibxlDomainShutdown (libxl_driver.c), giving some flexibility for driver-internal function naming. There is nothing preventing such change now, other than the future annoyance of backport conflicts.
FWIW, in retrospect, I think we shouldn't have used "libxl" as a naming convention anywhere in libvirt - neither filenames or method names. This is a Xen driver, and libxl is just an impl detail. IOW, I we ought to have just use "virXen" as the method name / typedef prefix, and xen_driver.c as filename, etc. Obviously we avoided this originally to distinguish the new impl from the old XenD, but I think that was a mistake in retrospect, as we optimized for something that was only going to exist for a few further years, as opposed to optimizing for the long term where the libxl impl is the only one. I don't feel strongly about whether you stick with current naming conventions of change it to anything else - just wanted to throw this out there as a option. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 3/22/21 4:28 AM, Daniel P. Berrangé wrote:
On Thu, Mar 18, 2021 at 09:51:18PM -0600, Jim Fehlig wrote:
On 3/18/21 5:00 PM, Olaf Hering wrote:
Am Thu, 18 Mar 2021 16:26:14 -0600 schrieb Jim Fehlig <jfehlig@suse.com>:
Maybe libxlDomainCreateRestoreWrap? The 'Wrap' suffix compliments the libxl_api_wrap.h name suggestion.
"Naming conventions" does not cover API wrapping.
I was referring to the use of '_' in the names. From the coding style doc: "Underscores should not be used in function names". The style doc doesn't dictate the words used to form function names, but does suggest a vir$object$verb$subject pattern.
Some of the names are already taken, like libxl_domain_shutdown/libxlDomainShutdown.
In hindsight I would have probably used the 'vir' prefix in the driver entry points, e.g. virlibxlDomainShutdown (libxl_driver.c), giving some flexibility for driver-internal function naming. There is nothing preventing such change now, other than the future annoyance of backport conflicts.
FWIW, in retrospect, I think we shouldn't have used "libxl" as a naming convention anywhere in libvirt - neither filenames or method names. This is a Xen driver, and libxl is just an impl detail. IOW, I we ought to have just use "virXen" as the method name / typedef prefix, and xen_driver.c as filename, etc.
Agreed. I had a memory lapse about our previous discussions around s/libxl/xen/, e.g. https://listman.redhat.com/archives/libvir-list/2020-May/msg00081.html It would have all come back if I started doing the work. Just thinking about it again reminds me of all the "difficult" places libxl has leaked. I mentioned the build option in above thread, but there's also deployment (/etc/libvirt/libxl*) and runtime (/var/{lib,log,run}/libvirt/libxl*) leakage. If starting on such an adventure I'm not sure where to stop. Handling the deployment/runtime leakages likely requires symlinks, %post{un,trans} hacks, etc. I'd be interested in the basic strategy you (or others) would take if embarking on such adventure :-). Regards, Jim

On Thu, Mar 25, 2021 at 05:54:07PM -0600, Jim Fehlig wrote:
On 3/22/21 4:28 AM, Daniel P. Berrangé wrote:
On Thu, Mar 18, 2021 at 09:51:18PM -0600, Jim Fehlig wrote:
On 3/18/21 5:00 PM, Olaf Hering wrote:
Am Thu, 18 Mar 2021 16:26:14 -0600 schrieb Jim Fehlig <jfehlig@suse.com>:
Maybe libxlDomainCreateRestoreWrap? The 'Wrap' suffix compliments the libxl_api_wrap.h name suggestion.
"Naming conventions" does not cover API wrapping.
I was referring to the use of '_' in the names. From the coding style doc: "Underscores should not be used in function names". The style doc doesn't dictate the words used to form function names, but does suggest a vir$object$verb$subject pattern.
Some of the names are already taken, like libxl_domain_shutdown/libxlDomainShutdown.
In hindsight I would have probably used the 'vir' prefix in the driver entry points, e.g. virlibxlDomainShutdown (libxl_driver.c), giving some flexibility for driver-internal function naming. There is nothing preventing such change now, other than the future annoyance of backport conflicts.
FWIW, in retrospect, I think we shouldn't have used "libxl" as a naming convention anywhere in libvirt - neither filenames or method names. This is a Xen driver, and libxl is just an impl detail. IOW, I we ought to have just use "virXen" as the method name / typedef prefix, and xen_driver.c as filename, etc.
Agreed. I had a memory lapse about our previous discussions around s/libxl/xen/, e.g.
https://listman.redhat.com/archives/libvir-list/2020-May/msg00081.html
It would have all come back if I started doing the work. Just thinking about it again reminds me of all the "difficult" places libxl has leaked. I mentioned the build option in above thread, but there's also deployment (/etc/libvirt/libxl*) and runtime (/var/{lib,log,run}/libvirt/libxl*) leakage. If starting on such an adventure I'm not sure where to stop. Handling the deployment/runtime leakages likely requires symlinks, %post{un,trans} hacks, etc.
I'd be interested in the basic strategy you (or others) would take if embarking on such adventure :-).
We've only done a rename of stuff on disk once IIRC, when we introduced the use of XDG dirs for the session libvirtd instances. In that case we just renamed all the dirs during libvirtd startup IIRC. This of course prevents downgrades entirely. We had to keep the rename logic around for a very long time too. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_retrieve_domain_configuration, which got a new parameter "libxl_asyncop_how" in Xen 4.12. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 16 ++++++++++++++++ src/libxl/libxl_domain.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 64ccd7a428..e985e6d302 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -42,3 +42,19 @@ Libxl_Domain_Create_Restore(libxl_ctx *ctx, return ret; } + +static inline int +Libxl_Retrieve_Domain_Configuration(libxl_ctx *ctx, + uint32_t domid, + libxl_domain_config *d_config) +{ + int ret; + +#if LIBXL_API_VERSION < 0x041300 + ret = libxl_retrieve_domain_configuration(ctx, domid, d_config); +#else + ret = libxl_retrieve_domain_configuration(ctx, domid, d_config, NULL); +#endif + + return ret; +} diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 2fe1d34e19..d970a05f3a 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -572,7 +572,7 @@ libxlDomainShutdownThread(void *opaque) } else if (xl_reason == LIBXL_SHUTDOWN_REASON_SOFT_RESET) { libxlDomainObjPrivatePtr priv = vm->privateData; - if (libxl_retrieve_domain_configuration(cfg->ctx, vm->def->id, + if (Libxl_Retrieve_Domain_Configuration(cfg->ctx, vm->def->id, &d_config) != 0) { VIR_ERROR(_("Failed to retrieve config for VM '%s'. " "Unable to perform soft reset. Destroying VM"),

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_domain_shutdown, which got a new parameter "ao_how" in Xen 4.12. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 14 ++++++++++++++ src/libxl/libxl_driver.c | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index e985e6d302..9a3dcba60c 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -58,3 +58,17 @@ Libxl_Retrieve_Domain_Configuration(libxl_ctx *ctx, return ret; } + +static inline int +Libxl_Domain_Shutdown(libxl_ctx *ctx, uint32_t domid) +{ + int ret; + +#if LIBXL_API_VERSION < 0x041300 + ret = libxl_domain_shutdown(ctx, domid); +#else + ret = libxl_domain_shutdown(ctx, domid, NULL); +#endif + + return ret; +} diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index e3d769b5d9..93db26903c 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -37,6 +37,7 @@ #include "viruuid.h" #include "virhook.h" #include "vircommand.h" +#include "libxl_api.h" #include "libxl_domain.h" #include "libxl_driver.h" #include "libxl_conf.h" @@ -1292,7 +1293,7 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags) goto cleanup; if (flags & VIR_DOMAIN_SHUTDOWN_PARAVIRT) { - ret = libxl_domain_shutdown(cfg->ctx, vm->def->id); + ret = Libxl_Domain_Shutdown(cfg->ctx, vm->def->id); if (ret == 0) goto cleanup;

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_domain_reboot, which got a new parameter "ao_how" in Xen 4.12. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 14 ++++++++++++++ src/libxl/libxl_driver.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 9a3dcba60c..1f09f3f888 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -72,3 +72,17 @@ Libxl_Domain_Shutdown(libxl_ctx *ctx, uint32_t domid) return ret; } + +static inline int +Libxl_Domain_Reboot(libxl_ctx *ctx, uint32_t domid) +{ + int ret; + +#if LIBXL_API_VERSION < 0x041300 + ret = libxl_domain_reboot(ctx, domid); +#else + ret = libxl_domain_reboot(ctx, domid, NULL); +#endif + + return ret; +} diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 93db26903c..1811df8acf 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1356,7 +1356,7 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags) goto cleanup; if (flags & VIR_DOMAIN_REBOOT_PARAVIRT) { - ret = libxl_domain_reboot(cfg->ctx, vm->def->id); + ret = Libxl_Domain_Reboot(cfg->ctx, vm->def->id); if (ret == 0) goto cleanup;

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_domain_pause, which got a new parameter "ao_how" in Xen 4.12. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 14 ++++++++++++++ src/libxl/libxl_driver.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 1f09f3f888..947e0c8d47 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -86,3 +86,17 @@ Libxl_Domain_Reboot(libxl_ctx *ctx, uint32_t domid) return ret; } + +static inline int +Libxl_Domain_Pause(libxl_ctx *ctx, uint32_t domid) +{ + int ret; + +#if LIBXL_API_VERSION < 0x041300 + ret = libxl_domain_pause(ctx, domid); +#else + ret = libxl_domain_pause(ctx, domid, NULL); +#endif + + return ret; +} diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 1811df8acf..929e8195f0 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1185,7 +1185,7 @@ libxlDomainSuspend(virDomainPtr dom) goto endjob; if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) { - if (libxl_domain_pause(cfg->ctx, vm->def->id) != 0) { + if (Libxl_Domain_Pause(cfg->ctx, vm->def->id) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to suspend domain '%d' with libxenlight"), vm->def->id); @@ -2048,7 +2048,7 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags) if (!(flags & VIR_DUMP_LIVE) && virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) { - if (libxl_domain_pause(cfg->ctx, vm->def->id) != 0) { + if (Libxl_Domain_Pause(cfg->ctx, vm->def->id) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Before dumping core, failed to suspend domain '%d'" " with libxenlight"),

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_domain_unpause, which got a new parameter "ao_how" in Xen 4.12. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 14 ++++++++++++++ src/libxl/libxl_domain.c | 4 ++-- src/libxl/libxl_driver.c | 4 ++-- src/libxl/libxl_migration.c | 3 ++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 947e0c8d47..86d2d64b37 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -100,3 +100,17 @@ Libxl_Domain_Pause(libxl_ctx *ctx, uint32_t domid) return ret; } + +static inline int +Libxl_Domain_Unpause(libxl_ctx *ctx, uint32_t domid) +{ + int ret; + +#if LIBXL_API_VERSION < 0x041300 + ret = libxl_domain_unpause(ctx, domid); +#else + ret = libxl_domain_unpause(ctx, domid, NULL); +#endif + + return ret; +} diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index d970a05f3a..6eca7027eb 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -594,7 +594,7 @@ libxlDomainShutdownThread(void *opaque) goto endjob; } libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW); - libxl_domain_unpause(cfg->ctx, vm->def->id); + Libxl_Domain_Unpause(cfg->ctx, vm->def->id); #endif } else { VIR_INFO("Unhandled shutdown_reason %d", xl_reason); @@ -1459,7 +1459,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, goto destroy_dom; if (!start_paused) { - libxl_domain_unpause(cfg->ctx, domid); + Libxl_Domain_Unpause(cfg->ctx, domid); virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED); } else { virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 929e8195f0..2823cdb9d8 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1238,7 +1238,7 @@ libxlDomainResume(virDomainPtr dom) goto endjob; if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) { - if (libxl_domain_unpause(cfg->ctx, vm->def->id) != 0) { + if (Libxl_Domain_Unpause(cfg->ctx, vm->def->id) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to resume domain '%d' with libxenlight"), vm->def->id); @@ -2091,7 +2091,7 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags) unpause: if (virDomainObjIsActive(vm) && paused) { - if (libxl_domain_unpause(cfg->ctx, vm->def->id) != 0) { + if (Libxl_Domain_Unpause(cfg->ctx, vm->def->id) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("After dumping core, failed to resume domain '%d' with" " libxenlight"), vm->def->id); diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index a5a9df98ad..f65f68b839 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -34,6 +34,7 @@ #include "virthread.h" #include "virhook.h" #include "rpc/virnetsocket.h" +#include "libxl_api.h" #include "libxl_domain.h" #include "libxl_driver.h" #include "libxl_conf.h" @@ -1298,7 +1299,7 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn, /* Unpause if requested */ if (!(flags & VIR_MIGRATE_PAUSED)) { - if (libxl_domain_unpause(cfg->ctx, vm->def->id) != 0) { + if (Libxl_Domain_Unpause(cfg->ctx, vm->def->id) != 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Failed to unpause domain")); goto cleanup;

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_domain_need_memory, which changed the storage size of "need_memkb" in Xen 4.8. With Xen 4.12 the libxl_domain_config parameter was changed No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 24 ++++++++++++++++++++++++ src/libxl/libxl_domain.c | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 86d2d64b37..5c1545c3c0 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -114,3 +114,27 @@ Libxl_Domain_Unpause(libxl_ctx *ctx, uint32_t domid) return ret; } + +#define INVALID_DOMID ~0 +static inline int +Libxl_Domain_Need_Memory(libxl_ctx *ctx, + libxl_domain_config *d_config, + uint64_t *need_memkb) +{ + int ret; + +#if LIBXL_API_VERSION < 0x040800 + { + uint32_t val32 = 0; + + ret = libxl_domain_need_memory(ctx, &d_config->b_info, &val32); + *need_memkb = val32; + } +#elif LIBXL_API_VERSION < 0x041300 + ret = libxl_domain_need_memory(ctx, &d_config->b_info, need_memkb); +#else + ret = libxl_domain_need_memory(ctx, d_config, INVALID_DOMID, need_memkb); +#endif + + return ret; +} diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 6eca7027eb..337764b5c7 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1008,13 +1008,13 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm) static int libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) { - uint32_t needed_mem; + uint64_t needed_mem; uint32_t free_mem; int32_t target_mem; int tries = 3; int wait_secs = 10; - if (libxl_domain_need_memory(ctx, &d_config->b_info, &needed_mem) < 0) + if (Libxl_Domain_Need_Memory(ctx, d_config, &needed_mem) < 0) goto error; do {

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_get_free_memory, which changed storage size of parameter "memkb" in Xen 4.8. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 19 +++++++++++++++++++ src/libxl/libxl_conf.c | 5 +++-- src/libxl/libxl_domain.c | 4 ++-- tests/libxlmock.c | 7 ++++++- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 5c1545c3c0..1c13781ae6 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -138,3 +138,22 @@ Libxl_Domain_Need_Memory(libxl_ctx *ctx, return ret; } + +static inline int +Libxl_Get_Free_Memory(libxl_ctx *ctx, uint64_t *memkb) +{ + int ret; + +#if LIBXL_API_VERSION < 0x040800 + { + uint32_t val32 = 0; + + ret = libxl_get_free_memory(ctx, &val32); + *memkb = val32; + } +#else + ret = libxl_get_free_memory(ctx, memkb); +#endif + + return ret; +} diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 4b6a7e6096..74551ff804 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -36,6 +36,7 @@ #include "viruuid.h" #include "vircommand.h" #include "virsocketaddr.h" +#include "libxl_api.h" #include "libxl_domain.h" #include "libxl_conf.h" #include "libxl_utils.h" @@ -1785,7 +1786,7 @@ libxlDriverConfigNew(void) int libxlDriverConfigInit(libxlDriverConfigPtr cfg) { - unsigned int free_mem; + uint64_t free_mem; if (g_mkdir_with_parents(cfg->logDir, 0777) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1817,7 +1818,7 @@ libxlDriverConfigInit(libxlDriverConfigPtr cfg) /* This will fill xenstore info about free and dom0 memory if missing, * should be called before starting first domain */ - if (libxl_get_free_memory(cfg->ctx, &free_mem)) { + if (Libxl_Get_Free_Memory(cfg->ctx, &free_mem)) { VIR_ERROR(_("Unable to configure libxl's memory management parameters")); return -1; } diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 337764b5c7..264a730c6c 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1009,7 +1009,7 @@ static int libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) { uint64_t needed_mem; - uint32_t free_mem; + uint64_t free_mem; int32_t target_mem; int tries = 3; int wait_secs = 10; @@ -1018,7 +1018,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) goto error; do { - if (libxl_get_free_memory(ctx, &free_mem) < 0) + if (Libxl_Get_Free_Memory(ctx, &free_mem) < 0) goto error; if (free_mem >= needed_mem) diff --git a/tests/libxlmock.c b/tests/libxlmock.c index a36ca135f6..7a43f9196b 100644 --- a/tests/libxlmock.c +++ b/tests/libxlmock.c @@ -67,7 +67,12 @@ VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info, VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory, int, 0, libxl_ctx *, ctx, - uint32_t *, memkb); +#if LIBXL_API_VERSION < 0x040800 + uint32_t *, +#else + uint64_t *, +#endif + memkb); VIR_MOCK_STUB_RET_ARGS(xc_interface_close, int, 0,

On 3/17/21 4:57 AM, Olaf Hering wrote:
Upcoming changes will use different LIBXL_API_VERSION variants.
Prepare libxl_get_free_memory, which changed storage size of parameter "memkb" in Xen 4.8.
No functional change intended.
Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 19 +++++++++++++++++++ src/libxl/libxl_conf.c | 5 +++-- src/libxl/libxl_domain.c | 4 ++-- tests/libxlmock.c | 7 ++++++- 4 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 5c1545c3c0..1c13781ae6 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -138,3 +138,22 @@ Libxl_Domain_Need_Memory(libxl_ctx *ctx,
return ret; } + +static inline int +Libxl_Get_Free_Memory(libxl_ctx *ctx, uint64_t *memkb) +{ + int ret; + +#if LIBXL_API_VERSION < 0x040800 + { + uint32_t val32 = 0; + + ret = libxl_get_free_memory(ctx, &val32); + *memkb = val32; + } +#else + ret = libxl_get_free_memory(ctx, memkb); +#endif + + return ret; +} diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 4b6a7e6096..74551ff804 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -36,6 +36,7 @@ #include "viruuid.h" #include "vircommand.h" #include "virsocketaddr.h" +#include "libxl_api.h" #include "libxl_domain.h" #include "libxl_conf.h" #include "libxl_utils.h" @@ -1785,7 +1786,7 @@ libxlDriverConfigNew(void) int libxlDriverConfigInit(libxlDriverConfigPtr cfg) { - unsigned int free_mem; + uint64_t free_mem;
if (g_mkdir_with_parents(cfg->logDir, 0777) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1817,7 +1818,7 @@ libxlDriverConfigInit(libxlDriverConfigPtr cfg)
/* This will fill xenstore info about free and dom0 memory if missing, * should be called before starting first domain */ - if (libxl_get_free_memory(cfg->ctx, &free_mem)) { + if (Libxl_Get_Free_Memory(cfg->ctx, &free_mem)) { VIR_ERROR(_("Unable to configure libxl's memory management parameters")); return -1; } diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 337764b5c7..264a730c6c 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1009,7 +1009,7 @@ static int libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) { uint64_t needed_mem; - uint32_t free_mem; + uint64_t free_mem; int32_t target_mem; int tries = 3; int wait_secs = 10; @@ -1018,7 +1018,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) goto error;
do { - if (libxl_get_free_memory(ctx, &free_mem) < 0) + if (Libxl_Get_Free_Memory(ctx, &free_mem) < 0) goto error;
if (free_mem >= needed_mem) diff --git a/tests/libxlmock.c b/tests/libxlmock.c index a36ca135f6..7a43f9196b 100644 --- a/tests/libxlmock.c +++ b/tests/libxlmock.c @@ -67,7 +67,12 @@ VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info, VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory, int, 0, libxl_ctx *, ctx, - uint32_t *, memkb); +#if LIBXL_API_VERSION < 0x040800 + uint32_t *, +#else + uint64_t *, +#endif + memkb);
Fails syntax-check cppi: /home/jfehlig/virt/gitlab/libvirt/tests/libxlmock.c: line 70: not properly indented cppi: /home/jfehlig/virt/gitlab/libvirt/tests/libxlmock.c: line 72: not properly indented cppi: /home/jfehlig/virt/gitlab/libvirt/tests/libxlmock.c: line 74: not properly indented build-aux/syntax-check.mk: incorrect preprocessor indentation You can install cppi in your build env to catch those. Regards, Jim

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_set_vcpuonline, which got a new parameter "ao_how" in Xen 4.12. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 14 ++++++++++++++ src/libxl/libxl_driver.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 1c13781ae6..415e2cb32c 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -157,3 +157,17 @@ Libxl_Get_Free_Memory(libxl_ctx *ctx, uint64_t *memkb) return ret; } + +static inline int +Libxl_Set_Vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap) +{ + int ret; + +#if LIBXL_API_VERSION < 0x041300 + ret = libxl_set_vcpuonline(ctx, domid, cpumap); +#else + ret = libxl_set_vcpuonline(ctx, domid, cpumap, NULL); +#endif + + return ret; +} diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2823cdb9d8..1d37ae6c89 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2331,7 +2331,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, break; case VIR_DOMAIN_VCPU_LIVE: - if (libxl_set_vcpuonline(cfg->ctx, vm->def->id, &map) != 0) { + if (Libxl_Set_Vcpuonline(cfg->ctx, vm->def->id, &map) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to set vcpus for domain '%d'" " with libxenlight"), vm->def->id); @@ -2342,7 +2342,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, break; case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG: - if (libxl_set_vcpuonline(cfg->ctx, vm->def->id, &map) != 0) { + if (Libxl_Set_Vcpuonline(cfg->ctx, vm->def->id, &map) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to set vcpus for domain '%d'" " with libxenlight"), vm->def->id);

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_send_trigger, which got a new parameter "ao_how" in Xen 4.12. libvirt does not use this parameter. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 17 +++++++++++++++++ src/libxl/libxl_driver.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index 415e2cb32c..c7174f5133 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -171,3 +171,20 @@ Libxl_Set_Vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap) return ret; } + +static inline int +Libxl_Send_Trigger(libxl_ctx *ctx, + uint32_t domid, + libxl_trigger trigger, + uint32_t vcpuid) +{ + int ret; + +#if LIBXL_API_VERSION < 0x041300 + ret = libxl_send_trigger(ctx, domid, trigger, vcpuid); +#else + ret = libxl_send_trigger(ctx, domid, trigger, vcpuid, NULL); +#endif + + return ret; +} diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 1d37ae6c89..cf3a2d9775 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1308,7 +1308,7 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags) } if (flags & VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN) { - ret = libxl_send_trigger(cfg->ctx, vm->def->id, + ret = Libxl_Send_Trigger(cfg->ctx, vm->def->id, LIBXL_TRIGGER_POWER, 0); if (ret == 0) goto cleanup;

Upcoming changes will use different LIBXL_API_VERSION variants. Prepare libxl_set_memory_target, which changed the storage size of parameter "target_memkb" in Xen 4.8. No functional change intended. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 29 +++++++++++++++++++++++++++++ src/libxl/libxl_domain.c | 4 ++-- src/libxl/libxl_driver.c | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index c7174f5133..1507dbd38e 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -20,6 +20,7 @@ #pragma once +#include <limits.h> #include <libxl.h> static inline int @@ -188,3 +189,31 @@ Libxl_Send_Trigger(libxl_ctx *ctx, return ret; } + +static inline int +Libxl_Set_Memory_Target(libxl_ctx *ctx, + uint32_t domid, + uint64_t target_memkb, + int relative, + int enforce) +{ + int ret = -1; + + /* Technically this guard could be LIBXL_HAVE_MEMKB_64BITS */ +#if LIBXL_API_VERSION < 0x040800 + if (target_memkb < UINT_MAX) + { + uint32_t val32 = target_memkb; + + ret = libxl_set_memory_target(ctx, domid, val32, relative, enforce); + } +#else + if (target_memkb < LLONG_MAX) + { + int64_t val64 = target_memkb; + ret = libxl_set_memory_target(ctx, domid, val64, relative, enforce); + } +#endif + + return ret; +} diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 264a730c6c..0b0c3865fa 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1010,7 +1010,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) { uint64_t needed_mem; uint64_t free_mem; - int32_t target_mem; + uint64_t target_mem; int tries = 3; int wait_secs = 10; @@ -1025,7 +1025,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) return 0; target_mem = free_mem - needed_mem; - if (libxl_set_memory_target(ctx, 0, target_mem, + if (Libxl_Set_Memory_Target(ctx, 0, target_mem, /* relative */ 1, 0) < 0) goto error; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index cf3a2d9775..97aed9949d 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1695,7 +1695,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, /* Unlock virDomainObj while ballooning memory */ virObjectUnlock(vm); - res = libxl_set_memory_target(cfg->ctx, vm->def->id, newmem, 0, + res = Libxl_Set_Memory_Target(cfg->ctx, vm->def->id, newmem, 0, /* force */ 1); virObjectLock(vm); if (res < 0) {

On 3/17/21 4:57 AM, Olaf Hering wrote:
Upcoming changes will use different LIBXL_API_VERSION variants.
Prepare libxl_set_memory_target, which changed the storage size of parameter "target_memkb" in Xen 4.8.
No functional change intended.
Signed-off-by: Olaf Hering <olaf@aepfle.de> --- src/libxl/libxl_api.h | 29 +++++++++++++++++++++++++++++ src/libxl/libxl_domain.c | 4 ++-- src/libxl/libxl_driver.c | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h index c7174f5133..1507dbd38e 100644 --- a/src/libxl/libxl_api.h +++ b/src/libxl/libxl_api.h @@ -20,6 +20,7 @@
#pragma once
+#include <limits.h> #include <libxl.h>
static inline int @@ -188,3 +189,31 @@ Libxl_Send_Trigger(libxl_ctx *ctx,
return ret; } + +static inline int +Libxl_Set_Memory_Target(libxl_ctx *ctx, + uint32_t domid, + uint64_t target_memkb, + int relative, + int enforce) +{ + int ret = -1; + + /* Technically this guard could be LIBXL_HAVE_MEMKB_64BITS */ +#if LIBXL_API_VERSION < 0x040800 + if (target_memkb < UINT_MAX) + {
Here
+ uint32_t val32 = target_memkb; + + ret = libxl_set_memory_target(ctx, domid, val32, relative, enforce); + } +#else + if (target_memkb < LLONG_MAX) + {
and here fail syntax-check make: Entering directory '/home/jfehlig/virt/gitlab/libvirt/build/build-aux' curly_braces_style /home/jfehlig/virt/gitlab/libvirt/src/libxl/libxl_api.h-205- { /home/jfehlig/virt/gitlab/libvirt/src/libxl/libxl_api.h-212- { Regards, Jim
+ int64_t val64 = target_memkb; + ret = libxl_set_memory_target(ctx, domid, val64, relative, enforce); + } +#endif + + return ret; +} diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 264a730c6c..0b0c3865fa 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1010,7 +1010,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) { uint64_t needed_mem; uint64_t free_mem; - int32_t target_mem; + uint64_t target_mem; int tries = 3; int wait_secs = 10;
@@ -1025,7 +1025,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) return 0;
target_mem = free_mem - needed_mem; - if (libxl_set_memory_target(ctx, 0, target_mem, + if (Libxl_Set_Memory_Target(ctx, 0, target_mem, /* relative */ 1, 0) < 0) goto error;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index cf3a2d9775..97aed9949d 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1695,7 +1695,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
/* Unlock virDomainObj while ballooning memory */ virObjectUnlock(vm); - res = libxl_set_memory_target(cfg->ctx, vm->def->id, newmem, 0, + res = Libxl_Set_Memory_Target(cfg->ctx, vm->def->id, newmem, 0, /* force */ 1); virObjectLock(vm); if (res < 0) {

To support domUs with more than 4TB memory it is required to use LIBXL_API_VERSION >= 0x040800, which uses uint64_t for certained guest memory related quantities. Unfortunately this change is not straight forward. While most of the code in libxl.h handles the various LIBXL_API_VERSION variants correctly, the check for valid a LIBXL_API_VERSION at the beginning of the file was broken between Xen 4.7 and 4.13 - it did not cover for API changes introduced in Xen 4.7 and 4.8. This was fixed with xen-project/xen@c3999835df, which for libvirt means in practice either the libxl API from Xen 4.5 or 4.13+ can be used. This change uses pkgconfig to decide which API can be safely selected. Xen provides a pkgconfig file since Xen 4.6, which is also the lowest version expected by libvirt. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- meson.build | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index ea93a2a8ec..d246886cbf 100644 --- a/meson.build +++ b/meson.build @@ -1592,8 +1592,13 @@ if not get_option('driver_libxl').disabled() and conf.has('WITH_LIBVIRTD') xtl_link_dep = cc.find_library('xenctrl') endif + if libxl_dep.version().version_compare('>=4.13.0') + LIBXL_API_VERSION='0x041300' + else + LIBXL_API_VERSION='0x040500' + endif libxl_dep = declare_dependency( - compile_args: '-DLIBXL_API_VERSION=0x040500', + compile_args: '-DLIBXL_API_VERSION=' + LIBXL_API_VERSION, dependencies: [ libxl_dep, xtl_link_dep,

On 3/17/21 4:57 AM, Olaf Hering wrote:
Various changes to handle libxl API variants.
Thanks for taking this on! It is much simpler than the crap I've cooked up in the past. I haven't taken another stab since we've moved to meson, and I'd like to blame autotools, but... We'll need to sort out the naming I mentioned in patch 1, which will affect the others. I also pointed out a few small problems in patches 8 and 11, but otherwise looking good! Regards, Jim
Olaf
Olaf Hering (12): libxl: add API wrapper for libxl_domain_create_restore libxl: add API wrapper for libxl_retrieve_domain_configuration libxl: add API wrapper for libxl_domain_shutdown libxl: add API wrapper for libxl_domain_reboot libxl: add API wrapper for libxl_domain_pause libxl: add API wrapper for libxl_domain_unpause libxl: add API wrapper for libxl_domain_need_memory libxl: add API wrapper for libxl_get_free_memory libxl: add API wrapper for libxl_set_vcpuonline libxl: add API wrapper for libxl_send_trigger libxl: add API wrapper for libxl_set_memory_target libxl: use API 4.13 to support domUs with more than 4TB
meson.build | 7 +- src/libxl/libxl_api.h | 219 ++++++++++++++++++++++++++++++++++++ src/libxl/libxl_conf.c | 5 +- src/libxl/libxl_domain.c | 23 ++-- src/libxl/libxl_driver.c | 21 ++-- src/libxl/libxl_migration.c | 3 +- tests/libxlmock.c | 7 +- 7 files changed, 259 insertions(+), 26 deletions(-) create mode 100644 src/libxl/libxl_api.h
participants (3)
-
Daniel P. Berrangé
-
Jim Fehlig
-
Olaf Hering