From patchwork Fri Aug 2 15:35:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EB5B1399 for ; Fri, 2 Aug 2019 15:59:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E3E428876 for ; Fri, 2 Aug 2019 15:59:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 725F628877; Fri, 2 Aug 2019 15:59:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B539328880 for ; Fri, 2 Aug 2019 15:59:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwo-0006MN-C2; Fri, 02 Aug 2019 15:58:26 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwn-0006Js-1u for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:25 +0000 X-Inumbo-ID: 5ab57478-b53e-11e9-8980-bc764e045a96 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 5ab57478-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:22 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@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 (esa4.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=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: ryG2UEzmzU47op5zZH8OObEgkLtSM4TafK+f4q9sbuw4vlyM/jt9Wn7Toj3vw+uNvFGjcp1CqH zQrrRtyCWtmebiqmS06a1wgz8aX1dfUfqoOzgBn5HmgSTs5CBBdmowG+iUQCgVI6YJ6JtBsR8N 0dyOYMQaFPG2cHv2dxKSoJYU9BvUl3xH+goYgP8wqK4smXQWMzaFlWpTBJQ4lZXURz6JteZU4F aeTJnGv/32q+dNFVt9ZUg6rYJklfgEW/iHK1BRfR0p34Ys8fBu53MUdf5QfLsy8nca+R9tgjRF 7AU= X-SBRS: 2.7 X-MesageID: 3951240 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3951240" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:41 +0100 Message-ID: <20190802153606.32061-11-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 10/35] libxl: Re-introduce libxl__domain_resume 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: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP libxl__domain_resume is a rework libxl__domain_resume_deprecated. It makes uses of ev_xswatch and ev_qmp, to replace synchronous QMP calls and libxl__wait_for_device_model_deprecated call. This patch also introduce libxl__dm_resume which is a sub-operation of both libxl__domain_resume and libxl__domain_unpause and can be used instead of libxl__domain_resume_device_model_deprecated. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_dom_suspend.c | 192 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 27 +++++ 2 files changed, 219 insertions(+) diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.c index 2460021e5a..9bb2d00bec 100644 --- a/tools/libxl/libxl_dom_suspend.c +++ b/tools/libxl/libxl_dom_suspend.c @@ -481,6 +481,198 @@ int libxl__domain_resume_deprecated(libxl__gc *gc, uint32_t domid, int suspend_c return rc; } +static void dm_resume_init(libxl__dm_resume_state *dmrs) +{ + libxl__ev_qmp_init(&dmrs->qmp); + libxl__ev_time_init(&dmrs->time); + libxl__ev_xswatch_init(&dmrs->watch); +} + +static void dm_resume_dispose(libxl__gc *gc, + libxl__dm_resume_state *dmrs) +{ + libxl__ev_qmp_dispose(gc, &dmrs->qmp); + libxl__ev_time_deregister(gc, &dmrs->time); + libxl__ev_xswatch_deregister(gc, &dmrs->watch); +} + +static void dm_resume_xswatch_cb(libxl__egc *egc, + libxl__ev_xswatch *, const char *watch_path, const char *); +static void dm_resume_qmp_done(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *, int rc); +static void dm_resume_timeout(libxl__egc *egc, + libxl__ev_time *, const struct timeval *, int rc); +static void dm_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, int rc); + +void libxl__dm_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs) +{ + STATE_AO_GC(dmrs->ao); + int rc = 0; + + /* Convenience aliases */ + libxl_domid domid = dmrs->domid; + libxl__ev_qmp *qmp = &dmrs->qmp; + + dm_resume_init(dmrs); + + rc = libxl__ev_time_register_rel(dmrs->ao, + &dmrs->time, + dm_resume_timeout, + LIBXL_DEVICE_MODEL_START_TIMEOUT); + if (rc) goto out; + + switch (libxl__device_model_version_running(gc, domid)) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: { + uint32_t dm_domid = libxl_get_stubdom_id(CTX, domid); + const char *path, *state; + + path = DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/state"); + rc = libxl__xs_read_checked(gc, XBT_NULL, path, &state); + if (rc) goto out; + if (!state || strcmp(state, "paused")) { + /* already running */ + rc = 0; + goto out; + } + + rc = libxl__qemu_traditional_cmd(gc, domid, "continue"); + if (rc) goto out; + rc = libxl__ev_xswatch_register(gc, &dmrs->watch, + dm_resume_xswatch_cb, + path); + if (rc) goto out; + break; + } + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + qmp->ao = dmrs->ao; + qmp->domid = domid; + qmp->callback = dm_resume_qmp_done; + qmp->payload_fd = -1; + rc = libxl__ev_qmp_send(gc, qmp, "cont", NULL); + if (rc) goto out; + break; + default: + rc = ERROR_INVAL; + goto out; + } + + return; + +out: + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_xswatch_cb(libxl__egc *egc, + libxl__ev_xswatch *xsw, + const char *watch_path, + const char *event_path) +{ + EGC_GC; + libxl__dm_resume_state *dmrs = CONTAINER_OF(xsw, *dmrs, watch); + int rc; + const char *value; + + rc = libxl__xs_read_checked(gc, XBT_NULL, watch_path, &value); + if (rc) goto out; + + if (!value || strcmp(value, "running")) + return; + + rc = 0; +out: + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_qmp_done(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + libxl__dm_resume_state *dmrs = CONTAINER_OF(qmp, *dmrs, qmp); + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_timeout(libxl__egc *egc, + libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + libxl__dm_resume_state *dmrs = CONTAINER_OF(ev, *dmrs, time); + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + int rc) +{ + EGC_GC; + + if (rc) { + LOGD(ERROR, dmrs->domid, + "Failed to resume device model: rc=%d", rc); + } + + dm_resume_dispose(gc, dmrs); + dmrs->dm_resumed_callback(egc, dmrs, rc); +} + + +static void domain_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, int rc); + +void libxl__domain_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + bool suspend_cancel) +{ + STATE_AO_GC(dmrs->ao); + int rc = 0; + libxl_domain_type type = libxl__domain_type(gc, dmrs->domid); + + if (type == LIBXL_DOMAIN_TYPE_INVALID) { + rc = ERROR_FAIL; + goto out; + } + + if (type != LIBXL_DOMAIN_TYPE_HVM) { + rc = 0; + goto out; + } + + dmrs->suspend_cancel = suspend_cancel; + dmrs->dm_resumed_callback = domain_resume_done; + libxl__dm_resume(egc, dmrs); /* must be last */ + return; + +out: + domain_resume_done(egc, dmrs, rc); +} + +static void domain_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, int rc) +{ + EGC_GC; + + /* Convenience aliases */ + libxl_domid domid = dmrs->domid; + + if (rc) goto out; + + if (xc_domain_resume(CTX->xch, domid, dmrs->suspend_cancel)) { + LOGED(ERROR, domid, "xc_domain_resume failed"); + rc = ERROR_FAIL; + goto out; + } + + if (!xs_resume_domain(CTX->xsh, domid)) { + LOGED(ERROR, domid, "xs_resume_domain failed"); + rc = ERROR_FAIL; + } +out: + dmrs->callback(egc, dmrs, rc); +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index da3631d853..bdc9677527 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -197,6 +197,7 @@ typedef struct libxl__device_type libxl__device_type; typedef struct libxl__json_object libxl__json_object; typedef struct libxl__carefd libxl__carefd; typedef struct libxl__ev_lock libxl__ev_lock; +typedef struct libxl__dm_resume_state libxl__dm_resume_state; typedef struct libxl__domain_create_state libxl__domain_create_state; typedef void libxl__domain_create_cb(struct libxl__egc *egc, @@ -1339,6 +1340,32 @@ _hidden int libxl__domain_resume_deprecated(libxl__gc *gc, uint32_t domid, _hidden int libxl__domain_unpause_deprecated(libxl__gc *, libxl_domid domid); +/* Call libxl__dm_resume_init() and fill the first few fields, + * then call one of libxl__domain_resume / libxl__domain_unpause + * or directly libxl__dm_resume if only the device model needs to be + * "resumed". */ +struct libxl__dm_resume_state { + /* caller must fill these in, and they must all remain valid */ + libxl__ao *ao; + libxl_domid domid; + void (*callback)(libxl__egc *, libxl__dm_resume_state *, int rc); + + /* private to libxl__domain_resume */ + void (*dm_resumed_callback)(libxl__egc *, + libxl__dm_resume_state *, int rc); + bool suspend_cancel; + + /* private to libxl__dm_resume */ + libxl__ev_qmp qmp; + libxl__ev_time time; + libxl__ev_xswatch watch; +}; +_hidden void libxl__dm_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs); +_hidden void libxl__domain_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + bool suspend_cancel); + /* returns 0 or 1, or a libxl error code */ _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);