From nobody Mon Feb 9 09:15:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568914925; cv=none; d=zoho.com; s=zohoarc; b=QwIUswTDLwU583DlGdZqhpBape7dt4x9+EaNEEd9V59R1VFYd6pfhLcTZV2qH8eXjanE245DAoFeHffBS74YdCj2m8VCMAx52C2mq7M5pU6I2NIhGMcN4aNSSBaqi4s0CGN3k8D/CqPxlHiNt86ScV4FXvyH5kZadY/cqVGzs8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568914925; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=E2DNZxZ91CTf7HXnYfUw55+i+jGD+zpPcUcEuh/JaBA=; b=U/rFCfG61rPVFl7LARAhflusVeC0tJZqv9TcwwToe6UvGIHCC9nTC6QC6UTTyrsNBF8wzFiQvrScMjz7aDA2AX6BYXC42fzMRpUrvJJc9ka0wP7WL83m1+hzRRGauoK4ZaYXgka/5M3/pTk4hkoGJXmIz2Llz7wYhDHkYKnLaBs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568914925332704.5943558899363; Thu, 19 Sep 2019 10:42:05 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Ql-0004gt-T2; Thu, 19 Sep 2019 17:41:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Ql-0004fn-6U for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:23 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ac9f697a-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:41:13 +0000 (UTC) X-Inumbo-ID: ac9f697a-db04-11e9-b299-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4vmb6q9uBGnMtjELoo6IgRr4nyI+2xREBkcx+dW76/Y=; b=KOtcU8ytiuQBJB+i39CRvO4fsfycjbNQPGfH/bAnMA9cRKRAPfJV5O9C 0Nqx94COl9hltvVDsqklVpVn6PDtlC4LDom7QsD4wVMi0ray2PqaimVvc zlgt9wS9skChgBJUw/K05R1HaqacQscjgoTgGs+fdIwnSrKQrbzg4D4SH A=; Authentication-Results: esa6.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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.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=esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: G+/WbNeXrhZOp2sEhhfN1e+8P26ZiA12LkWDKv6WcZD7wqzr1dqzu/b9Mxvqfdls4QS+VrZV4H KjCzZ2IAHXqp8T6nbJ3nqmeDaqLXoWsyVJQWoopLCXdalqiWLSgXqw3qtjtUC1ojTBjhvCirPV jWaqYB/i4H0rFDkJsXpM+H6z9nGQmQg2/xv3fbzDeWbWShvCWwo/OU79bqzU/5L+snJCSSS5J7 jAG+1zITMVhScYJGYUPaOq+agLKePNxjJgqtGmmCHN+jhk9QMk2vzSZew7TydAga4/CvSVoUE/ Ln0= X-SBRS: 2.7 X-MesageID: 6064353 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,524,1559534400"; d="scan'208";a="6064353" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:30 +0100 Message-ID: <20190919171656.899649-11-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919171656.899649-1-anthony.perard@citrix.com> References: <20190919171656.899649-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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_suspen= d.c index 2460021e5a59..9bb2d00bec9a 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, ui= nt32_t domid, int suspend_c return rc; } =20 +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 =3D 0; + + /* Convenience aliases */ + libxl_domid domid =3D dmrs->domid; + libxl__ev_qmp *qmp =3D &dmrs->qmp; + + dm_resume_init(dmrs); + + rc =3D 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 =3D libxl_get_stubdom_id(CTX, domid); + const char *path, *state; + + path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/state"); + rc =3D libxl__xs_read_checked(gc, XBT_NULL, path, &state); + if (rc) goto out; + if (!state || strcmp(state, "paused")) { + /* already running */ + rc =3D 0; + goto out; + } + + rc =3D libxl__qemu_traditional_cmd(gc, domid, "continue"); + if (rc) goto out; + rc =3D 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 =3D dmrs->ao; + qmp->domid =3D domid; + qmp->callback =3D dm_resume_qmp_done; + qmp->payload_fd =3D -1; + rc =3D libxl__ev_qmp_send(gc, qmp, "cont", NULL); + if (rc) goto out; + break; + default: + rc =3D 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 =3D CONTAINER_OF(xsw, *dmrs, watch); + int rc; + const char *value; + + rc =3D libxl__xs_read_checked(gc, XBT_NULL, watch_path, &value); + if (rc) goto out; + + if (!value || strcmp(value, "running")) + return; + + rc =3D 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 =3D 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 =3D 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=3D%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 =3D 0; + libxl_domain_type type =3D libxl__domain_type(gc, dmrs->domid); + + if (type =3D=3D LIBXL_DOMAIN_TYPE_INVALID) { + rc =3D ERROR_FAIL; + goto out; + } + + if (type !=3D LIBXL_DOMAIN_TYPE_HVM) { + rc =3D 0; + goto out; + } + + dmrs->suspend_cancel =3D suspend_cancel; + dmrs->dm_resumed_callback =3D 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 =3D dmrs->domid; + + if (rc) goto out; + + if (xc_domain_resume(CTX->xch, domid, dmrs->suspend_cancel)) { + LOGED(ERROR, domid, "xc_domain_resume failed"); + rc =3D ERROR_FAIL; + goto out; + } + + if (!xs_resume_domain(CTX->xsh, domid)) { + LOGED(ERROR, domid, "xs_resume_domain failed"); + rc =3D 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 db8860507b18..6bb6d6d2e166 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_devlock libxl__ev_devlock; +typedef struct libxl__dm_resume_state libxl__dm_resume_state; =20 typedef struct libxl__domain_create_state libxl__domain_create_state; typedef void libxl__domain_create_cb(struct libxl__egc *egc, @@ -1340,6 +1341,32 @@ _hidden int libxl__domain_resume_deprecated(libxl__g= c *gc, uint32_t domid, _hidden int libxl__domain_unpause_deprecated(libxl__gc *, libxl_domid domid); =20 +/* 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 domi= d); =20 --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel