From patchwork Fri Aug 2 15:35: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: 11073763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 844F0746 for ; Fri, 2 Aug 2019 15:37:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7406428620 for ; Fri, 2 Aug 2019 15:37:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 681CD2886F; Fri, 2 Aug 2019 15:37:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B7A5528620 for ; Fri, 2 Aug 2019 15:37:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbN-00036j-Vd; Fri, 02 Aug 2019 15:36:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbM-00034i-JR for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:16 +0000 X-Inumbo-ID: 430044fd-b53b-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 430044fd-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:14 +0000 (UTC) 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: rtPpRBmXn6T/tvIvnAEfe2fkjT0aukz8tD9q9wzQylqDR+mTLVis9pmV5+Z1BiGsQdyMbDKuz5 ZF9uHeQzLDUODlbpUI4IGlYMooEYhXR1uwMaBDR8p8Nkfqosqa57gDWTYSsYGVSMtLvrUCmNQU o2vcF4g8Vagp3dZm64IXDR/HL27BvudIwiv+wMbJFRNM6XmtC6B22/0xhlTl0vF5+0rHeuBvNu IRC0JCzrTG7Wyy21zAmI/LcY1oKd4Pag/zAhIMrVZ4kkDmdW8dk2m6Ks8lHe0zLzBxvCo0Z44W TAQ= X-SBRS: 2.7 X-MesageID: 3825677 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,338,1559534400"; d="scan'208";a="3825677" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:32 +0100 Message-ID: <20190802153606.32061-2-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- tools/libxl/libxl.h | 26 +++++++++++++++-- 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, 65 insertions(+), 28 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index e40546c23a..7a31169611 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -619,7 +619,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 @@ -1595,8 +1596,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 0c535bd95d..aaa70552b8 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 3247cce3a7..1d261a1639 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 5fe25b56f5..00da59153d 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 11a29b235b..1c313005db 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 cf9287c488..7bd08032cf 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -4108,6 +4108,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 1f0e87df50..22f0429b84 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 9afeadeeb2..5c70e2e874 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 a1d633795c..419bf780a4 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 Fri Aug 2 15:35: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: 11073757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BEA1746 for ; Fri, 2 Aug 2019 15:37:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEFE228620 for ; Fri, 2 Aug 2019 15:37:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E325628874; Fri, 2 Aug 2019 15:37:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 79616286F3 for ; Fri, 2 Aug 2019 15:37:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbJ-00032v-Ay; Fri, 02 Aug 2019 15:36:13 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbH-00032M-L0 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:11 +0000 X-Inumbo-ID: 402268c3-b53b-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 402268c3-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:09 +0000 (UTC) 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: LTrPfIHvPJyaLQm7Hg7lDDlN/giksmwG8uKsrq/lgh8/0pz3p5U1XXlFCQ6cce93u0iu0BAvSS vA/LwXkMGDBQeFVDlJ/n3qly+5d38NW2J7DJwSJka41ZTKaupLhrPReLoLB3MRaMF5FaZMGU0q +LOURgpZITutoc1kxoXNYfRmgRs0AA2/bioix081NhYujmBphoZ58axjs7n8LnG/9ArT+YkJgt ljES/K+pJG/bi0yJpwNaHolyx//Z34GWdtUfPUooEtHXC1yq0vvq2mwQrxl6iK6h6jPSWrN0Ez 6eQ= X-SBRS: 2.7 X-MesageID: 3825667 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,338,1559534400"; d="scan'208";a="3825667" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:33 +0100 Message-ID: <20190802153606.32061-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP .. because it makes QMP calls which are going to be async. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl.h | 12 +++++++++++- tools/libxl/libxl_domain.c | 12 ++++++++---- tools/xl/xl_misc.c | 4 ++-- tools/xl/xl_vmcontrol.c | 4 ++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 7a31169611..0164d93adf 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -2350,7 +2350,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 1c313005db..86cddc05a9 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 dcf940a6d4..50c8436337 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 419bf780a4..3fc6f56574 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 Fri Aug 2 15:35: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: 11073771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F422746 for ; Fri, 2 Aug 2019 15:37:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E7C5286F3 for ; Fri, 2 Aug 2019 15:37:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72A6328872; Fri, 2 Aug 2019 15:37:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0493A286F3 for ; Fri, 2 Aug 2019 15:37:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbJ-00032p-1v; Fri, 02 Aug 2019 15:36:13 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbH-00032L-K3 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:11 +0000 X-Inumbo-ID: 40cc03d6-b53b-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 40cc03d6-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:10 +0000 (UTC) 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: n65uTvD2AdDmT0zmnaVGCgaKo7+N7xtrBAt+XoVhcwIjYEfcY821bc4NyD1A8mJ+okZI1RnYR0 vxC2JExWp1IrBl4fdUtDmR2vt1V51IP68CnAR7+/m8g+LY5Rv45uUc4CaEapzlzRO2kbfCGDDG BPqExrpZGJVTczMThtkAXsW4R6zvNWKwYyeHengo33dDy0O8Sf1DwXoeCLpbyK48d3AHvxYjh4 I+/YW+ODIQv3vkjcNSROZEvuyZnlJX1dRm2O/9/TruhxxdNYe0Q08GqXrUC86rL1DLxE8/ETx0 JKY= X-SBRS: 2.7 X-MesageID: 3825668 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,338,1559534400"; d="scan'208";a="3825668" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:34 +0100 Message-ID: <20190802153606.32061-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP .. 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_domain.c | 12 ++++++++---- tools/xl/xl_cpupool.c | 2 +- tools/xl/xl_vcpu.c | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 0164d93adf..224c9af1c6 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -2287,7 +2287,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 86cddc05a9..60c3f7a34b 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 273811b663..cffe87e0c7 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 329512eaaf..9ff5354f74 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 Fri Aug 2 15:35: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: 11073773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9314D13AC for ; Fri, 2 Aug 2019 15:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8269B286F3 for ; Fri, 2 Aug 2019 15:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76FB828870; Fri, 2 Aug 2019 15:38:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0F0F4286F3 for ; Fri, 2 Aug 2019 15:38:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbJ-000336-NM; Fri, 02 Aug 2019 15:36:13 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbH-00032Z-Tl for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:11 +0000 X-Inumbo-ID: 40c2365c-b53b-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 40c2365c-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:11 +0000 (UTC) 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: geMqhCiz6YsLai/a3Mh5JW9ggx7whFKc6vA6/9AQB+NRp9o+9dMxCyEsWFFYlRoWq96edO9/3A 0fnuJ625KECdzOCNmy/7tupXqrAdJt3M5MaZjGEVyEuDFGkETffBma7Wur1lWBiEW0QcjElAxu HaXdQgX+EG5MvfTat4Ba94WasdHztig/HV1yVGfjJSHvQIe+EO7WSvmfWX7TUMaNVFOIWe57vB neZcln4+zsSaFECXm7JGKAfTt3GvxWNxHCJFXmo7izYAW38P5NMStHHQORcEOpJyqIwQeWyr8Q Cws= X-SBRS: 2.7 X-MesageID: 3825669 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,338,1559534400"; d="scan'208";a="3825669" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:35 +0100 Message-ID: <20190802153606.32061-5-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP .. because it makes QMP calls which are going to be async. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl.h | 12 +++++++++++- 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, 24 insertions(+), 11 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 224c9af1c6..96489a74ca 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1532,8 +1532,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 60c3f7a34b..f2d5c86427 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 46d9c9f712..74a7884479 100644 --- a/tools/xl/xl_info.c +++ b/tools/xl/xl_info.c @@ -461,7 +461,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 5c70e2e874..9be033fe65 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 3fc6f56574..eb6779a561 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 Fri Aug 2 15:35: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: 11073755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6702713AC for ; Fri, 2 Aug 2019 15:37:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 564FB286F3 for ; Fri, 2 Aug 2019 15:37:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A7E628876; Fri, 2 Aug 2019 15:37:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E5D31286F3 for ; Fri, 2 Aug 2019 15:37:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbK-00033Q-5Q; Fri, 02 Aug 2019 15:36:14 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbI-00032e-KS for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:12 +0000 X-Inumbo-ID: 412ba0c8-b53b-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 412ba0c8-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:11 +0000 (UTC) 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: Cs7Bp/KqHvffa+x9gtcZC2dDpcK2DMruxNhgQir7MNItRPU0foxlkerZ6DcIgmvukBNCIYBBLB lIFQqz/c0TCDwUD/NSeqN46Vg/Z01Tgjrha3ToMzRI0/qBi98LZGAPAtPi4eiP2mSATssKLZnF gmyQWQhv5thpkJlDJU1idkgWCq9MC91d6zZLqIhB4alBb8RHTA0FulYDAXYaPxaeFbRaAkc7wF JagG8DJUfAS0vDGOG+6MT2RJpnXzS8COUmXEaCq8EsGX73UlfM1lWNSjjmjUtcOKgIkoDvrCx/ /YM= X-SBRS: 2.7 X-MesageID: 3825670 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,338,1559534400"; d="scan'208";a="3825670" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:36 +0100 Message-ID: <20190802153606.32061-6-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP .. 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_qmp.c | 9 +++++---- tools/xl/xl_misc.c | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 96489a74ca..d001ffc75e 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -2538,7 +2538,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 20d9eed8dd..505e0e5469 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 50c8436337..20ed605f4f 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 Fri Aug 2 15:35: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: 11073775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55B2F13AC for ; Fri, 2 Aug 2019 15:38:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 459BD2886F for ; Fri, 2 Aug 2019 15:38:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A03B28872; Fri, 2 Aug 2019 15:38:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B95FC2886F for ; Fri, 2 Aug 2019 15:38:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbd-0003Iw-CT; Fri, 02 Aug 2019 15:36:33 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbc-0003I7-Fa for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:32 +0000 X-Inumbo-ID: 4ced3835-b53b-11e9-8980-bc764e045a96 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4ced3835-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:31 +0000 (UTC) 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: qHN4Yt3Behz+pPhLlMfTRKCkcajJ+8Ao74zocPUZ88qn2/jldG14xyjUS2GUM6T5Ews8B8OSrm GZeFNVplDAM0hkr/vrXEEf/YNmo/LAEDljhg27W9IFMbvfw3ey93DG8pOwd/XU9w/MtW0UL0OC J/i/v6A05OhY/5ROfrOshVAUXuiAONqBxEzd4Izts4EkURJTM38vR39vzRs3lDNaGab1DW+BLZ Hwu3HBmn5MchPM8tm3mdCo6LRiSPS1tXSD1Sp1/1fLWaZiMGY5kWcdyzpOJGLaaqJbsKotNf0I P4Q= X-SBRS: 2.7 X-MesageID: 3796634 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,338,1559534400"; d="scan'208";a="3796634" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:37 +0100 Message-ID: <20190802153606.32061-7-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anthony PERARD --- 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 13d08d6dae..e70aa15859 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 7bd08032cf..effc1c5bf9 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1957,8 +1957,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 */ @@ -3412,6 +3410,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 505e0e5469..f1529925ee 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 Fri Aug 2 15:35: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: 11073759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 059D013AC for ; Fri, 2 Aug 2019 15:37:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAB8928870 for ; Fri, 2 Aug 2019 15:37:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEF4228877; Fri, 2 Aug 2019 15:37:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F088028870 for ; Fri, 2 Aug 2019 15:37:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbI-00032g-PH; Fri, 02 Aug 2019 15:36:12 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbH-00032K-Id for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:11 +0000 X-Inumbo-ID: 40705e20-b53b-11e9-8980-bc764e045a96 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 40705e20-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:10 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: NOMjw+w0X2lefXBHn54FoG+DJ22oVErXqVJmdQXPXky6HFSuYDE6KorpoUfx+WPLcLLnbm8OpA v9eWTb0E8U7ikjexwxpMJ0a1C/R3BI2yVYHrYNr+TWZPswpbXUQ8KZ83T3TDadCbZF9Sih+uvQ PJxXV42gKjypLjSVE42VW2mqIE5XLqIAtT1AcPgZY99371HIzcxW0SNDtGWWVzcFIwAsezMnp1 mTuXoSIjOyjqwl8bX2D9UATCdVmXbNcNr9kRGMxTQKgrsxNWomBaksF+8hvyn6jFuSwYdqM2pD VzQ= X-SBRS: 2.7 X-MesageID: 3950106 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3950106" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:38 +0100 Message-ID: <20190802153606.32061-8-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 9f56851be2..7144d6ff53 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1543,21 +1543,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 00da59153d..5a2e349776 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 Fri Aug 2 15:35: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: 11073777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FD35746 for ; Fri, 2 Aug 2019 15:38:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DB132886F for ; Fri, 2 Aug 2019 15:38:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81F2228872; Fri, 2 Aug 2019 15:38:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 872D02886F for ; Fri, 2 Aug 2019 15:38:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbM-00034d-D6; Fri, 02 Aug 2019 15:36:16 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbK-00033B-0X for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:14 +0000 X-Inumbo-ID: 412785bc-b53b-11e9-8980-bc764e045a96 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 412785bc-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:11 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Fsu0rvVh4CFK2k+AnTkl4T9Mh1d44h5ik1TS1VALKkri0sjn3OHPcIhbwKt1EqNHGIVKWioCzx maCt0gQue60moZdz7ULeOng4VTEjqMnvQ/Sex4leg7O860f3lnMgOO+WLo7uccB5xslLscq6+0 yF4skGTrY4L9su1ndfxxpb17xixEwalPlQbXn9FHu5Iify7nQ/9GFBd6GmAjDgBsSMo4b//T3b BhgbDgixU5RTkBUZgIvArUErFVgGERyvMNFhdg1+LT6a6YZdAZDr+DuOWnT4J68qFggpIINuvi gEg= X-SBRS: 2.7 X-MesageID: 3950108 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3950108" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:39 +0100 Message-ID: <20190802153606.32061-9-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 5a2e349776..bb5339784e 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 effc1c5bf9..5e09e602ed 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 @@ -1946,8 +1947,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); @@ -1993,10 +1992,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 @@ -3953,6 +3948,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 f1529925ee..0d6aedcc7d 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 Fri Aug 2 15:35: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: 11073761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A680B14DB for ; Fri, 2 Aug 2019 15:37:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95729286F3 for ; Fri, 2 Aug 2019 15:37:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8986D28874; Fri, 2 Aug 2019 15:37:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C5132286F3 for ; Fri, 2 Aug 2019 15:37:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbM-00034R-2U; Fri, 02 Aug 2019 15:36:16 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZbK-00033A-0Y for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:36:14 +0000 X-Inumbo-ID: 4122ca74-b53b-11e9-8980-bc764e045a96 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4122ca74-b53b-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:36:11 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: iIopPvFFWRQPOo+6lnRf89Fm0ADPcMpK8VUCRqSfwdONB4aKP+K1fmUbqXZybzDXAbbuxmJC1W 2RKan1AGhOL5OuWf1Z8dtBs+RFtJ1kciGQtmtn0SGDiJygGQZLFZ+/ers8LzfHrjoBAK7N1qAF gYT52Ipkzsejn4ugPPy+dPg2ttGlHeO5zIANz8dTzRaNgvwkg6lGHzI/ArOZNF6iYAcS6Xkw9H /SfcX++i/m6iD4tdgDG2UtnFf1yjpOgCgGg7hDBFCVFBP5ILjvgbl8AXUpmxzHAf+LWJg98r8/ yng= X-SBRS: 2.7 X-MesageID: 3950109 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3950109" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:40 +0100 Message-ID: <20190802153606.32061-10-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 aaa70552b8..aa365670fb 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 1d261a1639..b47f038f6e 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 bb5339784e..246c570121 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 d1af3a6573..2460021e5a 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 f2d5c86427..80797c5ed2 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 5e09e602ed..da3631d853 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1314,7 +1314,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, @@ -1331,8 +1332,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); @@ -4103,7 +4108,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 29a47838c8..6338a1bae5 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 Fri Aug 2 15:35:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EB5B1399 for ; Fri, 2 Aug 2019 15:59:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E3E428876 for ; Fri, 2 Aug 2019 15:59:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 725F628877; Fri, 2 Aug 2019 15:59:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B539328880 for ; Fri, 2 Aug 2019 15:59:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwo-0006MN-C2; Fri, 02 Aug 2019 15:58:26 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwn-0006Js-1u for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:25 +0000 X-Inumbo-ID: 5ab57478-b53e-11e9-8980-bc764e045a96 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 5ab57478-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:22 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: ryG2UEzmzU47op5zZH8OObEgkLtSM4TafK+f4q9sbuw4vlyM/jt9Wn7Toj3vw+uNvFGjcp1CqH zQrrRtyCWtmebiqmS06a1wgz8aX1dfUfqoOzgBn5HmgSTs5CBBdmowG+iUQCgVI6YJ6JtBsR8N 0dyOYMQaFPG2cHv2dxKSoJYU9BvUl3xH+goYgP8wqK4smXQWMzaFlWpTBJQ4lZXURz6JteZU4F aeTJnGv/32q+dNFVt9ZUg6rYJklfgEW/iHK1BRfR0p34Ys8fBu53MUdf5QfLsy8nca+R9tgjRF 7AU= X-SBRS: 2.7 X-MesageID: 3951240 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3951240" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:41 +0100 Message-ID: <20190802153606.32061-11-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 10/35] libxl: Re-introduce libxl__domain_resume X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP libxl__domain_resume is a rework libxl__domain_resume_deprecated. It makes uses of ev_xswatch and ev_qmp, to replace synchronous QMP calls and libxl__wait_for_device_model_deprecated call. This patch also introduce libxl__dm_resume which is a sub-operation of both libxl__domain_resume and libxl__domain_unpause and can be used instead of libxl__domain_resume_device_model_deprecated. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_dom_suspend.c | 192 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 27 +++++ 2 files changed, 219 insertions(+) diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.c index 2460021e5a..9bb2d00bec 100644 --- a/tools/libxl/libxl_dom_suspend.c +++ b/tools/libxl/libxl_dom_suspend.c @@ -481,6 +481,198 @@ int libxl__domain_resume_deprecated(libxl__gc *gc, uint32_t domid, int suspend_c return rc; } +static void dm_resume_init(libxl__dm_resume_state *dmrs) +{ + libxl__ev_qmp_init(&dmrs->qmp); + libxl__ev_time_init(&dmrs->time); + libxl__ev_xswatch_init(&dmrs->watch); +} + +static void dm_resume_dispose(libxl__gc *gc, + libxl__dm_resume_state *dmrs) +{ + libxl__ev_qmp_dispose(gc, &dmrs->qmp); + libxl__ev_time_deregister(gc, &dmrs->time); + libxl__ev_xswatch_deregister(gc, &dmrs->watch); +} + +static void dm_resume_xswatch_cb(libxl__egc *egc, + libxl__ev_xswatch *, const char *watch_path, const char *); +static void dm_resume_qmp_done(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *, int rc); +static void dm_resume_timeout(libxl__egc *egc, + libxl__ev_time *, const struct timeval *, int rc); +static void dm_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, int rc); + +void libxl__dm_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs) +{ + STATE_AO_GC(dmrs->ao); + int rc = 0; + + /* Convenience aliases */ + libxl_domid domid = dmrs->domid; + libxl__ev_qmp *qmp = &dmrs->qmp; + + dm_resume_init(dmrs); + + rc = libxl__ev_time_register_rel(dmrs->ao, + &dmrs->time, + dm_resume_timeout, + LIBXL_DEVICE_MODEL_START_TIMEOUT); + if (rc) goto out; + + switch (libxl__device_model_version_running(gc, domid)) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: { + uint32_t dm_domid = libxl_get_stubdom_id(CTX, domid); + const char *path, *state; + + path = DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/state"); + rc = libxl__xs_read_checked(gc, XBT_NULL, path, &state); + if (rc) goto out; + if (!state || strcmp(state, "paused")) { + /* already running */ + rc = 0; + goto out; + } + + rc = libxl__qemu_traditional_cmd(gc, domid, "continue"); + if (rc) goto out; + rc = libxl__ev_xswatch_register(gc, &dmrs->watch, + dm_resume_xswatch_cb, + path); + if (rc) goto out; + break; + } + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + qmp->ao = dmrs->ao; + qmp->domid = domid; + qmp->callback = dm_resume_qmp_done; + qmp->payload_fd = -1; + rc = libxl__ev_qmp_send(gc, qmp, "cont", NULL); + if (rc) goto out; + break; + default: + rc = ERROR_INVAL; + goto out; + } + + return; + +out: + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_xswatch_cb(libxl__egc *egc, + libxl__ev_xswatch *xsw, + const char *watch_path, + const char *event_path) +{ + EGC_GC; + libxl__dm_resume_state *dmrs = CONTAINER_OF(xsw, *dmrs, watch); + int rc; + const char *value; + + rc = libxl__xs_read_checked(gc, XBT_NULL, watch_path, &value); + if (rc) goto out; + + if (!value || strcmp(value, "running")) + return; + + rc = 0; +out: + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_qmp_done(libxl__egc *egc, + libxl__ev_qmp *qmp, + const libxl__json_object *response, + int rc) +{ + libxl__dm_resume_state *dmrs = CONTAINER_OF(qmp, *dmrs, qmp); + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_timeout(libxl__egc *egc, + libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + libxl__dm_resume_state *dmrs = CONTAINER_OF(ev, *dmrs, time); + dm_resume_done(egc, dmrs, rc); +} + +static void dm_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + int rc) +{ + EGC_GC; + + if (rc) { + LOGD(ERROR, dmrs->domid, + "Failed to resume device model: rc=%d", rc); + } + + dm_resume_dispose(gc, dmrs); + dmrs->dm_resumed_callback(egc, dmrs, rc); +} + + +static void domain_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, int rc); + +void libxl__domain_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + bool suspend_cancel) +{ + STATE_AO_GC(dmrs->ao); + int rc = 0; + libxl_domain_type type = libxl__domain_type(gc, dmrs->domid); + + if (type == LIBXL_DOMAIN_TYPE_INVALID) { + rc = ERROR_FAIL; + goto out; + } + + if (type != LIBXL_DOMAIN_TYPE_HVM) { + rc = 0; + goto out; + } + + dmrs->suspend_cancel = suspend_cancel; + dmrs->dm_resumed_callback = domain_resume_done; + libxl__dm_resume(egc, dmrs); /* must be last */ + return; + +out: + domain_resume_done(egc, dmrs, rc); +} + +static void domain_resume_done(libxl__egc *egc, + libxl__dm_resume_state *dmrs, int rc) +{ + EGC_GC; + + /* Convenience aliases */ + libxl_domid domid = dmrs->domid; + + if (rc) goto out; + + if (xc_domain_resume(CTX->xch, domid, dmrs->suspend_cancel)) { + LOGED(ERROR, domid, "xc_domain_resume failed"); + rc = ERROR_FAIL; + goto out; + } + + if (!xs_resume_domain(CTX->xsh, domid)) { + LOGED(ERROR, domid, "xs_resume_domain failed"); + rc = ERROR_FAIL; + } +out: + dmrs->callback(egc, dmrs, rc); +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index da3631d853..bdc9677527 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -197,6 +197,7 @@ typedef struct libxl__device_type libxl__device_type; typedef struct libxl__json_object libxl__json_object; typedef struct libxl__carefd libxl__carefd; typedef struct libxl__ev_lock libxl__ev_lock; +typedef struct libxl__dm_resume_state libxl__dm_resume_state; typedef struct libxl__domain_create_state libxl__domain_create_state; typedef void libxl__domain_create_cb(struct libxl__egc *egc, @@ -1339,6 +1340,32 @@ _hidden int libxl__domain_resume_deprecated(libxl__gc *gc, uint32_t domid, _hidden int libxl__domain_unpause_deprecated(libxl__gc *, libxl_domid domid); +/* Call libxl__dm_resume_init() and fill the first few fields, + * then call one of libxl__domain_resume / libxl__domain_unpause + * or directly libxl__dm_resume if only the device model needs to be + * "resumed". */ +struct libxl__dm_resume_state { + /* caller must fill these in, and they must all remain valid */ + libxl__ao *ao; + libxl_domid domid; + void (*callback)(libxl__egc *, libxl__dm_resume_state *, int rc); + + /* private to libxl__domain_resume */ + void (*dm_resumed_callback)(libxl__egc *, + libxl__dm_resume_state *, int rc); + bool suspend_cancel; + + /* private to libxl__dm_resume */ + libxl__ev_qmp qmp; + libxl__ev_time time; + libxl__ev_xswatch watch; +}; +_hidden void libxl__dm_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs); +_hidden void libxl__domain_resume(libxl__egc *egc, + libxl__dm_resume_state *dmrs, + bool suspend_cancel); + /* returns 0 or 1, or a libxl error code */ _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid); From patchwork Fri Aug 2 15:35: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: 11073835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 248CA1395 for ; Fri, 2 Aug 2019 15:59:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14CC028613 for ; Fri, 2 Aug 2019 15:59:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0946B28872; Fri, 2 Aug 2019 15:59:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B287B286DB for ; Fri, 2 Aug 2019 15:59:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwf-00066e-VS; Fri, 02 Aug 2019 15:58:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwe-00065E-FK for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:16 +0000 X-Inumbo-ID: 56240c68-b53e-11e9-8980-bc764e045a96 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 56240c68-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:15 +0000 (UTC) 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: FpxYhue0rTmDZ0Yc/0mvIIlQSJeM63NhVo4S7+ZLmf8MB3AkKsHqb931Qi3xncWFlHZIE0oN5/ yhsGvCIAS8Vd50Lm461LfyVYpLdDpF0tKCuMw0WVnq6cs76Fam1eVIFGHWW8Y/joNA6iw+qOcx wvK81Rdk4YbiePSLAJaLerqsxg23v9LvoP79FWyqoOrxqiVIHrMnCWb31H86XzacFfF1zeORTb 0t0cMXURFjZhN8XBCJLqTeNhF10nLJ477RVIECFTHhwWz7ZcRYWeuvjO+l8PBZD5P+xR0meKTb LxU= X-SBRS: 2.7 X-MesageID: 3787824 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,338,1559534400"; d="scan'208";a="3787824" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:42 +0100 Message-ID: <20190802153606.32061-12-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 80797c5ed2..d78ffa6b60 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 Fri Aug 2 15:35: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: 11073821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72CA31395 for ; Fri, 2 Aug 2019 15:59:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 633D4286DB for ; Fri, 2 Aug 2019 15:59:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57EC928876; Fri, 2 Aug 2019 15:59:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F239F28872 for ; Fri, 2 Aug 2019 15:59:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwK-0005o0-Ds; Fri, 02 Aug 2019 15:57: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 1htZwJ-0005nY-8c for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:57:55 +0000 X-Inumbo-ID: 4784b75c-b53e-11e9-88c6-d7550dcbd3a0 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4784b75c-b53e-11e9-88c6-d7550dcbd3a0; Fri, 02 Aug 2019 15:57:50 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: YTNn9mWiPmVoaR/3r5d6oXyOiwVlzUyRxDWdeKlIvzrfDwk8fxwUDmJWWZQYG1wTAKQaDss+eb pszbjjZwTfLWGn3bQDQccuxjPGKIOovB2JoqHX95g4evUHOET2da/3pdld9wsmuk2DRfbNRdhp w1oH41TTVuLm4pXeSo7WFz+W0Qzz4nd7KfBotQA1dejpRJCnheuaeFnuATR4x0lTiAWkINZ5YQ 4ETDKzpzPLcttotJ+FKH0wHrEXrBfT3YK2eA83GbsADPo6aWD2sFt5ZyM7rS4mo2gz/eDBkrLz E1c= X-SBRS: 2.7 X-MesageID: 3951211 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3951211" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:43 +0100 Message-ID: <20190802153606.32061-13-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 d78ffa6b60..52a8bd7895 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 bdc9677527..1cfe3cf83f 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1350,9 +1350,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 */ @@ -1365,6 +1366,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 Fri Aug 2 15:35: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: 11073805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3BFC1399 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3D8128872 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7E7F2887B; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5282E28872 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZx5-0006sI-Ra; Fri, 02 Aug 2019 15:58:43 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZx5-0006qy-77 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:43 +0000 X-Inumbo-ID: 660fee57-b53e-11e9-8980-bc764e045a96 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 660fee57-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:41 +0000 (UTC) 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: Mys2SgZAiQ9+r4VKCFV0wLPXOxfBN32PVeRIpoIlAUqt7QX7+WksXIWn9KgFlRZ55VdMJG7LeV lfQdShPfbSMCFd9obnvCzzg0HobA9Jokwn88hnWfg4Fv5IURQSLpJhBiVzksd/ScvGW1zZn6AG RF6nO52ifIVDbffKxbYToh/CeyGiJ4yJuD/f8cfxJ1YqG0kW1zNZ2vKJ0YSHsYUHh2kZALkecp V89B04qqY3MKyLMMsh8kE74HxV4zlAD8O4jXB8pYoGc1FTrxYia6F9sp3vcLUZrJH5+nWjpHu8 DG8= X-SBRS: 2.7 X-MesageID: 3797676 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,338,1559534400"; d="scan'208";a="3797676" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:44 +0100 Message-ID: <20190802153606.32061-14-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 246c570121..c00356a2f1 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 1cfe3cf83f..7cabfd61b7 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3984,6 +3984,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 Fri Aug 2 15:35: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: 11073819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59BC61399 for ; Fri, 2 Aug 2019 15:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4889B286DB for ; Fri, 2 Aug 2019 15:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CA4928876; Fri, 2 Aug 2019 15:59:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C4A0728872 for ; Fri, 2 Aug 2019 15:59:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwO-0005qC-4B; Fri, 02 Aug 2019 15:58:00 +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 1htZwM-0005pU-P2 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:57:58 +0000 X-Inumbo-ID: 49ce068a-b53e-11e9-830f-1be5d4030396 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 49ce068a-b53e-11e9-830f-1be5d4030396; Fri, 02 Aug 2019 15:57:54 +0000 (UTC) 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: s+GR/ZGdbxONnQGtnwqHbjCzTSYLXHfRiRY2TOgIgyX9zDIRKeWEaqmsBQzkUyPedCLPStvY7K pCR6oKVF3U0C1Id48DgCN2SAh5BIj8gK3LEIg4LUf/HgfpXu6ZcfTpfFQzIqLp9WCmqt911tVo sMZvDAIlvCYkJJ2q+UW/LDWvltEo6yNjl9S37PPboBq3y1GH2rIpsE0oQuudbGKbsY7vtwpZLq Zsf58TG7tVy43EgPxC3ntCv4U/Sls7yogKeg22it+1eP4wmM4Jxji/bcRv/mrWtbgEXOi2arza Hj8= X-SBRS: 2.7 X-MesageID: 3826756 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,338,1559534400"; d="scan'208";a="3826756" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:45 +0100 Message-ID: <20190802153606.32061-15-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 52a8bd7895..f3c39fa86f 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 Fri Aug 2 15:35: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: 11073815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BF9A17E0 for ; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C14828872 for ; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20FBE28876; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A8EAE28613 for ; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwf-00066F-JO; Fri, 02 Aug 2019 15:58:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwe-00064t-4H for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:16 +0000 X-Inumbo-ID: 5602e1f0-b53e-11e9-8980-bc764e045a96 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 5602e1f0-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:14 +0000 (UTC) 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: aa0TOMMODD5cqOZBZlWPgeqE5h5GW4jqGv6t9lzVLyq1ugv1C+lBSMsVz5Z7np+2qE7D7olauz yqQ+KI4Q75LvVF9XYx344tAy/5xBX31pqEOPmjB+tuDJC0bg+lVmD7vJ3LTvP7MX4QsfB9ifWd LFoLMzX3y7o7kI7SqBU547wUs8TvS1lj6aQMBchZHFox0v04njuImmTWrvddaR9uMzS311vQpq ScDGCcGkbfScedAGKS1eNF4jVNBwIZ9cBegJ8XFZqkT9wdhHOkKb7smsfgLBE9DMqGCyFdx22q +sI= X-SBRS: 2.7 X-MesageID: 3931682 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,338,1559534400"; d="scan'208";a="3931682" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:46 +0100 Message-ID: <20190802153606.32061-16-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 3d69379c20..43c8ad3ee3 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -1519,72 +1519,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: @@ -1610,6 +1544,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); @@ -1628,6 +1563,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 */ @@ -1657,14 +1593,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 Fri Aug 2 15:35: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: 11073789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B97141395 for ; Fri, 2 Aug 2019 15:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8FAD28613 for ; Fri, 2 Aug 2019 15:59:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D63728872; Fri, 2 Aug 2019 15:59:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A97A28613 for ; Fri, 2 Aug 2019 15:59:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwP-0005rK-Gy; Fri, 02 Aug 2019 15:58: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 1htZwP-0005qv-37 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:01 +0000 X-Inumbo-ID: 4c0f9440-b53e-11e9-93aa-3b465ba5a6ef Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4c0f9440-b53e-11e9-93aa-3b465ba5a6ef; Fri, 02 Aug 2019 15:57:58 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: qYRdTk2KQiWh5YL8vxxW8ipoOFKvX4nFjZGSIMmptrG5pjopCSJ8uxoDPp0KMM8/TtML4bzq74 9IFvxpiOqwAHT12Sp7AQp3yJGuwzUFrfIVXJDrE6AkVpETbl+t+S3knwMDuXUHUrTgcn3IJJdF LHRllUv4kNha9iMvSc9ZAjDvWq+ieP5m/5fpwSJueJ1srVebbU5Vplm87UnNBXP7ZOgZyNLuev DPvn3ubJ/w9zBS/LI2lK27/8WHo+zMQtuxLC7enDIVQIIfBtR8eEE/qFBNRhwfu2gwyWx83Sos Jkk= X-SBRS: 2.7 X-MesageID: 3951217 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3951217" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:47 +0100 Message-ID: <20190802153606.32061-17-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 43c8ad3ee3..cc176f6d01 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -1655,17 +1655,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); @@ -1743,44 +1764,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 Fri Aug 2 15:35: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: 11073831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 602F11399 for ; Fri, 2 Aug 2019 15:59:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EA0628872 for ; Fri, 2 Aug 2019 15:59:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 415922887A; Fri, 2 Aug 2019 15:59:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CBA7C28872 for ; Fri, 2 Aug 2019 15:59:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwZ-0005zp-2I; Fri, 02 Aug 2019 15:58:11 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwX-0005xR-HD for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:09 +0000 X-Inumbo-ID: 51e265e2-b53e-11e9-8980-bc764e045a96 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 51e265e2-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:07 +0000 (UTC) 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: Zwo0tK+j90azTdoeZCpSfruYC0ajv+jLcIcd/1dwkrUU2YUdyF6Za4iMxcHxqkb4Arki+1N0r0 H08NZPnMGQwbeJnVa5PiZYBsyMXhlGh5csnmL4VsM6vQJeWvvXO4ner4fIDDgqvA7yxWY3CBLA mf5Za5vn1MF1SXc+BdO8OJ+RbXf57qRxeqp7rYUN5Qyem1DSN1NH1KK2juDL9y4dGfKmsq6jSK GD7r9DDHKrG/BzhZypEMJolTe7+nlSDKWjjg0F24VGOF+bo4Jl/8nKmFml90h2zP1Wfbj0jUim g9g= X-SBRS: 2.7 X-MesageID: 3911349 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,338,1559534400"; d="scan'208";a="3911349" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:48 +0100 Message-ID: <20190802153606.32061-18-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP `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 --- tools/libxl/libxl_device.c | 2 ++ tools/libxl/libxl_internal.h | 1 + 2 files changed, 3 insertions(+) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 1941fe780a..1402b61a81 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 7cabfd61b7..cc9318f33a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2622,6 +2622,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 Fri Aug 2 15:35: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: 11073809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2E211395 for ; Fri, 2 Aug 2019 15:59:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3C5C28876 for ; Fri, 2 Aug 2019 15:59:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B88E428877; Fri, 2 Aug 2019 15:59:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 703E428872 for ; Fri, 2 Aug 2019 15:59:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwj-0006CJ-0M; Fri, 02 Aug 2019 15:58:21 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwg-000681-NY for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:18 +0000 X-Inumbo-ID: 577fb2b2-b53e-11e9-8980-bc764e045a96 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 577fb2b2-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:17 +0000 (UTC) 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: /dKiIlC9o2Aom6t1j2477ZEZxP3y3UnU3ECXNVXeJ5wvCPxGdntEA7G814F4ozESYvZZRBhs3e ZvTQeM/nZjdhpiULCcoXky/UA8xfEQ5XGnCgV3w9VtmLFSqDAPLRrT7OdYgBeJ1dxaeeFeo4uq Sxfcaod4zcA/n79Y0p7a4oIwQTwGb4shv4Ui+Z684DrONwyzvcVAHCF17aptghGNcn0RlbDn8N bHVLDqX6FCp3YrQw8w+KA0LeTrprQ/8Xe1LUQGOVx/Ixip5WrZztMnOJfW7hNsThUW7dIHYOLW mFU= X-SBRS: 2.7 X-MesageID: 3787839 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,338,1559534400"; d="scan'208";a="3787839" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:49 +0100 Message-ID: <20190802153606.32061-19-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 cc9318f33a..8dea44b221 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2623,6 +2623,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 Fri Aug 2 15:35: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: 11073801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05A1F1399 for ; Fri, 2 Aug 2019 15:59:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9A5628613 for ; Fri, 2 Aug 2019 15:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDF8F28872; Fri, 2 Aug 2019 15:59:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EFF7D28613 for ; Fri, 2 Aug 2019 15:59:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwY-0005yY-BZ; Fri, 02 Aug 2019 15:58:10 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwW-0005wK-3w for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:08 +0000 X-Inumbo-ID: 510c3c92-b53e-11e9-8980-bc764e045a96 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 510c3c92-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:06 +0000 (UTC) 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: KfWsUDIWZ5u0EbKTxoGQ5k0+U5xFavKOzJHqnjLVSITuUIafDRNOOyNLEdPCfWp8R9wseRlRe6 1gg+baddVCwBQMebyPIDFahy/GXTEv3+kC0pLo1zwskxDlhkiNOjVaT6K5cdRhpzDRZIqqz3qz kvh6d7LNEOYlgmYNDSgH5GQzJBucygHXtU05G0KRGxpZrbfLW0gMBsFhAVqJlYRcfhAR1YEA+I XhEQGzqrYysgspnJGwmhlH/4c6DvmSE/kX1r11pG0j6fIckLLGDIAP4/A7WvIFcfihceP1VSsa Z3s= X-SBRS: 2.7 X-MesageID: 3911363 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,338,1559534400"; d="scan'208";a="3911363" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:50 +0100 Message-ID: <20190802153606.32061-20-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 cc176f6d01..5975c1d192 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -350,34 +350,37 @@ 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: assert(0); /* Should not be possible. */ return ERROR_INVAL; } - 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. */ @@ -432,6 +435,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: @@ -452,6 +462,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; @@ -466,14 +480,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; @@ -481,9 +506,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 Fri Aug 2 15:35: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: 11073785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF9E01399 for ; Fri, 2 Aug 2019 15:59:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E8C028876 for ; Fri, 2 Aug 2019 15:59:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 928B72887A; Fri, 2 Aug 2019 15:59:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1FF4728877 for ; Fri, 2 Aug 2019 15:59:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwH-0005mq-4A; Fri, 02 Aug 2019 15:57:53 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwF-0005ma-Nj for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:57:51 +0000 X-Inumbo-ID: 46febe8e-b53e-11e9-8980-bc764e045a96 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 46febe8e-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:57:49 +0000 (UTC) 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: VXq2FcEM5kKhzfKqIX5nsX4YRQ0PoIsi4lEbUMFPwjRCxdIwJek4Eeodp6uJKChEZqanWybtRG SAZknu9r6Ue4o+D3NGWTG8Oca78PaYfrhM807ByuIJuk1KOODVZKtMAEhS9CYjQ0ggWF+b+VFD GxcYDTuQlcKvb33dmxtWBPYpmvCSIkO2pKRS+y7BQ2zYXgei8yRvXzt3Vo8yLOaTkVkzfOwDyg dBAkC/Ne/pCkMaMU1qpkTaZ4NmIxe0Iu1sPrC/NmbWz3hdOxcrjWQTzPp2aWqYRSwQyFkwPGSF tvo= X-SBRS: 2.7 X-MesageID: 3931648 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,338,1559534400"; d="scan'208";a="3931648" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:51 +0100 Message-ID: <20190802153606.32061-21-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 5975c1d192..92eeeb27f0 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -384,15 +384,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. */ @@ -559,6 +560,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: @@ -578,13 +586,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); @@ -599,24 +612,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 Fri Aug 2 15:35: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: 11073795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 422E91399 for ; Fri, 2 Aug 2019 15:59:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 320F528613 for ; Fri, 2 Aug 2019 15:59:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25FE828872; Fri, 2 Aug 2019 15:59:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A2A3028613 for ; Fri, 2 Aug 2019 15:59:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZws-0006Tn-Ie; Fri, 02 Aug 2019 15:58:30 +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 1htZwr-0006S5-Mi for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:29 +0000 X-Inumbo-ID: 5d25b412-b53e-11e9-bdca-4ff00e5ac374 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5d25b412-b53e-11e9-bdca-4ff00e5ac374; Fri, 02 Aug 2019 15:58:27 +0000 (UTC) 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: VVqjn1/GqfDHhGXCJvgjdlpbVgqYW7vaIxLCSgbJmDyxN1B68mDb3XMrtVj+nCAbUP8sllDudj ChG6t8cucofw6cYS44eMesIee4scPq5VLZYxLMlIHqhzV75wg8SjzkjaeZER6RUKrdmz62YWg2 TGmcI1Rqz7yWIXUSVuVvz0xKudpfBpyCMDK7DDwrceRQZAdrrxoqFVYrNnASq4xL6s8WA9eHL3 4SwBKqszA1EXXMZkR59hVi4Rt99sz+OIaUt7qEYAdY/alXx8u8puC1O1E3Navs3C6c5HqrFLaq NIw= X-SBRS: 2.7 X-MesageID: 3787851 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,338,1559534400"; d="scan'208";a="3787851" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:52 +0100 Message-ID: <20190802153606.32061-22-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 92eeeb27f0..6b3e388a18 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -397,26 +397,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. */ @@ -1641,6 +1640,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: @@ -1667,9 +1673,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. @@ -1753,12 +1764,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"); @@ -1770,6 +1791,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 Fri Aug 2 15:35: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: 11073829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 698331395 for ; Fri, 2 Aug 2019 15:59:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58EC828613 for ; Fri, 2 Aug 2019 15:59:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D05C28872; Fri, 2 Aug 2019 15:59:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C914B28613 for ; Fri, 2 Aug 2019 15:59:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZx0-0006hk-4M; Fri, 02 Aug 2019 15:58:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwy-0006es-MJ for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:36 +0000 X-Inumbo-ID: 62692693-b53e-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 62692693-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:35 +0000 (UTC) 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: 34CbmWvo6apQGjTt0e89UZHXb4fHJDmovNUWyVIpigV+s4NAf7W1cx50ftz35zft4yIGgH7t+f OEzVbP5DiQ6zsf7gD3exgARxluxb9Jsk8L2CGbRcJODqeKnW3mxWm7SshdDDfrDMCxLlerVxkp OhQqb2QtpcfrgHTU04gDskmkw8NCCsqQHypDOGhfMPSIqiUmnRd+I8o9FEsMp64OroHk/+FbCk v5AU7U1MrqcUFKqFHkDiTa0eBcpvGjKMUPHO20C0VC3YnTeTmpkuwG9nJ9YzPCvZLc9O/052q2 AS4= X-SBRS: 2.7 X-MesageID: 3826803 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,338,1559534400"; d="scan'208";a="3826803" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:53 +0100 Message-ID: <20190802153606.32061-23-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 6b3e388a18..8e3a419805 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -556,9 +556,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, @@ -566,6 +568,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: @@ -586,6 +593,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); @@ -603,14 +616,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; @@ -620,10 +648,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; } @@ -1847,20 +1875,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; @@ -1946,7 +1985,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, @@ -1955,11 +1995,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 Fri Aug 2 15:35: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: 11073833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C13171399 for ; Fri, 2 Aug 2019 15:59:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B10F3286DB for ; Fri, 2 Aug 2019 15:59:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A552A28876; Fri, 2 Aug 2019 15:59:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 389BC286DB for ; Fri, 2 Aug 2019 15:59:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwX-0005xp-S7; Fri, 02 Aug 2019 15:58:09 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwV-0005w3-Qf for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:07 +0000 X-Inumbo-ID: 50e314fb-b53e-11e9-8980-bc764e045a96 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 50e314fb-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:06 +0000 (UTC) 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: DGYr0AE1MMMp0rbwzpi/gZwnTxXHizmvKuhoLEgFeHs0tdwWYSFdl1T0b/NqxG5XQOew/vlzO0 GdvX0qG2Lfbv1WTqn9hXmpKTLlaccwXys1NWgI3fu5Ywf3WcwfC0664JW3+ghEDUA4E2r2O5YO pKWYH3tWWse6jMz0gNmWC+QIc3qT4iwpUSbqNGS30GZz2o9AbFkQqhqYVFPVAYczFG+an5gBxL lWKPRmZAwl03sfR8CUyfIq/RRln4womBrZF2SMwjFk/ATyuqFLM3lSbEQ5Wh6UaDFE9gGpxZ1c MAg= X-SBRS: 2.7 X-MesageID: 3797638 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,338,1559534400"; d="scan'208";a="3797638" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:54 +0100 Message-ID: <20190802153606.32061-24-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 8e3a419805..2c11896f9e 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -419,18 +419,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) @@ -1868,6 +1866,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: @@ -1887,6 +1892,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; @@ -1966,14 +1972,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"); @@ -1985,6 +2000,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 Fri Aug 2 15:35: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: 11073807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1162017E0 for ; Fri, 2 Aug 2019 15:59:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0278C28872 for ; Fri, 2 Aug 2019 15:59:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9ED42887A; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 84D0728877 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwh-00069j-Ny; Fri, 02 Aug 2019 15:58:19 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwf-00066R-S7 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:17 +0000 X-Inumbo-ID: 572c8184-b53e-11e9-8980-bc764e045a96 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 572c8184-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:16 +0000 (UTC) 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: KcSqSv4Os+NxNdOYh7DX71CxqjoRi3jm93ESonRPUeV9BX9W3zBOGDytULFHSD+LRt17dwfQST ku8IMZi8JCAWmIEzDoJuZJ/qdrZObaGQLNK/MHbHErQflcSwCHigBf5o7Ch2PdKMB9onICTaqk /82xZp2ay24N66SRYAiAkz8UltmotoBTJpXNV/ZzBRvdz8O+wgpI6hFS/TzarI0mFlb40gOElK DT+8wpzm9hxU0BvNhPlCwktio9YiRHr8VwKz46jTbJfO8riRsi3kM8511n7FYiZcnc8HqnmNPF eos= X-SBRS: 2.7 X-MesageID: 3787818 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,338,1559534400"; d="scan'208";a="3787818" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:55 +0100 Message-ID: <20190802153606.32061-25-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 8dea44b221..5c15a73a08 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1979,9 +1979,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 0d6aedcc7d..c78ef4637d 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 Fri Aug 2 15:35:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30CC41395 for ; Fri, 2 Aug 2019 15:59:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1ED7428613 for ; Fri, 2 Aug 2019 15:59:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1191C28872; Fri, 2 Aug 2019 15:59:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8671828613 for ; Fri, 2 Aug 2019 15:59:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwz-0006gm-Io; Fri, 02 Aug 2019 15:58:37 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwy-0006eI-EQ for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:36 +0000 X-Inumbo-ID: 61a2ee97-b53e-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 61a2ee97-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:34 +0000 (UTC) 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: 7EKsGSLKpzpsq5fIgsofCkQYL5rLoB/rMSkNSELfGw1BWZhynvVBgEufhrV1t8gyxnkNGBN6iA ck5lO2JDeogn+KxVNTo9QvSr2lY2PxA78pgOBNqM5FpEpRBlQytm/Zg6DNhRw3mgmzX2Dyhr3z k3gvHkeGZLVbEvgFLG+Aj9KPIMxQRWj+2Iz9S5OMJdzpt6RrtuONmTN9RQmp7anM9tTKK2KeeH 2rms9upg10sNu4wu6HH7iXkmVW7k+u6VQhcjvgUbFsvpdyFi1cZYeF1jq+UGbkDkm8UHAtob/U 5gQ= X-SBRS: 2.7 X-MesageID: 3826801 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,338,1559534400"; d="scan'208";a="3826801" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:56 +0100 Message-ID: <20190802153606.32061-26-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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'. 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 4b1aed1895..b9ca69f5f0 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 Fri Aug 2 15:35:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A9EA1399 for ; Fri, 2 Aug 2019 15:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87FE928613 for ; Fri, 2 Aug 2019 15:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BE0D28872; Fri, 2 Aug 2019 15:59:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 287E328613 for ; Fri, 2 Aug 2019 15:59:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwi-0006AU-5A; Fri, 02 Aug 2019 15:58:20 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwf-00066P-QL for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:17 +0000 X-Inumbo-ID: 56cb0470-b53e-11e9-8980-bc764e045a96 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 56cb0470-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:16 +0000 (UTC) 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: 8SXjRg9qcptp5ea2C5Jc+Z1rSfAeunhsiXNVuexUmMacf8PdAY4/MSnTox7vnTa/3Z4X+EiMF5 WK+LKUPIUZ06TuU9RDMMnP8TlQCJPy+p7X8BwWUgCqcXKHvLJJNGPZ7RUFyL3J24IMuFLodJ7n 5/k4VlPPfdIqfJMKaXzAiNXx/K5GG1/i1PPJWG88Q7zSXfpLfZn1Kj8dIBf1ZKI/astLOi74sh /l6xpW2AZYncIG351NIZpr8QTDtl/l5CoGzy3zheNYWxecKHhp+FCLAeCnLTcGIFXnr+Tl+87b 5BI= X-SBRS: 2.7 X-MesageID: 3787825 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,338,1559534400"; d="scan'208";a="3787825" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:57 +0100 Message-ID: <20190802153606.32061-27-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 b9ca69f5f0..071880b855 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 Fri Aug 2 15:35:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E95D81399 for ; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8D4828613 for ; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCB9828872; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 267B5286DB for ; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwU-0005uc-3e; Fri, 02 Aug 2019 15:58: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 1htZwS-0005tm-Bq for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:04 +0000 X-Inumbo-ID: 4e4939a0-b53e-11e9-a1ad-ffb9cc75931d Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4e4939a0-b53e-11e9-a1ad-ffb9cc75931d; Fri, 02 Aug 2019 15:58:01 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: EZTo8lTXZmgTU+dMVYJ0BJxfwtTobgE3Ei6AvjuVQeqwtZ+w9sfzcSGDuSH3u2KdbIUDI3Frup Gac/wVGGQNFH4eqJf7lEIHW6WJva4tL/pNmBuAvDQi3vT4HeQ+gdd93eeFSQVtlT2SL0VNP9ve RMIkZcOjSxWuIAU/Vaiiq0+1MMVhiFTORYbrGNpM62r3ShF7yPOmQ0D4+wbdFuFZcc7I6JZlfp Dk3+kijOr0BfGbNpfz+T9/o9+5r30sWz4Hie6669B4rIoXo4Y2UCRO4c0XdmrsDQNMvIrS0Qly E18= X-SBRS: 2.7 X-MesageID: 3951219 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3951219" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:58 +0100 Message-ID: <20190802153606.32061-28-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 5c15a73a08..dd9934141f 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_lock libxl__ev_lock; 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, @@ -1592,8 +1593,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); @@ -2571,7 +2573,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 071880b855..503db6c260 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 Fri Aug 2 15:35:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB9321399 for ; Fri, 2 Aug 2019 15:59:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA83E28613 for ; Fri, 2 Aug 2019 15:59:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE42828872; Fri, 2 Aug 2019 15:59:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFB3228613 for ; Fri, 2 Aug 2019 15:59:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwk-0006G0-Pt; Fri, 02 Aug 2019 15:58:22 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwi-0006AN-6m for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:20 +0000 X-Inumbo-ID: 5784d0f8-b53e-11e9-8980-bc764e045a96 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 5784d0f8-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:17 +0000 (UTC) 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: M9oMceXj7vBExvf/ooJQ0YtkC+NKuIB339bDPGQuVersbVgQCMtzA1QTPMftsf3MpNCB9zf25v dom3nLaxRJNAHCL9AOJvRqmqPjAMKqf0ojox/pC4y8uDPb807toro67+0U8quIydV2QAZCd5Lx lLld6WsFfsxZIOtx4esqCkyiB0C8vRl6a+QFmchgcPNGP0GexwxQhJrdptH5YJ9OWgczEEbsy7 L+w9Azm2aYeDSOxCRYkh0jVHToUnzaLaaUO/T1S6RVxboHcPwnRiWC1nMThBO57JsWCmYF3fT8 qFg= X-SBRS: 2.7 X-MesageID: 3787841 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,338,1559534400"; d="scan'208";a="3787841" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:59 +0100 Message-ID: <20190802153606.32061-29-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 dd9934141f..277e322e09 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1981,7 +1981,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 503db6c260..3477f3aba6 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 c78ef4637d..38ba63d5b9 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 Fri Aug 2 15:36:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 207F017E0 for ; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 105AD28613 for ; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04A3F28876; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B8D8286DB for ; Fri, 2 Aug 2019 15:59:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwX-0005xT-ES; Fri, 02 Aug 2019 15:58:09 +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 1htZwV-0005vs-JV for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:07 +0000 X-Inumbo-ID: 4f42198a-b53e-11e9-9f66-bfeb907b07a4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4f42198a-b53e-11e9-9f66-bfeb907b07a4; Fri, 02 Aug 2019 15:58:03 +0000 (UTC) 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: N/1+5RGIHt0R9CTfuy+zTQP3BJ3FEFis3qiIUWqOhgv6OV/26UgNFtt2Qx1NmGDoW3/TIscFWu GE92YkzOD8jPL23D/h9HuJPpGav+VZfEtzW2zLyzIg0uMNQ34Y8UlxCdXS/MokZcO2VyJBl+/L 8BRRvezczTpw6mXJUHl9LIIMPgWHzwe1nkTjQYbSRaPDcpPWd2ZbZkze7jEV+vuyfH1HNgMYm5 /aPizX/a+7u6JcjhKfZIPfPC2NTgK0xbXeRgPUISfjU2JpzaGIzM4BpqCLP1UszF016hq0p7pH Etc= X-SBRS: 2.7 X-MesageID: 3931669 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,338,1559534400"; d="scan'208";a="3931669" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:00 +0100 Message-ID: <20190802153606.32061-30-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 f3c39fa86f..cd71900350 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 277e322e09..ca3d3c7090 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_lock libxl__ev_lock; 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, @@ -1596,7 +1597,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); @@ -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__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 @@ -3919,6 +3920,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 3477f3aba6..a5f700f0bf 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 Fri Aug 2 15:36:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA19817E0 for ; Fri, 2 Aug 2019 15:59:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B95B528613 for ; Fri, 2 Aug 2019 15:59:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACE2528872; Fri, 2 Aug 2019 15:59:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B8D6B28613 for ; Fri, 2 Aug 2019 15:59:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwn-0006Kp-FP; Fri, 02 Aug 2019 15:58:25 +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 1htZwl-0006Hd-NF for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:23 +0000 X-Inumbo-ID: 5a10cc76-b53e-11e9-b58a-734243b1be32 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5a10cc76-b53e-11e9-b58a-734243b1be32; Fri, 02 Aug 2019 15:58:22 +0000 (UTC) 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: JqPNpPvZKuLmcup7YZzxGt53j9Zomfs4TauNqrxjrz3+CgjnlPCY4h1IA82EKX1hf1fLN9XMpV zE7FiE6tyLXw8mVdDcx9J5uSfqFNbhkGz4b8sBKvvoRTI22osV4CIYiLfAnKJ54zpXpzmoAIH5 Fgbz8iTskuyBu/LI2BH0/d4tt/LTF1mptGp1drnN/4/2fe+K7EGZ3o9vO8HPh/StwXKIrgjiUn hXPszKNQMe2+1Dh6al68z9yjyixUCegi5CPoUdw2WKRWOlNd+azQxhRFrBLxQ6Yh7dtNWBQ5wb 3RA= X-SBRS: 2.7 X-MesageID: 3931690 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,338,1559534400"; d="scan'208";a="3931690" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:01 +0100 Message-ID: <20190802153606.32061-31-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Notes: In do_pci_remove, 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. (possible improvement) tools/libxl/libxl_internal.h | 2 - tools/libxl/libxl_pci.c | 219 +++++++++++++++++++++++++++++++++-- tools/libxl/libxl_qmp.c | 77 ------------ 3 files changed, 207 insertions(+), 91 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index ca3d3c7090..3e7cb4005d 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1983,8 +1983,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 a5f700f0bf..c4ac677f3d 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,160 @@ 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 + * comfirmed that the device is removed. */ + 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 +2045,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 +2092,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 +2109,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 +2133,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 +2163,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 +2191,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 38ba63d5b9..8fac737fad 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 Fri Aug 2 15:36:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C73617E0 for ; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CA4D28613 for ; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80CE128876; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B78228613 for ; Fri, 2 Aug 2019 15:59:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwx-0006dV-T8; Fri, 02 Aug 2019 15:58:35 +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 1htZww-0006aH-1j for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:34 +0000 X-Inumbo-ID: 60d1086e-b53e-11e9-8f4b-ffbcaae814cf Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 60d1086e-b53e-11e9-8f4b-ffbcaae814cf; Fri, 02 Aug 2019 15:58:32 +0000 (UTC) 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: xzcBt1ITsz0PlRLz7RLYxHuXGRC7tFnIqz5VT++3xWRx/laF06sl4wlnkVR2a1L9wah8J8Zy3s XPEa8+UdRDBM9zjQkHLUnJcpzz0gOyxywm75YmjopgzCN3H8o8CbVraZc9rh5kJvYPOjtgIV4B j+BAJXxY88PQg16bKELSa3Um0MCyRzE12PXYlTX/UFwZUf0Xp/+Rft3vsg5Wp/rP++bd8hBb51 NIf+ohhMZUwzEqJUqHL6TfNPug5ESrv+7EdbsluXB4i5A6s3bpl44k3ipLscmr2W2AzqDG1IdT 9jg= X-SBRS: 2.7 X-MesageID: 3787857 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,338,1559534400"; d="scan'208";a="3787857" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:02 +0100 Message-ID: <20190802153606.32061-32-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 cd71900350..08d3fc9fbc 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 3e7cb4005d..c6b9655af2 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1983,8 +1983,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 8fac737fad..40043a0a45 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 Fri Aug 2 15:36:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2300E1395 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10AAE28872 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 046E72887A; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4EF4728872 for ; Fri, 2 Aug 2019 15:59:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwj-0006Dg-MN; Fri, 02 Aug 2019 15:58:21 +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 1htZwg-00067y-MM for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:18 +0000 X-Inumbo-ID: 56d67ab0-b53e-11e9-a82f-d74d7edca8ec Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 56d67ab0-b53e-11e9-a82f-d74d7edca8ec; Fri, 02 Aug 2019 15:58:16 +0000 (UTC) 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: pbKiToo7/G4gAxD0gP+aXCl+MK+IX1CGSK/RyALmc+QmVjRvxCRVrnuL9hivfiWvcDF6kqvrVZ FRLHzXTmBDzPYbQtYZDiGNC30bXicw6NXwlgznegJ9G1ujlZgxZ9uhK8ZB4uz5Z0Z8Dl4rzbVY z9EQW+hswiJkCv1/+hQafrsDGYZsXD3P+2xtcdlFYpW3eMALtMu62CzYJcY0snYb83aBdTSeMv E9c5Wd9QTsDNyESpYHyfrqFqt9/vvCeGAVeWq1okAjoRNMuvBWIK8mvkxtsS9NA585XYUyI3+/ mW8= X-SBRS: 2.7 X-MesageID: 3787823 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,338,1559534400"; d="scan'208";a="3787823" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:03 +0100 Message-ID: <20190802153606.32061-33-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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" X-Virus-Scanned: ClamAV using ClamSMTP Removed libxl__qmp_cpu_add since it's not used anymore. `cpumap' arg of libxl__set_vcpuonline_xenstore is constified. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 205 ++++++++++++++++++++++++++--------- tools/libxl/libxl_internal.h | 2 - tools/libxl/libxl_qmp.c | 9 -- 3 files changed, 153 insertions(+), 63 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 08d3fc9fbc..4726e27d20 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,43 +1457,27 @@ 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) -{ - int i, rc; - libxl_bitmap current_map, final_map; - - 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; - } - } - - rc = 0; -out: - libxl_bitmap_dispose(¤t_map); - libxl_bitmap_dispose(&final_map); - return rc; -} +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, @@ -1501,11 +1485,22 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, { AO_CREATE(ctx, domid, ao_how); int rc, maxcpus; - libxl_dominfo info; + set_vcpuonline_state *svos; - libxl_dominfo_init(&info); + 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); + libxl_dominfo_init(&svos->info); + libxl_bitmap_init(&svos->final_map); - rc = libxl_domain_info(CTX, &info, domid); + /* Convenience aliases */ + libxl_dominfo *info = &svos->info; + libxl__ev_qmp *qmp = &svos->qmp; + + rc = libxl_domain_info(CTX, info, domid); if (rc < 0) { LOGED(ERROR, domid, "Getting domain info list"); goto out; @@ -1518,10 +1513,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 +1527,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 +1546,115 @@ 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); + const libxl__json_object *cpu; + 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); + libxl_bitmap_set_none(¤t_map); + + 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, qmp->domid, "Failed to retrieve CPU index."); + rc = ERROR_QEMU_API; + goto out; + } + + cpu_index = libxl__json_object_get_integer(o); + libxl_bitmap_set(¤t_map, cpu_index); + } + + + 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_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 c6b9655af2..03e99b23f5 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1987,8 +1987,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 40043a0a45..27183bc6c4 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 Fri Aug 2 15:36:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 537671395 for ; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 446B028613 for ; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38D4E2887A; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C51DA286DB for ; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZws-0006Sk-07; Fri, 02 Aug 2019 15:58:30 +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 1htZwq-0006Q9-ES for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:28 +0000 X-Inumbo-ID: 5c8cfe20-b53e-11e9-a756-af28f40f8b76 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5c8cfe20-b53e-11e9-a756-af28f40f8b76; Fri, 02 Aug 2019 15:58:26 +0000 (UTC) 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: 8tUW1R3M9FgMZ6W4R2LZpeBUCi7J9hhshiYdfJ9RdfgtfA11CmY1I+MLIX1re6H3ckaWntISkG J019ObP6MGqSlvBpnnb+qRIL/5qcR46dDJyLFqZLiTZmOH1JIfeyUpD0enS2llwNGj+dI/iUBe P+oEj86IjkV+fN5MsnV60ykcfBkNpyHUF+jU8csJ57/dc+JzlpmVrI+0J91LzTLXEbdJ1Q8Rfl lIdBSNOT2t1Bu5PWx9WYtF2Uxi73FlTO/sgwSRnWrOcFI14IJYszHFMQCbfIUp0KSuDN3qewQh Fmw= X-SBRS: 2.7 X-MesageID: 3911387 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,338,1559534400"; d="scan'208";a="3911387" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:04 +0100 Message-ID: <20190802153606.32061-34-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 33/35] libxl: Extract qmp_parse_query_cpus X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The QMP command "query-cpus" is called from different places, extract the algorithm that parse the answer into a separate function. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 69 ++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 4726e27d20..b97e874a9c 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1457,6 +1457,35 @@ static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid, return rc; } +static int qmp_parse_query_cpus(libxl__gc *gc, + libxl_domid domid, + const libxl__json_object *response, + libxl_bitmap *const map) +{ + int i; + const libxl__json_object *cpu; + + 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); + } + + return 0; +} + typedef struct set_vcpuonline_state { libxl__ev_qmp qmp; libxl__ev_time timeout; @@ -1466,18 +1495,14 @@ typedef struct set_vcpuonline_state { 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_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); + set_vcpuonline_state *svos, int rc); int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap, @@ -1493,6 +1518,7 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, 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); @@ -1556,7 +1582,6 @@ static void set_vcpuonline_qmp_cpus_queried(libxl__egc *egc, { EGC_GC; set_vcpuonline_state *svos = CONTAINER_OF(qmp, *svos, qmp); - const libxl__json_object *cpu; int i; libxl_bitmap current_map; @@ -1568,23 +1593,8 @@ static void set_vcpuonline_qmp_cpus_queried(libxl__egc *egc, if (rc) goto out; libxl_bitmap_alloc(CTX, ¤t_map, svos->info.vcpu_max_id + 1); - libxl_bitmap_set_none(¤t_map); - - 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, qmp->domid, "Failed to retrieve CPU index."); - rc = ERROR_QEMU_API; - goto out; - } - - cpu_index = libxl__json_object_get_integer(o); - libxl_bitmap_set(¤t_map, cpu_index); - } - + rc = qmp_parse_query_cpus(gc, qmp->domid, response, ¤t_map); + if (rc) goto out; libxl_bitmap_copy_alloc(CTX, final_map, svos->cpumap); @@ -1653,6 +1663,7 @@ static void set_vcpuonline_done(libxl__egc *egc, 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); } From patchwork Fri Aug 2 15:36:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E79361399 for ; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D83B728872 for ; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCB3B28877; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA9B828872 for ; Fri, 2 Aug 2019 15:59:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZw8-0005lY-MX; Fri, 02 Aug 2019 15:57:44 +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 1htZw7-0005lT-Mk for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:57:43 +0000 X-Inumbo-ID: 41901864-b53e-11e9-a0ec-5f7986644955 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 41901864-b53e-11e9-a0ec-5f7986644955; Fri, 02 Aug 2019 15:57:40 +0000 (UTC) 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: y3W7NMF+KWLERxRDL3PmPmo5OWlijjhHKY1LRJxtxtKonnU1JVAu3HdHrbj36KlCY5e7sDHUY+ mFAjN0z/JdI5f5oqjz7moFvqZ+L1yaqxnJa+KBGVjV+5IB8Vgk8az5kZE+EMUrhftOGm8WoToP dVlT8x+N40IHOFATNWXLNaS3+hSdKjVJ1VAYsWh1taRnfTGV7Y72t0FcoxlTupSjgStZ+HLnfq Pww/5BT7r4vFkVmrgEYMo7ThboPU5FGwWVUdYCeL4+tmQtG5FjMkCsBD1dJR7gqcoD83W0tEg2 mv0= X-SBRS: 2.7 X-MesageID: 3911343 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,338,1559534400"; d="scan'208";a="3911343" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:05 +0100 Message-ID: <20190802153606.32061-35-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 34/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" X-Virus-Scanned: ClamAV using ClamSMTP This was the last user of libxl__qmp_query_cpus which can now be removed. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- 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 b97e874a9c..6a8ffe10f0 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_lock ev_lock; + libxl_bitmap qemuu_cpus; +} retrieve_domain_configuration_state; + +static void retrieve_domain_configuration_lock_acquired( + libxl__egc *egc, libxl__ev_lock *, 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_lock_init(&rdcs->ev_lock); + rdcs->ev_lock.ao = ao; + rdcs->ev_lock.domid = domid; + rdcs->ev_lock.callback = retrieve_domain_configuration_lock_acquired; + libxl__ev_lock_get(egc, &rdcs->ev_lock); + return AO_INPROGRESS; +} + +static void retrieve_domain_configuration_lock_acquired( + libxl__egc *egc, libxl__ev_lock *ev_lock, int rc) +{ + retrieve_domain_configuration_state *rdcs = + CONTAINER_OF(ev_lock, *rdcs, ev_lock); + 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_unlock(gc, &rdcs->ev_lock); 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 03e99b23f5..9144bc202d 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1987,9 +1987,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 27183bc6c4..9639d491d9 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 Fri Aug 2 15:36:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B64691395 for ; Fri, 2 Aug 2019 15:59:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A58782887A for ; Fri, 2 Aug 2019 15:59:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99A2428877; Fri, 2 Aug 2019 15:59:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3EF4628872 for ; Fri, 2 Aug 2019 15:59:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwL-0005ob-PK; Fri, 02 Aug 2019 15:57:57 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwK-0005np-7m for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:57:56 +0000 X-Inumbo-ID: 4a78d4cb-b53e-11e9-8980-bc764e045a96 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4a78d4cb-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:57:55 +0000 (UTC) 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: /6TKK2qH5S5YElF3zwnOvD2vnWV1w9jTvnBMmkqf6FdWRB3RbWyPhDQewOhv3aOm5aPBzYLn18 OUBiWVNZWGoEz2PNbcK5ghH4Asmumgr18kd561LBb2VC1n796qMdA59gtzFFn/Qb25fceMy4ma Uuli3t5sNVOpGn8Ew04nwY5CfzGDGBf/o+kiPHVns+5UsuYy7b+xth58/nerb9VNxBZ6ql5m2H BLbajjkuveB+cYsfe7qMizwR7gDkErvwzEAvFQZ4MQO2uVMl7co+hTJQ7SB+Ud/9H5OIAohWLi 41o= X-SBRS: 2.7 X-MesageID: 3931659 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,338,1559534400"; d="scan'208";a="3931659" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:06 +0100 Message-ID: <20190802153606.32061-36-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 35/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" X-Virus-Scanned: ClamAV using ClamSMTP 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 9639d491d9..9aabad74fa 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