diff mbox series

[12/35] libxl: Re-introduce libxl__domain_unpause

Message ID 20190802153606.32061-13-anthony.perard@citrix.com (mailing list archive)
State Superseded
Headers show
Series libxl refactoring to use ev_qmp (with API changes) | expand

Commit Message

Anthony PERARD Aug. 2, 2019, 3:35 p.m. UTC
libxl__domain_unpause is a reimplementation of
libxl__domain_unpause_deprecated with asynchronous operation.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libxl/libxl_domain.c   | 52 ++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  5 +++-
 2 files changed, 56 insertions(+), 1 deletion(-)

Comments

Ian Jackson Sept. 17, 2019, 5:05 p.m. UTC | #1
Anthony PERARD writes ("[PATCH 12/35] libxl: Re-introduce libxl__domain_unpause"):
> libxl__domain_unpause is a reimplementation of
> libxl__domain_unpause_deprecated with asynchronous operation.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
diff mbox series

Patch

diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c
index d78ffa6b60..52a8bd7895 100644
--- a/tools/libxl/libxl_domain.c
+++ b/tools/libxl/libxl_domain.c
@@ -639,6 +639,58 @@  int libxl__domain_unpause_deprecated(libxl__gc *gc, libxl_domid domid)
     return rc;
 }
 
+static void domain_unpause_done(libxl__egc *egc,
+                                libxl__dm_resume_state *,
+                                int rc);
+
+void libxl__domain_unpause(libxl__egc *egc,
+                           libxl__dm_resume_state *dmrs)
+{
+    STATE_AO_GC(dmrs->ao);
+    int rc = 0;
+
+    /* Convenience aliases */
+    libxl_domid domid = dmrs->domid;
+
+    libxl_domain_type type = libxl__domain_type(gc, domid);
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (type == LIBXL_DOMAIN_TYPE_HVM) {
+        dmrs->dm_resumed_callback = domain_unpause_done;
+        libxl__dm_resume(egc, dmrs); /* must be last */
+        return;
+    }
+    rc = 0;
+out:
+    domain_unpause_done(egc, dmrs, rc);
+}
+
+static void domain_unpause_done(libxl__egc *egc,
+                                libxl__dm_resume_state *dmrs,
+                                int rc)
+{
+    EGC_GC;
+    int r;
+
+    /* Convenience aliases */
+    libxl_domid domid = dmrs->domid;
+
+    if (rc) goto out;
+
+    r = xc_domain_unpause(CTX->xch, domid);
+    if (r < 0) {
+        LOGED(ERROR, domid, "Unpausing domain");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    rc = 0;
+out:
+    dmrs->callback(egc, dmrs, rc);
+}
+
 int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid,
                          const libxl_asyncop_how *ao_how)
 {
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index bdc9677527..1cfe3cf83f 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1350,9 +1350,10 @@  struct libxl__dm_resume_state {
     libxl_domid domid;
     void (*callback)(libxl__egc *, libxl__dm_resume_state *, int rc);
 
-    /* private to libxl__domain_resume */
+    /* private to libxl__domain_resume and libxl__domain_unpause */
     void (*dm_resumed_callback)(libxl__egc *,
                                 libxl__dm_resume_state *, int rc);
+    /* private to libxl__domain_resume */
     bool suspend_cancel;
 
     /* private to libxl__dm_resume */
@@ -1365,6 +1366,8 @@  _hidden void libxl__dm_resume(libxl__egc *egc,
 _hidden void libxl__domain_resume(libxl__egc *egc,
                                   libxl__dm_resume_state *dmrs,
                                   bool suspend_cancel);
+_hidden void libxl__domain_unpause(libxl__egc *,
+                                   libxl__dm_resume_state *dmrs);
 
 /* returns 0 or 1, or a libxl error code */
 _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);