From patchwork Fri Oct 25 17:05: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: 11212721 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AF15112B for ; Fri, 25 Oct 2019 17:06:27 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9EAC20867 for ; Fri, 25 Oct 2019 17:06:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="bMmjkAGD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9EAC20867 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31S-0000Cr-U2; Fri, 25 Oct 2019 17:05:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31R-0000Cb-Kf for xen-devel@lists.xenproject.org; Fri, 25 Oct 2019 17:05:09 +0000 X-Inumbo-ID: 98c37f84-f749-11e9-a531-bc764e2007e4 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 98c37f84-f749-11e9-a531-bc764e2007e4; Fri, 25 Oct 2019 17:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1572023108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hZArzNpHpPpwto8C5wZO6UU0W8B8tHq5yuGtVwWY6b8=; b=bMmjkAGDa6JTmJlmm+dQFD8ELEWMVJKEBxFhfvQpxJD0B/YCK7IPm8Qi qaadBjLg2r67PDKu1S7cgG01om5DpF4rflmI/t28KzLAouwoMprmj/Xof UZQa2RPgW5rL2rui4LRmrMJWIL4pk4bTIcWWIKLa08ZDNXD54pKRLCrB9 o=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~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: kbhoLUtLxotktq8FBwJPiHdnAQhZlAT+4Q6jMNzKWpWiVyemnllm7htwrLG85rULg0pGON8CVs ZqYNIQVQFHVvFZ1wNsSMX871S2WWYhRp19+Jb+d172YUwGrsXtH57D4SocDaACqw6Bj5xaGMg7 PV921c1TWEDj5fkBPCiJtkoJctAaOXa1jM4jQwKmko4kFeaPkBRBdlWvKG8QxnSU56hnad/2ZR IP3xdagJbIn0jDoM7O7LoCs5xPJGXcqVNNmFBBc/tP26oP/3mYvg/UuWsKUoqcF8nfgIVE1+2g Z+8= X-SBRS: 2.7 X-MesageID: 7443687 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.68,229,1569297600"; d="scan'208";a="7443687" From: Anthony PERARD To: Date: Fri, 25 Oct 2019 18:05:02 +0100 Message-ID: <20191025170505.2834957-2-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191025170505.2834957-1-anthony.perard@citrix.com> References: <20191025170505.2834957-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC XEN PATCH for-4.13 1/4] libxl: Introduce libxl__ev_child_kill 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" Allow to kill a child and deregister the callback associated with it. The death isn't immediate will need to be collected later, so the ev_child machinery register its own callback. libxl__ev_child_kill() might be called by an AO operation that is finishing/cleaning up without a chance for libxl to be notified of the child death (via SIGCHLD). So it is possible that the application calls libxl_ctx_free() while there are still child around. To avoid the application getting unexpected SIGCHLD, the libxl__ao responsible for killing a child will have to wait until it has been properly reaped. Signed-off-by: Anthony PERARD --- tools/libxl/libxl_event.c | 3 +- tools/libxl/libxl_fork.c | 55 ++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 8 ++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index 0370b6acdd1c..f57c16da1fd9 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -1891,7 +1891,8 @@ static bool ao_work_outstanding(libxl__ao *ao) * decrement progress_reports_outstanding, and call * libxl__ao_complete_check_progress_reports. */ - return !ao->complete || ao->progress_reports_outstanding; + return !ao->complete || ao->progress_reports_outstanding + || ao->outstanding_killed_child; } void libxl__ao_complete_check_progress_reports(libxl__egc *egc, libxl__ao *ao) diff --git a/tools/libxl/libxl_fork.c b/tools/libxl/libxl_fork.c index eea3d5d4e68e..d99d40107f71 100644 --- a/tools/libxl/libxl_fork.c +++ b/tools/libxl/libxl_fork.c @@ -678,6 +678,61 @@ int libxl__ev_child_xenstore_reopen(libxl__gc *gc, const char *what) { return rc; } +typedef struct ev_child_killed { + libxl__ao *ao; + libxl__ev_child ch; +} ev_child_killed; +static void deregistered_child_callback(libxl__egc *, libxl__ev_child *, + pid_t, int status); + +/* + * Allow to send a SIGKILL signal to a child and deregister the death + * callback. + * state: Active/Idle -> Idle + */ +void libxl__ev_child_kill(libxl__ao *ao, libxl__ev_child *ch) +{ + AO_GC; + + if (!libxl__ev_child_inuse(ch)) + return; + + pid_t pid = ch->pid; + + ev_child_killed *new_ch = GCNEW(new_ch); + new_ch->ao = ao; + new_ch->ch.pid = pid; + new_ch->ch.callback = deregistered_child_callback; + LIBXL_LIST_INSERT_HEAD(&CTX->children, &new_ch->ch, entry); + ao->outstanding_killed_child++; + + LIBXL_LIST_REMOVE(ch, entry); + ch->pid = -1; + int r = kill(pid, SIGKILL); + if (r) + LOGE(ERROR, "failed to kill child [%ld]", + (unsigned long)pid); +} + +static void deregistered_child_callback(libxl__egc *egc, + libxl__ev_child *ch, + pid_t pid, + int status) +{ + ev_child_killed *ck = CONTAINER_OF(ch, *ck, ch); + EGC_GC; + + if (status) { + libxl_report_child_exitstatus(CTX, XTL_ERROR, + "killed fork (dying as expected)", + pid, status); + } else { + LOG(DEBUG, "killed child exit cleanly, unexpected"); + } + ck->ao->outstanding_killed_child--; + libxl__ao_complete_check_progress_reports(egc, ck->ao); +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index d2d5af746b50..5823890703ad 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -727,6 +727,7 @@ struct libxl__ao { libxl__poller *poller; uint32_t domid; LIBXL_TAILQ_ENTRY(libxl__ao) entry_for_callback; + int outstanding_killed_child; }; #define LIBXL_INIT_GC(gc,ctx) do{ \ @@ -1168,6 +1169,13 @@ static inline int libxl__ev_child_inuse(const libxl__ev_child *childw_out) * message>". */ _hidden int libxl__ev_child_xenstore_reopen(libxl__gc *gc, const char *what); +/* + * Allow to send a SIGKILL signal to a child and deregister the death + * callback. + * state: Active/Idle -> Idle + */ +_hidden void libxl__ev_child_kill(libxl__ao *ao, libxl__ev_child *ch); + /* * Other event-handling support provided by the libxl event core to From patchwork Fri Oct 25 17:05: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: 11212723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DE9513BD for ; Fri, 25 Oct 2019 17:06:27 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E98D72084C for ; Fri, 25 Oct 2019 17:06:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="K8P5vqr/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E98D72084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31T-0000D0-6t; Fri, 25 Oct 2019 17:05:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31R-0000Ch-Tv for xen-devel@lists.xenproject.org; Fri, 25 Oct 2019 17:05:09 +0000 X-Inumbo-ID: 9907aa56-f749-11e9-8aca-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9907aa56-f749-11e9-8aca-bc764e2007e4; Fri, 25 Oct 2019 17:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1572023108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eQNKxqrS2zcY6hc8GgmyvHkuncNCP0wD6X8ZyfLhupM=; b=K8P5vqr/ZbPW6SBuCy0A3lAeGb2FUcprbFtAs+4znO5jE221vCl4TlXr dJm8QNDpD0TqV7Ibu1xwH6jMpsjhekc6uFu3X9AKHjAnM1IWNCSsyXMn+ PXfLB7/vw4NcAO3o9qVhnSpZjqelmlAWcsPuZIZUeP3dpjzJDa/Y22r3F o=; 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 ip4:168.245.78.127 ~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: JR+eR7ViY7qRP2OcH3NO3hK9tS1Tg6nXawQvB7pU2Bj3QHKO57fYArKTMK5F3ZowaaL5k/d0iQ cUPmJMEVaGix/fBiZaBiDeENbl1WjAITM07iD7XM+rjrsdaATl74V975tZFDwZ/ib4xK44P7x+ hCI0LY7WAFZmWdh4PDOnDaJEzXjhXOnP2NIQEWmPkLRHWp1HfRjE+tnRFZOWUeqayA+BVOoR2Q iLGr8TiZGL2/GG9WzpTPzEmzxBj1zoIKvtvB7XgwxBpMtN3n7O94HgAi2JhGFWaFw6t0acyAnM dbM= X-SBRS: 2.7 X-MesageID: 7801960 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.68,229,1569297600"; d="scan'208";a="7801960" From: Anthony PERARD To: Date: Fri, 25 Oct 2019 18:05:03 +0100 Message-ID: <20191025170505.2834957-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191025170505.2834957-1-anthony.perard@citrix.com> References: <20191025170505.2834957-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC XEN PATCH for-4.13 2/4] libxl: Introduce libxl__ev_qmplock X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This lock will be used to prevent concurrent access the QEMU's QMP socket. It is based on libxl__ev_devlock implementation and have the same properties. There is one addition to the ev_devlock API, libxl__ev_qmplock_dispose, which allow to cancel the lock operation while it is in Active state. Signed-off-by: Anthony PERARD --- tools/libxl/libxl_internal.c | 31 ++++++++++++++++++++++++++++++- tools/libxl/libxl_internal.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 0750b69cba61..afbb01c5722f 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -583,17 +583,25 @@ void libxl__ev_devlock_init(libxl__ev_devlock *lock) lock->held = false; } +static void ev_lock_lock(libxl__egc *egc, libxl__ev_devlock *lock, + const char *userdata_userid); static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_devlock *lock); static void ev_lock_child_callback(libxl__egc *egc, libxl__ev_child *child, pid_t pid, int status); void libxl__ev_devlock_lock(libxl__egc *egc, libxl__ev_devlock *lock) +{ + ev_lock_lock(egc, lock, "libxl-device-changes-lock"); +} + +static void ev_lock_lock(libxl__egc *egc, libxl__ev_devlock *lock, + const char *userdata_userid) { STATE_AO_GC(lock->ao); const char *lockfile; lockfile = libxl__userdata_path(gc, lock->domid, - "libxl-device-changes-lock", "l"); + userdata_userid, "l"); if (!lockfile) goto out; lock->path = libxl__strdup(NOGC, lockfile); @@ -757,6 +765,27 @@ void libxl__ev_devlock_unlock(libxl__gc *gc, libxl__ev_devlock *lock) libxl__ev_devlock_init(lock); } +void libxl__ev_qmplock_init(libxl__ev_qmplock *lock) +{ + libxl__ev_devlock_init(lock); +} + +void libxl__ev_qmplock_lock(libxl__egc *egc, libxl__ev_qmplock *lock) +{ + ev_lock_lock(egc, lock, "qmp-socket-lock"); +} + +void libxl__ev_qmplock_unlock(libxl__gc *gc, libxl__ev_qmplock *lock) +{ + libxl__ev_devlock_unlock(gc, lock); +} + +void libxl__ev_qmplock_dispose(libxl__gc *gc, libxl__ev_qmplock *lock) +{ + libxl__ev_child_kill(lock->ao, &lock->child); + libxl__ev_devlock_unlock(gc, lock); +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 5823890703ad..115c79d034d4 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -197,6 +197,7 @@ typedef struct libxl__device_type libxl__device_type; typedef struct libxl__json_object libxl__json_object; typedef struct libxl__carefd libxl__carefd; typedef struct libxl__ev_devlock libxl__ev_devlock; +typedef struct libxl__ev_devlock libxl__ev_qmplock; typedef struct libxl__dm_resume_state libxl__dm_resume_state; typedef struct libxl__ao_device libxl__ao_device; typedef struct libxl__multidev libxl__multidev; @@ -4725,6 +4726,19 @@ _hidden void libxl__ev_devlock_init(libxl__ev_devlock *); _hidden void libxl__ev_devlock_lock(libxl__egc *, libxl__ev_devlock *); _hidden void libxl__ev_devlock_unlock(libxl__gc *, libxl__ev_devlock *); +/* libxl__ev_qmplock + * + * See "Lock for device hotplug, qmp_lock." as it is similar but is used + * to regulate access the QEMU's QMP socket. + * + * libxl__ev_qmplock_dispose: Idle/Active/LockAcquired -> Idle + * The callback will not be called anymore. + */ +_hidden void libxl__ev_qmplock_init(libxl__ev_qmplock *); +_hidden void libxl__ev_qmplock_lock(libxl__egc *, libxl__ev_qmplock *); +_hidden void libxl__ev_qmplock_unlock(libxl__gc *, libxl__ev_qmplock *); +_hidden void libxl__ev_qmplock_dispose(libxl__gc *, libxl__ev_qmplock *); + /* Send control commands over xenstore and wait for an Ack. */ _hidden int libxl__domain_pvcontrol(libxl__egc *egc, libxl__xswait_state *pvcontrol, From patchwork Fri Oct 25 17:05: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: 11212727 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7F0F112B for ; Fri, 25 Oct 2019 17:06:31 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B7BFB20867 for ; Fri, 25 Oct 2019 17:06:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="Bn/NoFOV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7BFB20867 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31U-0000Dv-KQ; Fri, 25 Oct 2019 17:05:12 +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 1iO31T-0000DG-R3 for xen-devel@lists.xenproject.org; Fri, 25 Oct 2019 17:05:11 +0000 X-Inumbo-ID: 9931babd-f749-11e9-94ca-12813bfff9fa Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9931babd-f749-11e9-94ca-12813bfff9fa; Fri, 25 Oct 2019 17:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1572023110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SmAc//pgooso4+IlFU4g65sc6VdhaWuiP3Q3tOeM35I=; b=Bn/NoFOVXfQdWrIgzi/6pJ//uwaoxT5O/lh29bH9IVAb82M+PqNRAFy1 2B3uZ7J0ZMcnXX1YI6fYbJ2IDXH1W4g3A1bPaN7SJbZy54e0zBrQnEwUo olbnRHSYdp7vJUOzYu2cydGDj1riDGw0cPQBJA45o0il/1gDF1CBbSJjz g=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~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: GvT8EENjJDgLGwzE6hwByoYetBAiFnelG06u8Cybdx+oCd91DzTbJRRv4QRQUfZPwhH/i9Sf0v O8r96eGvTPg0x4DUxwxA1l+wzYpsqxqm5QevKEq54q8xA5hVPWEwSx0BI7NtUWXKrMEyTYTcou amq0wPMfRdDMGGdI+USHBqeqgJVVFfgkgIGn3C2ssoNnkkDJdIuyIQSqasNakZUZ9ImRGPLLeW plY/wlTS5o4pf+b3I8O47r6IBXyOwusxQVwGtd6L+It6owG/2F5IbbV/CYms78gRKuHgmu/TXL wC4= X-SBRS: 2.7 X-MesageID: 7801962 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.68,229,1569297600"; d="scan'208";a="7801962" From: Anthony PERARD To: Date: Fri, 25 Oct 2019 18:05:04 +0100 Message-ID: <20191025170505.2834957-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191025170505.2834957-1-anthony.perard@citrix.com> References: <20191025170505.2834957-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC XEN PATCH for-4.13 3/4] libxl: libxl__ev_qmp_send now takes an egc 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" No functionnal changes. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_disk.c | 6 +++--- tools/libxl/libxl_dm.c | 8 ++++---- tools/libxl/libxl_dom_save.c | 2 +- tools/libxl/libxl_dom_suspend.c | 2 +- tools/libxl/libxl_domain.c | 8 ++++---- tools/libxl/libxl_internal.h | 2 +- tools/libxl/libxl_pci.c | 8 ++++---- tools/libxl/libxl_qmp.c | 10 +++++----- tools/libxl/libxl_usb.c | 28 ++++++++++++++++------------ 9 files changed, 39 insertions(+), 35 deletions(-) diff --git a/tools/libxl/libxl_disk.c b/tools/libxl/libxl_disk.c index 733ad284c866..7cbee3953320 100644 --- a/tools/libxl/libxl_disk.c +++ b/tools/libxl/libxl_disk.c @@ -776,7 +776,7 @@ static void cdrom_insert_lock_acquired(libxl__egc *egc, QMP_PARAMETERS_SPRINTF(&args, "device", "ide-%i", devid); cis->qmp.callback = cdrom_insert_ejected; - rc = libxl__ev_qmp_send(gc, &cis->qmp, "eject", args); + rc = libxl__ev_qmp_send(egc, &cis->qmp, "eject", args); if (rc) goto out; } else { cdrom_insert_ejected(egc, &cis->qmp, NULL, 0); /* must be last */ @@ -884,7 +884,7 @@ static void cdrom_insert_ejected(libxl__egc *egc, libxl_disk_format_to_string(disk->format), disk->pdev_path); qmp->callback = cdrom_insert_addfd_cb; - rc = libxl__ev_qmp_send(gc, qmp, "add-fd", args); + rc = libxl__ev_qmp_send(egc, qmp, "add-fd", args); if (rc) goto out; has_callback = true; } else { @@ -938,7 +938,7 @@ static void cdrom_insert_addfd_cb(libxl__egc *egc, libxl__qmp_param_add_string(gc, &args, "arg", libxl__qemu_disk_format_string(disk->format)); qmp->callback = cdrom_insert_inserted; - rc = libxl__ev_qmp_send(gc, qmp, "change", args); + rc = libxl__ev_qmp_send(egc, qmp, "change", args); out: if (rc) cdrom_insert_done(egc, cis, rc); /* must be last */ diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index c00356a2f16a..47cf6dda7ec1 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2650,7 +2650,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->qmp.callback = device_model_qmp_cb; dmss->qmp.domid = domid; dmss->qmp.payload_fd = -1; - rc = libxl__ev_qmp_send(gc, &dmss->qmp, "query-status", NULL); + rc = libxl__ev_qmp_send(egc, &dmss->qmp, "query-status", NULL); if (rc) goto out_close; } @@ -2808,7 +2808,7 @@ static void device_model_spawn_outcome(libxl__egc *egc, 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); + rc = libxl__ev_qmp_send(egc, &dmss->qmp, "query-chardev", NULL); if (rc) goto out; return; } @@ -2880,7 +2880,7 @@ static void device_model_postconfig_chardev(libxl__egc *egc, } qmp->callback = device_model_postconfig_vnc; - rc = libxl__ev_qmp_send(gc, qmp, "query-vnc", NULL); + rc = libxl__ev_qmp_send(egc, qmp, "query-vnc", NULL); if (rc) goto out; return; @@ -2940,7 +2940,7 @@ static void device_model_postconfig_vnc(libxl__egc *egc, 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); + rc = libxl__ev_qmp_send(egc, qmp, "change-vnc-password", args); if (rc) goto out; return; } diff --git a/tools/libxl/libxl_dom_save.c b/tools/libxl/libxl_dom_save.c index e70aa1585976..65610e6055a7 100644 --- a/tools/libxl/libxl_dom_save.c +++ b/tools/libxl/libxl_dom_save.c @@ -226,7 +226,7 @@ static void domain_suspend_switch_qemu_xen_logdirty 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); + rc = libxl__ev_qmp_send(egc, qmp, "xen-set-global-dirty-log", args); if (rc) goto out; return; diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.c index 248dbc33e384..940ac334f4b1 100644 --- a/tools/libxl/libxl_dom_suspend.c +++ b/tools/libxl/libxl_dom_suspend.c @@ -545,7 +545,7 @@ void libxl__dm_resume(libxl__egc *egc, qmp->domid = domid; qmp->callback = dm_resume_qmp_done; qmp->payload_fd = -1; - rc = libxl__ev_qmp_send(gc, qmp, "cont", NULL); + rc = libxl__ev_qmp_send(egc, qmp, "cont", NULL); if (rc) goto out; break; default: diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 9d0eb5aed11d..621df32c5dd8 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1600,7 +1600,7 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, 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); + rc = libxl__ev_qmp_send(egc, qmp, "query-cpus", NULL); if (rc) goto out; return AO_INPROGRESS; default: @@ -1666,7 +1666,7 @@ static void set_vcpuonline_qmp_add_cpu(libxl__egc *egc, 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); + rc = libxl__ev_qmp_send(egc, qmp, "cpu-add", args); if (rc) goto out; return; } @@ -1740,7 +1740,7 @@ static void domain_s3_resume(libxl__ao *ao, libxl__egc *egc, int domid) } break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc = libxl__ev_qmp_send(gc, qmp, "system_wakeup", NULL); + rc = libxl__ev_qmp_send(egc, qmp, "system_wakeup", NULL); if (rc) goto out; return; default: @@ -1958,7 +1958,7 @@ static void retrieve_domain_configuration_lock_acquired( 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); + rc = libxl__ev_qmp_send(egc, &rdcs->qmp, "query-cpus", NULL); if (rc) goto out; has_callback = true; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 115c79d034d4..ef6655587b79 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -421,7 +421,7 @@ typedef void libxl__ev_qmp_callback(libxl__egc *egc, libxl__ev_qmp *ev, int rc); _hidden void libxl__ev_qmp_init(libxl__ev_qmp *ev); -_hidden int libxl__ev_qmp_send(libxl__gc *gc, libxl__ev_qmp *ev, +_hidden int libxl__ev_qmp_send(libxl__egc *egc, libxl__ev_qmp *ev, const char *cmd, libxl__json_object *args); _hidden void libxl__ev_qmp_dispose(libxl__gc *gc, libxl__ev_qmp *ev); diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index b5444d15523a..0dc4a83e166d 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1163,7 +1163,7 @@ static void pci_add_qmp_device_add(libxl__egc *egc, pci_add_state *pas) 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); + rc = libxl__ev_qmp_send(egc, qmp, "device_add", args); if (rc) goto out; return; @@ -1182,7 +1182,7 @@ static void pci_add_qmp_device_add_cb(libxl__egc *egc, if (rc) goto out; qmp->callback = pci_add_qmp_query_pci_cb; - rc = libxl__ev_qmp_send(gc, qmp, "query-pci", NULL); + rc = libxl__ev_qmp_send(egc, qmp, "query-pci", NULL); if (rc) goto out; return; @@ -1997,7 +1997,7 @@ static void pci_remove_qmp_device_del(libxl__egc *egc, 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); + rc = libxl__ev_qmp_send(egc, &prs->qmp, "device_del", args); if (rc) goto out; return; @@ -2036,7 +2036,7 @@ static void pci_remove_qmp_retry_timer_cb(libxl__egc *egc, libxl__ev_time *ev, 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); + rc = libxl__ev_qmp_send(egc, &prs->qmp, "query-pci", NULL); if (rc) goto out; return; diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 9aabad74fabd..f0e0b50bd1c5 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -924,7 +924,7 @@ int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid, 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); + rc = libxl__ev_qmp_send(egc, &qmcs->qmp, "human-monitor-command", args); out: if (rc) return AO_CREATE_FAIL(rc); return AO_INPROGRESS; @@ -978,7 +978,7 @@ void libxl__qmp_suspend_save(libxl__egc *egc, ev->callback = dm_stopped; ev->payload_fd = -1; - rc = libxl__ev_qmp_send(gc, ev, "stop", NULL); + rc = libxl__ev_qmp_send(egc, ev, "stop", NULL); if (rc) goto error; @@ -1007,7 +1007,7 @@ static void dm_stopped(libxl__egc *egc, libxl__ev_qmp *ev, } ev->callback = dm_state_fd_ready; - rc = libxl__ev_qmp_send(gc, ev, "add-fd", NULL); + rc = libxl__ev_qmp_send(egc, ev, "add-fd", NULL); if (rc) goto error; @@ -1052,7 +1052,7 @@ static void dm_state_fd_ready(libxl__egc *egc, libxl__ev_qmp *ev, if (qmp_ev_qemu_compare_version(ev, 2, 11, 0) >= 0) libxl__qmp_param_add_bool(gc, &args, "live", dsps->live); QMP_PARAMETERS_SPRINTF(&args, "filename", "/dev/fdset/%d", fdset); - rc = libxl__ev_qmp_send(gc, ev, "xen-save-devices-state", args); + rc = libxl__ev_qmp_send(egc, ev, "xen-save-devices-state", args); if (rc) goto error; @@ -1781,7 +1781,7 @@ void libxl__ev_qmp_init(libxl__ev_qmp *ev) ev->qemu_version.micro = -1; } -int libxl__ev_qmp_send(libxl__gc *unused_gc, libxl__ev_qmp *ev, +int libxl__ev_qmp_send(libxl__egc *egc, libxl__ev_qmp *ev, const char *cmd, libxl__json_object *args) /* disconnected -> connecting * connected -> waiting_reply (with msg set) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 1fc7ccf41f86..da5e3708e6cf 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -349,9 +349,10 @@ 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, libxl__ev_qmp *qmp, +static int libxl__device_usbctrl_add_hvm(libxl__egc *egc, libxl__ev_qmp *qmp, libxl_device_usbctrl *usbctrl) { + EGC_GC; libxl__json_object *qmp_args = NULL; switch (usbctrl->version) { @@ -378,26 +379,28 @@ static int libxl__device_usbctrl_add_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, libxl__qmp_param_add_string(gc, &qmp_args, "id", GCSPRINTF("xenusb-%d", usbctrl->devid)); - return libxl__ev_qmp_send(gc, qmp, "device_add", qmp_args); + return libxl__ev_qmp_send(egc, qmp, "device_add", qmp_args); } /* Send qmp commands to delete a usb controller in qemu. */ -static int libxl__device_usbctrl_del_hvm(libxl__gc *gc, +static int libxl__device_usbctrl_del_hvm(libxl__egc *egc, libxl__ev_qmp *qmp, int devid) { + EGC_GC; libxl__json_object *qmp_args = NULL; libxl__qmp_param_add_string(gc, &qmp_args, "id", GCSPRINTF("xenusb-%d", devid)); - return libxl__ev_qmp_send(gc, qmp, "device_del", qmp_args); + return libxl__ev_qmp_send(egc, qmp, "device_del", qmp_args); } /* Send qmp commands to create a usb device in qemu. */ -static int libxl__device_usbdev_add_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, +static int libxl__device_usbdev_add_hvm(libxl__egc *egc, libxl__ev_qmp *qmp, libxl_device_usbdev *usbdev) { + EGC_GC; libxl__json_object *qmp_args = NULL; libxl__qmp_param_add_string(gc, &qmp_args, "id", @@ -413,20 +416,21 @@ static int libxl__device_usbdev_add_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, 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); + return libxl__ev_qmp_send(egc, qmp, "device_add", qmp_args); } /* Send qmp commands to delete a usb device in qemu. */ -static int libxl__device_usbdev_del_hvm(libxl__gc *gc, libxl__ev_qmp *qmp, +static int libxl__device_usbdev_del_hvm(libxl__egc *egc, libxl__ev_qmp *qmp, libxl_device_usbdev *usbdev) { + EGC_GC; libxl__json_object *qmp_args = NULL; libxl__qmp_param_add_string(gc, &qmp_args, "id", GCSPRINTF("xenusb-%d-%d", usbdev->u.hostdev.hostbus, usbdev->u.hostdev.hostaddr)); - return libxl__ev_qmp_send(gc, qmp, "device_del", qmp_args); + return libxl__ev_qmp_send(egc, qmp, "device_del", qmp_args); } static LIBXL_DEFINE_UPDATE_DEVID(usbctrl) @@ -490,7 +494,7 @@ static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, qmp->domid = domid; qmp->payload_fd = -1; qmp->callback = device_usbctrl_add_qmp_cb; - rc = libxl__device_usbctrl_add_hvm(gc, qmp, usbctrl); + rc = libxl__device_usbctrl_add_hvm(egc, qmp, usbctrl); if (rc) goto outrm; return; } @@ -647,7 +651,7 @@ static void device_usbctrl_usbdevs_removed(libxl__egc *egc, qmp->domid = aodev->dev->domid; qmp->callback = device_usbctrl_remove_qmp_cb; qmp->payload_fd = -1; - rc = libxl__device_usbctrl_del_hvm(gc, qmp, aodev->dev->devid); + rc = libxl__device_usbctrl_del_hvm(egc, qmp, aodev->dev->devid); if (rc) goto out; return; } @@ -1797,7 +1801,7 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, 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); + rc = libxl__device_usbdev_add_hvm(egc, &aodev->qmp, usbdev); if (rc) { libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, LIBXL_USBCTRL_TYPE_DEVICEMODEL); @@ -1979,7 +1983,7 @@ static void libxl__device_usbdev_remove(libxl__egc *egc, uint32_t domid, 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); + rc = libxl__device_usbdev_del_hvm(egc, &aodev->qmp, usbdev); if (rc) { libxl__device_usbdev_add_xenstore(gc, domid, usbdev, LIBXL_USBCTRL_TYPE_DEVICEMODEL, From patchwork Fri Oct 25 17:05: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: 11212729 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 62F4F112B for ; Fri, 25 Oct 2019 17:06:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32B8820867 for ; Fri, 25 Oct 2019 17:06:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="QzKjjxUx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32B8820867 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31X-0000FG-Tc; Fri, 25 Oct 2019 17:05:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31W-0000En-K3 for xen-devel@lists.xenproject.org; Fri, 25 Oct 2019 17:05:14 +0000 X-Inumbo-ID: 99df8d54-f749-11e9-8aca-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 99df8d54-f749-11e9-8aca-bc764e2007e4; Fri, 25 Oct 2019 17:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1572023109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IF2jPDNtvh5oIUB6R7x7BJzJR24lsWGIp7A/ZN2ODJ8=; b=QzKjjxUx9pqLpR7R/SH715u58k+aMdj+CyB7S8uk2oJGxPJAv39zxhDq K42OhNetu2syMAV6kK62AyY/C8oTRAI3Ft3hkEgTts63fWymAAxeB3pSH z2vtZu86yDd5QjSkiwKgDci58qfudlwddJHEZdPBrfOIUo5qR9nwZHwM1 0=; 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 ip4:168.245.78.127 ~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: 4b0kYyL+obajI34/AlfhAcEcam6FsYEfV6Ch+olJIm+0HHfpS0BcZL5xfXec/tIG2F/PUR8ZPK 0Xwquwk9b0LO4xMPYTu1l85LH7LuqvnUhaHRJ8foR0FNyTvxjjOIOkO1xIq1EbeOIYtDUgzruR d9pyhaBmQGe29bXLzfn6mlg+atEyIKPm2WNu4TntCIUFeVDp5Z+xbAw5vTlP5vKhPbMnFQAhuP hGqyzksVFUgFZQo9Lwmqkw9YpwRxjixJieQ5ouCmcVhW0h2QSr8VxejQnaXTUGWwPZhF80yRdU av4= X-SBRS: 2.7 X-MesageID: 7801961 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.68,229,1569297600"; d="scan'208";a="7801961" From: Anthony PERARD To: Date: Fri, 25 Oct 2019 18:05:05 +0100 Message-ID: <20191025170505.2834957-5-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191025170505.2834957-1-anthony.perard@citrix.com> References: <20191025170505.2834957-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC XEN PATCH for-4.13 4/4] libxl_qmp: Have a lock for QMP socket access 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" FIXME: The case where something failed when trying to acquired the lock isn't handled yet. This patch workaround the fact that it's not possible to connect multiple time to a single QMP socket. QEMU listen on the socket with a backlog value of 1, which mean that on Linux when concurrent thread call connect() on the socket, they get EAGAIN. To work around this, we use a new lock. Signed-off-by: Anthony PERARD --- tools/libxl/libxl_internal.h | 29 ++++++++++------ tools/libxl/libxl_qmp.c | 65 +++++++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index ef6655587b79..d650188586e9 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -364,6 +364,18 @@ struct libxl__ev_child { LIBXL_LIST_ENTRY(struct libxl__ev_child) entry; }; +struct libxl__ev_devlock { + /* filled by user */ + libxl__ao *ao; + libxl_domid domid; + void (*callback)(libxl__egc *, libxl__ev_devlock *, int rc); + /* private to libxl__ev_devlock* */ + libxl__ev_child child; + char *path; /* path of the lock file itself */ + int fd; + bool held; +}; + /* * QMP asynchronous calls * @@ -428,6 +440,8 @@ _hidden void libxl__ev_qmp_dispose(libxl__gc *gc, libxl__ev_qmp *ev); typedef enum { /* initial state */ qmp_state_disconnected = 1, + /* waiting for lock */ + qmp_state_waiting_lock, /* connected to QMP socket, waiting for greeting message */ qmp_state_connecting, /* qmp_capabilities command sent, waiting for reply */ @@ -461,6 +475,7 @@ struct libxl__ev_qmp { libxl__carefd *cfd; libxl__ev_fd efd; libxl__qmp_state state; + libxl__ev_qmplock lock; int id; int next_id; /* next id to use */ /* receive buffer */ @@ -4686,6 +4701,9 @@ static inline const char *libxl__qemu_qmp_path(libxl__gc *gc, int domid) * which may take a significant amount time. * It is to be acquired by an ao event callback. * + * If libxl__ev_devlock is needed, it should be acquired while every + * libxl__ev_qmp are Idle for the current domain. + * * It is to be acquired when adding/removing devices or making changes * to them when this is a slow operation and json_lock isn't appropriate. * @@ -4711,17 +4729,6 @@ static inline const char *libxl__qemu_qmp_path(libxl__gc *gc, int domid) * callback: When called: Active -> LockAcquired (on error: Idle) * The callback is only called once. */ -struct libxl__ev_devlock { - /* filled by user */ - libxl__ao *ao; - libxl_domid domid; - void (*callback)(libxl__egc *, libxl__ev_devlock *, int rc); - /* private to libxl__ev_devlock* */ - libxl__ev_child child; - char *path; /* path of the lock file itself */ - int fd; - bool held; -}; _hidden void libxl__ev_devlock_init(libxl__ev_devlock *); _hidden void libxl__ev_devlock_lock(libxl__egc *, libxl__ev_devlock *); _hidden void libxl__ev_devlock_unlock(libxl__gc *, libxl__ev_devlock *); diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index f0e0b50bd1c5..1ac50a95a42d 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -1084,6 +1084,7 @@ static void dm_state_saved(libxl__egc *egc, libxl__ev_qmp *ev, * * qmp_state External cfd efd id rx_buf* tx_buf* msg* * disconnected Idle NULL Idle reset free free free + * waiting_lock Active open Idle reset used free set * connecting Active open IN reset used free set * cap.neg Active open IN|OUT sent used cap_neg set * cap.neg Active open IN sent used free set @@ -1153,6 +1154,10 @@ static void qmp_ev_ensure_reading_writing(libxl__gc *gc, libxl__ev_qmp *ev) { short events = POLLIN; + if (ev->state == qmp_state_waiting_lock) + /* We can't modifie the efd yet, as it isn't registered. */ + return; + if (ev->tx_buf) events |= POLLOUT; else if ((ev->state == qmp_state_waiting_reply) && ev->msg) @@ -1168,9 +1173,13 @@ static void qmp_ev_set_state(libxl__gc *gc, libxl__ev_qmp *ev, switch (new_state) { case qmp_state_disconnected: break; - case qmp_state_connecting: + case qmp_state_waiting_lock: assert(ev->state == qmp_state_disconnected); break; + case qmp_state_connecting: + assert(ev->state == qmp_state_disconnected || + ev->state == qmp_state_waiting_lock); + break; case qmp_state_capability_negotiation: assert(ev->state == qmp_state_connecting); break; @@ -1231,20 +1240,20 @@ static int qmp_error_class_to_libxl_error_code(libxl__gc *gc, /* Setup connection */ -static int qmp_ev_connect(libxl__gc *gc, libxl__ev_qmp *ev) +static void qmp_ev_lock_aquired(libxl__egc *, libxl__ev_qmplock *, int rc); + +static int qmp_ev_connect(libxl__egc *egc, libxl__ev_qmp *ev) /* disconnected -> connecting but with `msg` free * on error: broken */ { + EGC_GC; int fd; - int rc, r; - struct sockaddr_un un; - const char *qmp_socket_path; - - assert(ev->state == qmp_state_disconnected); + int rc; - qmp_socket_path = libxl__qemu_qmp_path(gc, ev->domid); + /* Convenience aliases */ + libxl__ev_qmplock *lock = &ev->lock; - LOGD(DEBUG, ev->domid, "Connecting to %s", qmp_socket_path); + assert(ev->state == qmp_state_disconnected); libxl__carefd_begin(); fd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -1258,6 +1267,35 @@ static int qmp_ev_connect(libxl__gc *gc, libxl__ev_qmp *ev) if (rc) goto out; + qmp_ev_set_state(gc, ev, qmp_state_waiting_lock); + + lock->ao = ev->ao; + lock->domid = ev->domid; + lock->callback = qmp_ev_lock_aquired; + libxl__ev_qmplock_lock(egc, &ev->lock); + + return 0; + +out: + return rc; +} + +static void qmp_ev_lock_aquired(libxl__egc *egc, libxl__ev_qmplock *lock, + int rc) +{ + libxl__ev_qmp *ev = CONTAINER_OF(lock, *ev, lock); + EGC_GC; + const char *qmp_socket_path; + struct sockaddr_un un; + int r; + + if (rc) + goto out; + + qmp_socket_path = libxl__qemu_qmp_path(gc, ev->domid); + + LOGD(DEBUG, ev->domid, "Connecting to %s", qmp_socket_path); + rc = libxl__prepare_sockaddr_un(gc, &un, qmp_socket_path, "QMP socket"); if (rc) @@ -1279,10 +1317,10 @@ static int qmp_ev_connect(libxl__gc *gc, libxl__ev_qmp *ev) qmp_ev_set_state(gc, ev, qmp_state_connecting); - return 0; + return; out: - return rc; + LOGD(ERROR, ev->domid, "connect failed"); } /* QMP FD callbacks */ @@ -1779,6 +1817,8 @@ void libxl__ev_qmp_init(libxl__ev_qmp *ev) ev->qemu_version.major = -1; ev->qemu_version.minor = -1; ev->qemu_version.micro = -1; + + libxl__ev_qmplock_init(&ev->lock); } int libxl__ev_qmp_send(libxl__egc *egc, libxl__ev_qmp *ev, @@ -1798,7 +1838,7 @@ int libxl__ev_qmp_send(libxl__egc *egc, libxl__ev_qmp *ev, /* Connect to QEMU if not already connected */ if (ev->state == qmp_state_disconnected) { - rc = qmp_ev_connect(gc, ev); + rc = qmp_ev_connect(egc, ev); if (rc) goto error; } @@ -1830,6 +1870,7 @@ void libxl__ev_qmp_dispose(libxl__gc *gc, libxl__ev_qmp *ev) libxl__ev_fd_deregister(gc, &ev->efd); libxl__carefd_close(ev->cfd); + libxl__ev_qmplock_dispose(gc, &ev->lock); libxl__ev_qmp_init(ev); }