]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: add libxl_domain_suspend_only to simply suspend a domain, without saving it
authorMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Wed, 4 Apr 2018 17:01:12 +0000 (19:01 +0200)
committerWei Liu <wei.liu2@citrix.com>
Fri, 6 Apr 2018 08:05:25 +0000 (09:05 +0100)
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 <marmarek@invisiblethingslab.com>
Signed-off-by: Marcus of Wetware Labs <marcus@wetwa.re>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxl/libxl.h
tools/libxl/libxl_domain.c

index eea57cac629eee99a640262c247c284f9df17d82..a09d0693589ce27d3aab884b1d73257f9e61d976 100644 (file)
@@ -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.
index 13b1c73d40966d3ef7c2b66984c1b3b6a4b7a3ff..533bcdf240d7c9f013d5a0da6baf966411714e15 100644 (file)
@@ -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;