From: Marek Marczykowski-Górecki Date: Wed, 4 Apr 2018 17:01:12 +0000 (+0200) Subject: libxl: add libxl_domain_suspend_only to simply suspend a domain, without saving it X-Git-Tag: 4.11.0-rc1~57 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9ee6308d5b9d227eba08b7a19fa660e7614e3d32;p=xen.git libxl: add libxl_domain_suspend_only to simply suspend a domain, without saving it Similar functionality to libxl_domain_suspend(), but do not save domains state to any file. Only suspend the domain and keep it in suspended shutdown state (do not destroy it). Such domain can be later woken up with libxl_domain_resume. The main reason for this functionality is to suspend the host while some domains are running, potentially holding PCI devices. This will give a chance to a driver in such a domain to properly suspend the device. Signed-off-by: Marek Marczykowski-Górecki Signed-off-by: Marcus of Wetware Labs Acked-by: Wei Liu --- diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index eea57cac62..a09d069358 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -838,6 +838,14 @@ typedef struct libxl__ctx libxl_ctx; #define LIBXL_HAVE_NO_SUSPEND_RESUME 1 #endif +/* + * LIBXL_HAVE_DOMAIN_SUSPEND_ONLY + * + * If this is defined, function libxl_domains_suspend_only() is available. + */ + +#define LIBXL_HAVE_DOMAIN_SUSPEND_ONLY 1 + /* * LIBXL_HAVE_DEVICE_PCI_SEIZE * @@ -1484,6 +1492,14 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, #define LIBXL_SUSPEND_DEBUG 1 #define LIBXL_SUSPEND_LIVE 2 +/* + * Only suspend domain, do not save its state to file, do not destroy it. + * Suspended domain can be resumed with libxl_domain_resume() + */ +int libxl_domain_suspend_only(libxl_ctx *ctx, uint32_t domid, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* @param suspend_cancel [from xenctrl.h:xc_domain_resume( @param fast )] * If this parameter is true, use co-operative resume. The guest * must support this. diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 13b1c73d40..533bcdf240 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -523,6 +523,40 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags, return AO_CREATE_FAIL(rc); } +static void domain_suspend_empty_cb(libxl__egc *egc, + libxl__domain_suspend_state *dss, int rc) +{ + STATE_AO_GC(dss->ao); + libxl__ao_complete(egc,ao,rc); +} + +int libxl_domain_suspend_only(libxl_ctx *ctx, uint32_t domid, + const libxl_asyncop_how *ao_how) +{ + AO_CREATE(ctx, domid, ao_how); + libxl__domain_suspend_state *dsps; + int rc; + + libxl_domain_type type = libxl__domain_type(gc, domid); + if (type == LIBXL_DOMAIN_TYPE_INVALID) { + rc = ERROR_FAIL; + goto out_err; + } + + GCNEW(dsps); + dsps->ao = ao; + dsps->domid = domid; + dsps->type = type; + rc = libxl__domain_suspend_init(egc, dsps, type); + if (rc < 0) goto out_err; + dsps->callback_common_done = domain_suspend_empty_cb; + libxl__domain_suspend(egc, dsps); + return AO_INPROGRESS; + + out_err: + return AO_CREATE_FAIL(rc); +} + int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid) { int ret;