Skip to contentSkip to conversation

libxl: wait for the ack when issuing power control requests

PATCH In review Roger Pau Monne 5 participants 7 messages Oct 1, 2019 – Oct 2, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libxl: wait for the ack when issuing power control requests

Currently only suspend power control requests wait for an ack from the domain, while power off or reboot requests simply write the command to xenstore and exit.

Introduce a 1 minute wait for the domain to acknowledge the request, or else return an error. The suspend code is slightly modified to use the new infrastructure added, but shouldn't have any functional change.

Fix the ocaml bindings and also provide a backwards compatible interface for the reboot and poweroff libxl API functions.

---
I believe applying this patch is not going to cause regressions in osstest, albeit FreeBSD doesn't acknowledge poweroff/reboot requests in the currently tested versions, it will shutdown in less than one minute, and thus the toolstack won't complain because the control node is going to be removed from xenstore.
---
Changes since v1:
- Expand LIBXL_HAVE_FN_USING_QMP_ASYNC comment to include reboot/poweroff functions.
- Check return value of libxl__xswait_start.
- Change position of pvcontrol_cb to be in chronological order.
- Use rc instead of ret in libxl_domain_{shutdown/poweroff}.
- Fix prototypes in xenlight.{mli/ml}.in.

---
 tools/libxl/libxl.h                  | 25 +++++++-
 tools/libxl/libxl_dom_suspend.c      | 11 +---
 tools/libxl/libxl_domain.c           | 88 ++++++++++++++++++++--------
 tools/libxl/libxl_internal.h         |  7 ++-
 tools/ocaml/libs/xl/xenlight.ml.in   |  4 +-
 tools/ocaml/libs/xl/xenlight.mli.in  |  4 +-
 tools/ocaml/libs/xl/xenlight_stubs.c | 18 ++++--
 tools/xl/xl_vmcontrol.c              |  4 +-
 8 files changed, 114 insertions(+), 47 deletions(-)
tools/libxl/libxl.h +23 -2
index f711cfc750..2555e9cd3b 100644
@@ -1239,6 +1239,8 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);
  *   libxl_set_vcpuonline()
  *   libxl_retrieve_domain_configuration()
  *   libxl_qemu_monitor_command()
+ *   libxl_domain_shutdown()
+ *   libxl_domain_reboot()
  */
 #define LIBXL_HAVE_FN_USING_QMP_ASYNC 1
 
@@ -1628,8 +1630,27 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
                              const libxl_asyncop_how *ao_how)
                              LIBXL_EXTERNAL_CALLERS_ONLY;
 
-int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid);
-int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid);
+int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid,
+                          const libxl_asyncop_how *ao_how)
+                          LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid,
+                        const libxl_asyncop_how *ao_how)
+                        LIBXL_EXTERNAL_CALLERS_ONLY;
+#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
+static inline int libxl_domain_shutdown_0x041200(libxl_ctx *ctx,
+                                                 uint32_t domid)
+{
+    return libxl_domain_shutdown(ctx, domid, NULL);
+}
+#define libxl_domain_shutdown libxl_domain_shutdown_0x041200
+static inline int libxl_domain_reboot_0x041200(libxl_ctx *ctx,
+                                               uint32_t domid)
+{
+    return libxl_domain_reboot(ctx, domid, NULL);
+}
+#define libxl_domain_reboot libxl_domain_reboot_0x041200
+#endif
+
 int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
                          const libxl_asyncop_how *ao_how)
                          LIBXL_EXTERNAL_CALLERS_ONLY;
tools/libxl/libxl_dom_suspend.c +3 -8
index 9bb2d00bec..248dbc33e3 100644
@@ -193,16 +193,11 @@ static void domain_suspend_callback_common(libxl__egc *egc,
     LOGD(DEBUG, domid, "issuing %s suspend request via XenBus control node",
         dsps->type != LIBXL_DOMAIN_TYPE_PV ? "PVH/HVM" : "PV");
 
-    libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, "suspend");
-
-    dsps->pvcontrol.path = libxl__domain_pvcontrol_xspath(gc, domid);
-    if (!dsps->pvcontrol.path) { rc = ERROR_FAIL; goto err; }
-
     dsps->pvcontrol.ao = ao;
-    dsps->pvcontrol.what = "guest acknowledgement of suspend request";
-    dsps->pvcontrol.timeout_ms = 60 * 1000;
     dsps->pvcontrol.callback = domain_suspend_common_pvcontrol_suspending;
-    libxl__xswait_start(gc, &dsps->pvcontrol);
+    rc = libxl__domain_pvcontrol(egc, &dsps->pvcontrol, domid, "suspend");
+    if (rc) goto err;
+
     return;
 
  err:
tools/libxl/libxl_domain.c +65 -23

114 lines not on this page · raw message

tools/libxl/libxl_internal.h +5 -2
index bfeb38e0ed..d2d5af746b 100644
@@ -1378,8 +1378,6 @@ _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);
 _hidden const char *libxl__domain_pvcontrol_xspath(libxl__gc*, uint32_t domid);
 _hidden char * libxl__domain_pvcontrol_read(libxl__gc *gc,
                                             xs_transaction_t t, uint32_t domid);
-_hidden int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
-                                          uint32_t domid, const char *cmd);
 
 /* from xl_device */
 _hidden char *libxl__device_disk_string_of_backend(libxl_disk_backend backend);
@@ -4719,6 +4717,11 @@ _hidden void libxl__ev_devlock_init(libxl__ev_devlock *);
 _hidden void libxl__ev_devlock_lock(libxl__egc *, libxl__ev_devlock *);
 _hidden void libxl__ev_devlock_unlock(libxl__gc *, libxl__ev_devlock *);
 
+/* Send control commands over xenstore and wait for an Ack. */
+_hidden int libxl__domain_pvcontrol(libxl__egc *egc,
+                                    libxl__xswait_state *pvcontrol,
+                                    domid_t domid, const char *cmd);
+
 #endif
 
 /*
tools/ocaml/libs/xl/xenlight.ml.in +2 -2
index 954e56fc74..6989bb6638 100644
@@ -37,8 +37,8 @@ module Domain = struct
 	external create_new : ctx -> Domain_config.t -> ?async:'a -> unit -> domid = "stub_libxl_domain_create_new"
 	external create_restore : ctx -> Domain_config.t -> (Unix.file_descr * Domain_restore_params.t) ->
 		?async:'a -> unit -> domid = "stub_libxl_domain_create_restore"
-	external shutdown : ctx -> domid -> unit = "stub_libxl_domain_shutdown"
-	external reboot : ctx -> domid -> unit = "stub_libxl_domain_reboot"
+	external shutdown : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_shutdown"
+	external reboot : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_reboot"
 	external destroy : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_destroy"
 	external suspend : ctx -> domid -> Unix.file_descr -> ?async:'a -> unit -> unit = "stub_libxl_domain_suspend"
 	external pause : ctx -> domid -> ?async:'a -> unit = "stub_libxl_domain_pause"
tools/ocaml/libs/xl/xenlight.mli.in +2 -2
index c08304ae8b..b98a3db7e7 100644
@@ -39,8 +39,8 @@ module Domain : sig
 	external create_new : ctx -> Domain_config.t -> ?async:'a -> unit -> domid = "stub_libxl_domain_create_new"
 	external create_restore : ctx -> Domain_config.t -> (Unix.file_descr * Domain_restore_params.t) ->
 		?async:'a -> unit -> domid = "stub_libxl_domain_create_restore"
-	external shutdown : ctx -> domid -> unit = "stub_libxl_domain_shutdown"
-	external reboot : ctx -> domid -> unit = "stub_libxl_domain_reboot"
+	external shutdown : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_shutdown"
+	external reboot : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_reboot"
 	external destroy : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_destroy"
 	external suspend : ctx -> domid -> Unix.file_descr -> ?async:'a -> unit -> unit = "stub_libxl_domain_suspend"
 	external pause : ctx -> domid -> ?async:'a -> unit = "stub_libxl_domain_pause"
tools/ocaml/libs/xl/xenlight_stubs.c +12 -6
index 37b046df63..ff16b8710b 100644
@@ -551,32 +551,38 @@ value stub_libxl_domain_create_restore(value ctx, value domain_config, value par
 	CAMLreturn(Val_int(c_domid));
 }
 
-value stub_libxl_domain_shutdown(value ctx, value domid)
+value stub_libxl_domain_shutdown(value ctx, value domid, value async, value unit)
 {
-	CAMLparam2(ctx, domid);
+	CAMLparam4(ctx, domid, async, unit);
 	int ret;
 	uint32_t c_domid = Int_val(domid);
+	libxl_asyncop_how *ao_how = aohow_val(async);
 
 	caml_enter_blocking_section();
-	ret = libxl_domain_shutdown(CTX, c_domid);
+	ret = libxl_domain_shutdown(CTX, c_domid, ao_how);
 	caml_leave_blocking_section();
 
+	free(ao_how);
+
 	if (ret != 0)
 		failwith_xl(ret, "domain_shutdown");
 
 	CAMLreturn(Val_unit);
 }
 
-value stub_libxl_domain_reboot(value ctx, value domid)
+value stub_libxl_domain_reboot(value ctx, value domid, value async, value unit)
 {
-	CAMLparam2(ctx, domid);
+	CAMLparam4(ctx, domid, async, unit);
 	int ret;
 	uint32_t c_domid = Int_val(domid);
+	libxl_asyncop_how *ao_how = aohow_val(async);
 
 	caml_enter_blocking_section();
-	ret = libxl_domain_reboot(CTX, c_domid);
+	ret = libxl_domain_reboot(CTX, c_domid, ao_how);
 	caml_leave_blocking_section();
 
+	free(ao_how);
+
 	if (ret != 0)
 		failwith_xl(ret, "domain_reboot");
 
tools/xl/xl_vmcontrol.c +2 -2
index eb6779a561..b20582e15b 100644
@@ -103,7 +103,7 @@ static void reboot_domain(uint32_t domid, libxl_evgen_domain_death **deathw,
     int rc;
 
     fprintf(stderr, "Rebooting domain %u\n", domid);
-    rc=libxl_domain_reboot(ctx, domid);
+    rc = libxl_domain_reboot(ctx, domid, NULL);
     if (rc == ERROR_NOPARAVIRT) {
         if (fallback_trigger) {
             fprintf(stderr, "PV control interface not available:"
@@ -136,7 +136,7 @@ static void shutdown_domain(uint32_t domid,
     int rc;
 
     fprintf(stderr, "Shutting down domain %u\n", domid);
-    rc=libxl_domain_shutdown(ctx, domid);
+    rc = libxl_domain_shutdown(ctx, domid, NULL);
     if (rc == ERROR_NOPARAVIRT) {
         if (fallback_trigger) {
             fprintf(stderr, "PV control interface not available:"
Signature · 7 lines
2.23.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

tools/libxl/libxl_domain.c char * libxl__domain_pvcontrol_read(libxl__gc *gc, xs_transaction_t t, · line 827

Quoted 7 lines · Roger Pau Monne
tools/libxl/libxl_domain.c +4 -1
+int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid,
+                        const libxl_asyncop_how *ao_how)
 {
-    GC_INIT(ctx);
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__xswait_state *pvcontrol;
     int ret;

Forgot to stg refresh before sending and this didn't get changed to rc. I can send a new version or this can be fixed on commit I guess if everything else is fine.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 9 lines · Roger Pau Monné

tools/libxl/libxl_domain.c char * libxl__domain_pvcontrol_read(libxl__gc *gc, xs_transaction_t t, · line 827

Quoted 7 lines · Roger Pau Monne
tools/libxl/libxl_domain.c +4 -1
+int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid,
+                        const libxl_asyncop_how *ao_how)
 {
-    GC_INIT(ctx);
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__xswait_state *pvcontrol;
     int ret;
Quoted 3 lines

Forgot to stg refresh before sending and this didn't get changed to rc. I can send a new version or this can be fixed on commit I guess if everything else is fine.

Fixed and pushed.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 1/1
#3 lore raw
In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

Currently only suspend power control requests wait for an ack from the domain, while power off or reboot requests simply write the command to xenstore and exit.

Introduce a 1 minute wait for the domain to acknowledge the request, or else return an error. The suspend code is slightly modified to use the new infrastructure added, but shouldn't have any functional change.

Quoted 5 lines

Fix the ocaml bindings and also provide a backwards compatible interface for the reboot and poweroff libxl API functions.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Adding Juergen for a release-ack.

Quoted 12 lines · Anthony PERARD
Quoted 11 lines · Roger Pau Monne

Currently only suspend power control requests wait for an ack from the domain, while power off or reboot requests simply write the command to xenstore and exit.

Introduce a 1 minute wait for the domain to acknowledge the request, or else return an error. The suspend code is slightly modified to use the new infrastructure added, but shouldn't have any functional change.

Fix the ocaml bindings and also provide a backwards compatible interface for the reboot and poweroff libxl API functions.

Quoted 9 lines
Quoted 2 lines

Thanks,

Signature · 1 line
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 19 lines · Roger Pau Monné

Adding Juergen for a release-ack.

Quoted 16 lines · Anthony PERARD
Quoted 8 lines · Roger Pau Monne

Currently only suspend power control requests wait for an ack from the domain, while power off or reboot requests simply write the command to xenstore and exit.

Introduce a 1 minute wait for the domain to acknowledge the request, or else return an error. The suspend code is slightly modified to use the new infrastructure added, but shouldn't have any functional change.

Quoted 5 lines

Fix the ocaml bindings and also provide a backwards compatible interface for the reboot and poweroff libxl API functions.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel