From patchwork Thu Sep 19 17:16:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152953 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 C641814DB for ; Thu, 19 Sep 2019 17:19:03 +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 963C4217D6 for ; Thu, 19 Sep 2019 17:19:03 +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="idwH2b7H" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 963C4217D6 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 1iB03X-0000zJ-9N; Thu, 19 Sep 2019 17:17: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 1iB03V-0000xz-8U for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:21 +0000 X-Inumbo-ID: 56163b22-db01-11e9-978d-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 56163b22-db01-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zKDJsTI0ke0OHp1k2Wdn9R406uNGoaYUwfweh4F2tb8=; b=idwH2b7HH7mSqpmhPuUFzt6BbBmda284Rb5cr6sRI4Bb8g1Ld5o07VHL uAXsxO7m+b6n/CIMLvQFAkp46FyX9Im+s99MJu7n+d0rC5/LKF5UD9/g3 GX0ivhgvXh7CXiAet2DdDgwPNSlhrXsNIyvaXnpSxPRmMunZOpau+NTZF o=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: rTjT31ajzXJ1scSXn1uB8F/o9cux+kA4TRYrrE0DmjEIpwEryAv81tNoJKf7jMuYX/V6Y6mbGh cPHEThg+mnVqZSti7KI4CFaEwTfQed/UJBIsXy9GlSF1MDfYhVWOGL0pZJ0gZ7aaClyKyHCz2R tybrTNNPj/9omVmV2GpteoYbKP908T8KPd2H3IFnVqDZoYAC5UchAxyoEPdVHRKYdv/vzPwS5u AGNbDkx7k/sUsmmCWETw7QLrxrcXxNN7g480kVsoY4+F6CIfn23KkMZSp8OOGoAHHrkYVWpK2L iBg= X-SBRS: 2.7 X-MesageID: 5800418 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,524,1559534400"; d="scan'208";a="5800418" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:21 +0100 Message-ID: <20190919171656.899649-2-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 01/35] libxl: Make libxl_domain_unpause async 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" libxl_domain_unpause needs to make QMP calls, which are asynchronous, change the API to reflect that. Do the same with libxl_domain_pause async, even if it will keep completing synchronously. Also fix some coding style issue in those functions. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: v2: - Added LIBXL_HAVE_FN_USING_QMP_ASYNC tools/libxl/libxl.h | 37 ++++++++++++++++++++++-- tools/libxl/libxl_colo_restore.c | 2 +- tools/libxl/libxl_colo_save.c | 2 +- tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_domain.c | 48 +++++++++++++++++++++----------- tools/libxl/libxl_internal.h | 1 + tools/xl/xl_migrate.c | 4 +-- tools/xl/xl_saverestore.c | 2 +- tools/xl/xl_vmcontrol.c | 6 ++-- 9 files changed, 76 insertions(+), 28 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index b165b2831176..10dfde3fd897 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -638,7 +638,8 @@ typedef struct libxl__ctx libxl_ctx; /* API compatibility. */ #ifdef LIBXL_API_VERSION #if LIBXL_API_VERSION != 0x040200 && LIBXL_API_VERSION != 0x040300 && \ - LIBXL_API_VERSION != 0x040400 && LIBXL_API_VERSION != 0x040500 + LIBXL_API_VERSION != 0x040400 && LIBXL_API_VERSION != 0x040500 && \ + LIBXL_API_VERSION != 0x041300 #error Unknown LIBXL_API_VERSION #endif #endif @@ -1210,6 +1211,17 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); */ #define LIBXL_HAVE_PVCALLS 1 +/* + * LIBXL_HAVE_FN_USING_QMP_ASYNC + * + * This define indicates that some function's API has changed and have an + * extra parameter "ao_how" which means that the function can be executed + * asynchronously. Those functions are: + * libxl_domain_pause() + * libxl_domain_unpause() + */ +#define LIBXL_HAVE_FN_USING_QMP_ASYNC 1 + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); @@ -1614,8 +1626,27 @@ int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid, * transactionally that the domain has the old old name; if * trans is not 0 we use caller's transaction and caller must do retries */ -int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid); -int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid); +int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_domain_unpause(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_pause_0x041200( + libxl_ctx *ctx, uint32_t domid) +{ + return libxl_domain_pause(ctx, domid, NULL); +} +static inline int libxl_domain_unpause_0x041200( + libxl_ctx *ctx, uint32_t domid) +{ + return libxl_domain_unpause(ctx, domid, NULL); +} +#define libxl_domain_pause libxl_domain_pause_0x041200 +#define libxl_domain_unpause libxl_domain_unpause_0x041200 +#endif + int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid, const char *filename, diff --git a/tools/libxl/libxl_colo_restore.c b/tools/libxl/libxl_colo_restore.c index 0c535bd95d69..aaa70552b8c4 100644 --- a/tools/libxl/libxl_colo_restore.c +++ b/tools/libxl/libxl_colo_restore.c @@ -853,7 +853,7 @@ static void colo_unpause_svm(libxl__egc *egc, EGC_GC; /* We have enabled secondary vm's logdirty, so we can unpause it now */ - rc = libxl_domain_unpause(CTX, domid); + rc = libxl__domain_unpause(gc, domid); if (rc) { LOGD(ERROR, domid, "cannot unpause secondary vm"); goto out; diff --git a/tools/libxl/libxl_colo_save.c b/tools/libxl/libxl_colo_save.c index 3247cce3a7e5..1d261a1639f7 100644 --- a/tools/libxl/libxl_colo_save.c +++ b/tools/libxl/libxl_colo_save.c @@ -480,7 +480,7 @@ static void colo_preresume_cb(libxl__egc *egc, * no disk migration. */ if (css->paused) { - rc = libxl_domain_unpause(CTX, dss->domid); + rc = libxl__domain_unpause(gc, dss->domid); if (rc) { LOGD(ERROR, dss->domid, "cannot unpause primary vm"); goto out; diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 5fe25b56f596..00da59153d67 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2402,7 +2402,7 @@ static void stubdom_pvqemu_cb(libxl__egc *egc, goto out; } - rc = libxl_domain_unpause(CTX, dm_domid); + rc = libxl__domain_unpause(gc, dm_domid); if (rc) goto out; sdss->xswait.ao = ao; diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 11a29b235b1d..1c313005db51 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -557,18 +557,18 @@ int libxl_domain_suspend_only(libxl_ctx *ctx, uint32_t domid, return AO_CREATE_FAIL(rc); } -int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid) +int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid, + const libxl_asyncop_how *ao_how) { - int ret; - GC_INIT(ctx); - ret = xc_domain_pause(ctx->xch, domid); - if (ret<0) { + AO_CREATE(ctx, domid, ao_how); + int r; + r = xc_domain_pause(ctx->xch, domid); + if (r < 0) { LOGED(ERROR, domid, "Pausing domain"); - GC_FREE; - return ERROR_FAIL; + return AO_CREATE_FAIL(ERROR_FAIL); } - GC_FREE; - return 0; + libxl__ao_complete(egc, ao, 0); + return AO_INPROGRESS; } int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid, @@ -593,10 +593,9 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid, return AO_INPROGRESS; } -int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid) +int libxl__domain_unpause(libxl__gc *gc, libxl_domid domid) { - GC_INIT(ctx); - int ret, rc = 0; + int r, rc; libxl_domain_type type = libxl__domain_type(gc, domid); if (type == LIBXL_DOMAIN_TYPE_INVALID) { @@ -612,16 +611,33 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid) goto out; } } - ret = xc_domain_unpause(ctx->xch, domid); - if (ret<0) { + r = xc_domain_unpause(CTX->xch, domid); + if (r < 0) { LOGED(ERROR, domid, "Unpausing domain"); rc = ERROR_FAIL; + goto out; } - out: - GC_FREE; + rc = 0; +out: return rc; } +int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid, + const libxl_asyncop_how *ao_how) +{ + AO_CREATE(ctx, domid, ao_how); + int rc = 0; + + rc = libxl__domain_unpause(gc, domid); + if (rc) goto out; + + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; + + out: + return AO_CREATE_FAIL(rc); +} + int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid) { libxl_ctx *ctx = libxl__gc_owner(gc); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 1fba10e39e71..7486b512fd54 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -4109,6 +4109,7 @@ _hidden void libxl__remus_teardown(libxl__egc *egc, int rc); _hidden void libxl__remus_restore_setup(libxl__egc *egc, libxl__domain_create_state *dcs); +_hidden int libxl__domain_unpause(libxl__gc *, libxl_domid domid); /* diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c index 1f0e87df50b5..22f0429b8488 100644 --- a/tools/xl/xl_migrate.c +++ b/tools/xl/xl_migrate.c @@ -394,7 +394,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, /* The guest is running after failover in COLO mode */ exit(rc ? -ERROR_FAIL: 0); - rc = libxl_domain_unpause(ctx, domid); + rc = libxl_domain_unpause(ctx, domid, NULL); if (rc) fprintf(stderr, "migration target (%s): " "Failed to unpause domain %s (id: %u):%d\n", @@ -429,7 +429,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, } if (!pause_after_migration) { - rc = libxl_domain_unpause(ctx, domid); + rc = libxl_domain_unpause(ctx, domid, NULL); if (rc) goto perhaps_destroy_notify_rc; } diff --git a/tools/xl/xl_saverestore.c b/tools/xl/xl_saverestore.c index 9afeadeeb29f..5c70e2e8747d 100644 --- a/tools/xl/xl_saverestore.c +++ b/tools/xl/xl_saverestore.c @@ -150,7 +150,7 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint, } else if (leavepaused || checkpoint) { if (leavepaused) - libxl_domain_pause(ctx, domid); + libxl_domain_pause(ctx, domid, NULL); libxl_domain_resume(ctx, domid, 1, 0); } else diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index a1d633795c9f..419bf780a4c2 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -34,12 +34,12 @@ static int fd_lock = -1; static void pause_domain(uint32_t domid) { - libxl_domain_pause(ctx, domid); + libxl_domain_pause(ctx, domid, NULL); } static void unpause_domain(uint32_t domid) { - libxl_domain_unpause(ctx, domid); + libxl_domain_unpause(ctx, domid, NULL); } static void destroy_domain(uint32_t domid, int force) @@ -972,7 +972,7 @@ int create_domain(struct domain_create *dom_info) } if (!paused) - libxl_domain_unpause(ctx, domid); + libxl_domain_unpause(ctx, domid, NULL); ret = domid; /* caller gets success in parent */ if (!daemonize && !monitor) From patchwork Thu Sep 19 17:16:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152941 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 5CA1614DB for ; Thu, 19 Sep 2019 17:18:34 +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 37F96217D6 for ; Thu, 19 Sep 2019 17:18:34 +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="dVaZHf6+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37F96217D6 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 1iB03W-0000ys-V3; Thu, 19 Sep 2019 17:17:22 +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 1iB03V-0000xu-5y for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:21 +0000 X-Inumbo-ID: 562832dc-db01-11e9-966e-12813bfff9fa Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 562832dc-db01-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MbnRjI82hWbvCN1nQSGi38agz+4XttQVMZpdaTc6yC4=; b=dVaZHf6+F1EJe5pe6+UcEOlG6AzdRvZxWW7gtbtmnrpzFzCHuNEQAFsp NKZc6y278S7XWHPker3GpfFtW0OKkQiAxIqK2wmzyNQGNB1vDErMlE5k9 6juzHtffrSLbaphNBeVTX+ZG6BP7tSkM9GBjM2ZkmZDjyAoGGVwNrT66m o=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: jCRVPSc94QQ7/bBh5yfKtIEEBLmQXIKp/V2iHnxJGrj41WakiyHrlbZ9LGvxHATycX+tvcX/Jo ZCMLB+4YN/ilMofknqjKJdEzrpDTZ/oaF9bfBVdEcWO69DOHmJZSDoYQWgWX7i/zxuboTafx6t OuvNgzqlra1HTa1kzdJVL4y/dKvZpH6zxD2Vdhio5wdFB1cG8EkARLXuww24GJHBstruG5ic/G IcEnKbWCYrc3MGncJ+cEtclSGU7YtWUflAMZpfxwoGV8dSxIm/+cDC5FplZP65g8rmB6E1y9sZ 9e4= X-SBRS: 2.7 X-MesageID: 5800420 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,524,1559534400"; d="scan'208";a="5800420" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:22 +0100 Message-ID: <20190919171656.899649-3-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 02/35] libxl: Make libxl_send_trigger async 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" .. because it makes QMP calls which are going to be async. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl.h | 13 ++++++++++++- tools/libxl/libxl_domain.c | 12 ++++++++---- tools/xl/xl_misc.c | 4 ++-- tools/xl/xl_vmcontrol.c | 4 ++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 10dfde3fd897..430123274964 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1219,6 +1219,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); * asynchronously. Those functions are: * libxl_domain_pause() * libxl_domain_unpause() + * libxl_send_trigger() */ #define LIBXL_HAVE_FN_USING_QMP_ASYNC 1 @@ -2380,7 +2381,17 @@ int libxl_vcpu_sched_params_set_all(libxl_ctx *ctx, uint32_t domid, const libxl_vcpu_sched_params *params); int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, - libxl_trigger trigger, uint32_t vcpuid); + libxl_trigger trigger, uint32_t vcpuid, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300 +static inline int libxl_send_trigger_0x041200( + libxl_ctx *ctx, uint32_t domid, libxl_trigger trigger, uint32_t vcpuid) +{ + return libxl_send_trigger_0x041200(ctx, domid, trigger, vcpuid, NULL); +} +#define libxl_send_trigger libxl_send_trigger_0x041200 +#endif int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq); int libxl_send_debug_keys(libxl_ctx *ctx, char *keys); int libxl_set_parameters(libxl_ctx *ctx, char *params); diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 1c313005db51..86cddc05a944 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1470,10 +1470,11 @@ static int libxl__domain_s3_resume(libxl__gc *gc, int domid) } int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, - libxl_trigger trigger, uint32_t vcpuid) + libxl_trigger trigger, uint32_t vcpuid, + const libxl_asyncop_how *ao_how) { + AO_CREATE(ctx, domid, ao_how); int rc; - GC_INIT(ctx); switch (trigger) { case LIBXL_TRIGGER_POWER: @@ -1509,10 +1510,13 @@ int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, LOGED(ERROR, domid, "Send trigger '%s' failed", libxl_trigger_to_string(trigger)); rc = ERROR_FAIL; + goto out; } - GC_FREE; - return rc; + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; +out: + return AO_CREATE_FAIL(rc); } uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid) diff --git a/tools/xl/xl_misc.c b/tools/xl/xl_misc.c index dcf940a6d4a6..50c8436337c9 100644 --- a/tools/xl/xl_misc.c +++ b/tools/xl/xl_misc.c @@ -36,7 +36,7 @@ static void button_press(uint32_t domid, const char *b) exit(EXIT_FAILURE); } - libxl_send_trigger(ctx, domid, trigger, 0); + libxl_send_trigger(ctx, domid, trigger, 0, NULL); } int main_button_press(int argc, char **argv) @@ -106,7 +106,7 @@ int main_trigger(int argc, char **argv) } } - libxl_send_trigger(ctx, domid, trigger, vcpuid); + libxl_send_trigger(ctx, domid, trigger, vcpuid, NULL); return EXIT_SUCCESS; } diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 419bf780a4c2..3fc6f565748c 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -108,7 +108,7 @@ static void reboot_domain(uint32_t domid, libxl_evgen_domain_death **deathw, if (fallback_trigger) { fprintf(stderr, "PV control interface not available:" " sending ACPI reset button event.\n"); - rc = libxl_send_trigger(ctx, domid, LIBXL_TRIGGER_RESET, 0); + rc = libxl_send_trigger(ctx, domid, LIBXL_TRIGGER_RESET, 0, NULL); } else { fprintf(stderr, "PV control interface not available:" " external graceful reboot not possible.\n"); @@ -141,7 +141,7 @@ static void shutdown_domain(uint32_t domid, if (fallback_trigger) { fprintf(stderr, "PV control interface not available:" " sending ACPI power button event.\n"); - rc = libxl_send_trigger(ctx, domid, LIBXL_TRIGGER_POWER, 0); + rc = libxl_send_trigger(ctx, domid, LIBXL_TRIGGER_POWER, 0, NULL); } else { fprintf(stderr, "PV control interface not available:" " external graceful shutdown not possible.\n"); From patchwork Thu Sep 19 17:16:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152951 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 9E97714DB for ; Thu, 19 Sep 2019 17:19:02 +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 7A2B7217D6 for ; Thu, 19 Sep 2019 17:19:02 +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="iConOlzS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A2B7217D6 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 1iB03c-00012x-7T; Thu, 19 Sep 2019 17:17:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB03a-00011l-8j for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:26 +0000 X-Inumbo-ID: 56b742ba-db01-11e9-978d-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 56b742ba-db01-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OLuZzJKxFUTuaM0Mdj8VXYdU4QrS/sprJgp1Ee4rYfY=; b=iConOlzS6GBhL8CD+ts1StZfVbpo5cL7B3vnXG1g7zQoZkpE1OGHNuM2 cefqeWRLwaKfOxS2OKOJhb8NE0afMSB/CVvqXo4IbZF48cr88V8dwSOzS 51y4kgoC937HQhDdqut8GBrfkW+ENrY8PqctsrqnVVCsETADWDzIJ5Z30 Q=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: ywRWtLWFYax6Wc8eCuIG42fTGAs7JCVZgm8iVZ6Py8bS5MhfEtyMGB8QK3AntSgj3butS0Y+tf G3Fxb9tKwgh5IjMD2wRCDqVZoZcjzilLqxEg0FLnJS40iZGdLIsKhKUtn8TQUlub/95mZU92fl HBSSJNC/QMN71IkAnzsW/18Qj3FIdQoC7a4D+snB7AkuACO9QGKPyplclzC7re92I09Bz7uP8T 553wqUpJJERMET0N2TbfkOzsnxTQgiOFB+79Hzd4rNMAzSCTP9qqAbRse5bUfLQGqyc3HNMZkd cG8= X-SBRS: 2.7 X-MesageID: 5800422 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,524,1559534400"; d="scan'208";a="5800422" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:23 +0100 Message-ID: <20190919171656.899649-4-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 03/35] libxl: Make libxl_set_vcpuonline async 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" .. because it makes QMP calls which are going to be async. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl.h | 15 ++++++++++++++- tools/libxl/libxl_domain.c | 12 ++++++++---- tools/xl/xl_cpupool.c | 2 +- tools/xl/xl_vcpu.c | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 430123274964..fd69e92166b8 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1220,6 +1220,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); * libxl_domain_pause() * libxl_domain_unpause() * libxl_send_trigger() + * libxl_set_vcpuonline() */ #define LIBXL_HAVE_FN_USING_QMP_ASYNC 1 @@ -2318,7 +2319,19 @@ int libxl_domain_set_nodeaffinity(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *nodemap); int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *nodemap); -int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap); +int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, + libxl_bitmap *cpumap, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300 +static inline int libxl_set_vcpuonline_0x041200(libxl_ctx *ctx, + uint32_t domid, + libxl_bitmap *cpumap) +{ + return libxl_set_vcpuonline(ctx, domid, cpumap, NULL); +} +#define libxl_set_vcpuonline libxl_set_vcpuonline_0x041200 +#endif /* A return value less than 0 should be interpreted as a libxl_error, while a * return value greater than or equal to 0 should be interpreted as a diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 86cddc05a944..60c3f7a34b4c 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1386,9 +1386,11 @@ static int libxl__set_vcpuonline_qmp(libxl__gc *gc, uint32_t domid, return rc; } -int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap) +int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, + libxl_bitmap *cpumap, + const libxl_asyncop_how *ao_how) { - GC_INIT(ctx); + AO_CREATE(ctx, domid, ao_how); int rc, maxcpus; libxl_dominfo info; @@ -1439,8 +1441,10 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap) out: libxl_dominfo_dispose(&info); - GC_FREE; - return rc; + if (rc) + return AO_CREATE_FAIL(rc); + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; } static int libxl__domain_s3_resume(libxl__gc *gc, int domid) diff --git a/tools/xl/xl_cpupool.c b/tools/xl/xl_cpupool.c index 273811b66366..cffe87e0c7cc 100644 --- a/tools/xl/xl_cpupool.c +++ b/tools/xl/xl_cpupool.c @@ -546,7 +546,7 @@ int main_cpupoolnumasplit(int argc, char **argv) fprintf(stderr, "error on getting info for Domain-0\n"); goto out; } - if (info.vcpu_online > n && libxl_set_vcpuonline(ctx, 0, &cpumap)) { + if (info.vcpu_online > n && libxl_set_vcpuonline(ctx, 0, &cpumap, NULL)) { fprintf(stderr, "error on removing vcpus for Domain-0\n"); goto out; } diff --git a/tools/xl/xl_vcpu.c b/tools/xl/xl_vcpu.c index 329512eaaf79..9ff5354f749b 100644 --- a/tools/xl/xl_vcpu.c +++ b/tools/xl/xl_vcpu.c @@ -369,7 +369,7 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host) for (i = 0; i < max_vcpus; i++) libxl_bitmap_set(&cpumap, i); - rc = libxl_set_vcpuonline(ctx, domid, &cpumap); + rc = libxl_set_vcpuonline(ctx, domid, &cpumap, NULL); if (rc == ERROR_DOMAIN_NOTFOUND) fprintf(stderr, "Domain %u does not exist.\n", domid); else if (rc) From patchwork Thu Sep 19 17:16:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152943 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 017DC14DB for ; Thu, 19 Sep 2019 17:18:38 +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 D1386217D6 for ; Thu, 19 Sep 2019 17:18:37 +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="C16mVM81" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1386217D6 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 1iB03b-00012e-UG; Thu, 19 Sep 2019 17:17:27 +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 1iB03a-00011Z-1v for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:26 +0000 X-Inumbo-ID: 562832dd-db01-11e9-966e-12813bfff9fa Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 562832dd-db01-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pD3+LqMEFKqS3Jy/yX0xvD5PBS4ym0EyMOr0w3gtMf0=; b=C16mVM814EKH4XgrEf3XfQuX+C2bSQBHbzUbJUH1do5Ir744Xwkq5AuA OJp1OCtzUSrXRJxBy/ouWCxHKgZW8l+KvK5Auus4YBQfqByAGTq0GrPHj QfFdYBBfxjiFlK1m66fHm8KB3LJK0mZ7U8+DeLj71SObGlQdi8DC8VcVZ U=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Br+9/HryDdL61N+qgPYZKVV97VSZb8yMO/vzycQtkY1/XNF3gt5BmkFflX6YnbtO61v02WZbUe HKjtC56la5kDH+cIuODTDELSgWRA0n4wa+5LQ78ZEcRXX3xcelRCS1xuIi8hNKEhHu7x1C2otb ynNaTn0qJBANmkYolFkp7Y2IubHOiK7OB1cs+siBbCSNR7VC4LrDX860iaJzfwB/tg8z/KZV+7 Jb4ne1BLCUHt84sehlPIibWONAyf+45fq//NwLvqsmmlp2tRhzSO7XQwFmfSt97ODhZRnyttgM hpk= X-SBRS: 2.7 X-MesageID: 5800423 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,524,1559534400"; d="scan'208";a="5800423" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:24 +0100 Message-ID: <20190919171656.899649-5-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 04/35] libxl: Make libxl_retrieve_domain_configuration async 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" .. because it makes QMP calls which are going to be async. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl.h | 13 ++++++++++++- tools/libxl/libxl_domain.c | 14 +++++++------- tools/xl/xl_info.c | 3 ++- tools/xl/xl_saverestore.c | 3 ++- tools/xl/xl_vmcontrol.c | 3 ++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index fd69e92166b8..fd1e1349bf6a 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1221,6 +1221,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); * libxl_domain_unpause() * libxl_send_trigger() * libxl_set_vcpuonline() + * libxl_retrieve_domain_configuration() */ #define LIBXL_HAVE_FN_USING_QMP_ASYNC 1 @@ -1564,8 +1565,18 @@ void libxl_domain_config_dispose(libxl_domain_config *d_config); * works with DomU. */ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, - libxl_domain_config *d_config) + libxl_domain_config *d_config, + const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; +#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300 +static inline int libxl_retrieve_domain_configuration_0x041200( + libxl_ctx *ctx, uint32_t domid, libxl_domain_config *d_config) +{ + return libxl_retrieve_domain_configuration(ctx, domid, d_config, NULL); +} +#define libxl_retrieve_domain_configuration \ + libxl_retrieve_domain_configuration_0x041200 +#endif int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags, /* LIBXL_SUSPEND_* */ diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 60c3f7a34b4c..f2d5c86427ad 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1594,14 +1594,13 @@ static int libxl__update_avail_vcpus_xenstore(libxl__gc *gc, uint32_t domid, } int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, - libxl_domain_config *d_config) + libxl_domain_config *d_config, + const libxl_asyncop_how *ao_how) { - GC_INIT(ctx); + AO_CREATE(ctx, domid, ao_how); int rc; libxl__domain_userdata_lock *lock = NULL; - CTX_LOCK; - lock = libxl__lock_domain_userdata(gc, domid); if (!lock) { rc = ERROR_LOCK_FAIL; @@ -1808,9 +1807,10 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, out: if (lock) libxl__unlock_domain_userdata(lock); - CTX_UNLOCK; - GC_FREE; - return rc; + if (rc) + return AO_CREATE_FAIL(rc); + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; } /* diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c index bfbca93997dd..ca417df8e8a5 100644 --- a/tools/xl/xl_info.c +++ b/tools/xl/xl_info.c @@ -464,7 +464,8 @@ static void list_domains_details(const libxl_dominfo *info, int nb_domain) for (i = 0; i < nb_domain; i++) { libxl_domain_config_init(&d_config); - rc = libxl_retrieve_domain_configuration(ctx, info[i].domid, &d_config); + rc = libxl_retrieve_domain_configuration(ctx, info[i].domid, + &d_config, NULL); if (rc) continue; if (default_output_format == OUTPUT_FORMAT_JSON) diff --git a/tools/xl/xl_saverestore.c b/tools/xl/xl_saverestore.c index 5c70e2e8747d..9be033fe65e4 100644 --- a/tools/xl/xl_saverestore.c +++ b/tools/xl/xl_saverestore.c @@ -56,7 +56,8 @@ void save_domain_core_begin(uint32_t domid, &d_config); free(config_v); } else { - rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config); + rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config, + NULL); if (rc) { fprintf(stderr, "unable to retrieve domain configuration\n"); exit(EXIT_FAILURE); diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 3fc6f565748c..eb6779a56197 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -377,7 +377,8 @@ static void reload_domain_config(uint32_t domid, } libxl_domain_config_init(&d_config_new); - rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config_new); + rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config_new, + NULL); if (rc) { LOG("failed to retrieve guest configuration (rc=%d). " "reusing old configuration", rc); From patchwork Thu Sep 19 17:16:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152937 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 2ADD114DB for ; Thu, 19 Sep 2019 17:18:24 +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 06A8E217D6 for ; Thu, 19 Sep 2019 17:18:24 +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="eHxTjhDo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06A8E217D6 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 1iB03M-0000uw-C8; Thu, 19 Sep 2019 17:17:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB03L-0000ua-8W for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:11 +0000 X-Inumbo-ID: 4cc3c9f4-db01-11e9-978d-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4cc3c9f4-db01-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5lXH6LoQMSLoUqlZd8iS2EJBv9405IMHRGZeH3BV5dI=; b=eHxTjhDoDIS4wY37/rcBH0ioSYaNWyVKI2d6ZFfvBtg+osQvcRkHZL7l 5BHWBlObQKHHHYg32yBmV3cxzUaZJQwfhVTfnszO6bF9zqolGASp4KAS5 2P5qLX61mXfbhwPemOwPTiKW+H0BjBdInI79i/RJdV77TPhrfWy5/o2uH I=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Cwu3crThgW2bcZGD4ePVaDfxsBOXl1n5/hNwPoX71Nwig6MXm0zhTkQcC3PStojCOSHvwEPhV+ N1xUXc67Qqz7w+oM1HKbP6+XuQ+g2beOklt6ZEowiswtQjexgKK1/Za0KvrES2x4SQMT8ZjmY2 Q1CEN+JNQG2hiJEf9lTyts59q5I3A9KFCnQIh98vZ0QHTeulPai3SthIHg3YqiU3iJFF5Xl8lE 9DKe3sVXm+TDBQ4NeB3t/+g9XvVmsP6qeLGyt+7BBLFQ5ilmEqw7Pg3G6fVfBG3uRI2q2YGOx6 IQI= X-SBRS: 2.7 X-MesageID: 6009422 X-Ironport-Server: esa5.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="6009422" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:25 +0100 Message-ID: <20190919171656.899649-6-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 05/35] libxl: Make libxl_qemu_monitor_command async 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" .. because it makes QMP calls which are going to be async. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl.h | 14 +++++++++++++- tools/libxl/libxl_qmp.c | 9 +++++---- tools/xl/xl_misc.c | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index fd1e1349bf6a..ba48e7e900d3 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1222,6 +1222,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); * libxl_send_trigger() * libxl_set_vcpuonline() * libxl_retrieve_domain_configuration() + * libxl_qemu_monitor_command() */ #define LIBXL_HAVE_FN_USING_QMP_ASYNC 1 @@ -2571,7 +2572,18 @@ int libxl_fd_set_nonblock(libxl_ctx *ctx, int fd, int nonblock); * via output. */ int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid, - const char *command_line, char **output); + const char *command_line, char **output, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300 +static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx, + uint32_t domid, const char *command_line, char **output) +{ + return libxl_qemu_monitor_command(ctx, domid, command_line, output, + NULL); +} +#define libxl_qemu_monitor_command libxl_qemu_monitor_command_0x041200 +#endif #include diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 20d9eed8ddc8..505e0e5469a9 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -1291,15 +1291,16 @@ int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line, } int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid, - const char *command_line, char **output) + const char *command_line, char **output, + const libxl_asyncop_how *ao_how) { - GC_INIT(ctx); + AO_CREATE(ctx, domid, ao_how); int rc; rc = libxl__qmp_hmp(gc, domid, command_line, output); - GC_FREE; - return rc; + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; } int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid, diff --git a/tools/xl/xl_misc.c b/tools/xl/xl_misc.c index 50c8436337c9..20ed605f4f44 100644 --- a/tools/xl/xl_misc.c +++ b/tools/xl/xl_misc.c @@ -228,7 +228,7 @@ int main_qemu_monitor_command(int argc, char **argv) return EXIT_FAILURE; } - ret = libxl_qemu_monitor_command(ctx, domid, cmd, &output); + ret = libxl_qemu_monitor_command(ctx, domid, cmd, &output, NULL); if (!ret && output) { printf("%s\n", output); free(output); From patchwork Thu Sep 19 17:16:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152955 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 0864C14ED for ; Thu, 19 Sep 2019 17:19:11 +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 D843E217D6 for ; Thu, 19 Sep 2019 17:19:10 +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="XaOIn2ct" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D843E217D6 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 1iB03g-00017F-UM; Thu, 19 Sep 2019 17:17:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB03f-00015f-9i for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:31 +0000 X-Inumbo-ID: 572994f0-db01-11e9-978d-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 572994f0-db01-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913442; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=49q/dBETBhu36aRlJejkevM+6DNxYO1BQnfYZjp8rME=; b=XaOIn2ctASluuVHqct0a7NYG4H/B6moCrU61oLt0ZhTyKsvV/wx939yp bvEXIaJ7iCxzO+Olv2VP9asHeP5co9WHdjX7Zn4RF0ur8z6nwKTUBO0pK gHs26h7l+hWfz28G5d9fOmP/GLUK2olYh7SbBshycf43xA0VigXQ4jwD2 w=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: G61ptleMwO4YNTmYQ6qYIgLlpS7T/2tSNsl4q9pnloDcH5KuBXxKTb4RWEqS6lQTtrFUW0N0kn cAtWAM7aA+iLOJGD8A2FZoYVxF18bZ+KNk7bfPXbpeFUCN/f3Jm/CPewlgCQIg8OmN3/O0WyiG kWlWe415qOno8Q16GUPFJbQAcg1/ebDUoVexOWW9LkMSdiBcba4hAWKyVoD95q6Nn/+l9zLzUC 8Szu3kbGKhdLUhJo9kTP6xF05vsTq3uh0Sn+zmzDZfeSOtIIOK3qwNcAG2D5ft33BpMui1l19d JJs= X-SBRS: 2.7 X-MesageID: 5800426 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,524,1559534400"; d="scan'208";a="5800426" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:26 +0100 Message-ID: <20190919171656.899649-7-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 06/35] libxl: Use ev_qmp for switch_qemu_xen_logdirty 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_dom_save.c | 41 ++++++++++++++++++++++++++++++++---- tools/libxl/libxl_internal.h | 3 +-- tools/libxl/libxl_qmp.c | 10 --------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/tools/libxl/libxl_dom_save.c b/tools/libxl/libxl_dom_save.c index 13d08d6dae14..e70aa1585976 100644 --- a/tools/libxl/libxl_dom_save.c +++ b/tools/libxl/libxl_dom_save.c @@ -44,6 +44,10 @@ static void switch_logdirty_xswatch(libxl__egc *egc, libxl__ev_xswatch*, static void domain_suspend_switch_qemu_xen_logdirty (libxl__egc *egc, int domid, unsigned enable, libxl__logdirty_switch *lds); +static void switch_qemu_xen_logdirty_done(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *, + int rc); static void switch_logdirty_timeout(libxl__egc *egc, libxl__ev_time *ev, const struct timeval *requested_abs, int rc); @@ -55,6 +59,7 @@ void libxl__logdirty_init(libxl__logdirty_switch *lds) lds->cmd_path = 0; libxl__ev_xswatch_init(&lds->watch); libxl__ev_time_init(&lds->timeout); + libxl__ev_qmp_init(&lds->qmp); } void libxl__domain_common_switch_qemu_logdirty(libxl__egc *egc, @@ -207,13 +212,40 @@ static void domain_suspend_switch_qemu_xen_logdirty { STATE_AO_GC(lds->ao); int rc; + libxl__json_object *args = NULL; + + /* Convenience aliases. */ + libxl__ev_qmp *const qmp = &lds->qmp; + + rc = libxl__ev_time_register_rel(ao, &lds->timeout, + switch_logdirty_timeout, 10 * 1000); + if (rc) goto out; + + qmp->ao = ao; + qmp->domid = domid; + qmp->payload_fd = -1; + qmp->callback = switch_qemu_xen_logdirty_done; + libxl__qmp_param_add_bool(gc, &args, "enable", enable); + rc = libxl__ev_qmp_send(gc, qmp, "xen-set-global-dirty-log", args); + if (rc) goto out; + + return; +out: + switch_qemu_xen_logdirty_done(egc, qmp, NULL, rc); +} + +static void switch_qemu_xen_logdirty_done(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *r, + int rc) +{ + EGC_GC; + libxl__logdirty_switch *lds = CONTAINER_OF(qmp, *lds, qmp); - rc = libxl__qmp_set_global_dirty_log(gc, domid, enable); if (rc) - LOGD(ERROR, domid, + LOGD(ERROR, qmp->domid, "logdirty switch failed (rc=%d), abandoning suspend",rc); - - lds->callback(egc, lds, rc); + switch_logdirty_done(egc, lds, rc); } static void switch_logdirty_timeout(libxl__egc *egc, libxl__ev_time *ev, @@ -234,6 +266,7 @@ static void switch_logdirty_done(libxl__egc *egc, libxl__ev_xswatch_deregister(gc, &lds->watch); libxl__ev_time_deregister(gc, &lds->timeout); + libxl__ev_qmp_dispose(gc, &lds->qmp); lds->callback(egc, lds, rc); } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 7486b512fd54..c4834ac9c6c5 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1958,8 +1958,6 @@ _hidden int libxl__qmp_system_wakeup(libxl__gc *gc, int domid); _hidden int libxl__qmp_resume(libxl__gc *gc, int domid); /* Load current QEMU state from file. */ _hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename); -/* Set dirty bitmap logging status */ -_hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable); /* Add a virtual CPU */ _hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index); /* Query the bitmap of CPUs */ @@ -3413,6 +3411,7 @@ typedef struct libxl__logdirty_switch { const char *ret_path; libxl__ev_xswatch watch; libxl__ev_time timeout; + libxl__ev_qmp qmp; } libxl__logdirty_switch; _hidden void libxl__logdirty_init(libxl__logdirty_switch *lds); diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 505e0e5469a9..f1529925ee0e 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -1108,16 +1108,6 @@ int libxl__qmp_resume(libxl__gc *gc, int domid) return qmp_run_command(gc, domid, "cont", NULL, NULL, NULL); } -int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable) -{ - libxl__json_object *args = NULL; - - libxl__qmp_param_add_bool(gc, &args, "enable", enable); - - return qmp_run_command(gc, domid, "xen-set-global-dirty-log", args, - NULL, NULL); -} - int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx) { libxl__json_object *args = NULL; From patchwork Thu Sep 19 17:16:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152945 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 1034114ED for ; Thu, 19 Sep 2019 17:18:41 +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 DF9C8217D6 for ; Thu, 19 Sep 2019 17:18:40 +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="LuR//gjM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF9C8217D6 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 1iB03f-00015z-Hx; Thu, 19 Sep 2019 17:17:31 +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 1iB03f-00015N-1l for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:31 +0000 X-Inumbo-ID: 56c2f84e-db01-11e9-966e-12813bfff9fa Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 56c2f84e-db01-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913442; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3OGLtYZfyPHawWBYlYohVh3qmyAkClcP/WYK0TFX9JA=; b=LuR//gjMGI/21MLKgbPuPOkQJ7/ol0XzmnoGqqoBpuw7uD9lI2n+bJRz krwW5kOSTwPQPSjyGMP3QksWCzMvgjujgkk3o2YMV8/b91AH1AsyZMTE/ sr2T7eRRdUbryHWqmdpnDURfoqljb2t4xnGBDQV3WjGCcc0Zkngh8LgGq 4=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: IrjH5+7w8Q72AUdumyl7zOv0XLTP4FfkTudINQ4GjgXr6EaBdqpXksUU3p+AI0OKHENxet4O3v F3UfyBteWsULz233sB4h/ROVjT3AB+2QwCXM1Xto8E0cZhi6OC8RDwHUXHPyVy9K/q91zXVZna HdRg6sIu7FYBRZfpu1dEeTIKGspB74znXvX3SckTgqQYteQbQmwOS03TDPxKVAGFYGihEkUVpL Y4uEexMd7SLKeOyQLnjkSNwbgeOWGPO4IxPiLfDr0SAiLD4+3w7qFeeb4r0/BoEN+xw8fuGrsp whk= X-SBRS: 2.7 X-MesageID: 5800425 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,524,1559534400"; d="scan'208";a="5800425" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:27 +0100 Message-ID: <20190919171656.899649-8-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 07/35] libxl: Move "qmp_initializations" to libxl_dm 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" libxl__qmp_initializations is part of the device domain startup, it queries information about the newly spawned QEMU and do some post-startup configuration. So the function call doesn't belong to the general domain creation, but only to the device model part of the process, thus the call belong to libxl_dm and libxl__dm_spawn_state's machinery. We move the call ahead of a follow-up patch which going to "inline" libxl__qmp_initializations. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_create.c | 10 ---------- tools/libxl/libxl_dm.c | 8 ++++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 3f31f2ebcd1f..93fbe1d74067 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1557,21 +1557,11 @@ static void domcreate_devmodel_started(libxl__egc *egc, STATE_AO_GC(dmss->spawn.ao); int domid = dcs->guest_domid; - /* convenience aliases */ - libxl_domain_config *const d_config = dcs->guest_config; - if (ret) { LOGD(ERROR, domid, "device model did not start: %d", ret); goto error_out; } - if (dcs->sdss.dm.guest_domid) { - if (d_config->b_info.device_model_version - == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { - libxl__qmp_initializations(gc, domid, d_config); - } - } - dcs->device_type_idx = -1; domcreate_attach_devices(egc, &dcs->multidev, 0); return; diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 00da59153d67..5a2e3497769d 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2744,6 +2744,9 @@ static void device_model_spawn_outcome(libxl__egc *egc, STATE_AO_GC(dmss->spawn.ao); int ret2; + /* Convenience aliases */ + libxl_domain_config *const d_config = dmss->guest_config; + if (rc) LOGD(ERROR, dmss->guest_domid, "%s: spawn failed (rc=%d)", dmss->spawn.what, rc); @@ -2760,6 +2763,11 @@ static void device_model_spawn_outcome(libxl__egc *egc, } } + if (d_config->b_info.device_model_version + == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { + libxl__qmp_initializations(gc, dmss->guest_domid, d_config); + } + out: dmss_dispose(gc, dmss); dmss->callback(egc, dmss, rc); From patchwork Thu Sep 19 17:16:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152939 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 23AE014DB for ; Thu, 19 Sep 2019 17:18:32 +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 E788B217D6 for ; Thu, 19 Sep 2019 17:18:31 +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="esrGqvXY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E788B217D6 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 1iB03C-0000sI-Im; Thu, 19 Sep 2019 17:17:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB03B-0000sC-8A for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:01 +0000 X-Inumbo-ID: 49ee74f4-db01-11e9-a337-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 49ee74f4-db01-11e9-a337-bc764e2007e4; Thu, 19 Sep 2019 17:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wpCQu9yT8V2b191ia7CuS8Z5qR1eobgDrX2wdGUOgKQ=; b=esrGqvXY0dKg7XwKYCdCCj6HxKBt/v9V7cnWgVxpCXfAM5JMhwryFwCJ Po0bsteBxtmXVLPHDlKx2eZ2sC+xAA96B3g+35x8TP0tfYCmXCWbuDaZ1 Nb+t8EsS0w/kzGMtl+v111BduWgqyrg/PWrOXYYZdY49hoX1mcDfjeMPN c=; 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 (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: 1Z9O12gCQAHWXw20DejDi4CPdmqS/Tf/oytM+cO6OcJrusLIXJei6RakMM/BaPuUukOspaXL/9 QWPAaOkg9bnAONYov//64rmhUU6kOM1dXM5AyjbflbfSJxKC40U5rIm+ShHJKoExgQ4+m3qxL+ rDKDD0GYOkZp9Gi3wgaBKRxOKihgbCqTw5xp3mTzqPph7v2tsd5GfHuXmPnSrvHxEXmhgHCL3d l6qBRq5opRWnDdCAekOamMPk5DtTFjUXiYPPzb8Vc+359IklKQc3oMFU0qB8Y48pavoFhk7Dgd tXY= X-SBRS: 2.7 X-MesageID: 6062784 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="6062784" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:28 +0100 Message-ID: <20190919171656.899649-9-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 08/35] libxl: Replace libxl__qmp_initializations by ev_qmp calls 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" Setup a timeout of 10s for all the commands. It used to be about 5s per commands. The order of command is changed, we call 'query-vnc' before 'change-vnc-password', but that should not matter. That makes it easier to call 'change-vnc-password' conditionally. Also 'change' command is replaced by 'change-vnc-password' because 'change' is deprecated. The new command is available in all QEMU versions that also have Xen support. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_dm.c | 211 ++++++++++++++++++++++++++++++++++- tools/libxl/libxl_internal.h | 8 +- tools/libxl/libxl_qmp.c | 169 ---------------------------- 3 files changed, 212 insertions(+), 176 deletions(-) diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 5a2e3497769d..bb5339784ea8 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2063,11 +2063,13 @@ static int libxl__write_stub_dmargs(libxl__gc *gc, static void dmss_init(libxl__dm_spawn_state *dmss) { libxl__ev_qmp_init(&dmss->qmp); + libxl__ev_time_init(&dmss->timeout); } static void dmss_dispose(libxl__gc *gc, libxl__dm_spawn_state *dmss) { libxl__ev_qmp_dispose(gc, &dmss->qmp); + libxl__ev_time_deregister(gc, &dmss->timeout); } static void spawn_stubdom_pvqemu_cb(libxl__egc *egc, @@ -2462,6 +2464,16 @@ static void device_model_qmp_cb(libxl__egc *egc, libxl__ev_qmp *ev, static void device_model_spawn_outcome(libxl__egc *egc, libxl__dm_spawn_state *dmss, int rc); +static void device_model_postconfig_chardev(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); +static void device_model_postconfig_vnc(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); +static void device_model_postconfig_vnc_passwd(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); +static void devise_model_postconfig_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void device_model_postconfig_done(libxl__egc *egc, + libxl__dm_spawn_state *dmss, int rc); void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss) { @@ -2763,12 +2775,209 @@ static void device_model_spawn_outcome(libxl__egc *egc, } } + /* Check if spawn failed */ + if (rc) goto out; + if (d_config->b_info.device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { - libxl__qmp_initializations(gc, dmss->guest_domid, d_config); + rc = libxl__ev_time_register_rel(ao, &dmss->timeout, + devise_model_postconfig_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + dmss->qmp.ao = ao; + dmss->qmp.domid = dmss->guest_domid; + dmss->qmp.payload_fd = -1; + dmss->qmp.callback = device_model_postconfig_chardev; + rc = libxl__ev_qmp_send(gc, &dmss->qmp, "query-chardev", NULL); + if (rc) goto out; + return; } out: + device_model_postconfig_done(egc, dmss, rc); /* must be last */ +} + +static void device_model_postconfig_chardev(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + EGC_GC; + libxl__dm_spawn_state *dmss = CONTAINER_OF(qmp, *dmss, qmp); + const libxl__json_object *item = NULL; + const libxl__json_object *o = NULL; + int i = 0; + const char *label; + const char *filename; + int port; + char *endptr; + const char *dompath; + const char serial[] = "serial"; + const size_t seriall = sizeof(serial) - 1; + const char pty[] = "pty:"; + const size_t ptyl = sizeof(pty) - 1; + + if (rc) goto out; + + /* + * query-chardev response: + * [{ 'label': 'str', + * 'filename': 'str', + * 'frontend-open': 'bool' }, ...] + */ + + for (i = 0; (item = libxl__json_array_get(response, i)); i++) { + o = libxl__json_map_get("label", item, JSON_STRING); + if (!o) goto protocol_error; + label = libxl__json_object_get_string(o); + + /* Check if the "label" start with "serial". */ + if (!label || strncmp(label, serial, seriall)) + continue; + port = strtol(label + seriall, &endptr, 10); + if (*(label + seriall) == '\0' || *endptr != '\0') { + LOGD(ERROR, qmp->domid, + "Invalid serial port number: %s", label); + rc = ERROR_QEMU_API; + goto out; + } + + o = libxl__json_map_get("filename", item, JSON_STRING); + if (!o) goto protocol_error; + filename = libxl__json_object_get_string(o); + + /* Check if filename start with "pty:" */ + if (!filename || strncmp(filename, pty, ptyl)) + continue; + + dompath = libxl__xs_get_dompath(gc, qmp->domid); + if (!dompath) { + rc = ERROR_FAIL; + goto out; + } + rc = libxl__xs_printf(gc, XBT_NULL, + GCSPRINTF("%s/serial/%d/tty", dompath, port), + "%s", filename + ptyl); + if (rc) goto out; + } + + qmp->callback = device_model_postconfig_vnc; + rc = libxl__ev_qmp_send(gc, qmp, "query-vnc", NULL); + if (rc) goto out; + return; + +protocol_error: + rc = ERROR_QEMU_API; + LOGD(ERROR, qmp->domid, + "unexpected response to QMP cmd 'query-chardev', received:\n%s", + JSON(response)); +out: + device_model_postconfig_done(egc, dmss, rc); /* must be last */ +} + +static void device_model_postconfig_vnc(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + EGC_GC; + libxl__dm_spawn_state *dmss = CONTAINER_OF(qmp, *dmss, qmp); + const libxl_vnc_info *vnc = libxl__dm_vnc(dmss->guest_config); + const libxl__json_object *o; + libxl__json_object *args = NULL; + + if (rc) goto out; + + /* + * query-vnc response: + * { 'enabled': 'bool', '*host': 'str', '*service': 'str' } + */ + + o = libxl__json_map_get("enabled", response, JSON_BOOL); + if (!o) goto protocol_error; + if (libxl__json_object_get_bool(o)) { + const char *addr, *port; + const char *dompath; + + o = libxl__json_map_get("host", response, JSON_STRING); + if (!o) goto protocol_error; + addr = libxl__json_object_get_string(o); + o = libxl__json_map_get("service", response, JSON_STRING); + if (!o) goto protocol_error; + port = libxl__json_object_get_string(o); + + dompath = libxl__xs_get_dompath(gc, qmp->domid); + if (!dompath) { + rc = ERROR_FAIL; + goto out; + } + rc = libxl__xs_printf(gc, XBT_NULL, + GCSPRINTF("%s/console/vnc-listen", dompath), + "%s", addr); + if (rc) goto out; + rc = libxl__xs_printf(gc, XBT_NULL, + GCSPRINTF("%s/console/vnc-port", dompath), + "%s", port); + if (rc) goto out; + } + + if (vnc && vnc->passwd) { + qmp->callback = device_model_postconfig_vnc_passwd; + libxl__qmp_param_add_string(gc, &args, "password", vnc->passwd); + rc = libxl__ev_qmp_send(gc, qmp, "change-vnc-password", args); + if (rc) goto out; + return; + } + + rc = 0; + goto out; + +protocol_error: + rc = ERROR_QEMU_API; + LOGD(ERROR, qmp->domid, + "unexpected response to QMP cmd 'query-vnc', received:\n%s", + JSON(response)); +out: + device_model_postconfig_done(egc, dmss, rc); /* must be last */ +} + +static void device_model_postconfig_vnc_passwd(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + EGC_GC; + libxl__dm_spawn_state *dmss = CONTAINER_OF(qmp, *dmss, qmp); + const libxl_vnc_info *vnc = libxl__dm_vnc(dmss->guest_config); + const char *dompath; + + if (rc) goto out; + + dompath = libxl__xs_get_dompath(gc, qmp->domid); + if (!dompath) { + rc = ERROR_FAIL; + goto out; + } + rc = libxl__xs_printf(gc, XBT_NULL, + GCSPRINTF("%s/console/vnc-pass", dompath), + "%s", vnc->passwd); + +out: + device_model_postconfig_done(egc, dmss, rc); /* must be last */ +} + +void devise_model_postconfig_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + libxl__dm_spawn_state *dmss = CONTAINER_OF(ev, *dmss, timeout); + device_model_postconfig_done(egc, dmss, rc); /* must be last */ +} + + +static void device_model_postconfig_done(libxl__egc *egc, + libxl__dm_spawn_state *dmss, + int rc) +{ + EGC_GC; + + if (rc) + LOGD(ERROR, dmss->guest_domid, + "Post DM startup configs failed, rc=%d", rc); dmss_dispose(gc, dmss); dmss->callback(egc, dmss, rc); } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index c4834ac9c6c5..f5f234be7e3c 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -100,6 +100,7 @@ #define LIBXL_DEVICE_MODEL_START_TIMEOUT 60 #define LIBXL_DEVICE_MODEL_SAVE_FILE XEN_LIB_DIR "/qemu-save" /* .$domid */ #define LIBXL_DEVICE_MODEL_RESTORE_FILE XEN_LIB_DIR "/qemu-resume" /* .$domid */ +#define LIBXL_QMP_CMD_TIMEOUT 10 #define LIBXL_STUBDOM_START_TIMEOUT 30 #define LIBXL_QEMU_BODGE_TIMEOUT 2 #define LIBXL_XENCONSOLE_LIMIT 1048576 @@ -1947,8 +1948,6 @@ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, _hidden int libxl__qmp_run_command_flexarray(libxl__gc *gc, int domid, const char *cmd, flexarray_t *array); -/* ask to QEMU the serial port information and store it in xenstore. */ -_hidden int libxl__qmp_query_serial(libxl__qmp_handler *qmp); _hidden int libxl__qmp_pci_add(libxl__gc *gc, int d, libxl_device_pci *pcidev); _hidden int libxl__qmp_pci_del(libxl__gc *gc, int domid, libxl_device_pci *pcidev); @@ -1994,10 +1993,6 @@ _hidden void libxl__qmp_close(libxl__qmp_handler *qmp); * nothing happen */ _hidden void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid); -/* this helper calls qmp_initialize, query_serial and qmp_close */ -_hidden int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid, - const libxl_domain_config *guest_config); - /* `data' should contain a byte to send. * When dealing with a non-blocking fd, it returns * ERROR_NOT_READY on EWOULDBLOCK @@ -3954,6 +3949,7 @@ struct libxl__dm_spawn_state { /* mixed - spawn.ao must be initialised by user; rest is private: */ libxl__spawn_state spawn; libxl__ev_qmp qmp; + libxl__ev_time timeout; /* filled in by user, must remain valid: */ uint32_t guest_domid; /* domain being served */ libxl_domain_config *guest_config; diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index f1529925ee0e..0d6aedcc7d3c 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -143,121 +143,6 @@ static const int QMP_SOCKET_CONNECT_TIMEOUT = 5; * QMP callbacks functions */ -static int store_serial_port_info(libxl__qmp_handler *qmp, - const char *chardev, - int port) -{ - GC_INIT(qmp->ctx); - char *path = NULL; - int ret = 0; - - if (!(chardev && strncmp("pty:", chardev, 4) == 0)) { - return 0; - } - - path = libxl__xs_get_dompath(gc, qmp->domid); - path = GCSPRINTF("%s/serial/%d/tty", path, port); - - ret = libxl__xs_printf(gc, XBT_NULL, path, "%s", chardev + 4); - - GC_FREE; - return ret; -} - -static int register_serials_chardev_callback(libxl__qmp_handler *qmp, - const libxl__json_object *o, - void *unused) -{ - const libxl__json_object *obj = NULL; - const libxl__json_object *label = NULL; - const char *s = NULL; - int i = 0; - const char *chardev = NULL; - int ret = 0; - - for (i = 0; (obj = libxl__json_array_get(o, i)); i++) { - if (!libxl__json_object_is_map(obj)) - continue; - label = libxl__json_map_get("label", obj, JSON_STRING); - s = libxl__json_object_get_string(label); - - if (s && strncmp("serial", s, strlen("serial")) == 0) { - const libxl__json_object *filename = NULL; - char *endptr = NULL; - int port_number; - - filename = libxl__json_map_get("filename", obj, JSON_STRING); - chardev = libxl__json_object_get_string(filename); - - s += strlen("serial"); - port_number = strtol(s, &endptr, 10); - if (*s == 0 || *endptr != 0) { - LIBXL__LOGD(qmp->ctx, LIBXL__LOG_ERROR, qmp->domid, - "Invalid serial port number: %s", s); - return -1; - } - ret = store_serial_port_info(qmp, chardev, port_number); - if (ret) { - LIBXL__LOGD_ERRNO(qmp->ctx, LIBXL__LOG_ERROR, qmp->domid, - "Failed to store serial port information" - " in xenstore"); - return ret; - } - } - }; - - return ret; -} - -static int qmp_write_domain_console_item(libxl__gc *gc, int domid, - const char *item, const char *value) -{ - char *path; - - path = libxl__xs_get_dompath(gc, domid); - path = GCSPRINTF("%s/console/%s", path, item); - - return libxl__xs_printf(gc, XBT_NULL, path, "%s", value); -} - -static int qmp_register_vnc_callback(libxl__qmp_handler *qmp, - const libxl__json_object *o, - void *unused) -{ - GC_INIT(qmp->ctx); - const libxl__json_object *obj; - const char *addr, *port; - int rc = -1; - - if (!libxl__json_object_is_map(o)) { - goto out; - } - - obj = libxl__json_map_get("enabled", o, JSON_BOOL); - if (!obj || !libxl__json_object_get_bool(obj)) { - rc = 0; - goto out; - } - - obj = libxl__json_map_get("host", o, JSON_STRING); - addr = libxl__json_object_get_string(obj); - obj = libxl__json_map_get("service", o, JSON_STRING); - port = libxl__json_object_get_string(obj); - - if (!addr || !port) { - LOGD(ERROR, qmp->domid, "Failed to retrieve VNC connect information."); - goto out; - } - - rc = qmp_write_domain_console_item(gc, qmp->domid, "vnc-listen", addr); - if (!rc) - rc = qmp_write_domain_console_item(gc, qmp->domid, "vnc-port", port); - -out: - GC_FREE; - return rc; -} - static int qmp_capabilities_callback(libxl__qmp_handler *qmp, const libxl__json_object *o, void *unused) { @@ -851,20 +736,6 @@ void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid) } } -int libxl__qmp_query_serial(libxl__qmp_handler *qmp) -{ - return qmp_synchronous_send(qmp, "query-chardev", NULL, - register_serials_chardev_callback, - NULL, qmp->timeout); -} - -static int qmp_query_vnc(libxl__qmp_handler *qmp) -{ - return qmp_synchronous_send(qmp, "query-vnc", NULL, - qmp_register_vnc_callback, - NULL, qmp->timeout); -} - static int pci_add_callback(libxl__qmp_handler *qmp, const libxl__json_object *response, void *opaque) { @@ -1085,24 +956,6 @@ int libxl__qmp_restore(libxl__gc *gc, int domid, const char *state_file) NULL, NULL); } -static int qmp_change(libxl__gc *gc, libxl__qmp_handler *qmp, - char *device, char *target, char *arg) -{ - libxl__json_object *args = NULL; - int rc = 0; - - libxl__qmp_param_add_string(gc, &args, "device", device); - libxl__qmp_param_add_string(gc, &args, "target", target); - if (arg) { - libxl__qmp_param_add_string(gc, &args, "arg", arg); - } - - rc = qmp_synchronous_send(qmp, "change", args, - NULL, NULL, qmp->timeout); - - return rc; -} - int libxl__qmp_resume(libxl__gc *gc, int domid) { return qmp_run_command(gc, domid, "cont", NULL, NULL, NULL); @@ -1293,28 +1146,6 @@ int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid, return AO_INPROGRESS; } -int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid, - const libxl_domain_config *guest_config) -{ - const libxl_vnc_info *vnc = libxl__dm_vnc(guest_config); - libxl__qmp_handler *qmp = NULL; - int ret = 0; - - qmp = libxl__qmp_initialize(gc, domid); - if (!qmp) - return -1; - ret = libxl__qmp_query_serial(qmp); - if (!ret && vnc && vnc->passwd) { - ret = qmp_change(gc, qmp, "vnc", "password", vnc->passwd); - qmp_write_domain_console_item(gc, domid, "vnc-pass", vnc->passwd); - } - if (!ret) { - ret = qmp_query_vnc(qmp); - } - libxl__qmp_close(qmp); - return ret; -} - /* * Functions using libxl__ev_qmp From patchwork Thu Sep 19 17:16:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152947 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 8C95814DB for ; Thu, 19 Sep 2019 17:18:55 +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 5D227217D6 for ; Thu, 19 Sep 2019 17:18:54 +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="MYTYxbW9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D227217D6 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 1iB03H-0000tC-TL; Thu, 19 Sep 2019 17:17:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB03G-0000ss-8M for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:17:06 +0000 X-Inumbo-ID: 4c605964-db01-11e9-a337-bc764e2007e4 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4c605964-db01-11e9-a337-bc764e2007e4; Thu, 19 Sep 2019 17:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568913424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4anWEIAxyS+Xid9vj3B3eTP68Z1g0RchEBW0hcaqr+k=; b=MYTYxbW9FWL/flBAHKYcJyXX1ae56K125pYOXcECv9AmFqNuRlR8vgWX xdO5KyKC8K8xCWqNNzlZv27Tt0QG705RReHtWAkmCWA04idGDA+9oOWxw tZzvFJxElGjaHQAEo1WqlS/WDsR+ku+pwXoFwKfyoS2UmUqIbzp2md9qH 8=; Authentication-Results: esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.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=esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: YXFkbCCEOGV410H9Rt0nMie0ITnI4uyAkvu4k3ZTXu2jrY7EmTn0pbjLnLgn6E1tDpRU00Y8FS DF7xA/6Jjtl3QIytUV+8R4S4imYqSs6wO2Qo9QStGwCoYtZ6mL8kLVCJT5343EyGyBMktZgtIm g0Dkzxk8a3cisI6kr75gN8Zm5thEYerw56AoYqkVEmvACiYA6fn+f1hjz1t55EwhLLuNvQgq16 V5FLfkLzwHmdZEaXQHL9OFYKgm7JOOfBkBDlJff3nhO7N39FhKrbPfjyDkfuwLsGp+TEtWg9iw qfk= X-SBRS: 2.7 X-MesageID: 5804915 X-Ironport-Server: esa3.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="5804915" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:29 +0100 Message-ID: <20190919171656.899649-10-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 09/35] libxl: Deprecate libxl__domain_{unpause, 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" These two functions are used from many places in libxl and need to change to be able to accomodate libxl__ev_qmp calls and thus needs to be asynchronous. (There is also libxl__domain_resume_device_model in the mix.) A later patch will introduce a new libxl__domain_resume and libxl__domain_unpause which will make use of libxl__ev_qmp. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_colo_restore.c | 4 ++-- tools/libxl/libxl_colo_save.c | 4 ++-- tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_dom_suspend.c | 6 +++--- tools/libxl/libxl_domain.c | 8 ++++---- tools/libxl/libxl_internal.h | 12 ++++++++---- tools/libxl/libxl_remus.c | 2 +- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tools/libxl/libxl_colo_restore.c b/tools/libxl/libxl_colo_restore.c index aaa70552b8c4..aa365670fb14 100644 --- a/tools/libxl/libxl_colo_restore.c +++ b/tools/libxl/libxl_colo_restore.c @@ -124,7 +124,7 @@ static void colo_resume_vm(libxl__egc *egc, return; } } - rc = libxl__domain_resume(gc, crs->domid, 0); + rc = libxl__domain_resume_deprecated(gc, crs->domid, 0); if (rc) LOGD(ERROR, crs->domid, "cannot resume secondary vm"); @@ -853,7 +853,7 @@ static void colo_unpause_svm(libxl__egc *egc, EGC_GC; /* We have enabled secondary vm's logdirty, so we can unpause it now */ - rc = libxl__domain_unpause(gc, domid); + rc = libxl__domain_unpause_deprecated(gc, domid); if (rc) { LOGD(ERROR, domid, "cannot unpause secondary vm"); goto out; diff --git a/tools/libxl/libxl_colo_save.c b/tools/libxl/libxl_colo_save.c index 1d261a1639f7..b47f038f6e6e 100644 --- a/tools/libxl/libxl_colo_save.c +++ b/tools/libxl/libxl_colo_save.c @@ -470,7 +470,7 @@ static void colo_preresume_cb(libxl__egc *egc, } /* Resumes the domain and the device model */ - if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1)) { + if (libxl__domain_resume_deprecated(gc, dss->domid, /* Fast Suspend */1)) { LOGD(ERROR, dss->domid, "cannot resume primary vm"); goto out; } @@ -480,7 +480,7 @@ static void colo_preresume_cb(libxl__egc *egc, * no disk migration. */ if (css->paused) { - rc = libxl__domain_unpause(gc, dss->domid); + rc = libxl__domain_unpause_deprecated(gc, dss->domid); if (rc) { LOGD(ERROR, dss->domid, "cannot unpause primary vm"); goto out; diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index bb5339784ea8..246c570121d3 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2404,7 +2404,7 @@ static void stubdom_pvqemu_cb(libxl__egc *egc, goto out; } - rc = libxl__domain_unpause(gc, dm_domid); + rc = libxl__domain_unpause_deprecated(gc, dm_domid); if (rc) goto out; sdss->xswait.ao = ao; diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.c index d1af3a657303..2460021e5a59 100644 --- a/tools/libxl/libxl_dom_suspend.c +++ b/tools/libxl/libxl_dom_suspend.c @@ -421,7 +421,7 @@ static void domain_suspend_callback_common_done(libxl__egc *egc, /*======================= Domain resume ========================*/ -int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid) +int libxl__domain_resume_device_model_deprecated(libxl__gc *gc, uint32_t domid) { const char *path, *state; @@ -449,7 +449,7 @@ int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid) return 0; } -int libxl__domain_resume(libxl__gc *gc, uint32_t domid, int suspend_cancel) +int libxl__domain_resume_deprecated(libxl__gc *gc, uint32_t domid, int suspend_cancel) { int rc = 0; @@ -460,7 +460,7 @@ int libxl__domain_resume(libxl__gc *gc, uint32_t domid, int suspend_cancel) } if (type == LIBXL_DOMAIN_TYPE_HVM) { - rc = libxl__domain_resume_device_model(gc, domid); + rc = libxl__domain_resume_device_model_deprecated(gc, domid); if (rc) { LOGD(ERROR, domid, "failed to resume device model:%d", rc); goto out; diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index f2d5c86427ad..80797c5ed21c 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -178,7 +178,7 @@ int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid, int suspend_cancel, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); - int rc = libxl__domain_resume(gc, domid, suspend_cancel); + int rc = libxl__domain_resume_deprecated(gc, domid, suspend_cancel); libxl__ao_complete(egc, ao, rc); return AO_INPROGRESS; } @@ -593,7 +593,7 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid, return AO_INPROGRESS; } -int libxl__domain_unpause(libxl__gc *gc, libxl_domid domid) +int libxl__domain_unpause_deprecated(libxl__gc *gc, libxl_domid domid) { int r, rc; @@ -604,7 +604,7 @@ int libxl__domain_unpause(libxl__gc *gc, libxl_domid domid) } if (type == LIBXL_DOMAIN_TYPE_HVM) { - rc = libxl__domain_resume_device_model(gc, domid); + rc = libxl__domain_resume_device_model_deprecated(gc, domid); if (rc < 0) { LOGD(ERROR, domid, "Failed to unpause device model for domain: %d", rc); @@ -628,7 +628,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid, AO_CREATE(ctx, domid, ao_how); int rc = 0; - rc = libxl__domain_unpause(gc, domid); + rc = libxl__domain_unpause_deprecated(gc, domid); if (rc) goto out; libxl__ao_complete(egc, ao, rc); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index f5f234be7e3c..db8860507b18 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1315,7 +1315,8 @@ _hidden int libxl__domain_rename(libxl__gc *gc, uint32_t domid, const char *old_name, const char *new_name, xs_transaction_t trans); -_hidden int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid); +/* Deprecated, use libxl__dm_resume instead. */ +_hidden int libxl__domain_resume_device_model_deprecated(libxl__gc *gc, uint32_t domid); _hidden const char *libxl__userdata_path(libxl__gc *gc, uint32_t domid, const char *userdata_userid, @@ -1332,8 +1333,12 @@ _hidden int libxl__userdata_store(libxl__gc *gc, uint32_t domid, const char *userdata_userid, const uint8_t *data, int datalen); -_hidden int libxl__domain_resume(libxl__gc *gc, uint32_t domid, - int suspend_cancel); +/* Deprecated, use libxl__domain_resume instead */ +_hidden int libxl__domain_resume_deprecated(libxl__gc *gc, uint32_t domid, + int suspend_cancel); +/* Deprecated, use libxl__domain_unpause instead */ +_hidden int libxl__domain_unpause_deprecated(libxl__gc *, + libxl_domid domid); /* returns 0 or 1, or a libxl error code */ _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid); @@ -4104,7 +4109,6 @@ _hidden void libxl__remus_teardown(libxl__egc *egc, int rc); _hidden void libxl__remus_restore_setup(libxl__egc *egc, libxl__domain_create_state *dcs); -_hidden int libxl__domain_unpause(libxl__gc *, libxl_domid domid); /* diff --git a/tools/libxl/libxl_remus.c b/tools/libxl/libxl_remus.c index 29a47838c8e6..6338a1bae5a5 100644 --- a/tools/libxl/libxl_remus.c +++ b/tools/libxl/libxl_remus.c @@ -267,7 +267,7 @@ static void remus_devices_preresume_cb(libxl__egc *egc, goto out; /* Resumes the domain and the device model */ - rc = libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1); + rc = libxl__domain_resume_deprecated(gc, dss->domid, /* Fast Suspend */1); if (rc) goto out; From patchwork Thu Sep 19 17:16:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153007 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 499FF16B1 for ; Thu, 19 Sep 2019 17:42:35 +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 1937F214AF for ; Thu, 19 Sep 2019 17:42:35 +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="KOtcU8yt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1937F214AF 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 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 X-Inumbo-ID: ac9f697a-db04-11e9-b299-bc764e2007e4 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) 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 (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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 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, 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 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; 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__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); From patchwork Thu Sep 19 17:16:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152979 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 530C915E6 for ; Thu, 19 Sep 2019 17:42:02 +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 2DB5D21A4C for ; Thu, 19 Sep 2019 17:42:02 +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="LwARxg7x" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DB5D21A4C 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 1iB0QI-0004DQ-LJ; Thu, 19 Sep 2019 17:40:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0QH-0004CN-4e for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:40:53 +0000 X-Inumbo-ID: 99251016-db04-11e9-b299-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 99251016-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914840; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P5gXE6loAUwR0Noo3tNpKxWqPNrwXEFLSMhwKLpISw4=; b=LwARxg7xsysCmsu9FVlo2UD+3AXf5LjmOATGqXAJwSnSB+gB6ZGTCMhl NNEXKvbmU6rzyShfA5/Qw5I4hxG/J3YT1hxUYDyPt/Esh5fegSCAkR37w naAmsqFemUjqFFKvFoh2MApbSlcqTw7O4tqTiEjtSEvIj9DuRuwtRNH8t Y=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: T/4CIALplJSiaTi7Zo6kd1ZX1uvRN3k9L4KMpxVRy/wp8/PcPXPvcGgkm03pZ24AJdGQhpJBg/ wn4dfGgbbBnVKE8FS6K+lKcfyYS02S6YScHWR2obd8md6aVsNxckuCRmqPSOUnAaINged2FVDJ fHTOb1AsBdHLs/NjmfQzMe6YYvM6XFThIOJG7JljNAKvrNf3DnOIgvM5Mp5oyxgiSbI5UjfjTM Z/5K351ta+79WiI1mJNqbewSdVWggcOMq29HEnEySL5yj3OnlzDvoCJXPxfES4wqKZZSXpR5JZ 9/E= X-SBRS: 2.7 X-MesageID: 5801748 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,524,1559534400"; d="scan'208";a="5801748" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:31 +0100 Message-ID: <20190919171656.899649-12-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 11/35] libxl_domain: Convert libxl_domain_resume to use 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 80797c5ed21c..d78ffa6b6019 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -174,15 +174,32 @@ int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid, return rc; } +static void domain_resume_done(libxl__egc *egc, + libxl__dm_resume_state *, + int rc); + int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid, int suspend_cancel, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); - int rc = libxl__domain_resume_deprecated(gc, domid, suspend_cancel); - libxl__ao_complete(egc, ao, rc); + libxl__dm_resume_state *dmrs; + + GCNEW(dmrs); + dmrs->ao = ao; + dmrs->domid = domid; + dmrs->callback = domain_resume_done; + libxl__domain_resume(egc, dmrs, suspend_cancel); return AO_INPROGRESS; } +static void domain_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + int rc) +{ + STATE_AO_GC(dmrs->ao); + libxl__ao_complete(egc, ao, rc); +} + /* * Preserves a domain but rewrites xenstore etc to make it unique so * that the domain can be restarted. From patchwork Thu Sep 19 17:16:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153011 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 BC10D15E6 for ; Thu, 19 Sep 2019 17:42:38 +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 982BD214AF for ; Thu, 19 Sep 2019 17:42:38 +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="NR6+Fh6M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 982BD214AF 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 1iB0QP-0004Hx-Sv; Thu, 19 Sep 2019 17:41:01 +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 1iB0QO-0004H7-84 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:00 +0000 X-Inumbo-ID: 9b73e626-db04-11e9-966e-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9b73e626-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914845; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ct3y9VN4/oARq6HH2/+/acuA16pIcgYioXDNbJ6HwRc=; b=NR6+Fh6Mgt6VfoUPkBia54uDTWpoJ9hbLZCIbfhn/XAh5VTdX2AeOBxs 0CI4+o5JOp6aGC1oiNgk8m/7Ec0or1gOywQ4xP47GYZYZF1+5b3SKingg pLWulKOvc4bdLtwiHEC+J1nTPY8fkMXtLEkVE4zX75IJCK7yswV8iaW3A Y=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 26kMB7hzM7IuVtEMWl3B7GS+GOwpzhg6yilkY0XyPb2v3zgAWJ/pqQxCJT8tW+MdcIlN1GrrXS jW2fYNymhU3rHhG+aFJg/IKXy5Pb3uqZP0RFS7gJ2zi0NNNYol2obNzKW19hOJ31T0gTzgSM29 /oKXlJ9rumDAp+NfWdM4RpBp/Kq0oOGYquSp4fTtXzyMcUnXPByL/aT2e6rUqxLtOPcVh5jnny 6lFA4J0gd+mRAPd9/mlaJ07Bk2Fw365zKowbM0J7sdzOBODqrk7aFM8U7f5liAKJWVoOgzw3ij o+8= X-SBRS: 2.7 X-MesageID: 6010733 X-Ironport-Server: esa5.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="6010733" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:32 +0100 Message-ID: <20190919171656.899649-13-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 12/35] libxl: Re-introduce libxl__domain_unpause 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" libxl__domain_unpause is a reimplementation of libxl__domain_unpause_deprecated with asynchronous operation. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 52 ++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 5 +++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index d78ffa6b6019..52a8bd7895cb 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 6bb6d6d2e166..a0cb6d28858f 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1351,9 +1351,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 */ @@ -1366,6 +1367,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); From patchwork Thu Sep 19 17:16:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153025 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 9F49D15E6 for ; Thu, 19 Sep 2019 17:43:02 +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 7B902214AF for ; Thu, 19 Sep 2019 17:43:02 +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="L3gRMs/c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B902214AF 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 1iB0Qi-0004cE-3U; Thu, 19 Sep 2019 17:41:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Qg-0004Zt-6f for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:18 +0000 X-Inumbo-ID: abed1cf2-db04-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id abed1cf2-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:41:12 +0000 (UTC) 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=vDiLQjrmBn9FqhHJY55/fbZV77Ew85zyUCNIqcXWb4E=; b=L3gRMs/cvaTIO3NlHWos+5ug/9WlJt3R3TM4KmC8r0WzhJWpZv7mGl1d CvwGybO21xG6MvnwV6lQzLQKuF0oDc+uylUF5F03aM/Ct88GENpXQjPOa GPzdCr1WYsUc+/OuXUJo0Yd9DWlrUBueOrYiSANQgQwYkn11QeqYbQbHn A=; Authentication-Results: esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.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=esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: FKx1F/tdUawXrIT7xL8tnR3V7sGXPCaSJs+Ruftbsujdy6XRJCn4lccU1wz3HRoCdeF+wAjcNl m8Gnu8KIaMtJqtCxBUj1UR8Lma6ePzhFaZlaGtOAVtnNTbcYx5dDEX/FJKyaBGX6dS7im0mzT9 AJyE6rDe/qu2SxfJN4yGViNLb5sfBkF9No0eIkqemkML048ImVWVW9b9syyXrik4oO8drBlb/F TtPl8lB71SCHCIxaV1BO/OGkz+2R1PnfSapyN3kEIjK+748edlKuUORArsUkT0S8U1qZjs3uvd JlI= X-SBRS: 2.7 X-MesageID: 5864910 X-Ironport-Server: esa1.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="5864910" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:33 +0100 Message-ID: <20190919171656.899649-14-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 13/35] libxl_dm: Update libxl__spawn_stub_dm to use libxl__domain_unpause 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_dm.c | 22 +++++++++++++++++++++- tools/libxl/libxl_internal.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 246c570121d3..c00356a2f16a 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2082,6 +2082,9 @@ static void spawn_stub_launch_dm(libxl__egc *egc, static void stubdom_pvqemu_cb(libxl__egc *egc, libxl__multidev *aodevs, int rc); +static void stubdom_pvqemu_unpaused(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + int rc); static void stubdom_xswait_cb(libxl__egc *egc, libxl__xswait_state *xswait, int rc, const char *p); @@ -2404,7 +2407,24 @@ static void stubdom_pvqemu_cb(libxl__egc *egc, goto out; } - rc = libxl__domain_unpause_deprecated(gc, dm_domid); + sdss->pvqemu.dmrs.ao = ao; + sdss->pvqemu.dmrs.domid = dm_domid; + sdss->pvqemu.dmrs.callback = stubdom_pvqemu_unpaused; + libxl__domain_unpause(egc, &sdss->pvqemu.dmrs); /* must be last */ + return; +out: + stubdom_pvqemu_unpaused(egc, &sdss->pvqemu.dmrs, rc); +} + +static void stubdom_pvqemu_unpaused(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + int rc) +{ + libxl__stub_dm_spawn_state *sdss = + CONTAINER_OF(dmrs, *sdss, pvqemu.dmrs); + STATE_AO_GC(sdss->dm.spawn.ao); + uint32_t dm_domid = sdss->pvqemu.guest_domid; + if (rc) goto out; sdss->xswait.ao = ao; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index a0cb6d28858f..1144aaa3a569 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3985,6 +3985,7 @@ struct libxl__dm_spawn_state { libxl__spawn_state spawn; libxl__ev_qmp qmp; libxl__ev_time timeout; + libxl__dm_resume_state dmrs; /* filled in by user, must remain valid: */ uint32_t guest_domid; /* domain being served */ libxl_domain_config *guest_config; From patchwork Thu Sep 19 17:16:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153001 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 8C39915E6 for ; Thu, 19 Sep 2019 17:42:26 +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 6855B2196E for ; Thu, 19 Sep 2019 17:42:26 +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="fkKzrNWA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6855B2196E 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 1iB0Q3-00048H-II; Thu, 19 Sep 2019 17:40:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Q2-000489-4N for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:40:38 +0000 X-Inumbo-ID: 9490b5fa-db04-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9490b5fa-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=12rXzUnuMrp3VqeYzpxzKZOLkATDgfN/xp0wydxrYzE=; b=fkKzrNWA/EX/e4jKudrkBjrROqYAhDw7Ai8iGIVIDJ+vzHFA9C7Vcj3P CA6sNq42pI2uOfxerMgeYSMVVVx04bcbte7HHn+eFhtxDTdrfFvr6wEVF 5cTIFs994I9LFqlpoW2gmqAjbT1o/ZTrNxXd7/w+p54rDdBOT9yCKjWLW k=; Authentication-Results: esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.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=esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: qlCQRPSyt5TugAavAp58Sb6toaLnuq5AeiM7cEyAlPfQlvn3WJPHrywkmpdUB6rRcYI9HZP/QT Ptfq9Gay2urAwa2YqVHUsyO6vC/PmG48jEMFw+sVglu+Xyt2dBWKHf9hrHALNi0r6BgPMtcOmz J7OdwagHa/6JfkjrC8VWGwvSWGsZ1vxO3s8z79cokLBnUk0g73eddBP8H/O9L4whxfoGahBZzy OGiwLzs1sryLbKKGhKHdfW9ks9OcsaYx7m6YC87LYSk7zzAPOyUwyInAMr4WhRiOgPx8vvXKpt ERY= X-SBRS: 2.7 X-MesageID: 5864876 X-Ironport-Server: esa1.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="5864876" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:34 +0100 Message-ID: <20190919171656.899649-15-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 14/35] libxl_domain: Convert libxl_domain_unpause to use libxl__domain_unpause 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 52a8bd7895cb..f3c39fa86fc9 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -691,20 +691,31 @@ static void domain_unpause_done(libxl__egc *egc, dmrs->callback(egc, dmrs, rc); } +static void domain_unpause_ao_done(libxl__egc *egc, + libxl__dm_resume_state *, + int rc); + int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); - int rc = 0; - - rc = libxl__domain_unpause_deprecated(gc, domid); - if (rc) goto out; + libxl__dm_resume_state *dmrs; - libxl__ao_complete(egc, ao, rc); + GCNEW(dmrs); + dmrs->ao = ao; + dmrs->domid = domid; + dmrs->callback = domain_unpause_ao_done; + libxl__domain_unpause(egc, dmrs); /* must be last */ return AO_INPROGRESS; +} - out: - return AO_CREATE_FAIL(rc); +static void domain_unpause_ao_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + int rc) +{ + STATE_AO_GC(dmrs->ao); + + libxl__ao_complete(egc, ao, rc); } int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid) From patchwork Thu Sep 19 17:16:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152999 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 B9E2D15E6 for ; Thu, 19 Sep 2019 17:42:25 +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 95AD62196E for ; Thu, 19 Sep 2019 17:42:25 +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="P2HcaqyY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95AD62196E 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 1iB0Qf-0004Ye-Ca; Thu, 19 Sep 2019 17:41:17 +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 1iB0Qd-0004WD-8q for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:15 +0000 X-Inumbo-ID: a57c38f8-db04-11e9-966e-12813bfff9fa Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a57c38f8-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GvfBfVWbKYsVVmq3VSTU20vdXI5aKBzajYBiYquCoLc=; b=P2HcaqyYYO6xIWJHx1gRH+tLIyl57AF27tgOeGJUI3dXjjcPksJVk38i KwwuZHtrts789d30k1RH6/AooSn/ICmtFTxEsrm6uOc0GYelTW2BYaNli S1E1FZyZ9rCFuaDQcnvB/T3svdM0narmC2EoU6UzZ5WPxtntIGUjnChkg o=; Authentication-Results: esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.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=esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 8zxmhCEdElQBTIUO/sspjVU5bvFrGxiGd81akG3av0Dl6wB3hqpW8lLwhY0FaDHx+fbhP3NXi4 52ulhNyVRm6MeSQ3rgN7vTpHoJplSyW6HQRrSnfuPh7SErEaazuF7r6o3LzO/9rE7LSVMhhy1o EYA5jHup8we+8jVZDDR5UIleHhJIzRDe2suStrJKs2nYhwECWhQPKs6dUpNZ4yTTvBZfWBcWOk J3vaQKd3G+QnNx/2CtpIpYuttOI4SH21gQGshnzAsKTxcQAqLGcSwKH5t1jFdome65OykmfDX9 1u4= X-SBRS: 2.7 X-MesageID: 5806205 X-Ironport-Server: esa3.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="5806205" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:35 +0100 Message-ID: <20190919171656.899649-16-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 15/35] libxl: Inline do_usbdev_add into libxl__device_usbdev_add 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" Having the function do_usbdev_add makes it harder to add asynchronous calls into it. Move its body back into libxl__device_usbdev_add and adjust the latter as there are no reason to have a separated function. No functional changes. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 121 ++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 68 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index f6a98860c8dc..0da7a725a720 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -1517,72 +1517,6 @@ static int usbback_dev_assign(libxl__gc *gc, const char *busid) return rc; } -static int do_usbdev_add(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev, - bool update_json) -{ - int rc; - char *busid; - libxl_device_usbctrl usbctrl; - - libxl_device_usbctrl_init(&usbctrl); - rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); - if (rc) goto out; - - switch (usbctrl.type) { - case LIBXL_USBCTRL_TYPE_PV: - busid = usbdev_busaddr_to_busid(gc, usbdev->u.hostdev.hostbus, - usbdev->u.hostdev.hostaddr); - if (!busid) { - rc = ERROR_FAIL; - goto out; - } - - rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_PV, - update_json); - if (rc) goto out; - - rc = usbback_dev_assign(gc, busid); - if (rc) { - libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_PV); - goto out; - } - break; - case LIBXL_USBCTRL_TYPE_QUSB: - rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_QUSB, - update_json); - if (rc) goto out; - - break; - case LIBXL_USBCTRL_TYPE_DEVICEMODEL: - rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_DEVICEMODEL, - update_json); - if (rc) goto out; - - rc = libxl__device_usbdev_add_hvm(gc, domid, usbdev); - if (rc) { - libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_DEVICEMODEL); - goto out; - } - break; - default: - LOGD(ERROR, domid, "Unsupported usb controller type"); - rc = ERROR_FAIL; - goto out; - } - - rc = 0; - -out: - libxl_device_usbctrl_dispose(&usbctrl); - return rc; -} - /* AO operation to add a usb device. * * Generally, it does: @@ -1608,6 +1542,7 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, libxl_device_usbdev *assigned; int num_assigned; libxl_device_usbctrl usbctrl; + char *busid; libxl_device_usbctrl_init(&usbctrl); @@ -1626,6 +1561,7 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, rc = ERROR_INVAL; goto out; } + libxl_device_usbctrl_dispose(&usbctrl); } /* check usb device is assignable type */ @@ -1655,14 +1591,63 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, aodev->update_json); if (rc) goto out; + rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); + if (rc) goto out; + /* do actual adding usb device operation */ - rc = do_usbdev_add(gc, domid, usbdev, aodev->update_json); + switch (usbctrl.type) { + case LIBXL_USBCTRL_TYPE_PV: + busid = usbdev_busaddr_to_busid(gc, usbdev->u.hostdev.hostbus, + usbdev->u.hostdev.hostaddr); + if (!busid) { + rc = ERROR_FAIL; + goto out; + } + + rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_PV, + aodev->update_json); + if (rc) goto out; + + rc = usbback_dev_assign(gc, busid); + if (rc) { + libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_PV); + goto out; + } + break; + case LIBXL_USBCTRL_TYPE_QUSB: + rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_QUSB, + aodev->update_json); + if (rc) goto out; + + break; + case LIBXL_USBCTRL_TYPE_DEVICEMODEL: + rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_DEVICEMODEL, + aodev->update_json); + if (rc) goto out; + + rc = libxl__device_usbdev_add_hvm(gc, domid, usbdev); + if (rc) { + libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_DEVICEMODEL); + goto out; + } + break; + default: + LOGD(ERROR, domid, "Unsupported usb controller type"); + rc = ERROR_FAIL; + goto out; + } + + rc = 0; out: libxl_device_usbctrl_dispose(&usbctrl); aodev->rc = rc; aodev->callback(egc, aodev); - return; } LIBXL_DEFINE_DEVICE_ADD(usbdev) From patchwork Thu Sep 19 17:16:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152991 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 109E315E6 for ; Thu, 19 Sep 2019 17:42:19 +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 E0DF521A49 for ; Thu, 19 Sep 2019 17:42:18 +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="FSZrTQRB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0DF521A49 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 1iB0Qv-0004uo-Lm; Thu, 19 Sep 2019 17:41:33 +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 1iB0Qu-0004sW-1c for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:32 +0000 X-Inumbo-ID: b1045cf0-db04-11e9-966e-12813bfff9fa Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b1045cf0-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914881; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lfU5Lz9mC5Tpd9BlxCQdv6MV7HYJTHP2JVQj7+pdKFg=; b=FSZrTQRB33AYJ01cegQ/bfAw2N17sx08luAWBpWtcKDXrdbrfxVBGwMz EA9OflHEVUL3aFy9bqR2hbgsbyZC74o+l8e5KfCIYR5jsXer+hTQk4vtg EHNosuQMCvO539pcSKoDSJbHDkoOt0tbytHceL8dsNN+ChZrPMZ2QIqFO s=; Authentication-Results: esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.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=esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: /in4ZC5diqKIdnFufZDqeyk9EiNtkTXWxCwsYpCwOtwcf7lKbAX0WIpSaBU/x7Hdn22MgT4Ds2 yU9B3BB+lEUUlXTwO6focBnVHLO1fH6pPdsI2Ry5w/qMuUfTLkmz3UC6LQWNj8JZr1FopNAqoI T2ww3iKm8pt22i8OSuZII3b6SpaYcLkmDj58Aej7wzUQEKZmTVwTEho4dT8hJcY8m1o4UtZZbN eeGlG2cG3dOMfyhZAPJ/fcMs70tMduF8+TnXNoKI5XaiEFA7wNdTf/H/Tg2H3Ls1U1EhjQ6klq nnE= X-SBRS: 2.7 X-MesageID: 5864921 X-Ironport-Server: esa1.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="5864921" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:36 +0100 Message-ID: <20190919171656.899649-17-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 16/35] libxl: Inline do_usbdev_remove into libxl__device_usbdev_remove 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" Having the function do_usbdev_remove makes it harder to add asynchronous calls into it. Move its body back into libxl__device_usbdev_remove and adjust the latter as there are no reason to have a separated function. No functional changes. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 63 +++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 0da7a725a720..de8122dc57e9 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -1653,17 +1653,38 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, LIBXL_DEFINE_DEVICE_ADD(usbdev) static LIBXL_DEFINE_DEVICES_ADD(usbdev) -static int do_usbdev_remove(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev) +/* Operation to remove usb device. + * + * Generally, it does: + * 1) check if the usb device is assigned to the domain + * 2) remove the usb device from xenstore controller/port. + * 3) unbind usb device from usbback and rebind to its original driver. + * If usb device has many interfaces, do it to each interface. + */ +static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, + libxl_device_usbdev *usbdev) { int rc; char *busid; libxl_device_usbctrl usbctrl; + if (usbdev->ctrl < 0 || usbdev->port < 1) { + LOGD(ERROR, domid, "Invalid USB device"); + return ERROR_FAIL; + } + libxl_device_usbctrl_init(&usbctrl); rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); if (rc) goto out; + if (usbctrl.backend_domid != LIBXL_TOOLSTACK_DOMID) { + LOGD(ERROR, domid, + "Don't support removing USB device from non-Dom0 backend"); + rc = ERROR_INVAL; + goto out; + } + + /* do actual removing usb device operation */ switch (usbctrl.type) { case LIBXL_USBCTRL_TYPE_PV: busid = usbdev_busid_from_ctrlport(gc, domid, usbdev, usbctrl.type); @@ -1741,44 +1762,6 @@ static int do_usbdev_remove(libxl__gc *gc, uint32_t domid, return rc; } -/* Operation to remove usb device. - * - * Generally, it does: - * 1) check if the usb device is assigned to the domain - * 2) remove the usb device from xenstore controller/port. - * 3) unbind usb device from usbback and rebind to its original driver. - * If usb device has many interfaces, do it to each interface. - */ -static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev) -{ - libxl_device_usbctrl usbctrl; - int rc; - - if (usbdev->ctrl < 0 || usbdev->port < 1) { - LOGD(ERROR, domid, "Invalid USB device"); - return ERROR_FAIL; - } - - libxl_device_usbctrl_init(&usbctrl); - rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); - if (rc) goto out; - - if (usbctrl.backend_domid != LIBXL_TOOLSTACK_DOMID) { - LOGD(ERROR, domid, - "Don't support removing USB device from non-Dom0 backend"); - rc = ERROR_INVAL; - goto out; - } - - /* do actual removing usb device operation */ - rc = do_usbdev_remove(gc, domid, usbdev); - -out: - libxl_device_usbctrl_dispose(&usbctrl); - return rc; -} - int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_usbdev *usbdev, const libxl_asyncop_how *ao_how) From patchwork Thu Sep 19 17:16:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152987 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 AB8D415E6 for ; Thu, 19 Sep 2019 17:42:12 +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 871A921A49 for ; Thu, 19 Sep 2019 17:42:12 +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="VqnPWQUE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 871A921A49 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 1iB0Qp-0004lI-9J; Thu, 19 Sep 2019 17:41:27 +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 1iB0Qn-0004il-B0 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:25 +0000 X-Inumbo-ID: b26c6ccc-db04-11e9-966e-12813bfff9fa Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b26c6ccc-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7ECqT2JZeGmajyZeTmnC9t4OeRYaTVuKKADJwtHtxIE=; b=VqnPWQUE408t+9zUzCWjlDdkwXjtySN+TdPKJMOaoYW66HLaUSwyIWxS Fw/0dIG2HpDq2hpJAM1q4Yc7zdyr9c5Fz1X2QslcPhiI4pIfTgzco4jqT AWnyCoZW8wI0dlpEOJQtWlUGI/vxmTJuKVQQy9XMGiwX0+EYi1OhyjD6Q I=; Authentication-Results: esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.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=esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: itYXpBqAFAzQZ77khrodyuZNTYbWa4JDaQwLMyaY6JOa5pFIToTW/GdzsTwqM9riq0rJG895Nq RykU9V4zS8TS/AiGddZEPMj9dLH7u3/g0FnzfnIAJ/Uge+1B3Z0AfOFXYg06iHUbrFZ9Cvt833 SMCJ+WQd+Fu/fDwOl4th+jrh8j/A8yTsLekJwl9FpAS3zHX5IY8wMJQLIc1ZRwDvWRZ4mEEgB+ yc3DL4oqOeIHpR+QS3KpjNbf1DwzLEoYZTKnWVxJ0VriyMEfi1c5fGoBrEUMeVhvocJFrj/0qm V/k= X-SBRS: 2.7 X-MesageID: 5806223 X-Ironport-Server: esa3.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="5806223" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:37 +0100 Message-ID: <20190919171656.899649-18-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 17/35] libxl: Add libxl__ev_qmp to libxl__ao_device 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" `aodev->qmp' is initialised in libxl__prepare_ao_device(), but since there isn't a single exit path for a `libxl__ao_device', users of this new `qmp' field will have to disposed of it. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: v2: - Added a comment to libxl__prepare_ao_device about fields like `qmp' which might needs to be cleaned up by the caller. tools/libxl/libxl_device.c | 2 ++ tools/libxl/libxl_internal.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 1941fe780ac0..1402b61a810b 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -644,6 +644,8 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev) * without actually calling any hotplug script */ libxl__async_exec_init(&aodev->aes); libxl__ev_child_init(&aodev->child); + + libxl__ev_qmp_init(&aodev->qmp); } /* multidev */ diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 1144aaa3a569..43a431f53565 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2592,6 +2592,10 @@ typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*); * Once _prepare has been called on a libxl__ao_device, it is safe to just * discard this struct, there's no need to call any destroy function. * _prepare can also be called multiple times with the same libxl__ao_device. + * + * But if any of the fields `backend_ds', `timeout', `xswait', `qmp' is + * used by a caller of _prepare, the caller will have to arrange to clean + * or dispose of them. */ _hidden void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev); @@ -2623,6 +2627,7 @@ struct libxl__ao_device { bool update_json; /* for asynchronous execution of synchronous-only syscalls etc. */ libxl__ev_child child; + libxl__ev_qmp qmp; }; /* From patchwork Thu Sep 19 17:16:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153019 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 45D2715E6 for ; Thu, 19 Sep 2019 17:42:55 +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 2195C214AF for ; Thu, 19 Sep 2019 17:42:55 +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="G6K9m0RX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2195C214AF 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 1iB0QU-0004Mt-LC; Thu, 19 Sep 2019 17:41:06 +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 1iB0QT-0004Li-8M for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:05 +0000 X-Inumbo-ID: a34a8ee0-db04-11e9-966e-12813bfff9fa Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a34a8ee0-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914857; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bhstzX2mGHbhKF9lCVRjufmTTbBG4VgbHRlhgrTDgu4=; b=G6K9m0RXlLLdzgNENmBDE7staeo7OqMAyESsvd49lEXNfo5lP0WjLW22 EVZPzkeskbzbE6gAnuEOJPLp4ci5QYUFfA+8luWlrSFqiSM2wHRRVGFGY n7SWtvUbzL3e6utFEo7uv985d9ABDjUQliKRfHes+E2ksZwJRdTqwQOmG A=; 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: OxqnILM6xHPZunjTQl8vEjlVqkyHoaR+FVqYgeGd4GVaKygtzWDeTRF7WD0XZX6COhrYMdXYeg 7MkzB6UYvbIbK1Y0CQls1QWdJKUlvtOyo6p41axMjNXKahSpoVkzttuErB/B50eFjL8pBxglXo UG7kTn4VvvrnscsBBJhLXNmoAkT7Tt30Ea6N+rqipiFHZ5VGhpxqj2UcTYjEUBijDfTh9hjV5F oGvH9+WEKVvy0HkxxBM4AvpTpyhmpgqnCXQlWVbHdkGMPV1Tcs//xLF4f2NCbK7AEIETAv2Uzf 0IE= X-SBRS: 2.7 X-MesageID: 6125259 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,524,1559534400"; d="scan'208";a="6125259" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:38 +0100 Message-ID: <20190919171656.899649-19-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 18/35] libxl: Add device_{config, type} to libxl__ao_device 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" These two fields help to give more information about the device been hotplug/hotunplug to callbacks. There is already `dev' of type `libxl__device', but it is mostly useful when the backend/frontend is xenstore. Some device (like `usbdev') don't have devid, so `dev' can't be used. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_internal.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 43a431f53565..6c09b93f91f1 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2628,6 +2628,12 @@ struct libxl__ao_device { /* for asynchronous execution of synchronous-only syscalls etc. */ libxl__ev_child child; libxl__ev_qmp qmp; + /* 'device_config' can be used to to pass to callbacks a pointer of one + * of the type 'libxl_device_$type' corresponding to the device been + * hotplug. 'device_type' should have the corresponding + * 'libxl__$type_devtype'. */ + void *device_config; + const libxl__device_type *device_type; }; /* From patchwork Thu Sep 19 17:16:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153015 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 9487515E6 for ; Thu, 19 Sep 2019 17:42:47 +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 70002214AF for ; Thu, 19 Sep 2019 17:42:47 +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="VswSrIpC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 70002214AF 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 1iB0QZ-0004SK-JL; Thu, 19 Sep 2019 17:41:11 +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 1iB0QY-0004Qi-A9 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:10 +0000 X-Inumbo-ID: a3fb4d49-db04-11e9-966e-12813bfff9fa Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a3fb4d49-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A3sIvBA7sFb7p5UsgHgoKIZqd18mZ4P0465g6VAmMw4=; b=VswSrIpCzOdi13kjg37aPYrOPweiUvmy/G62iBP4D382EqA4KQdcFkkT 64AN48eOklCapShwed/gThdbaD4QHk1YqFLd2fLU+5lmNHAY4/Mnj5gTq dcDBxCc7BRWpzErG8aW0OdpUwtOxj8POk/MMjWd9DQzQrt0mCmhXeo0ZD w=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: POvbL7taZ8ztiS04bu8pJB+ctWspmmpiZ4iwjtTxJcmBS9SbJSBLk9SYQ2zX16e+k2+VKxAPW9 sqCh/ajcIfXxZzUnxPefc1Y0yMJGr2h+sW5gktjSSlsBg5zyxCzGsP2cXuSUlgXzkRt1wApd7t n5p2wi5NpFPn3SQXZC5xLYCv5+4ygwRhLGZr1Qi6jFPM3WYYxKygZ09OP7NdsWudBG1eCPaHB7 G3eaKRvKl3nsFJM6iP7cyQ+cJRaZ4p2vo56WGm6p4hcUvYyR3bbHzwAAFUrzl0mG8df7Kf5A4O kf0= X-SBRS: 2.7 X-MesageID: 5801777 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,524,1559534400"; d="scan'208";a="5801777" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:39 +0100 Message-ID: <20190919171656.899649-20-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 19/35] libxl_usb: Make libxl__device_usbctrl_add uses ev_qmp 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 93 ++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 16 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index de8122dc57e9..506dbdcf5ee4 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -349,33 +349,36 @@ static char *pvusb_get_device_type(libxl_usbctrl_type type) * - usb-ehci (version=2), always 6 ports * - nec-usb-xhci (version=3), up to 15 ports */ -static int libxl__device_usbctrl_add_hvm(libxl__gc *gc, uint32_t domid, +static int libxl__device_usbctrl_add_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, libxl_device_usbctrl *usbctrl) { - flexarray_t *qmp_args; - - qmp_args = flexarray_make(gc, 8, 1); + libxl__json_object *qmp_args = NULL; switch (usbctrl->version) { case 1: - flexarray_append_pair(qmp_args, "driver", "piix3-usb-uhci"); + libxl__qmp_param_add_string(gc, &qmp_args, + "driver", "piix3-usb-uhci"); break; case 2: - flexarray_append_pair(qmp_args, "driver", "usb-ehci"); + libxl__qmp_param_add_string(gc, &qmp_args, + "driver", "usb-ehci"); break; case 3: - flexarray_append_pair(qmp_args, "driver", "nec-usb-xhci"); - flexarray_append_pair(qmp_args, "p2", GCSPRINTF("%d", usbctrl->ports)); - flexarray_append_pair(qmp_args, "p3", GCSPRINTF("%d", usbctrl->ports)); + libxl__qmp_param_add_string(gc, &qmp_args, + "driver", "nec-usb-xhci"); + libxl__qmp_param_add_string(gc, &qmp_args, "p2", + GCSPRINTF("%d", usbctrl->ports)); + libxl__qmp_param_add_string(gc, &qmp_args, "p3", + GCSPRINTF("%d", usbctrl->ports)); break; default: abort(); /* Should not be possible. */ } - flexarray_append_pair(qmp_args, "id", - GCSPRINTF("xenusb-%d", usbctrl->devid)); + libxl__qmp_param_add_string(gc, &qmp_args, "id", + GCSPRINTF("xenusb-%d", usbctrl->devid)); - return libxl__qmp_run_command_flexarray(gc, domid, "device_add", qmp_args); + return libxl__ev_qmp_send(gc, qmp, "device_add", qmp_args); } /* Send qmp commands to delete a usb controller in qemu. */ @@ -430,6 +433,13 @@ static int libxl__device_usbdev_del_hvm(libxl__gc *gc, uint32_t domid, static LIBXL_DEFINE_UPDATE_DEVID(usbctrl) +static void device_usbctrl_add_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void device_usbctrl_add_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *r, int rc); +static void device_usbctrl_add_done(libxl__egc *egc, + libxl__ao_device *aodev, int rc); + /* AO operation to add a usb controller. * * Generally, it does: @@ -450,6 +460,10 @@ static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, libxl__device *device; int rc; + /* Store *usbctrl to be used by callbacks */ + aodev->device_config = usbctrl; + aodev->device_type = &libxl__usbctrl_devtype; + rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl, aodev->update_json); if (rc < 0) goto out; @@ -464,14 +478,25 @@ static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, GCNEW(device); rc = libxl__device_from_usbctrl(gc, domid, usbctrl, device); if (rc) goto outrm; + aodev->dev = device; if (device->backend_kind == LIBXL__DEVICE_KIND_NONE) { - rc = libxl__device_usbctrl_add_hvm(gc, domid, usbctrl); + libxl__ev_qmp *const qmp = &aodev->qmp; + + rc = libxl__ev_time_register_rel(ao, &aodev->timeout, + device_usbctrl_add_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); if (rc) goto outrm; - goto out; + + qmp->ao = ao; + qmp->domid = domid; + qmp->payload_fd = -1; + qmp->callback = device_usbctrl_add_qmp_cb; + rc = libxl__device_usbctrl_add_hvm(gc, qmp, usbctrl); + if (rc) goto outrm; + return; } - aodev->dev = device; aodev->action = LIBXL__DEVICE_ACTION_ADD; libxl__wait_device_connection(egc, aodev); return; @@ -479,9 +504,45 @@ static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, outrm: libxl__device_usbctrl_del_xenstore(gc, domid, usbctrl); out: + device_usbctrl_add_done(egc, aodev, rc); +} + +static void device_usbctrl_add_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(ev, *aodev, timeout); + + if (rc == ERROR_TIMEDOUT) + LOGD(ERROR, aodev->dev->domid, "Adding usbctrl to QEMU timed out"); + device_usbctrl_add_qmp_cb(egc, &aodev->qmp, NULL, rc); +} + +static void device_usbctrl_add_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *r, + int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(qmp, *aodev, qmp); + libxl_device_usbctrl *const usbctrl = aodev->device_config; + + if (rc) + libxl__device_usbctrl_del_xenstore(gc, aodev->dev->domid, usbctrl); + + device_usbctrl_add_done(egc, aodev, rc); +} + +static void device_usbctrl_add_done(libxl__egc *egc, + libxl__ao_device *aodev, + int rc) +{ + EGC_GC; + libxl__ev_qmp_dispose(gc, &aodev->qmp); + libxl__ev_time_deregister(gc, &aodev->timeout); aodev->rc = rc; aodev->callback(egc, aodev); - return; } LIBXL_DEFINE_DEVICE_ADD(usbctrl) From patchwork Thu Sep 19 17:16:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153013 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 F30C0197C for ; Thu, 19 Sep 2019 17:42:38 +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 CE8A3214AF for ; Thu, 19 Sep 2019 17:42:38 +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="faRErvH+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE8A3214AF 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 1iB0Qr-0004oO-39; Thu, 19 Sep 2019 17:41:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Qq-0004n0-71 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:28 +0000 X-Inumbo-ID: ada25d64-db04-11e9-978d-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ada25d64-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914875; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XcpcwRqWNPjMhp/6//5+EFi3qcvUVQer8fd3t+9udoA=; b=faRErvH+2JPKdaLXQLSUcJy1TRzdfw8QItdV0qBQA6Zosl5GpKJTvDvE YrWZFrutLtU9di6I5grb8jgvk4iI9pZUR/g1L6chpdoN4QgS5rDZv0VuD vbkf0PiUTF7wlp1oSHsrxMnCmp6EOkxPcbUV9G9kl3Cr+oaHD+fIvlCel c=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Ce0TuEQoNZimlsg4o5NbXzCONX4VhwEugMlafRivpkkjPmOZAMQpuEG79H76nYUS+ZzLm5Np86 r6oD6VH5UpUPhoiIO7cdt1jHw7yYTz4cYB7jZt6BEWa4yo4N71qv1eswoGEHu1EXLZshf219dc oKy3dG1+fXdZruA0c1PpYpJOaPjQuMLPvwGB+GXDdzB8OVHE+c1WU0/ZS8gkZ7UD4t9XC2pnnn fmoCnlGPXFSUv7hCR4BBpYPi+V/+yu1/39hOjwryYhwoYxq9v9ID80+7EaVJofY2byXIvexa6P 5Js= X-SBRS: 2.7 X-MesageID: 6010742 X-Ironport-Server: esa5.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="6010742" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:40 +0100 Message-ID: <20190919171656.899649-21-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 20/35] libxl_usb: Make libxl__initiate_device_usbctrl_remove uses ev_qmp 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 97 +++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 18 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 506dbdcf5ee4..373b37d7159a 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -382,15 +382,16 @@ static int libxl__device_usbctrl_add_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, } /* Send qmp commands to delete a usb controller in qemu. */ -static int libxl__device_usbctrl_del_hvm(libxl__gc *gc, uint32_t domid, +static int libxl__device_usbctrl_del_hvm(libxl__gc *gc, + libxl__ev_qmp *qmp, int devid) { - flexarray_t *qmp_args; + libxl__json_object *qmp_args = NULL; - qmp_args = flexarray_make(gc, 2, 1); - flexarray_append_pair(qmp_args, "id", GCSPRINTF("xenusb-%d", devid)); + libxl__qmp_param_add_string(gc, &qmp_args, + "id", GCSPRINTF("xenusb-%d", devid)); - return libxl__qmp_run_command_flexarray(gc, domid, "device_del", qmp_args); + return libxl__ev_qmp_send(gc, qmp, "device_del", qmp_args); } /* Send qmp commands to create a usb device in qemu. */ @@ -557,6 +558,13 @@ static int libxl__device_usbdev_list_for_usbctrl(libxl__gc *gc, uint32_t domid, static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, libxl_device_usbdev *usbdev); +static void device_usbctrl_remove_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void device_usbctrl_remove_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *resp, int rc); +static void device_usbctrl_remove_done(libxl__egc *egc, + libxl__ao_device *, int rc); + /* AO function to remove a usb controller. * * Generally, it does: @@ -576,13 +584,18 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, int i, rc; uint32_t domid = aodev->dev->domid; int usbctrl_devid = aodev->dev->devid; - libxl_device_usbctrl usbctrl; + libxl_device_usbctrl *usbctrl; - libxl_device_usbctrl_init(&usbctrl); + GCNEW(usbctrl); + libxl_device_usbctrl_init(usbctrl); rc = libxl_devid_to_device_usbctrl(CTX, domid, usbctrl_devid, - &usbctrl); + usbctrl); if (rc) goto out; + /* Store *usbctrl to be used by callbacks */ + aodev->device_config = usbctrl; + aodev->device_type = &libxl__usbctrl_devtype; + /* Remove usb devices first */ rc = libxl__device_usbdev_list_for_usbctrl(gc, domid, usbctrl_devid, &usbdevs, &num_usbdev); @@ -597,24 +610,72 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, } } - if (usbctrl.type == LIBXL_USBCTRL_TYPE_DEVICEMODEL) { - rc = libxl__device_usbctrl_del_hvm(gc, domid, usbctrl_devid); - if (!rc) - libxl__device_usbctrl_del_xenstore(gc, domid, &usbctrl); - goto out; + if (usbctrl->type == LIBXL_USBCTRL_TYPE_DEVICEMODEL) { + libxl__ev_qmp *const qmp = &aodev->qmp; + + rc = libxl__ev_time_register_rel(ao, &aodev->timeout, + device_usbctrl_remove_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + + qmp->ao = ao; + qmp->domid = domid; + qmp->callback = device_usbctrl_remove_qmp_cb; + qmp->payload_fd = -1; + rc = libxl__device_usbctrl_del_hvm(gc, qmp, usbctrl_devid); + if (rc) goto out; + return; } - libxl_device_usbctrl_dispose(&usbctrl); + libxl_device_usbctrl_dispose(usbctrl); /* Remove usbctrl */ - libxl__initiate_device_generic_remove(egc, aodev); + libxl__initiate_device_generic_remove(egc, aodev); /* must be last */ return; - out: - libxl_device_usbctrl_dispose(&usbctrl); + device_usbctrl_remove_done(egc, aodev, rc); /* must be last */ +} + +static void device_usbctrl_remove_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(ev, *aodev, timeout); + + if (rc == ERROR_TIMEDOUT) + LOGD(ERROR, aodev->dev->domid, + "Removing usbctrl from QEMU timed out"); + device_usbctrl_remove_qmp_cb(egc, &aodev->qmp, NULL, rc); +} + +static void device_usbctrl_remove_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *resp, + int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(qmp, *aodev, qmp); + libxl_device_usbctrl *const usbctrl = aodev->device_config; + + if (!rc) + libxl__device_usbctrl_del_xenstore(gc, aodev->dev->domid, usbctrl); + + device_usbctrl_remove_done(egc, aodev, rc); +} + +static void device_usbctrl_remove_done(libxl__egc *egc, + libxl__ao_device *aodev, + int rc) +{ + EGC_GC; + libxl_device_usbctrl *const usbctrl = aodev->device_config; + + libxl_device_usbctrl_dispose(usbctrl); + libxl__ev_qmp_dispose(gc, &aodev->qmp); + libxl__ev_time_deregister(gc, &aodev->timeout); + aodev->rc = rc; aodev->callback(egc, aodev); - return; } static int libxl__usbctrl_from_xenstore(libxl__gc *gc, From patchwork Thu Sep 19 17:16: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: 11153031 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 D762515E6 for ; Thu, 19 Sep 2019 17:43:31 +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 B23B1214AF for ; Thu, 19 Sep 2019 17:43:31 +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="QtDJuh9p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B23B1214AF 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 1iB0RG-0005Oo-MF; Thu, 19 Sep 2019 17:41:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0RF-0005MC-7Z for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:53 +0000 X-Inumbo-ID: b30a5d2e-db04-11e9-b299-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b30a5d2e-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mnkGtlEWhipsE0tKDwXmE4lkKgt4Y2QgOJBeQ8/1xB4=; b=QtDJuh9p+dyfKvvHFmbVFcSlXb9Z8k6vLOKWV2CuNJnjASfI7B59fWxT QFkcVREcmD4/rhoEbyJii/46t5k+02Vsi7w/xWLwFmAhSLX/Jd8Ec1ovP kf/sg8f36YRFvR/1cV++tvyypiI2+TpprrecRHymjb6J0tUDNBMcueHp9 4=; 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 (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: nsIwUuJY4RYEi+DBPf3xCZ1C0bSciFsVH5Ch9AR3c8Y3pk1r0NTq42ZrMg9UvSeu1nqye+TarO H3o5L44E5E1QkFC0oZ4LSjp435S+aQI0oAskF5ufMydb+PJ0rMxqo+hd41kAhbudO5YMs7N/Uz p/ox+kAiapVghg7ivKsf/6J9kJmMWGyDDnRVobs0ekbV+EWaWfodNf5fbmjT1vHLV38CdEqD0w OI8QMxpGJTgNwDOIN1Mr+lbv6/V293m2FaiIi4TSxi2fgmk6roJiFib4iZw9gnmA2bxoSQ2CK9 btI= X-SBRS: 2.7 X-MesageID: 6064361 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="6064361" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:41 +0100 Message-ID: <20190919171656.899649-22-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 21/35] libxl_usb: Make libxl__device_usbdev_add uses ev_qmp 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 99 +++++++++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 373b37d7159a..b9a31f96ebe3 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -395,26 +395,25 @@ static int libxl__device_usbctrl_del_hvm(libxl__gc *gc, } /* Send qmp commands to create a usb device in qemu. */ -static int libxl__device_usbdev_add_hvm(libxl__gc *gc, uint32_t domid, +static int libxl__device_usbdev_add_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, libxl_device_usbdev *usbdev) { - flexarray_t *qmp_args; + libxl__json_object *qmp_args = NULL; - qmp_args = flexarray_make(gc, 12, 1); - flexarray_append_pair(qmp_args, "id", - GCSPRINTF("xenusb-%d-%d", - usbdev->u.hostdev.hostbus, - usbdev->u.hostdev.hostaddr)); - flexarray_append_pair(qmp_args, "driver", "usb-host"); - flexarray_append_pair(qmp_args, "bus", - GCSPRINTF("xenusb-%d.0", usbdev->ctrl)); - flexarray_append_pair(qmp_args, "port", GCSPRINTF("%d", usbdev->port)); - flexarray_append_pair(qmp_args, "hostbus", - GCSPRINTF("%d", usbdev->u.hostdev.hostbus)); - flexarray_append_pair(qmp_args, "hostaddr", - GCSPRINTF("%d", usbdev->u.hostdev.hostaddr)); - - return libxl__qmp_run_command_flexarray(gc, domid, "device_add", qmp_args); + libxl__qmp_param_add_string(gc, &qmp_args, "id", + GCSPRINTF("xenusb-%d-%d", usbdev->u.hostdev.hostbus, + usbdev->u.hostdev.hostaddr)); + libxl__qmp_param_add_string(gc, &qmp_args, "driver", "usb-host"); + libxl__qmp_param_add_string(gc, &qmp_args, "bus", + GCSPRINTF("xenusb-%d.0", usbdev->ctrl)); + libxl__qmp_param_add_string(gc, &qmp_args, "port", + GCSPRINTF("%d", usbdev->port)); + libxl__qmp_param_add_string(gc, &qmp_args, "hostbus", + GCSPRINTF("%d", usbdev->u.hostdev.hostbus)); + libxl__qmp_param_add_string(gc, &qmp_args, "hostaddr", + GCSPRINTF("%d", usbdev->u.hostdev.hostaddr)); + + return libxl__ev_qmp_send(gc, qmp, "device_add", qmp_args); } /* Send qmp commands to delete a usb device in qemu. */ @@ -1639,6 +1638,13 @@ static int usbback_dev_assign(libxl__gc *gc, const char *busid) return rc; } +static void device_usbdev_add_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *r, int rc); +static void device_usbdev_add_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void device_usbdev_add_done(libxl__egc *egc, + libxl__ao_device *aodev, int rc); + /* AO operation to add a usb device. * * Generally, it does: @@ -1665,9 +1671,14 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, int num_assigned; libxl_device_usbctrl usbctrl; char *busid; + bool has_callback = false; libxl_device_usbctrl_init(&usbctrl); + /* Store *usbdev to be used by callbacks */ + aodev->device_config = usbdev; + aodev->device_type = &libxl__usbdev_devtype; + /* Currently only support adding USB device from Dom0 backend. * So, if USB controller is specified, check its backend domain, * if it's not Dom0, report error. @@ -1751,12 +1762,22 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, aodev->update_json); if (rc) goto out; - rc = libxl__device_usbdev_add_hvm(gc, domid, usbdev); + rc = libxl__ev_time_register_rel(ao, &aodev->timeout, + device_usbdev_add_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + + aodev->qmp.ao = ao; + aodev->qmp.domid = domid; + aodev->qmp.callback = device_usbdev_add_qmp_cb; + aodev->qmp.payload_fd = -1; + rc = libxl__device_usbdev_add_hvm(gc, &aodev->qmp, usbdev); if (rc) { libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, LIBXL_USBCTRL_TYPE_DEVICEMODEL); goto out; } + has_callback = true; break; default: LOGD(ERROR, domid, "Unsupported usb controller type"); @@ -1768,6 +1789,48 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, out: libxl_device_usbctrl_dispose(&usbctrl); + /* Only call _done if no callback have been setup */ + if (!has_callback) + device_usbdev_add_done(egc, aodev, rc); /* must be last */ +} + +static void device_usbdev_add_timeout(libxl__egc *egc, + libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(ev, *aodev, timeout); + + if (rc == ERROR_TIMEDOUT) + LOGD(ERROR, aodev->qmp.domid, + "Adding usbdev to QEMU timed out"); + device_usbdev_add_qmp_cb(egc, &aodev->qmp, NULL, rc); +} + +static void device_usbdev_add_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *r, + int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(qmp, *aodev, qmp); + libxl_device_usbdev *const usbdev = aodev->device_config; + + if (rc) + libxl__device_usbdev_remove_xenstore(gc, qmp->domid, + usbdev, LIBXL_USBCTRL_TYPE_DEVICEMODEL); + device_usbdev_add_done(egc, aodev, rc); /* must be last */ +} + +static void device_usbdev_add_done(libxl__egc *egc, + libxl__ao_device *aodev, + int rc) +{ + EGC_GC; + + libxl__ev_time_deregister(gc, &aodev->timeout); + libxl__ev_qmp_dispose(gc, &aodev->qmp); aodev->rc = rc; aodev->callback(egc, aodev); } From patchwork Thu Sep 19 17:16:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152997 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 C4F7B16B1 for ; Thu, 19 Sep 2019 17:42:24 +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 A08F921A4C for ; Thu, 19 Sep 2019 17:42:24 +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="c89ntU5d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A08F921A4C 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 1iB0Qc-0004Vx-Ur; Thu, 19 Sep 2019 17:41:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Qb-0004U3-56 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:13 +0000 X-Inumbo-ID: aaa2a52e-db04-11e9-b299-bc764e2007e4 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aaa2a52e-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yOckcj6yovcmhN9pDR0SHR6o36KGwIV4SVH3LqweW0E=; b=c89ntU5dDY3LqaUqGT7uXdZTdGX8og9umnuyk3o7QiX+ZZVAZFTN8ZnW bd/gr4UnEWZEaXjN9lq/O8QAAyyVeWJGm9Zdpr1zF6KTzKNFoJxa2KEtU FYdSS70WziYPbH/H5zhKl45y3UT6SGkQ/Q/+2+WswTlpMTD4CJll6/tkQ A=; Authentication-Results: esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.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=esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: uPbAmj7f21ACptnSssdrDc5G3wfrd5EkIGDzemgyTiXUjrjDjPvu8+DKz7hd4PKE+GtT7ypr9U 57583BLeNGD824lAYLHTCRNjC0P2C0S2CKxkBNnxcKnbFNtFLTSKWgiGN/MX+ZVQOfWS74v6/r ZaoqW20/3bPmnaZmbwMC+sISLSOyULGUufOGGbSgXCOTEUdUjWdaSp3mkq0L5BfTKT6UVCJex7 etixPR9NiLRmmB7IQRZhjyvTvcjC2bYXZZs9J0xwcKeV463aho3aYJNqgTNvcAEnpRgpSOOUUv FNs= X-SBRS: 2.7 X-MesageID: 5806214 X-Ironport-Server: esa3.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="5806214" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:42 +0100 Message-ID: <20190919171656.899649-23-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 22/35] libxl: Use aodev for libxl__device_usbdev_remove 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" This also mean libxl__initiate_device_usbctrl_remove, which uses libxl__device_usbdev_remove synchronously, needs to be updated to use it with multidev. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 79 +++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index b9a31f96ebe3..3b432231ea85 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -554,9 +554,11 @@ static int libxl__device_usbdev_list_for_usbctrl(libxl__gc *gc, uint32_t domid, libxl_device_usbdev **usbdevs, int *num); -static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev); +static void libxl__device_usbdev_remove(libxl__egc *egc, + uint32_t domid, libxl_device_usbdev *usbdev, libxl__ao_device *aodev); +static void device_usbctrl_usbdevs_removed(libxl__egc *, + libxl__multidev *, int rc); static void device_usbctrl_remove_timeout(libxl__egc *egc, libxl__ev_time *ev, const struct timeval *requested_abs, int rc); static void device_usbctrl_remove_qmp_cb(libxl__egc *egc, @@ -564,6 +566,11 @@ static void device_usbctrl_remove_qmp_cb(libxl__egc *egc, static void device_usbctrl_remove_done(libxl__egc *egc, libxl__ao_device *, int rc); +typedef struct { + libxl__multidev multidev; + libxl__ao_device *aodev; +} usbctrl_remove_state; + /* AO function to remove a usb controller. * * Generally, it does: @@ -584,6 +591,12 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, uint32_t domid = aodev->dev->domid; int usbctrl_devid = aodev->dev->devid; libxl_device_usbctrl *usbctrl; + usbctrl_remove_state *ucrs; + + GCNEW(ucrs); + ucrs->aodev = aodev; + ucrs->multidev.callback = device_usbctrl_usbdevs_removed; + libxl__multidev_begin(ao, &ucrs->multidev); GCNEW(usbctrl); libxl_device_usbctrl_init(usbctrl); @@ -601,14 +614,29 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, if (rc) goto out; for (i = 0; i < num_usbdev; i++) { - rc = libxl__device_usbdev_remove(gc, domid, &usbdevs[i]); - if (rc) { - LOGD(ERROR, domid, "libxl__device_usbdev_remove failed: controller %d, " - "port %d", usbdevs[i].ctrl, usbdevs[i].port); - goto out; - } + libxl__ao_device *usbdev_aodev = + libxl__multidev_prepare(&ucrs->multidev); + usbdev_aodev->action = LIBXL__DEVICE_ACTION_REMOVE; + libxl__device_usbdev_remove(egc, domid, &usbdevs[i], usbdev_aodev); } +out: + libxl__multidev_prepared(egc, &ucrs->multidev, rc); /* must be last */ +} + +static void device_usbctrl_usbdevs_removed(libxl__egc *egc, + libxl__multidev *multidev, + int rc) +{ + usbctrl_remove_state *ucrs = + CONTAINER_OF(multidev, *ucrs, multidev); + libxl__ao_device *aodev = ucrs->aodev; + STATE_AO_GC(aodev->ao); + libxl_device_usbctrl *const usbctrl = aodev->device_config; + + if (rc) goto out; + + /* Remove usbctrl */ if (usbctrl->type == LIBXL_USBCTRL_TYPE_DEVICEMODEL) { libxl__ev_qmp *const qmp = &aodev->qmp; @@ -618,10 +646,10 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, if (rc) goto out; qmp->ao = ao; - qmp->domid = domid; + qmp->domid = aodev->dev->domid; qmp->callback = device_usbctrl_remove_qmp_cb; qmp->payload_fd = -1; - rc = libxl__device_usbctrl_del_hvm(gc, qmp, usbctrl_devid); + rc = libxl__device_usbctrl_del_hvm(gc, qmp, aodev->dev->devid); if (rc) goto out; return; } @@ -1845,20 +1873,31 @@ static LIBXL_DEFINE_DEVICES_ADD(usbdev) * 2) remove the usb device from xenstore controller/port. * 3) unbind usb device from usbback and rebind to its original driver. * If usb device has many interfaces, do it to each interface. + * + * Before calling this function, aodev should be properly filled: + * aodev->ao, aodev->callback, ... */ -static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev) +static void libxl__device_usbdev_remove(libxl__egc *egc, uint32_t domid, + libxl_device_usbdev *usbdev, + libxl__ao_device *aodev) { + STATE_AO_GC(aodev->ao); int rc; char *busid; libxl_device_usbctrl usbctrl; + /* Store *usbdev to be used by callbacks */ + aodev->device_config = usbdev; + aodev->device_type = &libxl__usbdev_devtype; + + libxl_device_usbctrl_init(&usbctrl); + if (usbdev->ctrl < 0 || usbdev->port < 1) { LOGD(ERROR, domid, "Invalid USB device"); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } - libxl_device_usbctrl_init(&usbctrl); rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); if (rc) goto out; @@ -1944,7 +1983,8 @@ static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, out: libxl_device_usbctrl_dispose(&usbctrl); - return rc; + aodev->rc = rc; + aodev->callback(egc, aodev); } int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid, @@ -1953,11 +1993,14 @@ int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid, { AO_CREATE(ctx, domid, ao_how); - int rc; + libxl__ao_device *aodev; - rc = libxl__device_usbdev_remove(gc, domid, usbdev); + GCNEW(aodev); + libxl__prepare_ao_device(ao, aodev); + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; + aodev->callback = device_addrm_aocomplete; + libxl__device_usbdev_remove(egc, domid, usbdev, aodev); - libxl__ao_complete(egc, ao, rc); return AO_INPROGRESS; } From patchwork Thu Sep 19 17:16:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153005 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 4A84C1745 for ; Thu, 19 Sep 2019 17:42:29 +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 2255A21D56 for ; Thu, 19 Sep 2019 17:42:29 +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="HO2SFx1Q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2255A21D56 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 1iB0R1-00053Z-8n; Thu, 19 Sep 2019 17:41:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0R0-00052A-7H for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:38 +0000 X-Inumbo-ID: af5d9a7e-db04-11e9-a337-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id af5d9a7e-db04-11e9-a337-bc764e2007e4; Thu, 19 Sep 2019 17:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914878; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=riibcUNR+m+jG1WH0pzxicB8ys53JqxoTIyAS95sEgI=; b=HO2SFx1Q5PoF3uAokwvzG7r9CWKdWi4PmWvXe8PkeGpZjgUQjJjmWCwK 103AVjItSbpZtwVPO7fU7+XiLR1v4bR0xZy8gurktm7wvVDPB3mStURoq ZiJ7CETHgvM5YIj7buu9Vm8+4ikwDDGpAI0m20HP7uwNpHuzAQ41MOyRq c=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: cQqwwqlCdmmvTW2Q5v54AyiOPL6G3d3z8rrdbQNbwCm/NgRHewEZggfhpyJflfj07zkL0SdLWg jNjWltAWOGM/DmSgEiJlf653IkzLIwjvebkDzZRr8oBPHu18MAs5vuA49r9PPym1SvR15yQb45 nmyLbXPIhMFEHfS0x2Vebxf/8kd74DxAKRt3AYEYgEMRwfAvViKW6pi47BxUhv5JG7NHc1Z/ey xIWBnrmNEZMcM2rliytUDBBwgxxnEDpaz1yJ9ii3LZWtrhfAqD3QKTny1L8/a0BysEU/Kem3TG xlw= X-SBRS: 2.7 X-MesageID: 6010801 X-Ironport-Server: esa5.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="6010801" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:43 +0100 Message-ID: <20190919171656.899649-24-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 23/35] libxl: libxl__initiate_device_usbdev_remove now use ev_qmp 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 78 +++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 3b432231ea85..1fc7ccf41f86 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -417,18 +417,16 @@ static int libxl__device_usbdev_add_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, } /* Send qmp commands to delete a usb device in qemu. */ -static int libxl__device_usbdev_del_hvm(libxl__gc *gc, uint32_t domid, +static int libxl__device_usbdev_del_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, libxl_device_usbdev *usbdev) { - flexarray_t *qmp_args; + libxl__json_object *qmp_args = NULL; - qmp_args = flexarray_make(gc, 2, 1); - flexarray_append_pair(qmp_args, "id", - GCSPRINTF("xenusb-%d-%d", - usbdev->u.hostdev.hostbus, - usbdev->u.hostdev.hostaddr)); + libxl__qmp_param_add_string(gc, &qmp_args, "id", + GCSPRINTF("xenusb-%d-%d", usbdev->u.hostdev.hostbus, + usbdev->u.hostdev.hostaddr)); - return libxl__qmp_run_command_flexarray(gc, domid, "device_del", qmp_args); + return libxl__ev_qmp_send(gc, qmp, "device_del", qmp_args); } static LIBXL_DEFINE_UPDATE_DEVID(usbctrl) @@ -1866,6 +1864,13 @@ static void device_usbdev_add_done(libxl__egc *egc, LIBXL_DEFINE_DEVICE_ADD(usbdev) static LIBXL_DEFINE_DEVICES_ADD(usbdev) +static void device_usbdev_remove_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void device_usbdev_remove_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *r, int rc); +static void device_usbdev_remove_done(libxl__egc *egc, + libxl__ao_device *aodev, int rc); + /* Operation to remove usb device. * * Generally, it does: @@ -1885,6 +1890,7 @@ static void libxl__device_usbdev_remove(libxl__egc *egc, uint32_t domid, int rc; char *busid; libxl_device_usbctrl usbctrl; + bool has_callback = false; /* Store *usbdev to be used by callbacks */ aodev->device_config = usbdev; @@ -1964,14 +1970,23 @@ static void libxl__device_usbdev_remove(libxl__egc *egc, uint32_t domid, LIBXL_USBCTRL_TYPE_DEVICEMODEL); if (rc) goto out; - rc = libxl__device_usbdev_del_hvm(gc, domid, usbdev); + rc = libxl__ev_time_register_rel(ao, &aodev->timeout, + device_usbdev_remove_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + + aodev->qmp.ao = ao; + aodev->qmp.domid = domid; + aodev->qmp.callback = device_usbdev_remove_qmp_cb; + aodev->qmp.payload_fd = -1; + rc = libxl__device_usbdev_del_hvm(gc, &aodev->qmp, usbdev); if (rc) { libxl__device_usbdev_add_xenstore(gc, domid, usbdev, LIBXL_USBCTRL_TYPE_DEVICEMODEL, false); goto out; } - + has_callback = true; break; default: LOGD(ERROR, domid, "Unsupported usb controller type"); @@ -1983,6 +1998,49 @@ static void libxl__device_usbdev_remove(libxl__egc *egc, uint32_t domid, out: libxl_device_usbctrl_dispose(&usbctrl); + /* Only call _done if no callback have been setup */ + if (!has_callback) + device_usbdev_remove_done(egc, aodev, rc); /* must be last */ +} + +static void device_usbdev_remove_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(ev, *aodev, timeout); + + if (rc == ERROR_TIMEDOUT) + LOGD(ERROR, aodev->qmp.domid, + "Removing usbdev from QEMU timed out"); + device_usbdev_remove_qmp_cb(egc, &aodev->qmp, NULL, rc); +} + +static void device_usbdev_remove_qmp_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *r, + int rc) +{ + EGC_GC; + libxl__ao_device *aodev = CONTAINER_OF(qmp, *aodev, qmp); + libxl_device_usbdev *const usbdev = aodev->device_config; + + if (rc) { + libxl__device_usbdev_add_xenstore(gc, qmp->domid, usbdev, + LIBXL_USBCTRL_TYPE_DEVICEMODEL, + false); + } + + device_usbdev_remove_done(egc, aodev, rc); /* must be last */ +} + +static void device_usbdev_remove_done(libxl__egc *egc, + libxl__ao_device *aodev, + int rc) +{ + EGC_GC; + + libxl__ev_time_deregister(gc, &aodev->timeout); + libxl__ev_qmp_dispose(gc, &aodev->qmp); aodev->rc = rc; aodev->callback(egc, aodev); } From patchwork Thu Sep 19 17:16:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153021 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 B0C8916B1 for ; Thu, 19 Sep 2019 17:42:55 +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 8BB1A214AF for ; Thu, 19 Sep 2019 17:42:55 +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="adf4k1lU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BB1A214AF 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 1iB0RB-0005Gu-6c; Thu, 19 Sep 2019 17:41:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0RA-0005FO-7b for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:48 +0000 X-Inumbo-ID: b17915ae-db04-11e9-a337-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b17915ae-db04-11e9-a337-bc764e2007e4; Thu, 19 Sep 2019 17:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914882; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1joyt2oTnmoDoh4BUR7K40cbB7Y8Nc6WE5CdjgCQcxg=; b=adf4k1lUtTlQbSutUhd12P2Ivwm4N3+0D3dQFjh6we1GH8ZcW4pFXkUp 4F58xcdoaLUr7QvALoiaGmLp97e3RdNyBukooFARXsWF1NXUIs2jXG6b0 QyjHHF01soMbTYaii/8EDTMPlgmuseVJkwRrPfdLszDyxHGq8p1fV5jx3 0=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: UYZ1MTGEY2TV0LZUQGlLG5Ve+mpx1Squ7lwgnwMsgAj0PS/XiDnQmbf/Pp/RWtQ+LG25rsOILE mbXXdai7SX1mv3TlHrGtyCglrpIsNJKaDWJ7EFUEV/UZQxlMXGzM3In3mHt0QGuUuGC7SOzhpz 4FQSMZ1xMVtQp/zjvr38KHEfxels7b0VFWs1E/c7jdDtayBLgmsZf1gM/tVZ88sNH34UPnSUox 7cYLnzk/+EJ97BZoNwMjZrlqMV+HutVpK70tkvRFgWW/yJf4CWEHxF7b6otiGgAXzOnnV1yH3c C3M= X-SBRS: 2.7 X-MesageID: 5801808 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,524,1559534400"; d="scan'208";a="5801808" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:44 +0100 Message-ID: <20190919171656.899649-25-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 24/35] libxl: Remove libxl__qmp_run_command_flexarray 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" There are no more users. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_internal.h | 3 --- tools/libxl/libxl_qmp.c | 16 ---------------- 2 files changed, 19 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 6c09b93f91f1..571301a5d5d8 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1980,9 +1980,6 @@ typedef struct libxl__qmp_handler libxl__qmp_handler; */ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, uint32_t domid); -_hidden int libxl__qmp_run_command_flexarray(libxl__gc *gc, int domid, - const char *cmd, - flexarray_t *array); _hidden int libxl__qmp_pci_add(libxl__gc *gc, int d, libxl_device_pci *pcidev); _hidden int libxl__qmp_pci_del(libxl__gc *gc, int domid, libxl_device_pci *pcidev); diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 0d6aedcc7d3c..c78ef4637d0a 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -833,22 +833,6 @@ static int qmp_run_command(libxl__gc *gc, int domid, return rc; } -int libxl__qmp_run_command_flexarray(libxl__gc *gc, int domid, - const char *cmd, flexarray_t *array) -{ - libxl__json_object *args = NULL; - int i; - void *name, *value; - - for (i = 0; i < array->count; i += 2) { - flexarray_get(array, i, &name); - flexarray_get(array, i + 1, &value); - libxl__qmp_param_add_string(gc, &args, (char *)name, (char *)value); - } - - return qmp_run_command(gc, domid, cmd, args, NULL, NULL); -} - int libxl__qmp_pci_add(libxl__gc *gc, int domid, libxl_device_pci *pcidev) { libxl__qmp_handler *qmp = NULL; From patchwork Thu Sep 19 17:16:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152989 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 E01BD1745 for ; Thu, 19 Sep 2019 17:42:12 +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 BBEB12196E for ; Thu, 19 Sep 2019 17:42:12 +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="IugjBX2K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBEB12196E 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 1iB0QN-0004GD-BD; Thu, 19 Sep 2019 17:40:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0QM-0004Fh-50 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:40:58 +0000 X-Inumbo-ID: 99d8d47a-db04-11e9-b299-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 99d8d47a-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914842; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/CS6ArKSdsCQwo1n1gxG9GakHmfYdgCTqatB6kPZ31w=; b=IugjBX2KCcnMKuyko3aHXJhfD/w3Gpbfq9UCFTRC/XlawxVHizWsk1o2 Pzegeg9c62RmSTjUSYIk6ErrJMK4b56OLlaWU6hjcfRL5tVmjPJDRE9YR k+VFwTx/EnuXCvogiIEvnKQVij20C6PFe17rH5R0Ztz6N5c9LHc6V5bIL c=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Y/r7nsTXplF6IaLvOBP4OIG6M9AF/0mCJi4E1ZnY2qmXmT40W8R1OzG8p83iE+RUX5qmrC/HtO QM55wbCEv3UV/9covw7Q9eDPOF5tRsDnjCWidQtiG+rzRtW7ntcN3Wsnt9QDi6g3lJ4W6Z5UzB pa3K8kmCx4JDf9b1AL4MZiF3fWoKoDAILfzUrz5qYYPYmdxEoz+SzEAlWMjwdrajePHiyCxJjK x0VhVvjwhjc8MLoyQFrqnYg5+G0C1+GyKPz8tF6Z5oBBsX1iSQzWE1PJbrvuorLPLnNEKHj4tC EYo= X-SBRS: 2.7 X-MesageID: 5801752 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,524,1559534400"; d="scan'208";a="5801752" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:45 +0100 Message-ID: <20190919171656.899649-26-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 25/35] libxl_pci: Coding style of do_pci_add 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" do_pci_add is going to be asynchronous, so we start by having a single path out of the function. All `return`s instead set rc and goto out. While here, some use of `rc' was used to store the return value of libxc calls, change them to store into `r'. Also, add the value of `r' in the error message of those calls. There were an `out' label that was use it seems to skip setting up the IRQ, the label has been renamed to `out_no_irq'. No functional changes. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_pci.c | 79 ++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 4b1aed1895cc..b9ca69f5f0b3 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -995,15 +995,19 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED; uint32_t domainid = domid; bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); + int r; - if (type == LIBXL_DOMAIN_TYPE_INVALID) - return ERROR_FAIL; + if (type == LIBXL_DOMAIN_TYPE_INVALID) { + rc = ERROR_FAIL; + goto out; + } if (type == LIBXL_DOMAIN_TYPE_HVM) { hvm = 1; if (libxl__wait_for_device_model_deprecated(gc, domid, "running", NULL, NULL, NULL) < 0) { - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: @@ -1013,10 +1017,10 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, rc = libxl__qmp_pci_add(gc, domid, pcidev); break; default: - return ERROR_INVAL; + rc = ERROR_INVAL; } if ( rc ) - return ERROR_FAIL; + goto out; } sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain, @@ -1027,7 +1031,8 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, if (f == NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) { if (fscanf(f, "0x%llx 0x%llx 0x%llx\n", &start, &end, &flags) != 3) @@ -1035,25 +1040,25 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, size = end - start + 1; if (start) { if (flags & PCI_BAR_IO) { - rc = xc_domain_ioport_permission(ctx->xch, domid, start, size, 1); - if (rc < 0) { + r = xc_domain_ioport_permission(ctx->xch, domid, start, size, 1); + if (r < 0) { LOGED(ERROR, domainid, - "Error: xc_domain_ioport_permission error 0x%llx/0x%llx", - start, - size); + "xc_domain_ioport_permission 0x%llx/0x%llx (error %d)", + start, size, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } else { - rc = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT, + r = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT, (size+(XC_PAGE_SIZE-1))>>XC_PAGE_SHIFT, 1); - if (rc < 0) { + if (r < 0) { LOGED(ERROR, domainid, - "Error: xc_domain_iomem_permission error 0x%llx/0x%llx", - start, - size); + "xc_domain_iomem_permission 0x%llx/0x%llx (error %d)", + start, size, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } } @@ -1064,20 +1069,24 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, f = fopen(sysfs_path, "r"); if (f == NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); - goto out; + goto out_no_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { - rc = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); - if (rc < 0) { - LOGED(ERROR, domainid, "Error: xc_physdev_map_pirq irq=%d", irq); + r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); + if (r < 0) { + LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)", + irq, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } - rc = xc_domain_irq_permission(ctx->xch, domid, irq, 1); - if (rc < 0) { - LOGED(ERROR, domainid, "Error: xc_domain_irq_permission irq=%d", irq); + r = xc_domain_irq_permission(ctx->xch, domid, irq, 1); + if (r < 0) { + LOGED(ERROR, domainid, + "xc_domain_irq_permission irq=%d (error=%d)", irq, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } fclose(f); @@ -1087,22 +1096,25 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive", pcidev) < 0 ) { LOGD(ERROR, domainid, "Setting permissive for device"); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } -out: +out_no_irq: if (!isstubdom) { if (pcidev->rdm_policy == LIBXL_RDM_RESERVE_POLICY_STRICT) { flag &= ~XEN_DOMCTL_DEV_RDM_RELAXED; } else if (pcidev->rdm_policy != LIBXL_RDM_RESERVE_POLICY_RELAXED) { LOGED(ERROR, domainid, "unknown rdm check flag."); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } - rc = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev), flag); - if (rc < 0 && (hvm || errno != ENOSYS)) { + r = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev), flag); + if (r < 0 && (hvm || errno != ENOSYS)) { LOGED(ERROR, domainid, "xc_assign_device failed"); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } @@ -1110,6 +1122,7 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, rc = libxl__device_pci_add_xenstore(gc, domid, pcidev, starting); else rc = 0; +out: return rc; } From patchwork Thu Sep 19 17:16:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153003 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 2255E16B1 for ; Thu, 19 Sep 2019 17:42:29 +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 EEA182196E for ; Thu, 19 Sep 2019 17:42:28 +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="Qxocw1Vm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEA182196E 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 1iB0QD-0004Ax-Aw; Thu, 19 Sep 2019 17:40:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0QC-0004Ac-4N for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:40:48 +0000 X-Inumbo-ID: 98c493f8-db04-11e9-b299-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 98c493f8-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914840; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a9J09fdodeDSbFx/jslZyCcYyIiZk3yNPrVs1emhmHk=; b=Qxocw1Vmxaxxg7NnH6g5KoZLRtBgVCEiI9qRhX4dhVkG74+dmvbhKGrb Ei02G0zye4j3KMchFjvZKiXAFAC8rQ0trC/SViUdQfzjFE1TeHVKMfV47 l6wiUCWSeesksTFyOiA/WfIDsbPYiMBTeVhe9nQyrC+4xRiZQuacAyLak c=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: fQ73rtjWQQcMhAZL/ih9nyDmAFf7j2gaEuyXRs+TKF+XPB3laAk0XE5zdALZGWzv72EkDajHOx 5G/sakTXh/QjLtXCk8PHBFybYVSFtgKN/AF6CLHRTzoeN+/b8JHpOlzyxGQsb/rHDSPThPs2Tp pGuw3WDh/4W58RBj5/F45IeE+sNECOV7ajYxximJLXK9XE9B4Sh0oR505fYT/fN6DJb0MyDB5u Slxh7bX6YIDG/pFa2H82oiGKZewr6BCT2TH+EEEm1sUUlqYVZBbEqWTIiZEbx6pm8z9bePSyWF pCk= X-SBRS: 2.7 X-MesageID: 5801743 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,524,1559534400"; d="scan'208";a="5801743" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:46 +0100 Message-ID: <20190919171656.899649-27-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 26/35] libxl_pci: Only check if qemu-dm is running in qemu-trad case 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" QEMU upstream (or qemu-xen) may not have set "running" state in xenstore. "running" with QEMU doesn't mean that the binary is running, it means that the emulation have started. When adding a pci-passthrough device to QEMU, we do so via QMP, we have a direct answer to whether QEMU is running or not, no need to check ahead. Moving the check to do it only with qemu-trad makes upcoming changes simpler. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_pci.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index b9ca69f5f0b3..071880b8556b 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1004,13 +1004,13 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, if (type == LIBXL_DOMAIN_TYPE_HVM) { hvm = 1; - if (libxl__wait_for_device_model_deprecated(gc, domid, "running", - NULL, NULL, NULL) < 0) { - rc = ERROR_FAIL; - goto out; - } switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + if (libxl__wait_for_device_model_deprecated(gc, domid, + "running", NULL, NULL, NULL) < 0) { + rc = ERROR_FAIL; + goto out; + } rc = qemu_pci_add_xenstore(gc, domid, pcidev); break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: @@ -1395,12 +1395,11 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, rc = ERROR_FAIL; if (type == LIBXL_DOMAIN_TYPE_HVM) { hvm = 1; - if (libxl__wait_for_device_model_deprecated(gc, domid, "running", - NULL, NULL, NULL) < 0) - goto out_fail; - switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + if (libxl__wait_for_device_model_deprecated(gc, domid, + "running", NULL, NULL, NULL) < 0) + goto out_fail; rc = qemu_pci_remove_xenstore(gc, domid, pcidev, force); break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: From patchwork Thu Sep 19 17:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152981 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 88D6A15E6 for ; Thu, 19 Sep 2019 17:42:03 +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 579B72196E for ; Thu, 19 Sep 2019 17:42:03 +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="IsnMNxu6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 579B72196E 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 1iB0Py-000482-8y; Thu, 19 Sep 2019 17:40:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Px-00047x-3v for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:40:33 +0000 X-Inumbo-ID: 9388799a-db04-11e9-978d-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9388799a-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914832; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PP+vnRAblMneTFTS7p0zE7UYiASGasi1qLf8ytAIQG8=; b=IsnMNxu6gZkSyiYIacDEZUV1MS2toQSGiUm3C3KAEqMxF4rQiW8kyJr+ x3GLaFpFo5h84/h5ulN4f35E2YbClBpB2gBtpeo4BvTPUPgZvz4Po3SbR T21L8h5BUL9lkUgHhogCAa6UlGnI5ebESXpULbGKDIi3mbU1XFk12znx6 0=; Authentication-Results: esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.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=esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: ZOBKLhvhg1X1ejU43Q+iisPia62/SSqEEcBuHMne3zQITvXTTdVl4CWEbK7PpiILn3deyeNfTZ J+VQe+9hjkjfnoMLKtmBa6hksDlHvh/aa8M03onz0jNX3QhJh/qPaYB5XIBTLVZnCT6s7aNZQw Ant5jb4KlztQpnMDtYAUo4GT6rF8UNfDJpcIGWmkLzVBDE6jE7ONlDMbmxtHfFbnrgutCmbwsN Zp/D6MCrj/wT0ayhLMEnVSImc5Z/4AAs2iXfSUDiUiTJtY2smJRbS+tXpZE+Ff9ZGdrGM9rEyt uNg= X-SBRS: 2.7 X-MesageID: 5864875 X-Ironport-Server: esa1.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="5864875" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:47 +0100 Message-ID: <20190919171656.899649-28-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 27/35] libxl_pci: Use libxl__ao_device with libxl__device_pci_add 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_internal.h | 7 +- tools/libxl/libxl_pci.c | 170 ++++++++++++++++++++++++++++++----- 2 files changed, 150 insertions(+), 27 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 571301a5d5d8..18c665d3dbe2 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -198,6 +198,7 @@ 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; +typedef struct libxl__ao_device libxl__ao_device; typedef struct libxl__domain_create_state libxl__domain_create_state; typedef void libxl__domain_create_cb(struct libxl__egc *egc, @@ -1593,8 +1594,9 @@ _hidden int libxl__pci_topology_init(libxl__gc *gc, /* from libxl_pci */ -_hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev, bool starting); +_hidden void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, + libxl_device_pci *pcidev, bool starting, + libxl__ao_device *aodev); _hidden int libxl__device_pci_destroy_all(libxl__gc *gc, uint32_t domid); _hidden bool libxl__is_igd_vga_passthru(libxl__gc *gc, const libxl_domain_config *d_config); @@ -2572,7 +2574,6 @@ _hidden void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what); /*----- device addition/removal -----*/ -typedef struct libxl__ao_device libxl__ao_device; typedef struct libxl__multidev libxl__multidev; typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*); diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 071880b8556b..503db6c26043 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -983,9 +983,24 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid, return rc; } -static int do_pci_add(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev, bool starting) +typedef struct pci_add_state { + /* filled by user of do_pci_add */ + libxl__ao_device *aodev; + libxl_domid domid; + bool starting; + void (*callback)(libxl__egc *, struct pci_add_state *, int rc); + + /* private to do_pci_add */ + libxl_device_pci *pcidev; + int pci_domid; +} pci_add_state; + +static void do_pci_add(libxl__egc *egc, + libxl_domid domid, + libxl_device_pci *pcidev, + pci_add_state *pas) { + STATE_AO_GC(pas->aodev->ao); libxl_ctx *ctx = libxl__gc_owner(gc); libxl_domain_type type = libxl__domain_type(gc, domid); char *sysfs_path; @@ -997,6 +1012,13 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); int r; + /* Convenience aliases */ + bool starting = pas->starting; + + /* init pci_add_state */ + pas->pcidev = pcidev; + pas->pci_domid = domid; + if (type == LIBXL_DOMAIN_TYPE_INVALID) { rc = ERROR_FAIL; goto out; @@ -1123,7 +1145,7 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, else rc = 0; out: - return rc; + pas->callback(egc, pas, rc); } static int libxl__device_pci_reset(libxl__gc *gc, unsigned int domain, unsigned int bus, @@ -1177,9 +1199,14 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); - int rc; - rc = libxl__device_pci_add(gc, domid, pcidev, false); - libxl__ao_complete(egc, ao, rc); + libxl__ao_device *aodev; + + GCNEW(aodev); + libxl__prepare_ao_device(ao, aodev); + aodev->action = LIBXL__DEVICE_ACTION_ADD; + aodev->callback = device_addrm_aocomplete; + aodev->update_json = true; + libxl__device_pci_add(egc, domid, pcidev, false, aodev); return AO_INPROGRESS; } @@ -1200,14 +1227,31 @@ static int libxl_pcidev_assignable(libxl_ctx *ctx, libxl_device_pci *pcidev) return i != num; } -int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev, bool starting) +static void device_pci_add_stubdom_done(libxl__egc *egc, + pci_add_state *, int rc); +static void device_pci_add_done(libxl__egc *egc, + pci_add_state *, int rc); + +void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, + libxl_device_pci *pcidev, bool starting, + libxl__ao_device *aodev) { + STATE_AO_GC(aodev->ao); libxl_ctx *ctx = libxl__gc_owner(gc); - unsigned int orig_vdev, pfunc_mask; libxl_device_pci *assigned; - int num_assigned, i, rc; + int num_assigned, rc; int stubdomid = 0; + pci_add_state *pas; + + /* Store *pcidev to be used by callbacks */ + aodev->device_config = pcidev; + aodev->device_type = &libxl__pcidev_devtype; + + GCNEW(pas); + pas->aodev = aodev; + pas->domid = domid; + pas->starting = starting; + pas->callback = device_pci_add_stubdom_done; if (libxl__domain_type(gc, domid) == LIBXL_DOMAIN_TYPE_HVM) { rc = xc_test_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev)); @@ -1254,13 +1298,39 @@ int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, stubdomid = libxl_get_stubdom_id(ctx, domid); if (stubdomid != 0) { - libxl_device_pci pcidev_s = *pcidev; + libxl_device_pci *pcidev_s; + + GCNEW(pcidev_s); + libxl_device_pci_init(pcidev_s); + libxl_device_pci_copy(CTX, pcidev_s, pcidev); /* stubdomain is always running by now, even at create time */ - rc = do_pci_add(gc, stubdomid, &pcidev_s, false); - if ( rc ) - goto out; + pas->callback = device_pci_add_stubdom_done; + do_pci_add(egc, stubdomid, pcidev_s, pas); /* must be last */ + return; } + device_pci_add_stubdom_done(egc, pas, 0); /* must be last */ + return; + +out: + device_pci_add_done(egc, pas, rc); /* must be last */ +} + +static void device_pci_add_stubdom_done(libxl__egc *egc, + pci_add_state *pas, + int rc) +{ + STATE_AO_GC(pas->aodev->ao); + unsigned int orig_vdev, pfunc_mask; + int i; + + /* Convenience aliases */ + libxl__ao_device *aodev = pas->aodev; + libxl_domid domid = pas->domid; + libxl_device_pci *pcidev = aodev->device_config; + + if (rc) goto out; + orig_vdev = pcidev->vdevfn & ~7U; if ( pcidev->vfunc_mask == LIBXL_PCI_FUNC_ALL ) { @@ -1291,31 +1361,83 @@ int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, */ pcidev->vdevfn = orig_vdev; } - if ( do_pci_add(gc, domid, pcidev, starting) ) - rc = ERROR_FAIL; + pas->callback = device_pci_add_done; + do_pci_add(egc, domid, pcidev, pas); /* must be last */ + return; } } out: - return rc; + device_pci_add_done(egc, pas, rc); +} + +static void device_pci_add_done(libxl__egc *egc, + pci_add_state *pas, + int rc) +{ + EGC_GC; + libxl__ao_device *aodev = pas->aodev; + libxl_domid domid = pas->domid; + libxl_device_pci *pcidev = aodev->device_config; + + if (rc) { + LOGD(ERROR, domid, + "libxl__device_pci_add failed for " + "PCI device %x:%x:%x.%x (rc %d)", + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func, + rc); + } + aodev->rc = rc; + aodev->callback(egc, aodev); } +typedef struct { + libxl__multidev multidev; + libxl__ao_device *outer_aodev; + libxl_domain_config *d_config; + libxl_domid domid; +} add_pcidevs_state; + +static void add_pcidevs_done(libxl__egc *, libxl__multidev *, int rc); + static void libxl__add_pcidevs(libxl__egc *egc, libxl__ao *ao, uint32_t domid, libxl_domain_config *d_config, libxl__multidev *multidev) { AO_GC; - libxl__ao_device *aodev = libxl__multidev_prepare(multidev); - int i, rc = 0; + add_pcidevs_state *apds; + int i; + + /* We need to start a new multidev in order to be able to execute + * libxl__create_pci_backend only once. */ + + GCNEW(apds); + apds->outer_aodev = libxl__multidev_prepare(multidev); + apds->d_config = d_config; + apds->domid = domid; + apds->multidev.callback = add_pcidevs_done; + libxl__multidev_begin(ao, &apds->multidev); for (i = 0; i < d_config->num_pcidevs; i++) { - rc = libxl__device_pci_add(gc, domid, &d_config->pcidevs[i], true); - if (rc < 0) { - LOGD(ERROR, domid, "libxl_device_pci_add failed: %d", rc); - goto out; - } + libxl__ao_device *aodev = libxl__multidev_prepare(&apds->multidev); + libxl__device_pci_add(egc, domid, &d_config->pcidevs[i], + true, aodev); } + libxl__multidev_prepared(egc, &apds->multidev, 0); +} + +static void add_pcidevs_done(libxl__egc *egc, libxl__multidev *multidev, + int rc) +{ + EGC_GC; + add_pcidevs_state *apds = CONTAINER_OF(multidev, *apds, multidev); + + /* Convenience aliases */ + libxl_domain_config *d_config = apds->d_config; + libxl_domid domid = apds->domid; + libxl__ao_device *aodev = apds->outer_aodev; + if (d_config->num_pcidevs > 0) { rc = libxl__create_pci_backend(gc, domid, d_config->pcidevs, d_config->num_pcidevs); From patchwork Thu Sep 19 17:16:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153027 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 9829215E6 for ; Thu, 19 Sep 2019 17:43:18 +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 68858214AF for ; Thu, 19 Sep 2019 17:43:18 +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="HYWPnEBv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68858214AF 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 1iB0RL-0005VM-Do; Thu, 19 Sep 2019 17:41:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0RK-0005Tj-7j for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:58 +0000 X-Inumbo-ID: b745ac18-db04-11e9-978d-bc764e2007e4 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b745ac18-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914892; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4ywWfZLEbmP7ZGXJPOEkF4hdVdqWKtMFSsjoXWWZH84=; b=HYWPnEBv3NgJmMXIp49/efUVtXcg514R/xGUnVgUTtkBDR8krzNu0lvn TgbiL8PXeuaKF9IlZLrIG7wv3f7K9p+hc2jdh7RhBUTVCRz0uOA+JwIdI 9RJdL2n0GAE7KgQIMJEBbrk7cw5EDq2EjUfVSsU0jQQXxWORGzWqYCebm E=; Authentication-Results: esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.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=esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: TQoAhTj7QihMrcMTYpSFJBeFPDabUrqTeRaolv1QofUh5XwMyqQZbzbgn5SP/C1pHQAe5daXbg 89W+TFJ/idwIrLhbknySvhrRWyDC091NS4atauzhNuma2+34AAo3wyYxqil4XtXJ3PqT9RyHvS w5pRtMHBVTPLcfIJlYpM+1tzpLtny6bNiNIE5p8u97tIEXb4OMOWN6zveqmO9gzFUXqEW/GhVO Sz2Wk+fZCVIXG0eZsfyd4d4f2jdh5QvtFdPz2RK/T4S8NcRWLr6c/8DndrZH/DrE2VrO7dz8B/ V+Q= X-SBRS: 2.7 X-MesageID: 5806237 X-Ironport-Server: esa3.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="5806237" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:48 +0100 Message-ID: <20190919171656.899649-29-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 28/35] libxl_pci: Use ev_qmp in do_pci_add 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" This patch also replaces the use of libxl__wait_for_device_model_deprecated() by its equivalent without the need for a thread. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_internal.h | 1 - tools/libxl/libxl_pci.c | 288 ++++++++++++++++++++++++++++++++--- tools/libxl/libxl_qmp.c | 96 ------------ 3 files changed, 265 insertions(+), 120 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 18c665d3dbe2..d60b9c416abf 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1982,7 +1982,6 @@ typedef struct libxl__qmp_handler libxl__qmp_handler; */ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, uint32_t domid); -_hidden int libxl__qmp_pci_add(libxl__gc *gc, int d, libxl_device_pci *pcidev); _hidden int libxl__qmp_pci_del(libxl__gc *gc, int domid, libxl_device_pci *pcidev); /* Resume hvm domain */ diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 503db6c26043..3477f3aba605 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -23,6 +23,7 @@ #define PCI_BDF_VDEVFN "%04x:%02x:%02x.%01x@%02x" #define PCI_OPTIONS "msitranslate=%d,power_mgmt=%d" #define PCI_BDF_XSPATH "%04x-%02x-%02x-%01x" +#define PCI_PT_QDEV_ID "pci-pt-%02x_%02x.%01x" static unsigned int pcidev_encode_bdf(libxl_device_pci *pcidev) { @@ -991,33 +992,40 @@ typedef struct pci_add_state { void (*callback)(libxl__egc *, struct pci_add_state *, int rc); /* private to do_pci_add */ + libxl__xswait_state xswait; + libxl__ev_qmp qmp; + libxl__ev_time timeout; libxl_device_pci *pcidev; int pci_domid; } pci_add_state; +static void pci_add_qemu_trad_watch_state_cb(libxl__egc *egc, + libxl__xswait_state *xswa, int rc, const char *state); +static void pci_add_qmp_device_add(libxl__egc *, pci_add_state *); +static void pci_add_qmp_device_add_cb(libxl__egc *, + libxl__ev_qmp *, const libxl__json_object *, int rc); +static void pci_add_qmp_query_pci_cb(libxl__egc *, + libxl__ev_qmp *, const libxl__json_object *, int rc); +static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, int rc); +static void pci_add_dm_done(libxl__egc *, + pci_add_state *, int rc); + static void do_pci_add(libxl__egc *egc, libxl_domid domid, libxl_device_pci *pcidev, pci_add_state *pas) { STATE_AO_GC(pas->aodev->ao); - libxl_ctx *ctx = libxl__gc_owner(gc); libxl_domain_type type = libxl__domain_type(gc, domid); - char *sysfs_path; - FILE *f; - unsigned long long start, end, flags, size; - int irq, i, rc, hvm = 0; - uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED; - uint32_t domainid = domid; - bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); - int r; - - /* Convenience aliases */ - bool starting = pas->starting; + int rc; /* init pci_add_state */ + libxl__xswait_init(&pas->xswait); + libxl__ev_qmp_init(&pas->qmp); pas->pcidev = pcidev; pas->pci_domid = domid; + libxl__ev_time_init(&pas->timeout); if (type == LIBXL_DOMAIN_TYPE_INVALID) { rc = ERROR_FAIL; @@ -1025,26 +1033,259 @@ static void do_pci_add(libxl__egc *egc, } if (type == LIBXL_DOMAIN_TYPE_HVM) { - hvm = 1; switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: - if (libxl__wait_for_device_model_deprecated(gc, domid, - "running", NULL, NULL, NULL) < 0) { - rc = ERROR_FAIL; - goto out; - } - rc = qemu_pci_add_xenstore(gc, domid, pcidev); - break; + pas->xswait.ao = ao; + pas->xswait.what = "Device Model"; + pas->xswait.path = DEVICE_MODEL_XS_PATH(gc, + libxl_get_stubdom_id(CTX, domid), domid, "/state"); + pas->xswait.timeout_ms = LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000; + pas->xswait.callback = pci_add_qemu_trad_watch_state_cb; + rc = libxl__xswait_start(gc, &pas->xswait); + if (rc) goto out; + return; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc = libxl__qmp_pci_add(gc, domid, pcidev); - break; + pci_add_qmp_device_add(egc, pas); /* must be last */ + return; default: rc = ERROR_INVAL; + break; } - if ( rc ) + } + + rc = 0; + +out: + pci_add_dm_done(egc, pas, rc); /* must be last */ +} + +static void pci_add_qemu_trad_watch_state_cb(libxl__egc *egc, + libxl__xswait_state *xswa, + int rc, + const char *state) +{ + pci_add_state *pas = CONTAINER_OF(xswa, *pas, xswait); + STATE_AO_GC(pas->aodev->ao); + + /* Convenience aliases */ + libxl_domid domid = pas->domid; + libxl_device_pci *pcidev = pas->pcidev; + + if (rc) { + if (rc == ERROR_TIMEDOUT) { + LOGD(ERROR, domid, "%s not ready", xswa->what); + } + goto out; + } + + if (!state) + return; + if (strcmp(state, "running")) + return; + + rc = qemu_pci_add_xenstore(gc, domid, pcidev); +out: + libxl__xswait_stop(gc, xswa); + pci_add_dm_done(egc, pas, rc); /* must be last */ +} + +static void pci_add_qmp_device_add(libxl__egc *egc, pci_add_state *pas) +{ + STATE_AO_GC(pas->aodev->ao); + libxl__json_object *args = NULL; + int rc; + + /* Convenience aliases */ + libxl_domid domid = pas->domid; + libxl_device_pci *pcidev = pas->pcidev; + libxl__ev_qmp *const qmp = &pas->qmp; + + rc = libxl__ev_time_register_rel(ao, &pas->timeout, + pci_add_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + + libxl__qmp_param_add_string(gc, &args, "driver", + "xen-pci-passthrough"); + QMP_PARAMETERS_SPRINTF(&args, "id", PCI_PT_QDEV_ID, + pcidev->bus, pcidev->dev, pcidev->func); + QMP_PARAMETERS_SPRINTF(&args, "hostaddr", + "%04x:%02x:%02x.%01x", pcidev->domain, + pcidev->bus, pcidev->dev, pcidev->func); + if (pcidev->vdevfn) { + QMP_PARAMETERS_SPRINTF(&args, "addr", "%x.%x", + PCI_SLOT(pcidev->vdevfn), + PCI_FUNC(pcidev->vdevfn)); + } + /* + * Version of QEMU prior to the XSA-131 fix did not support + * this property and were effectively always in permissive + * mode. The fix for XSA-131 switched the default to be + * restricted by default and added the permissive property. + * + * Therefore in order to support both old and new QEMU we only + * set the permissive flag if it is true. Users of older QEMU + * have no reason to set the flag so this is ok. + */ + if (pcidev->permissive) + libxl__qmp_param_add_bool(gc, &args, "permissive", true); + + qmp->ao = pas->aodev->ao; + qmp->domid = domid; + qmp->payload_fd = -1; + qmp->callback = pci_add_qmp_device_add_cb; + rc = libxl__ev_qmp_send(gc, qmp, "device_add", args); + if (rc) goto out; + return; + +out: + pci_add_dm_done(egc, pas, rc); /* must be last */ +} + +static void pci_add_qmp_device_add_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + EGC_GC; + pci_add_state *pas = CONTAINER_OF(qmp, *pas, qmp); + + if (rc) goto out; + + qmp->callback = pci_add_qmp_query_pci_cb; + rc = libxl__ev_qmp_send(gc, qmp, "query-pci", NULL); + if (rc) goto out; + return; + +out: + pci_add_dm_done(egc, pas, rc); /* must be last */ +} + +static void pci_add_qmp_query_pci_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + EGC_GC; + pci_add_state *pas = CONTAINER_OF(qmp, *pas, qmp); + const libxl__json_object *bus = NULL; + char *asked_id; + int i, j; + const libxl__json_object *devices = NULL; + const libxl__json_object *device = NULL; + const libxl__json_object *o = NULL; + const char *id = NULL; + int dev_slot, dev_func; + + /* Convenience aliases */ + libxl_device_pci *pcidev = pas->pcidev; + + if (rc) goto out; + + /* `query-pci' returns: + * [ + * {'bus': 'int', + * 'devices': [ + * {'bus': 'int', 'slot': 'int', 'function': 'int', + * 'class_info': 'PciDeviceClass', 'id': 'PciDeviceId', + * '*irq': 'int', 'qdev_id': 'str', + * '*pci_bridge': 'PciBridgeInfo', + * 'regions': ['PciMemoryRegion'] + * } + * ] + * } + * ] + * (See qemu.git/qapi/ for the struct that aren't detailed here) + */ + + asked_id = GCSPRINTF(PCI_PT_QDEV_ID, + pcidev->bus, pcidev->dev, pcidev->func); + + for (i = 0; (bus = libxl__json_array_get(response, i)); i++) { + devices = libxl__json_map_get("devices", bus, JSON_ARRAY); + if (!devices) { + rc = ERROR_QEMU_API; goto out; + } + + for (j = 0; (device = libxl__json_array_get(devices, j)); j++) { + o = libxl__json_map_get("qdev_id", device, JSON_STRING); + if (!o) { + rc = ERROR_QEMU_API; + goto out; + } + id = libxl__json_object_get_string(o); + if (!id || strcmp(asked_id, id)) + continue; + + o = libxl__json_map_get("slot", device, JSON_INTEGER); + if (!o) { + rc = ERROR_QEMU_API; + goto out; + } + dev_slot = libxl__json_object_get_integer(o); + o = libxl__json_map_get("function", device, JSON_INTEGER); + if (!o) { + rc = ERROR_QEMU_API; + goto out; + } + dev_func = libxl__json_object_get_integer(o); + + pcidev->vdevfn = PCI_DEVFN(dev_slot, dev_func); + + rc = 0; + goto out; + } } + rc = ERROR_FAIL; + LOGD(ERROR, qmp->domid, + "PCI device id '%s' wasn't found in QEMU's 'query-pci' response.", + asked_id); + +out: + if (rc == ERROR_QEMU_API) { + LOGD(ERROR, qmp->domid, + "Unexpected response to QMP cmd 'query-pci', received:\n%s", + JSON(response)); + } + pci_add_dm_done(egc, pas, rc); /* must be last */ +} + +static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + pci_add_state *pas = CONTAINER_OF(ev, *pas, timeout); + + pci_add_dm_done(egc, pas, rc); +} + +static void pci_add_dm_done(libxl__egc *egc, + pci_add_state *pas, + int rc) +{ + STATE_AO_GC(pas->aodev->ao); + libxl_ctx *ctx = libxl__gc_owner(gc); + libxl_domid domid = pas->pci_domid; + char *sysfs_path; + FILE *f; + unsigned long long start, end, flags, size; + int irq, i; + int r; + uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED; + uint32_t domainid = domid; + bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); + + /* Convenience aliases */ + bool starting = pas->starting; + libxl_device_pci *pcidev = pas->pcidev; + bool hvm = libxl__domain_type(gc, domid) == LIBXL_DOMAIN_TYPE_HVM; + + libxl__ev_qmp_dispose(gc, &pas->qmp); + + if (rc) goto out; + sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); f = fopen(sysfs_path, "r"); @@ -1145,6 +1386,7 @@ static void do_pci_add(libxl__egc *egc, else rc = 0; out: + libxl__ev_time_deregister(gc, &pas->timeout); pas->callback(egc, pas, rc); } diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index c78ef4637d0a..38ba63d5b920 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -736,54 +736,6 @@ void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid) } } -static int pci_add_callback(libxl__qmp_handler *qmp, - const libxl__json_object *response, void *opaque) -{ - libxl_device_pci *pcidev = opaque; - const libxl__json_object *bus = NULL; - GC_INIT(qmp->ctx); - int i, j, rc = -1; - char *asked_id = GCSPRINTF(PCI_PT_QDEV_ID, - pcidev->bus, pcidev->dev, pcidev->func); - - for (i = 0; (bus = libxl__json_array_get(response, i)); i++) { - const libxl__json_object *devices = NULL; - const libxl__json_object *device = NULL; - const libxl__json_object *o = NULL; - const char *id = NULL; - - devices = libxl__json_map_get("devices", bus, JSON_ARRAY); - - for (j = 0; (device = libxl__json_array_get(devices, j)); j++) { - o = libxl__json_map_get("qdev_id", device, JSON_STRING); - id = libxl__json_object_get_string(o); - - if (id && strcmp(asked_id, id) == 0) { - int dev_slot, dev_func; - - o = libxl__json_map_get("slot", device, JSON_INTEGER); - if (!o) - goto out; - dev_slot = libxl__json_object_get_integer(o); - o = libxl__json_map_get("function", device, JSON_INTEGER); - if (!o) - goto out; - dev_func = libxl__json_object_get_integer(o); - - pcidev->vdevfn = PCI_DEVFN(dev_slot, dev_func); - - rc = 0; - goto out; - } - } - } - - -out: - GC_FREE; - return rc; -} - static int pci_del_callback(libxl__qmp_handler *qmp, const libxl__json_object *response, void *opaque) { @@ -833,54 +785,6 @@ static int qmp_run_command(libxl__gc *gc, int domid, return rc; } -int libxl__qmp_pci_add(libxl__gc *gc, int domid, libxl_device_pci *pcidev) -{ - libxl__qmp_handler *qmp = NULL; - libxl__json_object *args = NULL; - char *hostaddr = NULL; - int rc = 0; - - qmp = libxl__qmp_initialize(gc, domid); - if (!qmp) - return -1; - - hostaddr = GCSPRINTF("%04x:%02x:%02x.%01x", pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->func); - if (!hostaddr) - return -1; - - libxl__qmp_param_add_string(gc, &args, "driver", "xen-pci-passthrough"); - QMP_PARAMETERS_SPRINTF(&args, "id", PCI_PT_QDEV_ID, - pcidev->bus, pcidev->dev, pcidev->func); - libxl__qmp_param_add_string(gc, &args, "hostaddr", hostaddr); - if (pcidev->vdevfn) { - QMP_PARAMETERS_SPRINTF(&args, "addr", "%x.%x", - PCI_SLOT(pcidev->vdevfn), PCI_FUNC(pcidev->vdevfn)); - } - /* - * Version of QEMU prior to the XSA-131 fix did not support this - * property and were effectively always in permissive mode. The - * fix for XSA-131 switched the default to be restricted by - * default and added the permissive property. - * - * Therefore in order to support both old and new QEMU we only set - * the permissive flag if it is true. Users of older QEMU have no - * reason to set the flag so this is ok. - */ - if (pcidev->permissive) - libxl__qmp_param_add_bool(gc, &args, "permissive", true); - - rc = qmp_synchronous_send(qmp, "device_add", args, - NULL, NULL, qmp->timeout); - if (rc == 0) { - rc = qmp_synchronous_send(qmp, "query-pci", NULL, - pci_add_callback, pcidev, qmp->timeout); - } - - libxl__qmp_close(qmp); - return rc; -} - static int qmp_device_del(libxl__gc *gc, int domid, char *id) { libxl__json_object *args = NULL; From patchwork Thu Sep 19 17:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153017 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 D324F15E6 for ; Thu, 19 Sep 2019 17:42:48 +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 A3525214AF for ; Thu, 19 Sep 2019 17:42:48 +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="GCAeu0l5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3525214AF 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 1iB0Qw-0004va-6D; Thu, 19 Sep 2019 17:41:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Qv-0004u4-6h for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:33 +0000 X-Inumbo-ID: af3b90aa-db04-11e9-978d-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id af3b90aa-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I5GOTjkWyrkZ0RQDztLKaC6Ig0iqextS75xs8JPRgxc=; b=GCAeu0l5vz2w1QZJUIxECBBu8T2mj42EzvIRrengK0V+11Oxl/TRZ4zz vYOTIYgOs/6c/rnZa+EYXLGorOKOTafQpcbVfOeKYekkCPbg+0XcZAQp3 gL0yq9nfi1Weas8WdNLOOsefr7xqVwIc5dc+7o00ND0/1obtYigeRa+/U I=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 6GtLjN3SpSY+xhfhj89cb2YqD+WKQnGKgEKZl3+WfiTwcd5Z+fr0zc1xQntAr99PlDCsfuiMai O+LO5OJT1ofu5WMfegP2/O276KkSscqp5Zunp2HkcXZ+gTUZK7Dz5TaKYxsWFTSuvrazDgjx3k abOB0B9wkIlNIBeCWUgSRZMyup6dwxYGm3zxkp1RoAjCfVHpJR4od2ddOCFa64JIvAmsUoSK8P zyYejKt6Fe9eOdGX5+9UYuUk0PKZU3gMJZtQLVV5pHmcs1NFmar53XjZjx84h/9jlKB9S0KmmL FRw= X-SBRS: 2.7 X-MesageID: 6010798 X-Ironport-Server: esa5.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="6010798" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:49 +0100 Message-ID: <20190919171656.899649-30-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 29/35] libxl_pci: Use libxl__ao_device with pci_remove 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" This is in preparation of using asynchronous operation to communicate with QEMU via QMP (libxl__ev_qmp). Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 49 ++++++-- tools/libxl/libxl_internal.h | 6 +- tools/libxl/libxl_pci.c | 221 ++++++++++++++++++++++++++--------- 3 files changed, 210 insertions(+), 66 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index f3c39fa86fc9..cd7190035005 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1104,6 +1104,9 @@ static void destroy_finish_check(libxl__egc *egc, } /* Callbacks for libxl__destroy_domid */ +static void destroy_domid_pci_done(libxl__egc *egc, + libxl__multidev *multidev, + int rc); static void dm_destroy_cb(libxl__egc *egc, libxl__destroy_devicemodel_state *ddms, int rc); @@ -1120,8 +1123,7 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) { STATE_AO_GC(dis->ao); uint32_t domid = dis->domid; - int rc, dm_present; - int r; + int rc; libxl__ev_child_init(&dis->destroyer); @@ -1135,6 +1137,41 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) goto out; } + libxl__multidev_begin(ao, &dis->multidev); + dis->multidev.callback = destroy_domid_pci_done; + libxl__device_pci_destroy_all(egc, domid, &dis->multidev); + libxl__multidev_prepared(egc, &dis->multidev, 0); + return; + +out: + assert(rc); + dis->callback(egc, dis, rc); +} + +static void destroy_domid_pci_done(libxl__egc *egc, + libxl__multidev *multidev, + int rc) +{ + STATE_AO_GC(multidev->ao); + libxl__destroy_domid_state *dis = + CONTAINER_OF(multidev, *dis, multidev); + int dm_present; + int r; + + /* Convenience aliases */ + libxl_domid domid = dis->domid; + + if (rc) { + LOGD(ERROR, domid, "Pci shutdown failed"); + goto out; + } + + r = xc_domain_pause(CTX->xch, domid); + if (r < 0) { + LOGEVD(ERROR, r, domid, "xc_domain_pause failed"); + rc = ERROR_FAIL; + } + switch (libxl__domain_type(gc, domid)) { case LIBXL_DOMAIN_TYPE_HVM: if (libxl_get_stubdom_id(CTX, domid)) { @@ -1153,14 +1190,6 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) abort(); } - if (libxl__device_pci_destroy_all(gc, domid) < 0) - LOGD(ERROR, domid, "Pci shutdown failed"); - r = xc_domain_pause(CTX->xch, domid); - if (r < 0) { - LOGEVD(ERROR, r, domid, "xc_domain_pause failed"); - rc = ERROR_FAIL; - } - if (dm_present) { dis->ddms.ao = ao; dis->ddms.domid = domid; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index d60b9c416abf..782cbfc09afb 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -199,6 +199,7 @@ typedef struct libxl__carefd libxl__carefd; typedef struct libxl__ev_devlock libxl__ev_devlock; typedef struct libxl__dm_resume_state libxl__dm_resume_state; typedef struct libxl__ao_device libxl__ao_device; +typedef struct libxl__multidev libxl__multidev; typedef struct libxl__domain_create_state libxl__domain_create_state; typedef void libxl__domain_create_cb(struct libxl__egc *egc, @@ -1597,7 +1598,8 @@ _hidden int libxl__pci_topology_init(libxl__gc *gc, _hidden void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, libxl_device_pci *pcidev, bool starting, libxl__ao_device *aodev); -_hidden int libxl__device_pci_destroy_all(libxl__gc *gc, uint32_t domid); +_hidden void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid, + libxl__multidev *); _hidden bool libxl__is_igd_vga_passthru(libxl__gc *gc, const libxl_domain_config *d_config); @@ -2573,7 +2575,6 @@ _hidden void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what); /*----- device addition/removal -----*/ -typedef struct libxl__multidev libxl__multidev; typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*); /* This functions sets the necessary libxl__ao_device struct values to use @@ -3924,6 +3925,7 @@ struct libxl__destroy_domid_state { libxl__destroy_devicemodel_state ddms; libxl__ev_child destroyer; bool soft_reset; + libxl__multidev multidev; }; struct libxl__domain_destroy_state { diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 3477f3aba605..a5f700f0bf64 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1730,24 +1730,47 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, return 0; } -static int libxl__device_pci_remove_common(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev, int force); - -static int do_pci_remove(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev, int force) +typedef struct pci_remove_state { + libxl__ao_device *aodev; + libxl_domid domid; + libxl_device_pci *pcidev; + bool force; + bool hvm; + unsigned int orig_vdev; + unsigned int pfunc_mask; + int next_func; + libxl__ao_device stubdom_aodev; +} pci_remove_state; + +static void libxl__device_pci_remove_common(libxl__egc *egc, + uint32_t domid, libxl_device_pci *pcidev, bool force, + libxl__ao_device *aodev); +static void device_pci_remove_common_next(libxl__egc *egc, + pci_remove_state *prs, int rc); +static void pci_remove_detatched(libxl__egc *egc, + pci_remove_state *prs, int rc); +static void pci_remove_stubdom_done(libxl__egc *egc, + libxl__ao_device *aodev); +static void pci_remove_done(libxl__egc *egc, + pci_remove_state *prs, int rc); + +static void do_pci_remove(libxl__egc *egc, uint32_t domid, + libxl_device_pci *pcidev, int force, + pci_remove_state *prs) { + STATE_AO_GC(prs->aodev->ao); libxl_ctx *ctx = libxl__gc_owner(gc); libxl_device_pci *assigned; libxl_domain_type type = libxl__domain_type(gc, domid); - int hvm = 0, rc, num; - int stubdomid = 0; + int rc, num; uint32_t domainid = domid; - bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); - assigned = libxl_device_pci_list(ctx, domid, &num); - if ( assigned == NULL ) - return ERROR_FAIL; + if (assigned == NULL) { + rc = ERROR_FAIL; + goto out_fail; + } + libxl__ptr_add(gc, assigned); rc = ERROR_INVAL; if ( !is_pcidev_in_array(assigned, num, pcidev->domain, @@ -1758,7 +1781,7 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, rc = ERROR_FAIL; if (type == LIBXL_DOMAIN_TYPE_HVM) { - hvm = 1; + prs->hvm = true; switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: if (libxl__wait_for_device_model_deprecated(gc, domid, @@ -1821,7 +1844,7 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, f = fopen(sysfs_path, "r"); if (f == NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); - goto out; + goto skip_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq); @@ -1835,52 +1858,134 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, } fclose(f); } -out: +skip_irq: + rc = 0; +out_fail: + pci_remove_detatched(egc, prs, rc); +} + +static void pci_remove_detatched(libxl__egc *egc, + pci_remove_state *prs, + int rc) +{ + STATE_AO_GC(prs->aodev->ao); + int stubdomid = 0; + uint32_t domainid = prs->domid; + bool isstubdom; + + /* Convenience aliases */ + libxl_device_pci *const pcidev = prs->pcidev; + libxl_domid domid = prs->domid; + + if (rc) goto out; + + isstubdom = libxl_is_stubdom(CTX, domid, &domainid); + /* don't do multiple resets while some functions are still passed through */ if ( (pcidev->vdevfn & 0x7) == 0 ) { libxl__device_pci_reset(gc, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); } if (!isstubdom) { - rc = xc_deassign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev)); - if (rc < 0 && (hvm || errno != ENOSYS)) + rc = xc_deassign_device(CTX->xch, domid, pcidev_encode_bdf(pcidev)); + if (rc < 0 && (prs->hvm || errno != ENOSYS)) LOGED(ERROR, domainid, "xc_deassign_device failed"); } - stubdomid = libxl_get_stubdom_id(ctx, domid); + stubdomid = libxl_get_stubdom_id(CTX, domid); if (stubdomid != 0) { - libxl_device_pci pcidev_s = *pcidev; - libxl__device_pci_remove_common(gc, stubdomid, &pcidev_s, force); - } + libxl_device_pci *pcidev_s; + libxl__ao_device *const stubdom_aodev = &prs->stubdom_aodev; + + GCNEW(pcidev_s); + libxl_device_pci_init(pcidev_s); + libxl_device_pci_copy(CTX, pcidev_s, pcidev); - libxl__device_pci_remove_xenstore(gc, domid, pcidev); + libxl__prepare_ao_device(ao, stubdom_aodev); + stubdom_aodev->action = LIBXL__DEVICE_ACTION_REMOVE; + stubdom_aodev->callback = pci_remove_stubdom_done; + stubdom_aodev->update_json = prs->aodev->update_json; + libxl__device_pci_remove_common(egc, stubdomid, pcidev_s, + prs->force, stubdom_aodev); + return; + } rc = 0; -out_fail: - free(assigned); - return rc; +out: + pci_remove_done(egc, prs, rc); +} + +static void pci_remove_stubdom_done(libxl__egc *egc, + libxl__ao_device *aodev) +{ + pci_remove_state *prs = CONTAINER_OF(aodev, *prs, stubdom_aodev); + pci_remove_done(egc, prs, 0); } -static int libxl__device_pci_remove_common(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev, int force) +static void pci_remove_done(libxl__egc *egc, + pci_remove_state *prs, + int rc) { - unsigned int orig_vdev, pfunc_mask; - int i, rc; + EGC_GC; - orig_vdev = pcidev->vdevfn & ~7U; + if (rc) goto out; + + libxl__device_pci_remove_xenstore(gc, prs->domid, prs->pcidev); +out: + device_pci_remove_common_next(egc, prs, rc); +} + +static void libxl__device_pci_remove_common(libxl__egc *egc, + uint32_t domid, + libxl_device_pci *pcidev, + bool force, + libxl__ao_device *aodev) +{ + STATE_AO_GC(aodev->ao); + int rc; + pci_remove_state *prs; + + GCNEW(prs); + prs->aodev = aodev; + prs->domid = domid; + prs->pcidev = pcidev; + prs->force = force; + + prs->orig_vdev = pcidev->vdevfn & ~7U; if ( pcidev->vfunc_mask == LIBXL_PCI_FUNC_ALL ) { - if ( pci_multifunction_check(gc, pcidev, &pfunc_mask) ) { + if ( pci_multifunction_check(gc, pcidev, &prs->pfunc_mask) ) { rc = ERROR_FAIL; goto out; } - pcidev->vfunc_mask &= pfunc_mask; + pcidev->vfunc_mask &= prs->pfunc_mask; }else{ - pfunc_mask = (1 << pcidev->func); + prs->pfunc_mask = (1 << pcidev->func); } - for(rc = 0, i = 7; i >= 0; --i) { + rc = 0; + prs->next_func = 7; +out: + device_pci_remove_common_next(egc, prs, rc); +} + +static void device_pci_remove_common_next(libxl__egc *egc, + pci_remove_state *prs, + int rc) +{ + /* Convenience aliases */ + libxl_domid domid = prs->domid; + libxl_device_pci *const pcidev = prs->pcidev; + libxl__ao_device *const aodev = prs->aodev; + const unsigned int pfunc_mask = prs->pfunc_mask; + const unsigned int orig_vdev = prs->orig_vdev; + + if (rc) goto out; + + while (prs->next_func >= 0) { + const int i = prs->next_func; + prs->next_func--; if ( (1 << i) & pfunc_mask ) { if ( pcidev->vfunc_mask == pfunc_mask ) { pcidev->func = i; @@ -1888,13 +1993,15 @@ static int libxl__device_pci_remove_common(libxl__gc *gc, uint32_t domid, }else{ pcidev->vdevfn = orig_vdev; } - if ( do_pci_remove(gc, domid, pcidev, force) ) - rc = ERROR_FAIL; + do_pci_remove(egc, domid, pcidev, prs->force, prs); + return; } } + rc = 0; out: - return rc; + aodev->rc = rc; + aodev->callback(egc, aodev); } int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, @@ -1903,11 +2010,14 @@ int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, { AO_CREATE(ctx, domid, ao_how); - int rc; - - rc = libxl__device_pci_remove_common(gc, domid, pcidev, 0); + libxl__ao_device *aodev; - libxl__ao_complete(egc, ao, rc); + GCNEW(aodev); + libxl__prepare_ao_device(ao, aodev); + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; + aodev->callback = device_addrm_aocomplete; + aodev->update_json = true; + libxl__device_pci_remove_common(egc, domid, pcidev, false, aodev); return AO_INPROGRESS; } @@ -1916,11 +2026,14 @@ int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); - int rc; - - rc = libxl__device_pci_remove_common(gc, domid, pcidev, 1); + libxl__ao_device *aodev; - libxl__ao_complete(egc, ao, rc); + GCNEW(aodev); + libxl__prepare_ao_device(ao, aodev); + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; + aodev->callback = device_addrm_aocomplete; + aodev->update_json = true; + libxl__device_pci_remove_common(egc, domid, pcidev, true, aodev); return AO_INPROGRESS; } @@ -2004,27 +2117,27 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num return pcidevs; } -int libxl__device_pci_destroy_all(libxl__gc *gc, uint32_t domid) +void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid, + libxl__multidev *multidev) { - libxl_ctx *ctx = libxl__gc_owner(gc); + STATE_AO_GC(multidev->ao); libxl_device_pci *pcidevs; - int num, i, rc = 0; + int num, i; - pcidevs = libxl_device_pci_list(ctx, domid, &num); + pcidevs = libxl_device_pci_list(CTX, domid, &num); if ( pcidevs == NULL ) - return 0; + return; + libxl__ptr_add(gc, pcidevs); for (i = 0; i < num; i++) { /* Force remove on shutdown since, on HVM, qemu will not always * respond to SCI interrupt because the guest kernel has shut down the * devices by the time we even get here! */ - if (libxl__device_pci_remove_common(gc, domid, pcidevs + i, 1) < 0) - rc = ERROR_FAIL; + libxl__ao_device *aodev = libxl__multidev_prepare(multidev); + libxl__device_pci_remove_common(egc, domid, pcidevs + i, true, + aodev); } - - free(pcidevs); - return rc; } int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, From patchwork Thu Sep 19 17:16:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152993 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 88F3D15E6 for ; Thu, 19 Sep 2019 17:42:20 +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 5956A21A49 for ; Thu, 19 Sep 2019 17:42:20 +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="dcRx/BsE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5956A21A49 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 1iB0QS-0004Kq-9E; Thu, 19 Sep 2019 17:41:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0QR-0004Jg-5B for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:03 +0000 X-Inumbo-ID: a032eb1c-db04-11e9-978d-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a032eb1c-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Iw2I/B7s31ISX9CNu9mPm0iEg1wk29jTSAZB3WChcrg=; b=dcRx/BsENo0h1agXijp3P+S5Qf7jcvrwE9Ige8tUDYKH6KVaIEpr1m0d Zrmt3cNqx8uX+z1nCsabYxR4Roak3vi065TfaXNVMccgYRuVZ/fQrwEQu 57KI0qb7s+h2ZGPHU2xkkJx2IppWuGfciA4sfEMH+NdfgaB1TDzPo8GaT g=; 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 (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: pBN10+tdxjkB7w5JiUvBBuN+9OGHvd0MRkAAgcs5M97C6rEZSJvYLeJVBRpgew7DufOASg5v97 Bio8Fi7/lAHciPFTf9tPX8AJz1VAIv0ENuE55z+FUssTrgq+Fmh6Fw86t/w0anDLnnhPZpOVCU ToYCBvuGYmA9UOyTCvtzm6SaJNzl+GPWPyGy9S9YExPkk3HtPQffkv5x8LDCFFbd85y/6WGkcd oso0Ru8CcE4mJuIHnBY9olKvOUa7U/sfTI6fWUiHtOpsZkTJa+FYYyx8LX9u7ntHfvTe5PZwnU fDc= X-SBRS: 2.7 X-MesageID: 6064338 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="6064338" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:50 +0100 Message-ID: <20190919171656.899649-31-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 30/35] libxl_pci: Use ev_qmp for pci_remove 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" This patch also replaces the use of libxl__wait_for_device_model_deprecated() by its equivalent without the need for a thread. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_internal.h | 2 - tools/libxl/libxl_pci.c | 222 +++++++++++++++++++++++++++++++++-- tools/libxl/libxl_qmp.c | 77 ------------ 3 files changed, 210 insertions(+), 91 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 782cbfc09afb..00e3cad996c4 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1984,8 +1984,6 @@ typedef struct libxl__qmp_handler libxl__qmp_handler; */ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, uint32_t domid); -_hidden int libxl__qmp_pci_del(libxl__gc *gc, int domid, - libxl_device_pci *pcidev); /* Resume hvm domain */ _hidden int libxl__qmp_system_wakeup(libxl__gc *gc, int domid); /* Resume QEMU. */ diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index a5f700f0bf64..2c4e2e5cff5e 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1740,6 +1740,10 @@ typedef struct pci_remove_state { unsigned int pfunc_mask; int next_func; libxl__ao_device stubdom_aodev; + libxl__xswait_state xswait; + libxl__ev_qmp qmp; + libxl__ev_time timeout; + libxl__ev_time retry_timer; } pci_remove_state; static void libxl__device_pci_remove_common(libxl__egc *egc, @@ -1747,10 +1751,23 @@ static void libxl__device_pci_remove_common(libxl__egc *egc, libxl__ao_device *aodev); static void device_pci_remove_common_next(libxl__egc *egc, pci_remove_state *prs, int rc); + +static void pci_remove_qemu_trad_watch_state_cb(libxl__egc *egc, + libxl__xswait_state *xswa, int rc, const char *state); +static void pci_remove_qmp_device_del(libxl__egc *egc, + pci_remove_state *prs); +static void pci_remove_qmp_device_del_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); +static void pci_remove_qmp_retry_timer_cb(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void pci_remove_qmp_query_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); static void pci_remove_detatched(libxl__egc *egc, pci_remove_state *prs, int rc); static void pci_remove_stubdom_done(libxl__egc *egc, libxl__ao_device *aodev); +static void pci_remove_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); static void pci_remove_done(libxl__egc *egc, pci_remove_state *prs, int rc); @@ -1784,22 +1801,22 @@ static void do_pci_remove(libxl__egc *egc, uint32_t domid, prs->hvm = true; switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: - if (libxl__wait_for_device_model_deprecated(gc, domid, - "running", NULL, NULL, NULL) < 0) - goto out_fail; - rc = qemu_pci_remove_xenstore(gc, domid, pcidev, force); - break; + prs->xswait.ao = ao; + prs->xswait.what = "Device Model"; + prs->xswait.path = DEVICE_MODEL_XS_PATH(gc, + libxl_get_stubdom_id(CTX, domid), domid, "/state"); + prs->xswait.timeout_ms = LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000; + prs->xswait.callback = pci_remove_qemu_trad_watch_state_cb; + rc = libxl__xswait_start(gc, &prs->xswait); + if (rc) goto out_fail; + return; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc = libxl__qmp_pci_del(gc, domid, pcidev); - break; + pci_remove_qmp_device_del(egc, prs); /* must be last */ + return; default: rc = ERROR_INVAL; goto out_fail; } - if (rc && !force) { - rc = ERROR_FAIL; - goto out_fail; - } } else { assert(type == LIBXL_DOMAIN_TYPE_PV); @@ -1861,9 +1878,163 @@ static void do_pci_remove(libxl__egc *egc, uint32_t domid, skip_irq: rc = 0; out_fail: + pci_remove_detatched(egc, prs, rc); /* must be last */ +} + +static void pci_remove_qemu_trad_watch_state_cb(libxl__egc *egc, + libxl__xswait_state *xswa, + int rc, + const char *state) +{ + pci_remove_state *prs = CONTAINER_OF(xswa, *prs, xswait); + STATE_AO_GC(prs->aodev->ao); + + /* Convenience aliases */ + libxl_domid domid = prs->domid; + libxl_device_pci *const pcidev = prs->pcidev; + + if (rc) { + if (rc == ERROR_TIMEDOUT) { + LOGD(ERROR, domid, "%s not ready", xswa->what); + } + goto out; + } + + if (!state) + return; + if (strcmp(state, "running")) + return; + + rc = qemu_pci_remove_xenstore(gc, domid, pcidev, prs->force); + +out: + libxl__xswait_stop(gc, xswa); pci_remove_detatched(egc, prs, rc); } +static void pci_remove_qmp_device_del(libxl__egc *egc, + pci_remove_state *prs) +{ + STATE_AO_GC(prs->aodev->ao); + libxl__json_object *args = NULL; + int rc; + + /* Convenience aliases */ + libxl_device_pci *const pcidev = prs->pcidev; + + rc = libxl__ev_time_register_rel(ao, &prs->timeout, + pci_remove_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + + QMP_PARAMETERS_SPRINTF(&args, "id", PCI_PT_QDEV_ID, + pcidev->bus, pcidev->dev, pcidev->func); + prs->qmp.callback = pci_remove_qmp_device_del_cb; + rc = libxl__ev_qmp_send(gc, &prs->qmp, "device_del", args); + if (rc) goto out; + return; + +out: + pci_remove_detatched(egc, prs, rc); +} + +static void pci_remove_qmp_device_del_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + EGC_GC; + pci_remove_state *prs = CONTAINER_OF(qmp, *prs, qmp); + + if (rc) goto out; + + /* Now that the command is sent, we want to wait until QEMU has + * confirmed that the device is removed. */ + /* TODO: Instead of using a poll loop { ev_timer ; query-pci }, it + * could be possible to listen to events sent by QEMU via QMP in order + * to wait for the passthrough pci-device to be removed from QEMU. */ + pci_remove_qmp_retry_timer_cb(egc, &prs->retry_timer, NULL, + ERROR_TIMEDOUT); + return; + +out: + pci_remove_detatched(egc, prs, rc); +} + +static void pci_remove_qmp_retry_timer_cb(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + EGC_GC; + pci_remove_state *prs = CONTAINER_OF(ev, *prs, retry_timer); + + prs->qmp.callback = pci_remove_qmp_query_cb; + rc = libxl__ev_qmp_send(gc, &prs->qmp, "query-pci", NULL); + if (rc) goto out; + return; + +out: + pci_remove_detatched(egc, prs, rc); +} + +static void pci_remove_qmp_query_cb(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + EGC_GC; + pci_remove_state *prs = CONTAINER_OF(qmp, *prs, qmp); + const libxl__json_object *bus = NULL; + const char *asked_id; + int i, j; + + /* Convenience aliases */ + libxl__ao *const ao = prs->aodev->ao; + libxl_device_pci *const pcidev = prs->pcidev; + + if (rc) goto out; + + asked_id = GCSPRINTF(PCI_PT_QDEV_ID, + pcidev->bus, pcidev->dev, pcidev->func); + + /* query-pci response: + * [{ 'devices': [ 'qdev_id': 'str', ... ], ... }] + * */ + + for (i = 0; (bus = libxl__json_array_get(response, i)); i++) { + const libxl__json_object *devices = NULL; + const libxl__json_object *device = NULL; + const libxl__json_object *o = NULL; + const char *id = NULL; + + devices = libxl__json_map_get("devices", bus, JSON_ARRAY); + if (!devices) { + rc = ERROR_QEMU_API; + goto out; + } + + for (j = 0; (device = libxl__json_array_get(devices, j)); j++) { + o = libxl__json_map_get("qdev_id", device, JSON_STRING); + if (!o) { + rc = ERROR_QEMU_API; + goto out; + } + id = libxl__json_object_get_string(o); + + if (id && !strcmp(asked_id, id)) { + /* Device still in QEMU, need to wait longuer. */ + rc = libxl__ev_time_register_rel(ao, &prs->retry_timer, + pci_remove_qmp_retry_timer_cb, 1000); + if (rc) goto out; + return; + } + } + } + +out: + pci_remove_detatched(egc, prs, rc); /* must be last */ +} + static void pci_remove_detatched(libxl__egc *egc, pci_remove_state *prs, int rc) @@ -1877,7 +2048,8 @@ static void pci_remove_detatched(libxl__egc *egc, libxl_device_pci *const pcidev = prs->pcidev; libxl_domid domid = prs->domid; - if (rc) goto out; + if (rc && !prs->force) + goto out; isstubdom = libxl_is_stubdom(CTX, domid, &domainid); @@ -1923,6 +2095,15 @@ static void pci_remove_stubdom_done(libxl__egc *egc, pci_remove_done(egc, prs, 0); } +static void pci_remove_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + pci_remove_state *prs = CONTAINER_OF(ev, *prs, timeout); + + pci_remove_done(egc, prs, rc); +} + static void pci_remove_done(libxl__egc *egc, pci_remove_state *prs, int rc) @@ -1931,6 +2112,10 @@ static void pci_remove_done(libxl__egc *egc, if (rc) goto out; + libxl__ev_qmp_dispose(gc, &prs->qmp); + libxl__ev_time_deregister(gc, &prs->timeout); + libxl__ev_time_deregister(gc, &prs->retry_timer); + libxl__device_pci_remove_xenstore(gc, prs->domid, prs->pcidev); out: device_pci_remove_common_next(egc, prs, rc); @@ -1951,6 +2136,13 @@ static void libxl__device_pci_remove_common(libxl__egc *egc, prs->domid = domid; prs->pcidev = pcidev; prs->force = force; + libxl__xswait_init(&prs->xswait); + libxl__ev_qmp_init(&prs->qmp); + prs->qmp.ao = prs->aodev->ao; + prs->qmp.domid = prs->domid; + prs->qmp.payload_fd = -1; + libxl__ev_time_init(&prs->timeout); + libxl__ev_time_init(&prs->retry_timer); prs->orig_vdev = pcidev->vdevfn & ~7U; @@ -1974,6 +2166,8 @@ static void device_pci_remove_common_next(libxl__egc *egc, pci_remove_state *prs, int rc) { + EGC_GC; + /* Convenience aliases */ libxl_domid domid = prs->domid; libxl_device_pci *const pcidev = prs->pcidev; @@ -2000,6 +2194,10 @@ static void device_pci_remove_common_next(libxl__egc *egc, rc = 0; out: + libxl__ev_qmp_dispose(gc, &prs->qmp); + libxl__xswait_stop(gc, &prs->xswait); + libxl__ev_time_deregister(gc, &prs->timeout); + libxl__ev_time_deregister(gc, &prs->retry_timer); aodev->rc = rc; aodev->callback(egc, aodev); } diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 38ba63d5b920..8fac737fad03 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -87,7 +87,6 @@ #define QMP_RECEIVE_BUFFER_SIZE 4096 #define QMP_MAX_SIZE_RX_BUF MB(1) -#define PCI_PT_QDEV_ID "pci-pt-%02x_%02x.%01x" /* * qmp_callback_t is call whenever a message from QMP contain the "id" @@ -736,38 +735,6 @@ void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid) } } -static int pci_del_callback(libxl__qmp_handler *qmp, - const libxl__json_object *response, void *opaque) -{ - const char *asked_id = opaque; - const libxl__json_object *bus = NULL; - GC_INIT(qmp->ctx); - int i, j, rc = 0; - - for (i = 0; (bus = libxl__json_array_get(response, i)); i++) { - const libxl__json_object *devices = NULL; - const libxl__json_object *device = NULL; - const libxl__json_object *o = NULL; - const char *id = NULL; - - devices = libxl__json_map_get("devices", bus, JSON_ARRAY); - - for (j = 0; (device = libxl__json_array_get(devices, j)); j++) { - o = libxl__json_map_get("qdev_id", device, JSON_STRING); - id = libxl__json_object_get_string(o); - - if (id && strcmp(asked_id, id) == 0) { - rc = 1; - goto out; - } - } - } - -out: - GC_FREE; - return rc; -} - static int qmp_run_command(libxl__gc *gc, int domid, const char *cmd, libxl__json_object *args, qmp_callback_t callback, void *opaque) @@ -785,50 +752,6 @@ static int qmp_run_command(libxl__gc *gc, int domid, return rc; } -static int qmp_device_del(libxl__gc *gc, int domid, char *id) -{ - libxl__json_object *args = NULL; - libxl__qmp_handler *qmp = NULL; - int rc = 0; - - qmp = libxl__qmp_initialize(gc, domid); - if (!qmp) - return ERROR_FAIL; - - libxl__qmp_param_add_string(gc, &args, "id", id); - rc = qmp_synchronous_send(qmp, "device_del", args, - NULL, NULL, qmp->timeout); - if (rc == 0) { - unsigned int retry = 0; - - do { - rc = qmp_synchronous_send(qmp, "query-pci", NULL, - pci_del_callback, id, qmp->timeout); - if (rc != 1) { - break; - } - sleep(1); - } while (retry++ < 5); - - if (rc != 0) { - LOGD(WARN, qmp->domid, - "device model may not complete removing device %s", id); - } - } - - libxl__qmp_close(qmp); - return rc; -} - -int libxl__qmp_pci_del(libxl__gc *gc, int domid, libxl_device_pci *pcidev) -{ - char *id = NULL; - - id = GCSPRINTF(PCI_PT_QDEV_ID, pcidev->bus, pcidev->dev, pcidev->func); - - return qmp_device_del(gc, domid, id); -} - int libxl__qmp_system_wakeup(libxl__gc *gc, int domid) { return qmp_run_command(gc, domid, "system_wakeup", NULL, NULL, NULL); From patchwork Thu Sep 19 17:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153023 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 7DCD115E6 for ; Thu, 19 Sep 2019 17:42:56 +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 595D1214AF for ; Thu, 19 Sep 2019 17:42:56 +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="hO6chc87" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 595D1214AF 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 1iB0R6-0005Ag-Nf; Thu, 19 Sep 2019 17:41:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0R5-00058c-6l for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:43 +0000 X-Inumbo-ID: b02ec61c-db04-11e9-978d-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b02ec61c-db04-11e9-978d-bc764e2007e4; Thu, 19 Sep 2019 17:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o3kw02pMw7RPV+3hTs5NSNRxwOudMz7z9RtfjH4vRfw=; b=hO6chc87jyk1H1KEUTXPSGrRH8cX89BQi+/64Anhcorh1Z85QELvwQkU UQSh2vTjkEpHxVUmFlf4ipS8yl99/QNHQ5GAg7gxnaUX0v/9OLew52cbU tY7NIzRJQnw52fx435EYagqFWU6IiMk2Nv6qsRa6m7olNm5t7RVA2vCOs 4=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 62Yu4TzZ2wEP++w/tcisTJ3Ta/GdKsRwyvJJoVB7oMKcqQI3bwwF+5aKbmbhUAIijYxGQOmplf 4upb/G5bmULibllwSor7rgF6h11bM5dsZECcCh8dnTsDtWn6c6xv/8lL4/jx5a+DeyMnGdkBCk xnL8t8lxCc7nAedOpwxRNiIKUljrM6mw/t1lDB3zxK9xC3LNR8XCnbot/iS8JZtfEU+YxPYyIJ M/XEeKL7VsoGdqXn1Cz8KIAhzBL8E9IFZ1qaEVLcfaxGDAprOS6Of+LTxHc1Xvx7edadqafEbl noQ= X-SBRS: 2.7 X-MesageID: 6010802 X-Ironport-Server: esa5.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="6010802" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:51 +0100 Message-ID: <20190919171656.899649-32-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 31/35] libxl: Use ev_qmp for libxl_send_trigger 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 49 ++++++++++++++++++++++++++++++------ tools/libxl/libxl_internal.h | 2 -- tools/libxl/libxl_qmp.c | 5 ---- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index cd7190035005..08d3fc9fbc03 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1556,19 +1556,39 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, return AO_INPROGRESS; } -static int libxl__domain_s3_resume(libxl__gc *gc, int domid) +static void domain_s3_resume_done(libxl__egc *egc, libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc); + +static void domain_s3_resume(libxl__ao *ao, libxl__egc *egc, int domid) { + AO_GC; + libxl__ev_qmp *qmp; int rc = 0; + int r; + + GCNEW(qmp); + libxl__ev_qmp_init(qmp); + qmp->ao = ao; + qmp->domid = domid; + qmp->payload_fd = -1; + qmp->callback = domain_s3_resume_done; switch (libxl__domain_type(gc, domid)) { case LIBXL_DOMAIN_TYPE_HVM: switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: - rc = xc_hvm_param_set(CTX->xch, domid, HVM_PARAM_ACPI_S_STATE, 0); + r = xc_hvm_param_set(CTX->xch, domid, HVM_PARAM_ACPI_S_STATE, 0); + if (r) { + LOGED(ERROR, domid, "Send trigger '%s' failed", + libxl_trigger_to_string(LIBXL_TRIGGER_S3RESUME)); + rc = ERROR_FAIL; + } break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc = libxl__qmp_system_wakeup(gc, domid); - break; + rc = libxl__ev_qmp_send(gc, qmp, "system_wakeup", NULL); + if (rc) goto out; + return; default: rc = ERROR_INVAL; break; @@ -1579,7 +1599,22 @@ static int libxl__domain_s3_resume(libxl__gc *gc, int domid) break; } - return rc; +out: + domain_s3_resume_done(egc, qmp, NULL, rc); +} + +static void domain_s3_resume_done(libxl__egc *egc, libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + EGC_GC; + + if (rc) + LOGD(ERROR, qmp->domid, "Send trigger '%s' failed, rc=%d", + libxl_trigger_to_string(LIBXL_TRIGGER_S3RESUME), rc); + + libxl__ev_qmp_dispose(gc, qmp); + libxl__ao_complete(egc, qmp->ao, rc); } int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, @@ -1611,8 +1646,8 @@ int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, XEN_DOMCTL_SENDTRIGGER_RESET, vcpuid); break; case LIBXL_TRIGGER_S3RESUME: - rc = libxl__domain_s3_resume(gc, domid); - break; + domain_s3_resume(ao, egc, domid); /* must be last */ + return AO_INPROGRESS; default: rc = -1; errno = EINVAL; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 00e3cad996c4..7aa1a6a92409 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1984,8 +1984,6 @@ typedef struct libxl__qmp_handler libxl__qmp_handler; */ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, uint32_t domid); -/* Resume hvm domain */ -_hidden int libxl__qmp_system_wakeup(libxl__gc *gc, int domid); /* Resume QEMU. */ _hidden int libxl__qmp_resume(libxl__gc *gc, int domid); /* Load current QEMU state from file. */ diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 8fac737fad03..40043a0a45b2 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -752,11 +752,6 @@ static int qmp_run_command(libxl__gc *gc, int domid, return rc; } -int libxl__qmp_system_wakeup(libxl__gc *gc, int domid) -{ - return qmp_run_command(gc, domid, "system_wakeup", NULL, NULL, NULL); -} - int libxl__qmp_restore(libxl__gc *gc, int domid, const char *state_file) { libxl__json_object *args = NULL; From patchwork Thu Sep 19 17:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11153009 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 7FE7016B1 for ; Thu, 19 Sep 2019 17:42:38 +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 4E331214AF for ; Thu, 19 Sep 2019 17:42:38 +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="QGRTMqGa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E331214AF 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 1iB0QK-0004EN-11; Thu, 19 Sep 2019 17:40:56 +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 1iB0QJ-0004Dp-A0 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:40:55 +0000 X-Inumbo-ID: 9a99338c-db04-11e9-966e-12813bfff9fa Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9a99338c-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914843; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YcdgtDOS0It6R3sB2Vb/MCDmoZKjt5H1K1hjKlUsM44=; b=QGRTMqGa9IFVJxBXsBJF1SNoOUFGGsZCcFk3kM8Z5iRI2d3nl9vWmvat atCL2BnQpsZ5gDrzkcPHN7MWqDamNxEJR6oDsj8flOzfFNZf5RJPRcpJl Nb/yRkfUgzHglhXUMZ4JGHatfEvsybTKpr9JQUsp88MISW1CYi5hkvpek A=; 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: 6Tg0k52GRN330BqJtgh3ZdTPyS6a7YhqpLsEOa35yqHtdbd4F7oQ3zTu4V8WXTrDmGJGmr1liQ 3dd11Citpm82b8e+RaYqhDonIEF5Qn/rF3W4JE/EM7PnjRoWjEXt3APGjWRc7tobN8ggzPfEtm B7I2zE2w8tsxnjXYc0oLagS1uY5XhqpGrmsr/f3/JbihKDXfcByYsosjUf3IlAnkXmVEDVHT/K dJxoeQmV2ljvAHbwrgMz9iaDWSqAHA1VcYGqH3vA+7IeRGvr5/07s9Gb4P5pfyDb9AJEkVCiw/ tgA= X-SBRS: 2.7 X-MesageID: 6125207 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,524,1559534400"; d="scan'208";a="6125207" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:52 +0100 Message-ID: <20190919171656.899649-33-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 32/35] libxl: Use ev_qmp in libxl_set_vcpuonline 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" Removed libxl__qmp_cpu_add since it's not used anymore. `cpumap' arg of libxl__set_vcpuonline_xenstore is constified. The QMP command "query-cpus" is going to be called from different places, so the algorithm that parse the answer is in a separate function, qmp_parse_query_cpus. Signed-off-by: Anthony PERARD --- Notes: v2: - the patch "libxl: Extract qmp_parse_query_cpus" have been squashed into this one. tools/libxl/libxl_domain.c | 204 +++++++++++++++++++++++++++-------- tools/libxl/libxl_internal.h | 2 - tools/libxl/libxl_qmp.c | 9 -- 3 files changed, 158 insertions(+), 57 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 08d3fc9fbc03..b97e874a9c05 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1432,8 +1432,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid, } static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid, - libxl_bitmap *cpumap, - const libxl_dominfo *info) + const libxl_bitmap *cpumap, + const libxl_dominfo *info) { char *dompath; xs_transaction_t t; @@ -1457,55 +1457,76 @@ static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid, return rc; } -static int libxl__set_vcpuonline_qmp(libxl__gc *gc, uint32_t domid, - libxl_bitmap *cpumap, - const libxl_dominfo *info) +static int qmp_parse_query_cpus(libxl__gc *gc, + libxl_domid domid, + const libxl__json_object *response, + libxl_bitmap *const map) { - int i, rc; - libxl_bitmap current_map, final_map; + int i; + const libxl__json_object *cpu; - libxl_bitmap_init(¤t_map); - libxl_bitmap_init(&final_map); - - libxl_bitmap_alloc(CTX, ¤t_map, info->vcpu_max_id + 1); - libxl_bitmap_set_none(¤t_map); - rc = libxl__qmp_query_cpus(gc, domid, ¤t_map); - if (rc) { - LOGD(ERROR, domid, "Failed to query cpus"); - goto out; - } - - libxl_bitmap_copy_alloc(CTX, &final_map, cpumap); - - libxl_for_each_set_bit(i, current_map) - libxl_bitmap_reset(&final_map, i); - - libxl_for_each_set_bit(i, final_map) { - rc = libxl__qmp_cpu_add(gc, domid, i); - if (rc) { - LOGD(ERROR, domid, "Failed to add cpu %d", i); - goto out; + libxl_bitmap_set_none(map); + /* Parse response to QMP command "query-cpus": + * [ { 'CPU': 'int',...} ] + */ + for (i = 0; (cpu = libxl__json_array_get(response, i)); i++) { + unsigned int cpu_index; + const libxl__json_object *o; + + o = libxl__json_map_get("CPU", cpu, JSON_INTEGER); + if (!o) { + LOGD(ERROR, domid, "Failed to retrieve CPU index."); + return ERROR_QEMU_API; } + + cpu_index = libxl__json_object_get_integer(o); + libxl_bitmap_set(map, cpu_index); } - rc = 0; -out: - libxl_bitmap_dispose(¤t_map); - libxl_bitmap_dispose(&final_map); - return rc; + return 0; } +typedef struct set_vcpuonline_state { + libxl__ev_qmp qmp; + libxl__ev_time timeout; + const libxl_bitmap *cpumap; + libxl_dominfo info; + libxl_bitmap final_map; + int index; /* for loop on final_map */ +} set_vcpuonline_state; + +static void set_vcpuonline_qmp_cpus_queried(libxl__egc *, + libxl__ev_qmp *, const libxl__json_object *, int rc); +static void set_vcpuonline_qmp_add_cpu(libxl__egc *, + libxl__ev_qmp *, const libxl__json_object *response, int rc); +static void set_vcpuonline_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void set_vcpuonline_done(libxl__egc *egc, + set_vcpuonline_state *svos, int rc); + int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); int rc, maxcpus; - libxl_dominfo info; + set_vcpuonline_state *svos; + + GCNEW(svos); + libxl__ev_qmp_init(&svos->qmp); + svos->qmp.ao = ao; + svos->qmp.domid = domid; + svos->qmp.payload_fd = -1; + libxl__ev_time_init(&svos->timeout); + svos->cpumap = cpumap; + libxl_dominfo_init(&svos->info); + libxl_bitmap_init(&svos->final_map); - libxl_dominfo_init(&info); + /* Convenience aliases */ + libxl_dominfo *info = &svos->info; + libxl__ev_qmp *qmp = &svos->qmp; - rc = libxl_domain_info(CTX, &info, domid); + rc = libxl_domain_info(CTX, info, domid); if (rc < 0) { LOGED(ERROR, domid, "Getting domain info list"); goto out; @@ -1518,10 +1539,10 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, rc = ERROR_FAIL; goto out; } - if (maxcpus > info.vcpu_max_id + 1) + if (maxcpus > info->vcpu_max_id + 1) { LOGED(ERROR, domid, "Requested %d VCPUs, however maxcpus is %d!", - maxcpus, info.vcpu_max_id + 1); + maxcpus, info->vcpu_max_id + 1); rc = ERROR_FAIL; goto out; } @@ -1532,8 +1553,14 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc = libxl__set_vcpuonline_qmp(gc, domid, cpumap, &info); - break; + rc = libxl__ev_time_register_rel(ao, &svos->timeout, + set_vcpuonline_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + qmp->callback = set_vcpuonline_qmp_cpus_queried; + rc = libxl__ev_qmp_send(gc, qmp, "query-cpus", NULL); + if (rc) goto out; + return AO_INPROGRESS; default: rc = ERROR_INVAL; } @@ -1545,15 +1572,100 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, rc = ERROR_INVAL; } - if (!rc) - rc = libxl__set_vcpuonline_xenstore(gc, domid, cpumap, &info); +out: + set_vcpuonline_done(egc, svos, rc); /* must be last */ + return AO_INPROGRESS; +} + +static void set_vcpuonline_qmp_cpus_queried(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + EGC_GC; + set_vcpuonline_state *svos = CONTAINER_OF(qmp, *svos, qmp); + int i; + libxl_bitmap current_map; + + /* Convenience aliases */ + libxl_bitmap *final_map = &svos->final_map; + + libxl_bitmap_init(¤t_map); + + if (rc) goto out; + + libxl_bitmap_alloc(CTX, ¤t_map, svos->info.vcpu_max_id + 1); + rc = qmp_parse_query_cpus(gc, qmp->domid, response, ¤t_map); + if (rc) goto out; + + libxl_bitmap_copy_alloc(CTX, final_map, svos->cpumap); + + libxl_for_each_set_bit(i, current_map) { + libxl_bitmap_reset(final_map, i); + } out: - libxl_dominfo_dispose(&info); - if (rc) - return AO_CREATE_FAIL(rc); + libxl_bitmap_dispose(¤t_map); + svos->index = -1; + set_vcpuonline_qmp_add_cpu(egc, qmp, NULL, rc); /* must be last */ +} + +static void set_vcpuonline_qmp_add_cpu(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + STATE_AO_GC(qmp->ao); + set_vcpuonline_state *svos = CONTAINER_OF(qmp, *svos, qmp); + libxl__json_object *args = NULL; + + /* Convenience aliases */ + libxl_bitmap *map = &svos->final_map; + + if (rc) goto out; + + while (libxl_bitmap_cpu_valid(map, ++svos->index)) { + if (libxl_bitmap_test(map, svos->index)) { + qmp->callback = set_vcpuonline_qmp_add_cpu; + libxl__qmp_param_add_integer(gc, &args, "id", svos->index); + rc = libxl__ev_qmp_send(gc, qmp, "cpu-add", args); + if (rc) goto out; + return; + } + } + +out: + set_vcpuonline_done(egc, svos, rc); +} + +static void set_vcpuonline_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + EGC_GC; + set_vcpuonline_state *svos = CONTAINER_OF(ev, *svos, timeout); + + if (rc == ERROR_TIMEDOUT) + LOGD(ERROR, svos->qmp.domid, + "Setting CPU online in QEMU timed out"); + + set_vcpuonline_done(egc, svos, rc); +} + +static void set_vcpuonline_done(libxl__egc *egc, + set_vcpuonline_state *svos, + int rc) +{ + STATE_AO_GC(svos->qmp.ao); + + /* Convenience aliases */ + libxl_domid domid = svos->qmp.domid; + + if (!rc) + rc = libxl__set_vcpuonline_xenstore(gc, domid, svos->cpumap, + &svos->info); + + libxl_bitmap_dispose(&svos->final_map); + libxl_dominfo_dispose(&svos->info); + libxl__ev_time_deregister(gc, &svos->timeout); + libxl__ev_qmp_dispose(gc, &svos->qmp); libxl__ao_complete(egc, ao, rc); - return AO_INPROGRESS; } static void domain_s3_resume_done(libxl__egc *egc, libxl__ev_qmp *qmp, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 7aa1a6a92409..1ecebf136984 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1988,8 +1988,6 @@ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, _hidden int libxl__qmp_resume(libxl__gc *gc, int domid); /* Load current QEMU state from file. */ _hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename); -/* Add a virtual CPU */ -_hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index); /* Query the bitmap of CPUs */ _hidden int libxl__qmp_query_cpus(libxl__gc *gc, int domid, libxl_bitmap *map); diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 40043a0a45b2..27183bc6c4a3 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -767,15 +767,6 @@ int libxl__qmp_resume(libxl__gc *gc, int domid) return qmp_run_command(gc, domid, "cont", NULL, NULL, NULL); } -int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx) -{ - libxl__json_object *args = NULL; - - libxl__qmp_param_add_integer(gc, &args, "id", idx); - - return qmp_run_command(gc, domid, "cpu-add", args, NULL, NULL); -} - static int query_cpus_callback(libxl__qmp_handler *qmp, const libxl__json_object *response, void *opaque) From patchwork Thu Sep 19 17:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152983 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 257FC1745 for ; Thu, 19 Sep 2019 17:42:04 +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 EAC3D2196E for ; Thu, 19 Sep 2019 17:42:03 +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="fGro8Pfy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAC3D2196E 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 1iB0Q7-00048y-S5; Thu, 19 Sep 2019 17:40:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Q7-00048q-3b for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:40:43 +0000 X-Inumbo-ID: 97cc77f4-db04-11e9-b299-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 97cc77f4-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914839; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ldbK2rJd08+BaTupRLkvzPdHJ6Ig2rL5PXIxfegX9xI=; b=fGro8PfyhbHkJgbXuHwib7C+J7pMINu9e9rudKI1dIF+AuyiSbK3yTk9 SUIVZxTg2/CyuBLDNjsyS6CdolYH0OqizK+uVqv5bbZYIhhj+BpaBk/95 sdN8lSLNsu41DUxOswOFsADOzJnIcti/hWMMaysHFLmcfxl0k7P9Yrgah A=; Authentication-Results: esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 7uuG80KyREpfwHP4j2d4ib/SgG0XiywBkLMT47/E0uw7InlPrb56O94hRSWoY0AcNWm4PvEHLk EX2PWTd6rAlFHGgIzB7mdgna7UtnoLcU/V/RImKvNoCQ93C5RVT4ZeKmKCeQ2u3ukzxi3Vhc4u tmuzAxfwfWwipOEsPmtUDK8LfbJfg3R30TeH6bX885XkqvT0YvGw2aWAMiI32ZUuwc7qqqvh06 MENdRUY65g2DkWcdH3tugkIrO9mNy+KEiXSLsw053Xet3nlE/U9OEp+oeM7CohG87SfmgG6wMm Cqc= X-SBRS: 2.7 X-MesageID: 5801739 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,524,1559534400"; d="scan'208";a="5801739" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:53 +0100 Message-ID: <20190919171656.899649-34-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 33/35] libxl: libxl_retrieve_domain_configuration now uses ev_qmp 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" This was the last user of libxl__qmp_query_cpus which can now be removed. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: v3: - following rename of ev_lock to ev_devlock, renamed field rdcs.ev_lock to rdcs.devlock tools/libxl/libxl_domain.c | 163 ++++++++++++++++++++++++++++------- tools/libxl/libxl_internal.h | 3 - tools/libxl/libxl_qmp.c | 38 -------- 3 files changed, 131 insertions(+), 73 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index b97e874a9c05..0dd5b7ffa963 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1800,27 +1800,6 @@ uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid) return ret; } -/* For QEMU upstream we always need to provide the number of cpus present to - * QEMU whether they are online or not; otherwise QEMU won't accept the saved - * state. See implementation of libxl__qmp_query_cpus. - */ -static int libxl__update_avail_vcpus_qmp(libxl__gc *gc, uint32_t domid, - unsigned int max_vcpus, - libxl_bitmap *map) -{ - int rc; - - rc = libxl__qmp_query_cpus(gc, domid, map); - if (rc) { - LOGD(ERROR, domid, "Fail to get number of cpus"); - goto out; - } - - rc = 0; -out: - return rc; -} - static int libxl__update_avail_vcpus_xenstore(libxl__gc *gc, uint32_t domid, unsigned int max_vcpus, libxl_bitmap *map) @@ -1849,13 +1828,61 @@ static int libxl__update_avail_vcpus_xenstore(libxl__gc *gc, uint32_t domid, return rc; } +typedef struct { + libxl__ev_qmp qmp; + libxl__ev_time timeout; + libxl_domain_config *d_config; /* user pointer */ + libxl__ev_devlock devlock; + libxl_bitmap qemuu_cpus; +} retrieve_domain_configuration_state; + +static void retrieve_domain_configuration_lock_acquired( + libxl__egc *egc, libxl__ev_devlock *, int rc); +static void retrieve_domain_configuration_cpu_queried( + libxl__egc *egc, libxl__ev_qmp *qmp, + const libxl__json_object *response, int rc); +static void retrieve_domain_configuration_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc); +static void retrieve_domain_configuration_end(libxl__egc *egc, + retrieve_domain_configuration_state *rdcs, int rc); + int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, libxl_domain_config *d_config, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); - int rc; + retrieve_domain_configuration_state *rdcs; + + GCNEW(rdcs); + libxl__ev_qmp_init(&rdcs->qmp); + rdcs->qmp.ao = ao; + rdcs->qmp.domid = domid; + rdcs->qmp.payload_fd = -1; + libxl__ev_time_init(&rdcs->timeout); + rdcs->d_config = d_config; + libxl_bitmap_init(&rdcs->qemuu_cpus); + libxl__ev_devlock_init(&rdcs->devlock); + rdcs->devlock.ao = ao; + rdcs->devlock.domid = domid; + rdcs->devlock.callback = retrieve_domain_configuration_lock_acquired; + libxl__ev_devlock_lock(egc, &rdcs->devlock); + return AO_INPROGRESS; +} + +static void retrieve_domain_configuration_lock_acquired( + libxl__egc *egc, libxl__ev_devlock *devlock, int rc) +{ + retrieve_domain_configuration_state *rdcs = + CONTAINER_OF(devlock, *rdcs, devlock); + STATE_AO_GC(rdcs->qmp.ao); libxl__domain_userdata_lock *lock = NULL; + bool has_callback = false; + + /* Convenience aliases */ + libxl_domid domid = rdcs->qmp.domid; + libxl_domain_config *const d_config = rdcs->d_config; + + if (rc) goto out; lock = libxl__lock_domain_userdata(gc, domid); if (!lock) { @@ -1870,10 +1897,81 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, goto out; } + libxl__unlock_domain_userdata(lock); + lock = NULL; + + /* We start by querying QEMU, if it is running, for its cpumap as this + * is a long operation. */ + if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM && + libxl__device_model_version_running(gc, domid) == + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { + /* For QEMU upstream we always need to provide the number + * of cpus present to QEMU whether they are online or not; + * otherwise QEMU won't accept the saved state. + */ + rc = libxl__ev_time_register_rel(ao, &rdcs->timeout, + retrieve_domain_configuration_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + libxl_bitmap_alloc(CTX, &rdcs->qemuu_cpus, + d_config->b_info.max_vcpus); + rdcs->qmp.callback = retrieve_domain_configuration_cpu_queried; + rc = libxl__ev_qmp_send(gc, &rdcs->qmp, "query-cpus", NULL); + if (rc) goto out; + has_callback = true; + } + +out: + if (lock) libxl__unlock_domain_userdata(lock); + if (!has_callback) + retrieve_domain_configuration_end(egc, rdcs, rc); +} + +static void retrieve_domain_configuration_cpu_queried( + libxl__egc *egc, libxl__ev_qmp *qmp, + const libxl__json_object *response, int rc) +{ + EGC_GC; + retrieve_domain_configuration_state *rdcs = + CONTAINER_OF(qmp, *rdcs, qmp); + + if (rc) goto out; + + rc = qmp_parse_query_cpus(gc, qmp->domid, response, &rdcs->qemuu_cpus); + +out: + retrieve_domain_configuration_end(egc, rdcs, rc); +} + +static void retrieve_domain_configuration_timeout(libxl__egc *egc, + libxl__ev_time *ev, const struct timeval *requested_abs, int rc) +{ + retrieve_domain_configuration_state *rdcs = + CONTAINER_OF(ev, *rdcs, timeout); + + retrieve_domain_configuration_end(egc, rdcs, rc); +} + +static void retrieve_domain_configuration_end(libxl__egc *egc, + retrieve_domain_configuration_state *rdcs, int rc) +{ + STATE_AO_GC(rdcs->qmp.ao); + libxl__domain_userdata_lock *lock; + + /* Convenience aliases */ + libxl_domain_config *const d_config = rdcs->d_config; + libxl_domid domid = rdcs->qmp.domid; + + lock = libxl__lock_domain_userdata(gc, domid); + if (!lock) { + rc = ERROR_LOCK_FAIL; + goto out; + } + /* Domain name */ { char *domname; - domname = libxl_domid_to_name(ctx, domid); + domname = libxl_domid_to_name(CTX, domid); if (!domname) { LOGD(ERROR, domid, "Fail to get domain name"); goto out; @@ -1886,13 +1984,13 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, { libxl_dominfo info; libxl_dominfo_init(&info); - rc = libxl_domain_info(ctx, &info, domid); + rc = libxl_domain_info(CTX, &info, domid); if (rc) { LOGD(ERROR, domid, "Fail to get domain info"); libxl_dominfo_dispose(&info); goto out; } - libxl_uuid_copy(ctx, &d_config->c_info.uuid, &info.uuid); + libxl_uuid_copy(CTX, &d_config->c_info.uuid, &info.uuid); libxl_dominfo_dispose(&info); } @@ -1913,8 +2011,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, assert(version != LIBXL_DEVICE_MODEL_VERSION_UNKNOWN); switch (version) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc = libxl__update_avail_vcpus_qmp(gc, domid, - max_vcpus, map); + libxl_bitmap_copy(CTX, map, &rdcs->qemuu_cpus); break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: rc = libxl__update_avail_vcpus_xenstore(gc, domid, @@ -1939,6 +2036,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, } } + /* Memory limits: * * Currently there are three memory limits: @@ -1972,7 +2070,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, /* Scheduler params */ { libxl_domain_sched_params_dispose(&d_config->b_info.sched_params); - rc = libxl_domain_sched_params_get(ctx, domid, + rc = libxl_domain_sched_params_get(CTX, domid, &d_config->b_info.sched_params); if (rc) { LOGD(ERROR, domid, "Fail to get scheduler parameters"); @@ -2034,7 +2132,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, if (j < num) { /* found in xenstore */ if (dt->merge) - dt->merge(ctx, p + dt->dev_elem_size * j, q); + dt->merge(CTX, p + dt->dev_elem_size * j, q); } else { /* not found in xenstore */ LOGD(WARN, domid, "Device present in JSON but not in xenstore, ignored"); @@ -2062,11 +2160,12 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, } out: + libxl__ev_devlock_unlock(gc, &rdcs->devlock); if (lock) libxl__unlock_domain_userdata(lock); - if (rc) - return AO_CREATE_FAIL(rc); + libxl_bitmap_dispose(&rdcs->qemuu_cpus); + libxl__ev_qmp_dispose(gc, &rdcs->qmp); + libxl__ev_time_deregister(gc, &rdcs->timeout); libxl__ao_complete(egc, ao, rc); - return AO_INPROGRESS; } /* diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 1ecebf136984..bfeb38e0eda3 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1988,9 +1988,6 @@ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, _hidden int libxl__qmp_resume(libxl__gc *gc, int domid); /* Load current QEMU state from file. */ _hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename); -/* Query the bitmap of CPUs */ -_hidden int libxl__qmp_query_cpus(libxl__gc *gc, int domid, - libxl_bitmap *map); /* Start NBD server */ _hidden int libxl__qmp_nbd_server_start(libxl__gc *gc, int domid, const char *host, const char *port); diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 27183bc6c4a3..9639d491d991 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -767,44 +767,6 @@ int libxl__qmp_resume(libxl__gc *gc, int domid) return qmp_run_command(gc, domid, "cont", NULL, NULL, NULL); } -static int query_cpus_callback(libxl__qmp_handler *qmp, - const libxl__json_object *response, - void *opaque) -{ - libxl_bitmap *map = opaque; - unsigned int i; - const libxl__json_object *cpu = NULL; - int rc; - GC_INIT(qmp->ctx); - - libxl_bitmap_set_none(map); - for (i = 0; (cpu = libxl__json_array_get(response, i)); i++) { - unsigned int idx; - const libxl__json_object *o; - - o = libxl__json_map_get("CPU", cpu, JSON_INTEGER); - if (!o) { - LOGD(ERROR, qmp->domid, "Failed to retrieve CPU index."); - rc = ERROR_FAIL; - goto out; - } - - idx = libxl__json_object_get_integer(o); - libxl_bitmap_set(map, idx); - } - - rc = 0; -out: - GC_FREE; - return rc; -} - -int libxl__qmp_query_cpus(libxl__gc *gc, int domid, libxl_bitmap *map) -{ - return qmp_run_command(gc, domid, "query-cpus", NULL, - query_cpus_callback, map); -} - int libxl__qmp_nbd_server_start(libxl__gc *gc, int domid, const char *host, const char *port) { From patchwork Thu Sep 19 17:16:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152995 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 CF70716B1 for ; Thu, 19 Sep 2019 17:42:21 +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 AAFCC2196E for ; Thu, 19 Sep 2019 17:42:21 +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="Aws0ABcf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAFCC2196E 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 1iB0QY-0004Qj-72; Thu, 19 Sep 2019 17:41:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0QW-0004Os-5x for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:08 +0000 X-Inumbo-ID: a4c8820e-db04-11e9-b76c-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a4c8820e-db04-11e9-b76c-bc764e2007e4; Thu, 19 Sep 2019 17:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yMkoyQJsVoTpLNhCoQP/lLHBUZYMQj1kOvYaINRWLG4=; b=Aws0ABcfhi6+BIkFoJ+EiNadq3cCSOsIF0Bf0hXf8/+C9UwXY6KOi5jg 4deSHYS6W4qVqqy/6hklqCxvmXlEHHKnTtfEUQBt5MEY4yy0zQyRxMz8O J4ETDoDzC3tvcJ3jgtfmtu7URJoPEeUVD7TEQTJ5W16uOsUkhyQTKkmyG s=; Authentication-Results: esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.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=esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: IFlyovukdGqWVInKeV5wKnNXWuROLj/O6XJd7RNRFBAenOhtsaPfBLaV47XCI68q2aLNWWIe29 sgpfnctBtY3fUapGvvlSD4UOy8Ph6HFX5+R06xEuVX8U6YjqNj7vaVjO8FrZPcqxZYDxO7phBw lY2UqrAQj30j6WLC4kSBEAnaUYX5L6aOAGT/fb44UQ6jfG/rSFMhQ57B+WeO25OAfqR7Dm/lmB 47J5mLFAFf76oNpI5dkOwZNquKLrfGh9Vsti68WaXmGD+zSKTEnNOi94HyTmDW3nsIhsj2ACqU S0g= X-SBRS: 2.7 X-MesageID: 5864905 X-Ironport-Server: esa1.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="5864905" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:54 +0100 Message-ID: <20190919171656.899649-35-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 34/35] libxl: libxl_qemu_monitor_command now uses ev_qmp 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" Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_qmp.c | 52 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 9639d491d991..9aabad74fabd 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -892,19 +892,67 @@ int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line, hmp_callback, output); } + +typedef struct { + libxl__ev_qmp qmp; + char **output; /* user pointer */ +} qemu_monitor_command_state; + +static void qemu_monitor_command_done(libxl__egc *, libxl__ev_qmp *, + const libxl__json_object *response, + int rc); + int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid, const char *command_line, char **output, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); + qemu_monitor_command_state *qmcs; + libxl__json_object *args = NULL; int rc; - rc = libxl__qmp_hmp(gc, domid, command_line, output); + if (!output) { + rc = ERROR_INVAL; + goto out; + } - libxl__ao_complete(egc, ao, rc); + GCNEW(qmcs); + libxl__ev_qmp_init(&qmcs->qmp); + qmcs->qmp.ao = ao; + qmcs->qmp.domid = domid; + qmcs->qmp.payload_fd = -1; + qmcs->qmp.callback = qemu_monitor_command_done; + qmcs->output = output; + libxl__qmp_param_add_string(gc, &args, "command-line", command_line); + rc = libxl__ev_qmp_send(gc, &qmcs->qmp, "human-monitor-command", args); +out: + if (rc) return AO_CREATE_FAIL(rc); return AO_INPROGRESS; } +static void qemu_monitor_command_done(libxl__egc *egc, libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + STATE_AO_GC(qmp->ao); + qemu_monitor_command_state *qmcs = CONTAINER_OF(qmp, *qmcs, qmp); + + if (rc) goto out; + + if (!libxl__json_object_is_string(response)) { + rc = ERROR_QEMU_API; + LOGD(ERROR, qmp->domid, "Response has unexpected format"); + goto out; + } + + *(qmcs->output) = + libxl__strdup(NOGC, libxl__json_object_get_string(response)); + rc = 0; + +out: + libxl__ev_qmp_dispose(gc, qmp); + libxl__ao_complete(egc, ao, rc); +} /* * Functions using libxl__ev_qmp From patchwork Thu Sep 19 17:16:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11152985 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 39DF215E6 for ; Thu, 19 Sep 2019 17:42:09 +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 149E02196E for ; Thu, 19 Sep 2019 17:42:09 +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="PpxjO1ug" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 149E02196E 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 1iB0Ql-0004gD-Eu; Thu, 19 Sep 2019 17:41:23 +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 1iB0Qj-0004e6-Jr for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:21 +0000 X-Inumbo-ID: b04a897e-db04-11e9-966e-12813bfff9fa Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b04a897e-db04-11e9-966e-12813bfff9fa; Thu, 19 Sep 2019 17:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=42g1nRsubz8/EWiCmW1IVEW9Gu3YO6Yy4ytl2VdE9Jw=; b=PpxjO1ugFcnIAfUW7kx0JEmZMyqcEK1o6p9VZYErcEim9lC1AYL41JXt vnii090ttD0yETw+7D9j4m9nzZXxS2/pnUXOEyxk5wF8EEblL+BL8SYEB p1cN/cifrAOOzuMWMC4EM/hYlawFKmDbPVSp/H7W0pzUPjovEH107tLlm A=; 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: kgm5NJrYKv9LNZjCc54brSfTpiEyTIjPIsRy7l4mhpOAOKVWjZaSDbBqpC7k4+tLkOsrhSoqfb wluhKQcY/1lfXZgoPOIIog3F3WAjJSzMCfMFZZFHL0tKIgEzaYdAyhWgyO1w1/6xEROmf23lde YUBt5rk+oUCY3Jtj/3GhOt8jVcaJPR7WxYTUbfzbSumvqeZ+/Cu6rqsKgu0M8u5gTpxBDgN1pp Al0yOhXAqEW5uO0C1oRzuRQc4x0y0jNfbaAHVYdZ4QIsf05IBvLBKusOM6WaVEo38rl19VBxic MAE= X-SBRS: 2.7 X-MesageID: 6125295 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,524,1559534400"; d="scan'208";a="6125295" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:55 +0100 Message-ID: <20190919171656.899649-36-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 35/35] libxl_pci: Extract common part of *qemu_trad_watch_state_cb 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" Functions pci_add_qemu_trad_watch_state_cb and pci_remove_qemu_trad_watch_state_cb are similar so the common part is extracted in a different function. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: v2: - new patch which attempt to combine the "basically-identical" functions pci_{add,remove}_qemu_trad_watch_state_cb tools/libxl/libxl_pci.c | 51 +++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 2c4e2e5cff5e..47258177bc71 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -984,6 +984,27 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid, return rc; } +static int check_qemu_running(libxl__gc *gc, + libxl_domid domid, + libxl__xswait_state *xswa, + int rc, + const char *state) +{ + if (rc) { + if (rc == ERROR_TIMEDOUT) { + LOGD(ERROR, domid, "%s not ready", xswa->what); + } + goto out; + } + + if (!state || strcmp(state, "running")) + return ERROR_NOT_READY; + +out: + libxl__xswait_stop(gc, xswa); + return rc; +} + typedef struct pci_add_state { /* filled by user of do_pci_add */ libxl__ao_device *aodev; @@ -1071,21 +1092,14 @@ static void pci_add_qemu_trad_watch_state_cb(libxl__egc *egc, libxl_domid domid = pas->domid; libxl_device_pci *pcidev = pas->pcidev; - if (rc) { - if (rc == ERROR_TIMEDOUT) { - LOGD(ERROR, domid, "%s not ready", xswa->what); - } - goto out; - } - - if (!state) - return; - if (strcmp(state, "running")) + rc = check_qemu_running(gc, domid, xswa, rc, state); + if (rc == ERROR_NOT_READY) return; + if (rc) + goto out; rc = qemu_pci_add_xenstore(gc, domid, pcidev); out: - libxl__xswait_stop(gc, xswa); pci_add_dm_done(egc, pas, rc); /* must be last */ } @@ -1893,22 +1907,15 @@ static void pci_remove_qemu_trad_watch_state_cb(libxl__egc *egc, libxl_domid domid = prs->domid; libxl_device_pci *const pcidev = prs->pcidev; - if (rc) { - if (rc == ERROR_TIMEDOUT) { - LOGD(ERROR, domid, "%s not ready", xswa->what); - } - goto out; - } - - if (!state) - return; - if (strcmp(state, "running")) + rc = check_qemu_running(gc, domid, xswa, rc, state); + if (rc == ERROR_NOT_READY) return; + if (rc) + goto out; rc = qemu_pci_remove_xenstore(gc, domid, pcidev, prs->force); out: - libxl__xswait_stop(gc, xswa); pci_remove_detatched(egc, prs, rc); }