From patchwork Tue Oct 1 10:12:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 11168391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDD4215AB for ; Tue, 1 Oct 2019 10:14:43 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDCA62133F for ; Tue, 1 Oct 2019 10:14:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="H5MvhwpJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDCA62133F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFF9e-0002Oz-0q; Tue, 01 Oct 2019 10:13:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFF9c-0002Ou-0E for xen-devel@lists.xenproject.org; Tue, 01 Oct 2019 10:13:12 +0000 X-Inumbo-ID: 121f7636-e434-11e9-96f7-12813bfff9fa Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by localhost (Halon) with ESMTPS id 121f7636-e434-11e9-96f7-12813bfff9fa; Tue, 01 Oct 2019 10:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1569924791; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ZwlN+mVM0FYnJ/ikyud9Z0KYmDUi6Ki6lAWYMxfy0zo=; b=H5MvhwpJaJHvi1C+RB+YoDwEn5JXTzLaBfbs5LCe8tXf3E/6xPlYjpC4 QH7lmR58kDV/UTclrVlAnG4SsWM6ZJsb5CBzEIEbZIAuXdjSLToOJja89 2F8WCRgoWshNVITIejQU92lVlH31xQFSpBU7ZdB3/YB0Yw65G7wi51Vaq s=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: QkMGjQaXorGRRw07deqrEe/uTkSiTxKgXpN+Gm1RkjWE0ier3f4OBmE6pkoTO1zGFIT9ov/FhZ 7H7xCKuxenaPstn5SPFCSNQfb5IlCyWb5jxDvb9nrGw8k+oKsgOZxDOPYHG/KSIpac1fOeMr0e /pPJ3pBsPwX5TFPqAroajbZIyBlRSzWkxPcNNljC9xr7acUlVktn4PFkogn7zFEFam6V32KM/d 2WR14OonAAWgCI/eYzStMj95QlH8PmmJaK9WVDhEB76WzJaveZCj9QaU/vjVIKi94std8XQU6q WLM= X-SBRS: 2.7 X-MesageID: 6297545 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,570,1559534400"; d="scan'208";a="6297545" From: Roger Pau Monne To: Date: Tue, 1 Oct 2019 12:12:59 +0200 Message-ID: <20191001101259.53162-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] libxl: wait for the ack when issuing power control requests X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Ian Jackson , Ross Lagerwall , Christian Lindig , David Scott , Anthony PERARD , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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. Reported-by: Ross Lagerwall Signed-off-by: Roger Pau Monné Acked-by: Christian Lindig --- 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. --- tools/libxl/libxl.h | 23 +++++++- tools/libxl/libxl_dom_suspend.c | 11 ++-- tools/libxl/libxl_domain.c | 81 ++++++++++++++++++++-------- tools/libxl/libxl_internal.h | 7 ++- tools/ocaml/libs/xl/xenlight_stubs.c | 18 ++++--- tools/xl/xl_vmcontrol.c | 4 +- 6 files changed, 102 insertions(+), 42 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index f711cfc750..03ea5ca740 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1628,8 +1628,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; diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.c index 9bb2d00bec..248dbc33e3 100644 --- a/tools/libxl/libxl_dom_suspend.c +++ b/tools/libxl/libxl_dom_suspend.c @@ -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: diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 0dd5b7ffa9..058f3c77ec 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -763,49 +763,86 @@ char * libxl__domain_pvcontrol_read(libxl__gc *gc, xs_transaction_t t, return libxl__xs_read(gc, t, shutdown_path); } -int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t, - uint32_t domid, const char *cmd) +int libxl__domain_pvcontrol(libxl__egc *egc, libxl__xswait_state *pvcontrol, + domid_t domid, const char *cmd) { + STATE_AO_GC(pvcontrol->ao); const char *shutdown_path; + int rc; + + rc = libxl__domain_pvcontrol_available(gc, domid); + if (rc < 0) + return rc; shutdown_path = libxl__domain_pvcontrol_xspath(gc, domid); if (!shutdown_path) return ERROR_FAIL; - return libxl__xs_printf(gc, t, shutdown_path, "%s", cmd); + rc = libxl__xs_printf(gc, XBT_NULL, shutdown_path, "%s", cmd); + if (rc) + return rc; + + pvcontrol->path = shutdown_path; + pvcontrol->what = GCSPRINTF("guest acknowledgement of %s request", cmd); + pvcontrol->timeout_ms = 60 * 1000; + libxl__xswait_start(gc, pvcontrol); + + return 0; } -static int libxl__domain_pvcontrol(libxl__gc *gc, uint32_t domid, - const char *cmd) +static bool pvcontrol_acked(const char *state) { - int ret; + if (!state || !strcmp(state,"")) + return true; + + return false; +} + +static void pvcontrol_cb(libxl__egc *egc, libxl__xswait_state *xswa, int rc, + const char *state) +{ + STATE_AO_GC(xswa->ao); + + if (!rc && !pvcontrol_acked(state)) + return; - ret = libxl__domain_pvcontrol_available(gc, domid); - if (ret < 0) - return ret; + libxl__xswait_stop(gc, xswa); - if (!ret) - return ERROR_NOPARAVIRT; + if (rc) + LOG(ERROR, "guest didn't acknowledge control request: %d", rc); - return libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, cmd); + libxl__ao_complete(egc, ao, rc); } -int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid) + +int libxl_domain_shutdown(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; - ret = libxl__domain_pvcontrol(gc, domid, "poweroff"); - GC_FREE; - return ret; + + GCNEW(pvcontrol); + pvcontrol->ao = ao; + pvcontrol->callback = pvcontrol_cb; + ret = libxl__domain_pvcontrol(egc, pvcontrol, domid, "poweroff"); + + return ret ? AO_CREATE_FAIL(ret) : AO_INPROGRESS; } -int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid) +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; - ret = libxl__domain_pvcontrol(gc, domid, "reboot"); - GC_FREE; - return ret; + + GCNEW(pvcontrol); + pvcontrol->ao = ao; + pvcontrol->callback = pvcontrol_cb; + ret = libxl__domain_pvcontrol(egc, pvcontrol, domid, "reboot"); + + return ret ? AO_CREATE_FAIL(ret) : AO_INPROGRESS; } static void domain_death_occurred(libxl__egc *egc, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index bfeb38e0ed..d2d5af746b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -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 /* diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c index 37b046df63..ff16b8710b 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -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"); diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index eb6779a561..b20582e15b 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -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:"