From nobody Sun May 5 00:34:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574097277; cv=none; d=zoho.com; s=zohoarc; b=Qi4V1Y45Sk5ytl2T35QXVEzzv/JyoWHu1g2kF3FOwD9GKn0b5KXDFc2uPr6XIfgTVoeBVXEXZttskw4UsepJAZ+7hG6ZhsXxkaaHFDnMBa/i4o5HX5uOVjsWwjZ5QpkP9vtHVt3QOPHNJ1tkZF/dmtQGpt2WWmDYseEldc29h5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574097277; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qd/FnsivVejZp7KsMK+wJKxMQzVlpYHZhF9KRb60QW0=; b=Zy2cLI2YTOVEcBy49uUDa78a2Y+HFw5GidBOwhua3AEZ0D7PZQlqwoZY0AOS2KiKYoUN4fa8WBSkLDcZdCD7KoEJSkyDcAp1PHospVA4ceHf0sw99xPjhIasfMpNWLC/ZDWMHaTzZ6ck8MbOl7mA6bDG/1QT72LW6sxKurN/LlU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 15740972775391015.1335755768482; Mon, 18 Nov 2019 09:14:37 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkap-00069G-Nl; Mon, 18 Nov 2019 17:13:39 +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 1iWkao-00068c-Dt for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 17:13:38 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b5d7699c-0a26-11ea-a2dc-12813bfff9fa; Mon, 18 Nov 2019 17:13:16 +0000 (UTC) X-Inumbo-ID: b5d7699c-0a26-11ea-a2dc-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574097196; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OPSYj/yytfjcIu6uS+v5Pj35ycSoLt2eaB7Pwu1ehiw=; b=Pih5VVFlkTUNCQ7mfBI/UhtN0iJgtyXpw+2XBvVw280tZHbO+wpuXkGi UKolnJOlrdIytkglPwwaT4pvrEG7rMdhRXkSvwRb7+vqpTQVkFiQGf6pj 2wUWkyXKoCol1uIpOtyAg9hw/eeDROPXw1VEDTkV/11XDA3nw6NJrK2VR I=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 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: QaqZEGu9bwQ7mP35um94W7HpUttL+SP+9SeJmkNjHdP5RKXYT0G+1e3QappyQE06NUsNLvOuc9 Je+Z+1BD6EEtElBrXTSx6BIv70bk2RNgl2pe7QMBLcD5rxcmWTrOUEiTyZf48mZiSY1uz7v48q DDwqkRxYghZvhmYtWQS06gHluRfDuAdpKeEHBM//oId88cJwkR/78bm76OCglZA1QWdkVtf5iV IBQ2SAaHoYgBwnVvpGCRM//Hw/2isWTn6Xd9rlt/Rt4ApADkkuUQePnery1MBUjLcpS8CBaK2A xx4= X-SBRS: 2.7 X-MesageID: 8888856 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,320,1569297600"; d="scan'208";a="8888856" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 17:13:02 +0000 Message-ID: <20191118171309.1459302-2-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118171309.1459302-1-anthony.perard@citrix.com> References: <20191118171309.1459302-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v3 1/7] libxl: Introduce libxl__ev_child_kill_deregister X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Allow to deregister the callback associated with a child death event. The death isn't immediate will need to be collected later, so the ev_child machinery register its own callback. libxl__ev_child_kill_deregister() 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 Acked-by: Ian Jackson --- Notes: v2: - Rename new fn to libxl__ev_child_kill_deregister - Rework documentation of the new API and if ev_child - Add debug log in libxl__ao_complete - Always call libxl_report_child_exitstatus() in child callback. tools/libxl/libxl_event.c | 6 ++++- tools/libxl/libxl_fork.c | 48 ++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 15 ++++++++--- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index 0370b6acdd1c..43155368de76 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -1878,6 +1878,9 @@ void libxl__ao_complete(libxl__egc *egc, libxl__ao *a= o, int rc) ao->complete =3D 1; ao->rc =3D rc; LIBXL_LIST_REMOVE(ao, inprogress_entry); + if (ao->outstanding_killed_child) + LOG(DEBUG, "ao %p: .. but waiting for %d fork to exit", + ao, ao->outstanding_killed_child); libxl__ao_complete_check_progress_reports(egc, ao); } =20 @@ -1891,7 +1894,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; } =20 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..0f1b6b518c5c 100644 --- a/tools/libxl/libxl_fork.c +++ b/tools/libxl/libxl_fork.c @@ -678,6 +678,54 @@ int libxl__ev_child_xenstore_reopen(libxl__gc *gc, con= st char *what) { return rc; } =20 +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); + +void libxl__ev_child_kill_deregister(libxl__ao *ao, libxl__ev_child *ch, + int sig) +{ + AO_GC; + + if (!libxl__ev_child_inuse(ch)) + return; + + pid_t pid =3D ch->pid; + + ev_child_killed *new_ch =3D GCNEW(new_ch); + new_ch->ao =3D ao; + new_ch->ch.pid =3D pid; + new_ch->ch.callback =3D deregistered_child_callback; + LIBXL_LIST_INSERT_HEAD(&CTX->children, &new_ch->ch, entry); + ao->outstanding_killed_child++; + + LIBXL_LIST_REMOVE(ch, entry); + ch->pid =3D -1; + int r =3D kill(pid, sig); + if (r) + LOGED(ERROR, ao->domid, + "failed to kill child [%ld] with signal %d", + (unsigned long)pid, sig); +} + +static void deregistered_child_callback(libxl__egc *egc, + libxl__ev_child *ch, + pid_t pid, + int status) +{ + ev_child_killed *ck =3D CONTAINER_OF(ch, *ck, ch); + EGC_GC; + + libxl_report_child_exitstatus(CTX, XTL_ERROR, + "killed fork (dying as expected)", + pid, status); + 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 6a614658c25d..4e433e110664 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -730,6 +730,7 @@ struct libxl__ao { libxl__poller *poller; uint32_t domid; LIBXL_TAILQ_ENTRY(libxl__ao) entry_for_callback; + int outstanding_killed_child; }; =20 #define LIBXL_INIT_GC(gc,ctx) do{ \ @@ -1155,9 +1156,14 @@ _hidden int libxl__ctx_evtchn_init(libxl__gc *gc); /= * for libxl_ctx_alloc */ * The parent may signal the child but it must not reap it. That will * be done by the event machinery. * - * It is not possible to "deregister" the child death event source. - * It will generate exactly one event callback; until then the childw - * is Active and may not be reused. + * The child death event will generate exactly one event callback; until + * then the childw is Active and may not be reused. + * + * libxl__ev_child_kill_deregister: Active -> Idle + * This will transfer ownership of the child process death event from + * `ch' to `ao', thus deregister the callback. + * The `ao' completion will wait until the child have been reaped by the + * event machinery. */ _hidden pid_t libxl__ev_child_fork(libxl__gc *gc, libxl__ev_child *childw_= out, libxl__ev_child_callback *death); @@ -1165,6 +1171,9 @@ static inline void libxl__ev_child_init(libxl__ev_chi= ld *childw_out) { childw_out->pid =3D -1; } static inline int libxl__ev_child_inuse(const libxl__ev_child *childw_out) { return childw_out->pid >=3D 0; } +_hidden void libxl__ev_child_kill_deregister(libxl__ao *ao, + libxl__ev_child *ch, + int sig); =20 /* Useable (only) in the child to once more make the ctx useable for * xenstore operations. logs failure in the form "what: (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 157409725668834.47841133247323; Mon, 18 Nov 2019 09:14:16 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkaV-0005z6-UH; Mon, 18 Nov 2019 17:13:19 +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 1iWkaU-0005yk-DQ for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 17:13:18 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b31107c2-0a26-11ea-a2db-12813bfff9fa; Mon, 18 Nov 2019 17:13:12 +0000 (UTC) X-Inumbo-ID: b31107c2-0a26-11ea-a2db-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574097192; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fnczp/eF3UyJbsIgVIcl4ET7CKgMkGsOqy37uq5fk9Y=; b=SzFAldN4M5gvGTfj60XHeQdmFESGfBlPUTorMETnNnrBT5qnO07rOHpE 9FFnbHSGI6PVFDkiv9+/YMoWbRTu9K0ZFzQo1vW511qpc+FGWnBBHRdr9 Y7SkLl/ke3ISQMMy9CO5ES8O8vRIQxrEv+YyiDUjsg7Wg0u6TwhHOJGor Q=; 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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (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 ip4:168.245.78.127 ~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: Not/o9/MWKXQSn/XCohsXADDyhLz8tsad28G+7pnHcazzscrMhwCdseTq17X5mUqXU2MSw8Qoz 2JzgjAvzybpbXWWyKMMdQcDluo8dAQOcBz9w2FoIV4jTRboSkR0FFuLOsd04LFZ7HAYUqQ6RlU OZRgkx2guHxOmT4BxuPuBGkhe+tFtkxsMunDzP2i4eoYRuCfU7uWZ3geX9qLqIrLBgxX4W812+ 8sOnX6At808hDlmyVk+Sbiisa842a4Bv4YtLV4rZaAJzBTMeShVBXkiW51nyunyShaqdBMQ79B LCE= X-SBRS: 2.7 X-MesageID: 8833204 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.68,320,1569297600"; d="scan'208";a="8833204" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 17:13:03 +0000 Message-ID: <20191118171309.1459302-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118171309.1459302-1-anthony.perard@citrix.com> References: <20191118171309.1459302-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v3 2/7] libxl: Move libxl__ev_devlock declaration X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We are going to want to include libxl__ev_devlock into libxl__ev_qmp. No functional changes. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: New patch in v2: Move of the struct was done in "libxl_qmp: Have a lock for QMP socket access" before. tools/libxl/libxl_internal.h | 96 ++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 4e433e110664..69d572c1866a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -363,6 +363,54 @@ struct libxl__ev_child { LIBXL_LIST_ENTRY(struct libxl__ev_child) entry; }; =20 +/* + * Lock for device hotplug, qmp_lock. + * + * libxl__ev_devlock implement a lock that is outside of CTX_LOCK in the + * lock hierarchy. It can be used when one want to make QMP calls to QEMU, + * which may take a significant amount time. + * It is to be acquired by an ao event callback. + * + * 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. + * + * Possible states of libxl__ev_devlock: + * Undefined + * Might contain anything. + * Idle + * Struct contents are defined enough to pass to any + * libxl__ev_devlock_* function. + * The struct does not contain references to any allocated private + * resources so can be thrown away. + * Active + * Waiting to get a lock. + * Needs to wait until the callback is called. + * LockAcquired + * libxl__ev_devlock_unlock will need to be called to release the lock + * and the resources of libxl__ev_devlock. + * + * libxl__ev_devlock_init: Undefined/Idle -> Idle + * libxl__ev_devlock_lock: Idle -> Active + * May call callback synchronously. + * libxl__ev_devlock_unlock: LockAcquired/Idle -> Idle + * 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 *); + /* * QMP asynchronous calls * @@ -4689,54 +4737,6 @@ static inline const char *libxl__qemu_qmp_path(libxl= __gc *gc, int domid) return GCSPRINTF("%s/qmp-libxl-%d", libxl__run_dir_path(), domid); } =20 -/* - * Lock for device hotplug, qmp_lock. - * - * libxl__ev_devlock implement a lock that is outside of CTX_LOCK in the - * lock hierarchy. It can be used when one want to make QMP calls to QEMU, - * which may take a significant amount time. - * It is to be acquired by an ao event callback. - * - * 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. - * - * Possible states of libxl__ev_devlock: - * Undefined - * Might contain anything. - * Idle - * Struct contents are defined enough to pass to any - * libxl__ev_devlock_* function. - * The struct does not contain references to any allocated private - * resources so can be thrown away. - * Active - * Waiting to get a lock. - * Needs to wait until the callback is called. - * LockAcquired - * libxl__ev_devlock_unlock will need to be called to release the lock - * and the resources of libxl__ev_devlock. - * - * libxl__ev_devlock_init: Undefined/Idle -> Idle - * libxl__ev_devlock_lock: Idle -> Active - * May call callback synchronously. - * libxl__ev_devlock_unlock: LockAcquired/Idle -> Idle - * 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 *); - /* Send control commands over xenstore and wait for an Ack. */ _hidden int libxl__domain_pvcontrol(libxl__egc *egc, libxl__xswait_state *pvcontrol, --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 00:34:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574097277; cv=none; d=zoho.com; s=zohoarc; b=fUnm+WIO71tasK0n+17uv1phmeYFcMnGC3Lx6iZGyF576wKQun29I6tjAB6PghHApVv4acny3oefW8ze4TD6yZvJuMVdzPNjbFowRzrZq1zICoz2As2/OCvRPcc/6d0uxTEbTaTLTs6M7rpYImJBPN9YvZo+Vps701W+/B4YOzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574097277; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uHelUa+TK2+D42enUkmdK5JcgmbW/3SWWZP/C6D1cEw=; b=Sb4H274QadCh5rWzsFWHl4AqWEgFT7CgpoJk6rwhbxKH4rZJfg6i/p+S2Se/Xtr4V385RI6itwucZ+9epzHG7ryYymk0Bf5XnxdXo2VMKWeooGJP6FF2bmmEx9I0peH8jb383hJPgSSFi/dMg9tKwD4I5VeKIjC/2a1fSlqCkIo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1574097277921569.731330021607; Mon, 18 Nov 2019 09:14:37 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkal-00066r-AX; Mon, 18 Nov 2019 17:13: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 1iWkaj-000664-EA for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 17:13:33 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b3ddfcfc-0a26-11ea-a2db-12813bfff9fa; Mon, 18 Nov 2019 17:13:14 +0000 (UTC) X-Inumbo-ID: b3ddfcfc-0a26-11ea-a2db-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574097194; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/ouj6bW0SGvRR2QWjz+CdUL7YluiHlGCFzA8U5WHgLc=; b=aJWdz8PQnimTLQulwZrKvpYQEtcSW7z7p+Z1TM5ix/EuW2xWJCLZpsMp VPg541CLtPK8T1LawkbA0PIS4tiQQBUr3tdA1FOVIGy54Wwr2qj/Mc9eH MYyeX/kst4eSu6Vowajk7S39qYGmLoT9k09mP+jpSuOFRFXz5zQH4Lcb1 s=; 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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (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 ip4:168.245.78.127 ~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: R0jceBMNmZHKyfQqjewQaY9bBBhIWVKWLpxmoqBgJaZwIcXfFV1CT0ABmX2igFfBuO5IVaNIJC s1M3CrHsgDf1Ojb3eu6axmvGBMPDOhg+r/Bic3jG4bYaD5tt2DiwBYIpWAKlbJO5cKF+R81KUz g1DRB1jBPwGV4tpf2dltW9UEt+Yw2ZOSxmgHFYzifmA2exN4y5gxpHfVpG8/rclMQa+ESpQndS XqxV5TsLLYPbaszJl8P303l1hLtbS16ofJUZyakAILTYRf1cq8r6vfOhIsKwP2+uA8ZPn9dELi RqI= X-SBRS: 2.7 X-MesageID: 8833205 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.68,320,1569297600"; d="scan'208";a="8833205" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 17:13:04 +0000 Message-ID: <20191118171309.1459302-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118171309.1459302-1-anthony.perard@citrix.com> References: <20191118171309.1459302-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v3 3/7] libxl: Rename ev_devlock to ev_slowlock X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We are going to introduce a different lock based on the same implementation as the ev_devlock but with a different path. The different slowlock will be differentiated by calling different _init() functions. So we rename libxl__ev_devlock to lib__ev_slowlock, but keep libxl__ev_devlock_init(). Some log messages produced ev_slowlock are changed to print the name of the lock file (userdata_userid). Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: New patch in v2. Instead of introducing many libxl__ev_qmplock*. tools/libxl/libxl_disk.c | 10 +++++----- tools/libxl/libxl_domain.c | 10 +++++----- tools/libxl/libxl_internal.c | 30 +++++++++++++++++++----------- tools/libxl/libxl_internal.h | 33 +++++++++++++++++---------------- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/tools/libxl/libxl_disk.c b/tools/libxl/libxl_disk.c index 733ad284c866..77ae3a59bfb6 100644 --- a/tools/libxl/libxl_disk.c +++ b/tools/libxl/libxl_disk.c @@ -648,13 +648,13 @@ typedef struct { libxl_domid domid; libxl_device_disk *disk; libxl_device_disk disk_saved; - libxl__ev_devlock qmp_lock; + libxl__ev_slowlock qmp_lock; int dm_ver; libxl__ev_time time; libxl__ev_qmp qmp; } libxl__cdrom_insert_state; =20 -static void cdrom_insert_lock_acquired(libxl__egc *, libxl__ev_devlock *, +static void cdrom_insert_lock_acquired(libxl__egc *, libxl__ev_slowlock *, int rc); static void cdrom_insert_ejected(libxl__egc *egc, libxl__ev_qmp *, const libxl__json_object *, int rc); @@ -746,13 +746,13 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid= , libxl_device_disk *disk, cdrom_insert_done(egc, cis, rc); /* must be last */ } else { cis->qmp_lock.callback =3D cdrom_insert_lock_acquired; - libxl__ev_devlock_lock(egc, &cis->qmp_lock); /* must be last */ + libxl__ev_slowlock_lock(egc, &cis->qmp_lock); /* must be last */ } return AO_INPROGRESS; } =20 static void cdrom_insert_lock_acquired(libxl__egc *egc, - libxl__ev_devlock *lock, + libxl__ev_slowlock *lock, int rc) { libxl__cdrom_insert_state *cis =3D CONTAINER_OF(lock, *cis, qmp_lock); @@ -1052,7 +1052,7 @@ static void cdrom_insert_done(libxl__egc *egc, libxl__ev_time_deregister(gc, &cis->time); libxl__ev_qmp_dispose(gc, &cis->qmp); if (cis->qmp.payload_fd >=3D 0) close(cis->qmp.payload_fd); - libxl__ev_devlock_unlock(gc, &cis->qmp_lock); + libxl__ev_slowlock_unlock(gc, &cis->qmp_lock); libxl_device_disk_dispose(&cis->disk_saved); libxl__ao_complete(egc, cis->ao, rc); } diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 33f9d9eaa481..7ca7a224f9a4 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1874,12 +1874,12 @@ typedef struct { libxl__ev_qmp qmp; libxl__ev_time timeout; libxl_domain_config *d_config; /* user pointer */ - libxl__ev_devlock devlock; + libxl__ev_slowlock devlock; libxl_bitmap qemuu_cpus; } retrieve_domain_configuration_state; =20 static void retrieve_domain_configuration_lock_acquired( - libxl__egc *egc, libxl__ev_devlock *, int rc); + libxl__egc *egc, libxl__ev_slowlock *, int rc); static void retrieve_domain_configuration_cpu_queried( libxl__egc *egc, libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); @@ -1907,12 +1907,12 @@ int libxl_retrieve_domain_configuration(libxl_ctx *= ctx, uint32_t domid, rdcs->devlock.ao =3D ao; rdcs->devlock.domid =3D domid; rdcs->devlock.callback =3D retrieve_domain_configuration_lock_acquired; - libxl__ev_devlock_lock(egc, &rdcs->devlock); + libxl__ev_slowlock_lock(egc, &rdcs->devlock); return AO_INPROGRESS; } =20 static void retrieve_domain_configuration_lock_acquired( - libxl__egc *egc, libxl__ev_devlock *devlock, int rc) + libxl__egc *egc, libxl__ev_slowlock *devlock, int rc) { retrieve_domain_configuration_state *rdcs =3D CONTAINER_OF(devlock, *rdcs, devlock); @@ -2204,7 +2204,7 @@ static void retrieve_domain_configuration_end(libxl__= egc *egc, } =20 out: - libxl__ev_devlock_unlock(gc, &rdcs->devlock); + libxl__ev_slowlock_unlock(gc, &rdcs->devlock); if (lock) libxl__unlock_domain_userdata(lock); libxl_bitmap_dispose(&rdcs->qemuu_cpus); libxl__ev_qmp_dispose(gc, &rdcs->qmp); diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 0750b69cba61..9520ac36149e 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -575,25 +575,32 @@ void libxl__update_domain_configuration(libxl__gc *gc, dst->b_info.video_memkb =3D src->b_info.video_memkb; } =20 -void libxl__ev_devlock_init(libxl__ev_devlock *lock) +static void ev_slowlock_init_internal(libxl__ev_slowlock *lock, + const char *userdata_userid) { libxl__ev_child_init(&lock->child); + lock->userdata_userid =3D userdata_userid; lock->path =3D NULL; lock->fd =3D -1; lock->held =3D false; } =20 -static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_devlock *lock); +void libxl__ev_devlock_init(libxl__ev_slowlock *lock) +{ + ev_slowlock_init_internal(lock, "libxl-device-changes-lock"); +} + +static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_slowlock *lock= ); static void ev_lock_child_callback(libxl__egc *egc, libxl__ev_child *child, pid_t pid, int status); =20 -void libxl__ev_devlock_lock(libxl__egc *egc, libxl__ev_devlock *lock) +void libxl__ev_slowlock_lock(libxl__egc *egc, libxl__ev_slowlock *lock) { STATE_AO_GC(lock->ao); const char *lockfile; =20 lockfile =3D libxl__userdata_path(gc, lock->domid, - "libxl-device-changes-lock", "l"); + lock->userdata_userid, "l"); if (!lockfile) goto out; lock->path =3D libxl__strdup(NOGC, lockfile); =20 @@ -603,7 +610,7 @@ void libxl__ev_devlock_lock(libxl__egc *egc, libxl__ev_= devlock *lock) lock->callback(egc, lock, ERROR_LOCK_FAIL); } =20 -static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_devlock *lock) +static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_slowlock *lock) { STATE_AO_GC(lock->ao); pid_t pid; @@ -670,7 +677,7 @@ static void ev_lock_prepare_fork(libxl__egc *egc, libxl= __ev_devlock *lock) libxl_fd_set_cloexec(CTX, fd, 1); return; out: - libxl__ev_devlock_unlock(gc, lock); + libxl__ev_slowlock_unlock(gc, lock); lock->callback(egc, lock, ERROR_LOCK_FAIL); } =20 @@ -678,7 +685,7 @@ static void ev_lock_child_callback(libxl__egc *egc, lib= xl__ev_child *child, pid_t pid, int status) { EGC_GC; - libxl__ev_devlock *lock =3D CONTAINER_OF(child, *lock, child); + libxl__ev_slowlock *lock =3D CONTAINER_OF(child, *lock, child); struct stat stab, fstab; int rc =3D ERROR_LOCK_FAIL; =20 @@ -726,13 +733,14 @@ static void ev_lock_child_callback(libxl__egc *egc, l= ibxl__ev_child *child, rc =3D ERROR_LOCK_FAIL; } if (rc) { - LOGD(ERROR, domid, "Failed to grab qmp-lock"); - libxl__ev_devlock_unlock(gc, lock); + LOGD(ERROR, domid, "Failed to grab lock for %s", + lock->userdata_userid); + libxl__ev_slowlock_unlock(gc, lock); } lock->callback(egc, lock, rc); } =20 -void libxl__ev_devlock_unlock(libxl__gc *gc, libxl__ev_devlock *lock) +void libxl__ev_slowlock_unlock(libxl__gc *gc, libxl__ev_slowlock *lock) { int r; =20 @@ -754,7 +762,7 @@ void libxl__ev_devlock_unlock(libxl__gc *gc, libxl__ev_= devlock *lock) close(lock->fd); } free(lock->path); - libxl__ev_devlock_init(lock); + ev_slowlock_init_internal(lock, lock->userdata_userid); } =20 /* diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 69d572c1866a..a0f99252c39c 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -196,7 +196,7 @@ typedef struct libxl__osevent_hook_nexi libxl__osevent_= hook_nexi; 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_slowlock libxl__ev_slowlock; typedef struct libxl__dm_resume_state libxl__dm_resume_state; typedef struct libxl__ao_device libxl__ao_device; typedef struct libxl__multidev libxl__multidev; @@ -366,7 +366,7 @@ struct libxl__ev_child { /* * Lock for device hotplug, qmp_lock. * - * libxl__ev_devlock implement a lock that is outside of CTX_LOCK in the + * libxl__ev_slowlock implement a lock that is outside of CTX_LOCK in the * lock hierarchy. It can be used when one want to make QMP calls to QEMU, * which may take a significant amount time. * It is to be acquired by an ao event callback. @@ -374,42 +374,43 @@ struct libxl__ev_child { * 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. * - * Possible states of libxl__ev_devlock: + * Possible states of libxl__ev_slowlock: * Undefined * Might contain anything. * Idle * Struct contents are defined enough to pass to any - * libxl__ev_devlock_* function. + * libxl__ev_slowlock_* function. * The struct does not contain references to any allocated private * resources so can be thrown away. * Active * Waiting to get a lock. * Needs to wait until the callback is called. * LockAcquired - * libxl__ev_devlock_unlock will need to be called to release the lock - * and the resources of libxl__ev_devlock. + * libxl__ev_slowlock_unlock will need to be called to release the lock + * and the resources of libxl__ev_slowlock. * - * libxl__ev_devlock_init: Undefined/Idle -> Idle - * libxl__ev_devlock_lock: Idle -> Active + * libxl__ev_*lock_init: Undefined/Idle -> Idle + * libxl__ev_slowlock_lock: Idle -> Active * May call callback synchronously. - * libxl__ev_devlock_unlock: LockAcquired/Idle -> Idle + * libxl__ev_slowlock_unlock: LockAcquired/Idle -> Idle * callback: When called: Active -> LockAcquired (on error: Idle) * The callback is only called once. */ -struct libxl__ev_devlock { +struct libxl__ev_slowlock { /* filled by user */ libxl__ao *ao; libxl_domid domid; - void (*callback)(libxl__egc *, libxl__ev_devlock *, int rc); - /* private to libxl__ev_devlock* */ + void (*callback)(libxl__egc *, libxl__ev_slowlock *, int rc); + /* private to libxl__ev_slowlock* */ libxl__ev_child child; + const char *userdata_userid; 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 *); +_hidden void libxl__ev_devlock_init(libxl__ev_slowlock *); +_hidden void libxl__ev_slowlock_lock(libxl__egc *, libxl__ev_slowlock *); +_hidden void libxl__ev_slowlock_unlock(libxl__gc *, libxl__ev_slowlock *); =20 /* * QMP asynchronous calls @@ -2853,7 +2854,7 @@ struct libxl__multidev { * unlock json config * * Or in case QEMU is the primary config, this pattern can be use: - * qmp_lock (libxl__ev_devlock) + * qmp_lock (libxl__ev_devlock_init) * lock json config (json_lock) * read json config * update in-memory json config with new entry, replacing --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 00:34:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574097255; cv=none; d=zoho.com; s=zohoarc; b=jcSbtl8Lrx+KR2QZkaPoJ4tgCUoUDf6Y4djEUaTXKMktgB2WlNiPpoIGwwmsWPq2hTFZ9RZOoKPsFiQc6e5BE3ohLi9DnSR91cDjAj2GfBqDfNL4+fPEx6sR6h+DW/UG1pZlr9+65YA2haOac3Xeaw2z54AiOabMupSv5btR69o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574097255; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WFr1uQIC8vTYsjn70vCtqKLgGbdiJVZVhnEl/YZjES8=; b=dmd4j0Ug85p1jaBwdaP2Mmm7F0U4Qw/Z9FpQRnKDx6gqwUNeSKLjXfBInm12D2ZKAqvK/N5nkHasfpayeiF3ucmNN60+zHEOn+cFH9SApPUDhiX6C0O4taL+PfBzGav8Ungxf5mWirkNtYNpFJ+9mjoySN0sNTyDFM07p5jjA/Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1574097255043568.0776172625598; Mon, 18 Nov 2019 09:14:15 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkaS-0005yA-Ix; Mon, 18 Nov 2019 17:13:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkaR-0005xy-Se for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 17:13:15 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b4910016-0a26-11ea-9631-bc764e2007e4; Mon, 18 Nov 2019 17:13:14 +0000 (UTC) X-Inumbo-ID: b4910016-0a26-11ea-9631-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574097194; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IezcV3OJSFGZi20L2tYeZ4LxjrHT99EIg0NiUFyKlQ0=; b=CkkVuxQcUc/bVlY4CoM/k5f25n1fCaYfd0B0aM4z0V1xSMAryTXrtOpE MrtXi4zodmWZQDUwl2zaf4zkr4Ush+6jr0F6zlzLKSeIWcMkyy9lE52+2 iHEv44n0eWhzHT+SfLSpe8mlOw5TAEk/lVyVz6mJpPbZBZFlbh6elLOsl I=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (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 ip4:168.245.78.127 ~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: gzLagkkO8v2PGHHyzyOULCRyBkOC5X7+uJXQfGHcZMkvRTVxPkwGQHFD5A+mD61MxuAtilGaVN 47L/qw51nJ4oX2oR1nUfNnWtJ2RgjZot/dTZy2SN/ONImYRGCcncJSpuhZFlXhgtIO39iSMNdX yELsMXSb0JtRBgaHR6XAtXrjx2PuhhJU8ZoIbEKHS8txtk6fv5nJ1IGucXabW7whv8c7KW/G40 pWAsrYoTgZiIemzN6EqfVu3VuwfYpPGwwENWCZIZ88p9Pv5lObCdnHrVxffJuHtyJ304lb2rLP nBs= X-SBRS: 2.7 X-MesageID: 8833206 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.68,320,1569297600"; d="scan'208";a="8833206" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 17:13:05 +0000 Message-ID: <20191118171309.1459302-5-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118171309.1459302-1-anthony.perard@citrix.com> References: <20191118171309.1459302-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v3 4/7] libxl: Introduce libxl__ev_slowlock_dispose X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Which allow to cancel the lock operation while it is in Active state. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: v2: - Renamed libxl__ev_qmplock_dispose to libxl__ev_slowlock_dispose - This new API was part of the patch "Introduce libxl__ev_qmplock" in v= 1. tools/libxl/libxl_internal.c | 6 ++++++ tools/libxl/libxl_internal.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 9520ac36149e..b2084157e4cd 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -765,6 +765,12 @@ void libxl__ev_slowlock_unlock(libxl__gc *gc, libxl__e= v_slowlock *lock) ev_slowlock_init_internal(lock, lock->userdata_userid); } =20 +void libxl__ev_slowlock_dispose(libxl__gc *gc, libxl__ev_slowlock *lock) +{ + libxl__ev_child_kill_deregister(lock->ao, &lock->child, SIGKILL); + libxl__ev_slowlock_unlock(gc, lock); +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index a0f99252c39c..9b84dddd3b7d 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -393,6 +393,8 @@ struct libxl__ev_child { * libxl__ev_slowlock_lock: Idle -> Active * May call callback synchronously. * libxl__ev_slowlock_unlock: LockAcquired/Idle -> Idle + * libxl__ev_slowlock_dispose: Idle/Active/LockAcquired -> Idle + * The callback will not be called anymore. * callback: When called: Active -> LockAcquired (on error: Idle) * The callback is only called once. */ @@ -411,6 +413,7 @@ struct libxl__ev_slowlock { _hidden void libxl__ev_devlock_init(libxl__ev_slowlock *); _hidden void libxl__ev_slowlock_lock(libxl__egc *, libxl__ev_slowlock *); _hidden void libxl__ev_slowlock_unlock(libxl__gc *, libxl__ev_slowlock *); +_hidden void libxl__ev_slowlock_dispose(libxl__gc *, libxl__ev_slowlock *); =20 /* * QMP asynchronous calls --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 00:34:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574097267; cv=none; d=zoho.com; s=zohoarc; b=HngCFsJp5FBuHxuiRJmB1eNflJCyAwvYkWZJQ55NML510o8kIbhL0F+QnIznosZL1QlVGupJH5S2gHK+9tsX06MjlyOGSfPCwZbJAbPP/7XmtDh+xGRjBEIxFHuVup5H9RsS6mPMBWsW1jpOfUK5ZH2vNCZJHmYTG2TI9Zl1Adg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574097267; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WpxAhUAfYdT/MT6E5fY3imWkw4OQF6BCIV38T6HSxMg=; b=VfcOymad0rpZAcJ8FQiVr8iZmMtjcjLdsu/vRyypEYKW4gGYfqiTIXJKpbwj/ROFtGLs3bY5aiQH++TpHYYfOAx0KFGQ1yJaaTebPQqrhR2jakNcR4S2WM3V3injyNJaMrk7a+bc3oX7WkNC+lMCqIziOUY+NwYsPy839i6fWF8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1574097267141897.0731912433496; Mon, 18 Nov 2019 09:14:27 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkaa-00061A-El; Mon, 18 Nov 2019 17:13:24 +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 1iWkaZ-00060b-DQ for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 17:13:23 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b2e67e50-0a26-11ea-a2db-12813bfff9fa; Mon, 18 Nov 2019 17:13:12 +0000 (UTC) X-Inumbo-ID: b2e67e50-0a26-11ea-a2db-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574097192; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aboUeJtbqj5tTk0rMmKX3R9Hcu6rZaOm0x/Cw+jDfLc=; b=E+6B1qlQDqwmf8JtIUQS0cocCqEBZCEyg2GHwf77/zz6u3o2tRXK7dDH fQMFY6Fwy5qf3ve3TXuJUsRPz8KruB7SVDylmmVHy/mc+lVIU4Fp0BVnA kieKS7rQpXtDTMX7jQdn3/j09rKVkXmSY4eLLaBqLi+PnYsUpeCsNhIfE 8=; 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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (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 ip4:168.245.78.127 ~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: JkmYOMSzugpAQHdXqbCyLeZmfu24cUs47Re0UQ3BniUTmRggexWZgXebknd57mAXk6z6FeMw/F WQl3X/EZMTHKz17WacDWkqzckoOmHWExxC9+andNSt94ukEUF+1SAOHDIFUdZPyKnXKRGd3pi1 P83HSHu+5Q6ppeIGu/+1S+AoGViLO028Kx1YAacWuYHsZhy+ngpzHeTB2D7XUKlDYuheGIwtxq SsbYRQB92UoEAo0SzFJvQ4UZ9G+e+q++u/5TJmpJZpFQT4HXzCMkvQ9VOgWgTRtyVx3AQ1fcW4 5zw= X-SBRS: 2.7 X-MesageID: 9014073 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.68,320,1569297600"; d="scan'208";a="9014073" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 17:13:06 +0000 Message-ID: <20191118171309.1459302-6-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118171309.1459302-1-anthony.perard@citrix.com> References: <20191118171309.1459302-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v3 5/7] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 77ae3a59bfb6..64a66914240a 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, =20 QMP_PARAMETERS_SPRINTF(&args, "device", "ide-%i", devid); cis->qmp.callback =3D cdrom_insert_ejected; - rc =3D libxl__ev_qmp_send(gc, &cis->qmp, "eject", args); + rc =3D 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 =3D cdrom_insert_addfd_cb; - rc =3D libxl__ev_qmp_send(gc, qmp, "add-fd", args); + rc =3D libxl__ev_qmp_send(egc, qmp, "add-fd", args); if (rc) goto out; has_callback =3D 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 =3D cdrom_insert_inserted; - rc =3D libxl__ev_qmp_send(gc, qmp, "change", args); + rc =3D 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 8e0fb78bd2f3..dac1b8ddb88a 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2649,7 +2649,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm= _spawn_state *dmss) dmss->qmp.callback =3D device_model_qmp_cb; dmss->qmp.domid =3D domid; dmss->qmp.payload_fd =3D -1; - rc =3D libxl__ev_qmp_send(gc, &dmss->qmp, "query-status", NULL); + rc =3D libxl__ev_qmp_send(egc, &dmss->qmp, "query-status", NULL); if (rc) goto out_close; } =20 @@ -2807,7 +2807,7 @@ static void device_model_spawn_outcome(libxl__egc *eg= c, dmss->qmp.domid =3D dmss->guest_domid; dmss->qmp.payload_fd =3D -1; dmss->qmp.callback =3D device_model_postconfig_chardev; - rc =3D libxl__ev_qmp_send(gc, &dmss->qmp, "query-chardev", NULL); + rc =3D libxl__ev_qmp_send(egc, &dmss->qmp, "query-chardev", NULL); if (rc) goto out; return; } @@ -2879,7 +2879,7 @@ static void device_model_postconfig_chardev(libxl__eg= c *egc, } =20 qmp->callback =3D device_model_postconfig_vnc; - rc =3D libxl__ev_qmp_send(gc, qmp, "query-vnc", NULL); + rc =3D libxl__ev_qmp_send(egc, qmp, "query-vnc", NULL); if (rc) goto out; return; =20 @@ -2939,7 +2939,7 @@ static void device_model_postconfig_vnc(libxl__egc *e= gc, if (vnc && vnc->passwd && vnc->passwd[0]) { qmp->callback =3D device_model_postconfig_vnc_passwd; libxl__qmp_param_add_string(gc, &args, "password", vnc->passwd); - rc =3D libxl__ev_qmp_send(gc, qmp, "change-vnc-password", args); + rc =3D 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 =3D -1; qmp->callback =3D switch_qemu_xen_logdirty_done; libxl__qmp_param_add_bool(gc, &args, "enable", enable); - rc =3D libxl__ev_qmp_send(gc, qmp, "xen-set-global-dirty-log", args); + rc =3D libxl__ev_qmp_send(egc, qmp, "xen-set-global-dirty-log", args); if (rc) goto out; =20 return; diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspen= d.c index 35ae337261ba..25d1571895f8 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 =3D domid; qmp->callback =3D dm_resume_qmp_done; qmp->payload_fd =3D -1; - rc =3D libxl__ev_qmp_send(gc, qmp, "cont", NULL); + rc =3D 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 7ca7a224f9a4..571450177858 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 dom= id, LIBXL_QMP_CMD_TIMEOUT * 1000); if (rc) goto out; qmp->callback =3D set_vcpuonline_qmp_cpus_queried; - rc =3D libxl__ev_qmp_send(gc, qmp, "query-cpus", NULL); + rc =3D 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 *eg= c, if (libxl_bitmap_test(map, svos->index)) { qmp->callback =3D set_vcpuonline_qmp_add_cpu; libxl__qmp_param_add_integer(gc, &args, "id", svos->index); - rc =3D libxl__ev_qmp_send(gc, qmp, "cpu-add", args); + rc =3D 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__eg= c *egc, int domid) } break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc =3D libxl__ev_qmp_send(gc, qmp, "system_wakeup", NULL); + rc =3D 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_acquir= ed( libxl_bitmap_alloc(CTX, &rdcs->qemuu_cpus, d_config->b_info.max_vcpus); rdcs->qmp.callback =3D retrieve_domain_configuration_cpu_queried; - rc =3D libxl__ev_qmp_send(gc, &rdcs->qmp, "query-cpus", NULL); + rc =3D libxl__ev_qmp_send(egc, &rdcs->qmp, "query-cpus", NULL); if (rc) goto out; has_callback =3D true; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 9b84dddd3b7d..f95895eae17d 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -472,7 +472,7 @@ typedef void libxl__ev_qmp_callback(libxl__egc *egc, li= bxl__ev_qmp *ev, int rc); =20 _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); =20 diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 2ccab033b460..a66915542b98 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1186,7 +1186,7 @@ static void pci_add_qmp_device_add(libxl__egc *egc, p= ci_add_state *pas) qmp->domid =3D domid; qmp->payload_fd =3D -1; qmp->callback =3D pci_add_qmp_device_add_cb; - rc =3D libxl__ev_qmp_send(gc, qmp, "device_add", args); + rc =3D libxl__ev_qmp_send(egc, qmp, "device_add", args); if (rc) goto out; return; =20 @@ -1205,7 +1205,7 @@ static void pci_add_qmp_device_add_cb(libxl__egc *egc, if (rc) goto out; =20 qmp->callback =3D pci_add_qmp_query_pci_cb; - rc =3D libxl__ev_qmp_send(gc, qmp, "query-pci", NULL); + rc =3D libxl__ev_qmp_send(egc, qmp, "query-pci", NULL); if (rc) goto out; return; =20 @@ -2020,7 +2020,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 =3D pci_remove_qmp_device_del_cb; - rc =3D libxl__ev_qmp_send(gc, &prs->qmp, "device_del", args); + rc =3D libxl__ev_qmp_send(egc, &prs->qmp, "device_del", args); if (rc) goto out; return; =20 @@ -2059,7 +2059,7 @@ static void pci_remove_qmp_retry_timer_cb(libxl__egc = *egc, libxl__ev_time *ev, pci_remove_state *prs =3D CONTAINER_OF(ev, *prs, retry_timer); =20 prs->qmp.callback =3D pci_remove_qmp_query_cb; - rc =3D libxl__ev_qmp_send(gc, &prs->qmp, "query-pci", NULL); + rc =3D libxl__ev_qmp_send(egc, &prs->qmp, "query-pci", NULL); if (rc) goto out; return; =20 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 =3D qemu_monitor_command_done; qmcs->output =3D output; libxl__qmp_param_add_string(gc, &args, "command-line", command_line); - rc =3D libxl__ev_qmp_send(gc, &qmcs->qmp, "human-monitor-command", arg= s); + rc =3D libxl__ev_qmp_send(egc, &qmcs->qmp, "human-monitor-command", ar= gs); 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 =3D dm_stopped; ev->payload_fd =3D -1; =20 - rc =3D libxl__ev_qmp_send(gc, ev, "stop", NULL); + rc =3D libxl__ev_qmp_send(egc, ev, "stop", NULL); if (rc) goto error; =20 @@ -1007,7 +1007,7 @@ static void dm_stopped(libxl__egc *egc, libxl__ev_qmp= *ev, } =20 ev->callback =3D dm_state_fd_ready; - rc =3D libxl__ev_qmp_send(gc, ev, "add-fd", NULL); + rc =3D libxl__ev_qmp_send(egc, ev, "add-fd", NULL); if (rc) goto error; =20 @@ -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) >=3D 0) libxl__qmp_param_add_bool(gc, &args, "live", dsps->live); QMP_PARAMETERS_SPRINTF(&args, "filename", "/dev/fdset/%d", fdset); - rc =3D libxl__ev_qmp_send(gc, ev, "xen-save-devices-state", args); + rc =3D libxl__ev_qmp_send(egc, ev, "xen-save-devices-state", args); if (rc) goto error; =20 @@ -1781,7 +1781,7 @@ void libxl__ev_qmp_init(libxl__ev_qmp *ev) ev->qemu_version.micro =3D -1; } =20 -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=3D2), always 6 ports * - nec-usb-xhci (version=3D3), 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 *q= mp, libxl_device_usbctrl *usbctrl) { + EGC_GC; libxl__json_object *qmp_args =3D NULL; =20 switch (usbctrl->version) { @@ -378,26 +379,28 @@ static int libxl__device_usbctrl_add_hvm(libxl__gc *g= c, libxl__ev_qmp *qmp, libxl__qmp_param_add_string(gc, &qmp_args, "id", GCSPRINTF("xenusb-%d", usbctrl->devid)); =20 - return libxl__ev_qmp_send(gc, qmp, "device_add", qmp_args); + return libxl__ev_qmp_send(egc, qmp, "device_add", qmp_args); } =20 /* 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 =3D NULL; =20 libxl__qmp_param_add_string(gc, &qmp_args, "id", GCSPRINTF("xenusb-%d", devid)); =20 - return libxl__ev_qmp_send(gc, qmp, "device_del", qmp_args); + return libxl__ev_qmp_send(egc, qmp, "device_del", qmp_args); } =20 /* 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 *qm= p, libxl_device_usbdev *usbdev) { + EGC_GC; libxl__json_object *qmp_args =3D NULL; =20 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)); =20 - return libxl__ev_qmp_send(gc, qmp, "device_add", qmp_args); + return libxl__ev_qmp_send(egc, qmp, "device_add", qmp_args); } =20 /* 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 *qm= p, libxl_device_usbdev *usbdev) { + EGC_GC; libxl__json_object *qmp_args =3D NULL; =20 libxl__qmp_param_add_string(gc, &qmp_args, "id", GCSPRINTF("xenusb-%d-%d", usbdev->u.hostdev.hostbus, usbdev->u.hostdev.hostaddr)); =20 - return libxl__ev_qmp_send(gc, qmp, "device_del", qmp_args); + return libxl__ev_qmp_send(egc, qmp, "device_del", qmp_args); } =20 static LIBXL_DEFINE_UPDATE_DEVID(usbctrl) @@ -490,7 +494,7 @@ static void libxl__device_usbctrl_add(libxl__egc *egc, = uint32_t domid, qmp->domid =3D domid; qmp->payload_fd =3D -1; qmp->callback =3D device_usbctrl_add_qmp_cb; - rc =3D libxl__device_usbctrl_add_hvm(gc, qmp, usbctrl); + rc =3D 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 =3D aodev->dev->domid; qmp->callback =3D device_usbctrl_remove_qmp_cb; qmp->payload_fd =3D -1; - rc =3D libxl__device_usbctrl_del_hvm(gc, qmp, aodev->dev->devid); + rc =3D 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 =3D domid; aodev->qmp.callback =3D device_usbdev_add_qmp_cb; aodev->qmp.payload_fd =3D -1; - rc =3D libxl__device_usbdev_add_hvm(gc, &aodev->qmp, usbdev); + rc =3D libxl__device_usbdev_add_hvm(egc, &aodev->qmp, usbdev); if (rc) { libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, LIBXL_USBCTRL_TYPE_DEVICEMODE= L); @@ -1979,7 +1983,7 @@ static void libxl__device_usbdev_remove(libxl__egc *e= gc, uint32_t domid, aodev->qmp.domid =3D domid; aodev->qmp.callback =3D device_usbdev_remove_qmp_cb; aodev->qmp.payload_fd =3D -1; - rc =3D libxl__device_usbdev_del_hvm(gc, &aodev->qmp, usbdev); + rc =3D libxl__device_usbdev_del_hvm(egc, &aodev->qmp, usbdev); if (rc) { libxl__device_usbdev_add_xenstore(gc, domid, usbdev, LIBXL_USBCTRL_TYPE_DEVICEMOD= EL, --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 00:34:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574097282; cv=none; d=zoho.com; s=zohoarc; b=lTIHSxT+MWYEJa1CqdiNDKtv8kIE13HQYsR4aN0xwfDwjWV3LLNN4pBJPZcw/BGjaHLTtYICySqShaiusLv8utSowgO+GFKhi2XLwbHk3uRjd58CUlieONekqpl0TFF3YCfAorwemY4COO2yNm4TBzI8eY8+sJpH7ON5SbYPDtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574097282; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qFIm/y2jvpzQZLg/el9Jd6neHjqThDf7IKSbZE9qqXI=; b=KfGNGyKh3TwX9Z8/q8lZ1ZewXvyXc0VRrz1sDd80Pmx1Cc3Gqu4FerVoJl6U4F65Kd5gkXO39tgTP8QMaNJjsMY175EcZ5j+ZCV98vn2cC63k7I6N7ioCw4bWlEyQKspYK4GNFntQv02sDLekKCr4uwWXypgr7bs0d+8ekaa7CA= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1574097282127258.6019041842162; Mon, 18 Nov 2019 09:14:42 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkav-0006Cu-3I; Mon, 18 Nov 2019 17:13:45 +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 1iWkat-0006Bj-EL for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 17:13:43 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b5ab0ba5-0a26-11ea-a2db-12813bfff9fa; Mon, 18 Nov 2019 17:13:17 +0000 (UTC) X-Inumbo-ID: b5ab0ba5-0a26-11ea-a2db-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574097197; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rew1fL2ZdPHuVA+KWJcp9mwcRFPGnMJ7PLoGwDkSx0g=; b=I4wW6oDVt4h7o84rAh7afF58uZC7rUTuWcBhGLgtpSkDbpJz4wkH5bPn bx587IdD/RIqNQpZhPVWGJsXHVAUcx72quhEqjpVkEGOR63Ayfp4Yyi9v g+SAdd13mE3Xufo97nqOG96YMjYrZiLfsymCRz8LQZ4FYkC15FOVuYYG6 Y=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (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 ip4:168.245.78.127 ~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: MNQ4lAN1AbRHEc8R9Ao9LGhFcyU4pIiVtqkFu1z93HTfbKJM8pBZTgE2i2NtgCTxfk/LA8wq48 PIh5lNWfgju/1iT/o1qZatmd88UOE6NI3Q0yaMI1GPMvOTK3FJ5vG5vbRkNPbWmTMdwJZ9shov /YXDIQkxtCd0t2hUr5kANvkqHerf1St/LujNMJEspFmsxaTsu19Ba7VpDllywfj3PqMg0KD32c 6HeC6suwQ2Cr/1JcjFcSkp34xkaiG8XiXavH/myYA+He5iEP/6ve+aDB7EuKEccWnJcouOiOLH ty8= X-SBRS: 2.7 X-MesageID: 8833209 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.68,320,1569297600"; d="scan'208";a="8833209" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 17:13:07 +0000 Message-ID: <20191118171309.1459302-7-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118171309.1459302-1-anthony.perard@citrix.com> References: <20191118171309.1459302-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v3 6/7] libxl: Introduce libxl__ev_immediate X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This new ev allows to arrange a non-reentrant callback to be called. This happen immediately after the current event is processed and after other ev_immediates that would have already been registered. Signed-off-by: Anthony PERARD --- Notes: v3: - new patch tools/libxl/libxl_event.c | 19 +++++++++++++++++++ tools/libxl/libxl_internal.h | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index 43155368de76..ceb775d8ca3f 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -914,6 +914,15 @@ int libxl__ev_devstate_wait(libxl__ao *ao, libxl__ev_d= evstate *ds, return rc; } =20 +/* + * immediate non-reentrant callback + */ + +void libxl__ev_immediate_register(libxl__egc *egc, libxl__ev_immediate *ei) +{ + LIBXL_TAILQ_INSERT_TAIL(&egc->ev_immediates, ei, entry); +} + /* * domain death/destruction */ @@ -1395,6 +1404,16 @@ static void egc_run_callbacks(libxl__egc *egc) EGC_GC; libxl_event *ev, *ev_tmp; libxl__aop_occurred *aop, *aop_tmp; + libxl__ev_immediate *ei, *ei_tmp; + + LIBXL_TAILQ_FOREACH_SAFE(ei, &egc->ev_immediates, entry, ei_tmp) { + LIBXL_TAILQ_REMOVE(&egc->ev_immediates, ei, entry); + CTX_LOCK; + /* This callback is internal to libxl and expects CTX to be + * locked. */ + ei->callback(egc, ei); + CTX_UNLOCK; + } =20 LIBXL_TAILQ_FOREACH_SAFE(ev, &egc->occurred_for_callback, link, ev_tmp= ) { LIBXL_TAILQ_REMOVE(&egc->occurred_for_callback, ev, link); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index f95895eae17d..400752a7f8fe 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -200,6 +200,7 @@ typedef struct libxl__ev_slowlock libxl__ev_slowlock; 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__ev_immediate libxl__ev_immediate; =20 typedef struct libxl__domain_create_state libxl__domain_create_state; typedef void libxl__domain_create_cb(struct libxl__egc *egc, @@ -363,6 +364,20 @@ struct libxl__ev_child { LIBXL_LIST_ENTRY(struct libxl__ev_child) entry; }; =20 +/* libxl__ev_immediate + * + * Allow to call a non-reentrant callback. + * + * `callback' will be called immediately as a new event. + */ +struct libxl__ev_immediate { + /* filled by user */ + void (*callback)(libxl__egc *, libxl__ev_immediate *); + /* private to libxl__ev_immediate */ + LIBXL_TAILQ_ENTRY(libxl__ev_immediate) entry; +}; +void libxl__ev_immediate_register(libxl__egc *, libxl__ev_immediate *); + /* * Lock for device hotplug, qmp_lock. * @@ -733,6 +748,7 @@ struct libxl__egc { struct libxl__event_list occurred_for_callback; LIBXL_TAILQ_HEAD(, libxl__ao) aos_for_callback; LIBXL_TAILQ_HEAD(, libxl__aop_occurred) aops_for_callback; + LIBXL_TAILQ_HEAD(, libxl__ev_immediate) ev_immediates; }; =20 struct libxl__aop_occurred { @@ -2322,6 +2338,7 @@ _hidden libxl_device_model_version libxl__default_dev= ice_model(libxl__gc *gc); LIBXL_TAILQ_INIT(&(egc).occurred_for_callback); \ LIBXL_TAILQ_INIT(&(egc).aos_for_callback); \ LIBXL_TAILQ_INIT(&(egc).aops_for_callback); \ + LIBXL_TAILQ_INIT(&(egc).ev_immediates); \ } while(0) =20 _hidden void libxl__egc_cleanup(libxl__egc *egc); --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 00:34:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574097271; cv=none; d=zoho.com; s=zohoarc; b=W7NS4FYDr5mV/X1mK6gX5vFLFlQbt9B2VFvPfEBQeMPdLJsG4yG5lwgUcp4da5uzt23EU4gddoT/pgdChUJ04zDFGWNL1yLh0HtWSGosovsa17tXQdWVQWpknEMqd0WagA5Tk6FRa5g8p5PIWgBucwRbHOrOnw9NChdRhkB1nmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574097271; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6axA3Vm9YFrfscthPXIbKBAzcHOQLvA7iGHuEhDi8Ss=; b=ddN9+Ri1Ze+L68U7mjQLFKqEZTkZ2ib3tLm8S6muX5F8UiZT5cSrhj8FVaUgqWV+WXm1F4QifzOWhiMx8KwqohwSz18XjHfQJhyoXSXDkPVx/a7nHegVxnemkVr+b5d+WYxRUQPir8RHPh9lTA5DT8jwkfsqyXV4Trc0kUrWGqY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 157409727134646.0995187953057; Mon, 18 Nov 2019 09:14:31 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWkaf-00063c-PQ; Mon, 18 Nov 2019 17:13:29 +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 1iWkae-000634-DN for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 17:13:28 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b2e61eeb-0a26-11ea-a2db-12813bfff9fa; Mon, 18 Nov 2019 17:13:13 +0000 (UTC) X-Inumbo-ID: b2e61eeb-0a26-11ea-a2db-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574097194; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a3skFAd4t1WXNTVyZd0fKvhw//JI7l7pv3gnWT3Cv4k=; b=E8mfQJR1UsQphfynKgdnad5BMsX4aTzaLaBo+i9GcPLgrtONwzsy+c8T mNaF8FtPotEx3ZPEZ8UOgJgnhADYtEVfZDuYTya+JItTI4d+xB/g2JRSr G89V4wYgda3edh+Ocl8GP0nofUS0xlG8289Nmuvg22t4SKbgFZKaFwfms w=; 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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (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 ip4:168.245.78.127 ~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: her1wDWF6ZDH/p5/sWQvx9w56QyR9v4HgMk5tJFXc95i7DVjMPeNUwOrb6/j1n56jGP2LUJ04I 6MRUbMJ9TqLQemUWJiWqvNwo0jVHsdfdBHolBsOBgqEWaoA/+j/8AT07621o9JiOlG7gJ2fHC7 VVJ/a1L+1tklBPSKYagYdMCnScXmLYkx+2+9kWexxKbnO2HGP6qgQ4qpHmr52ZMOO1V7qb/wVl kEMMb9hHdODk0Pz8ru//eDRfvoe+/VI2MpCRmaIYA7Te7tV/bn7N54SgQ2IMbuLWK1d6AYKwyv n3M= X-SBRS: 2.7 X-MesageID: 8592406 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.68,320,1569297600"; d="scan'208";a="8592406" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 17:13:08 +0000 Message-ID: <20191118171309.1459302-8-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118171309.1459302-1-anthony.perard@citrix.com> References: <20191118171309.1459302-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v3 7/7] 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 , Sander Eikelenboom , Ian Jackson , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Background: This happens when attempting to create a guest with multiple pci devices passthrough, libxl creates one connection per device to attach and execute connect() on all at once before any single connection has finished. To work around this, we use a new lock. Reported-by: Sander Eikelenboom Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: v3: - Use new libxl_ev_immediate in qmp_ev_connect's callbacks error path. - Add `lock' state into the internal state table. And add comments about state changes to the new functions. =20 v2: - Handle error path tools/libxl/libxl_internal.c | 5 ++ tools/libxl/libxl_internal.h | 9 +++ tools/libxl/libxl_qmp.c | 118 +++++++++++++++++++++++++++-------- 3 files changed, 107 insertions(+), 25 deletions(-) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index b2084157e4cd..ba5637358e7c 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -590,6 +590,11 @@ void libxl__ev_devlock_init(libxl__ev_slowlock *lock) ev_slowlock_init_internal(lock, "libxl-device-changes-lock"); } =20 +void libxl__ev_qmplock_init(libxl__ev_slowlock *lock) +{ + ev_slowlock_init_internal(lock, "qmp-socket-lock"); +} + static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_slowlock *lock= ); static void ev_lock_child_callback(libxl__egc *egc, libxl__ev_child *child, pid_t pid, int status); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 400752a7f8fe..8988831ae5f7 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -386,6 +386,9 @@ void libxl__ev_immediate_register(libxl__egc *, libxl__= ev_immediate *); * 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. * @@ -426,6 +429,7 @@ struct libxl__ev_slowlock { bool held; }; _hidden void libxl__ev_devlock_init(libxl__ev_slowlock *); +_hidden void libxl__ev_qmplock_init(libxl__ev_slowlock *); _hidden void libxl__ev_slowlock_lock(libxl__egc *, libxl__ev_slowlock *); _hidden void libxl__ev_slowlock_unlock(libxl__gc *, libxl__ev_slowlock *); _hidden void libxl__ev_slowlock_dispose(libxl__gc *, libxl__ev_slowlock *); @@ -494,6 +498,8 @@ _hidden void libxl__ev_qmp_dispose(libxl__gc *gc, libxl= __ev_qmp *ev); typedef enum { /* initial state */ qmp_state_disconnected =3D 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 */ @@ -527,6 +533,9 @@ struct libxl__ev_qmp { libxl__carefd *cfd; libxl__ev_fd efd; libxl__qmp_state state; + libxl__ev_slowlock lock; + libxl__ev_immediate ei; + int rc; int id; int next_id; /* next id to use */ /* receive buffer */ diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index f0e0b50bd1c5..c8eac2588a89 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -1082,16 +1082,17 @@ static void dm_state_saved(libxl__egc *egc, libxl__= ev_qmp *ev, /* * Possible internal state compared to qmp_state: * - * qmp_state External cfd efd id rx_buf* tx_buf* msg* - * disconnected Idle NULL Idle reset free free free - * 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 - * connected Connected open IN any used free free - * waiting_reply Active open IN|OUT sent used free set - * waiting_reply Active open IN|OUT sent used user's free - * waiting_reply Active open IN sent used free free - * broken[1] none[2] any Active any any any any + * qmp_state External cfd efd id rx_buf* tx_buf* msg* lock + * disconnected Idle NULL Idle reset free free free Id= le + * waiting_lock Active open Idle reset used free set Ac= tive + * connecting Active open IN reset used free set Ac= quired + * cap.neg Active open IN|OUT sent used cap_neg set Ac= quired + * cap.neg Active open IN sent used free set Ac= quired + * connected Connected open IN any used free free Ac= quired + * waiting_reply Active open IN|OUT sent used free set Ac= quired + * waiting_reply Active open IN|OUT sent used user's free Ac= quired + * waiting_reply Active open IN sent used free free Ac= quired + * broken[1] none[2] any Active any any any any any * * [1] When an internal function return an error, it can leave ev_qmp in a * `broken` state but only if the caller is another internal function. @@ -1118,7 +1119,8 @@ static void dm_state_saved(libxl__egc *egc, libxl__ev= _qmp *ev, * msg_id 0 id assoctiated with the command in `msg` * * - Allowed internal state transition: - * disconnected -> connecting + * disconnected -> waiting_lock + * waiting_lock -> connecting * connection -> capability_negotiation * capability_negotiation/connected -> waiting_reply * waiting_reply -> connected @@ -1153,6 +1155,10 @@ static void qmp_ev_ensure_reading_writing(libxl__gc = *gc, libxl__ev_qmp *ev) { short events =3D POLLIN; =20 + if (ev->state =3D=3D qmp_state_waiting_lock) + /* We can't modifie the efd yet, as it isn't registered. */ + return; + if (ev->tx_buf) events |=3D POLLOUT; else if ((ev->state =3D=3D qmp_state_waiting_reply) && ev->msg) @@ -1168,9 +1174,12 @@ static void qmp_ev_set_state(libxl__gc *gc, libxl__e= v_qmp *ev, switch (new_state) { case qmp_state_disconnected: break; - case qmp_state_connecting: + case qmp_state_waiting_lock: assert(ev->state =3D=3D qmp_state_disconnected); break; + case qmp_state_connecting: + assert(ev->state =3D=3D qmp_state_waiting_lock); + break; case qmp_state_capability_negotiation: assert(ev->state =3D=3D qmp_state_connecting); break; @@ -1231,20 +1240,22 @@ static int qmp_error_class_to_libxl_error_code(libx= l__gc *gc, =20 /* Setup connection */ =20 -static int qmp_ev_connect(libxl__gc *gc, libxl__ev_qmp *ev) - /* disconnected -> connecting but with `msg` free +static void qmp_ev_lock_aquired(libxl__egc *, libxl__ev_slowlock *, + int rc); +static void lock_error_callback(libxl__egc *, libxl__ev_immediate *); + +static int qmp_ev_connect(libxl__egc *egc, libxl__ev_qmp *ev) + /* disconnected -> waiting_lock/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 =3D=3D qmp_state_disconnected); + int rc; =20 - qmp_socket_path =3D libxl__qemu_qmp_path(gc, ev->domid); + /* Convenience aliases */ + libxl__ev_slowlock *lock =3D &ev->lock; =20 - LOGD(DEBUG, ev->domid, "Connecting to %s", qmp_socket_path); + assert(ev->state =3D=3D qmp_state_disconnected); =20 libxl__carefd_begin(); fd =3D socket(AF_UNIX, SOCK_STREAM, 0); @@ -1258,6 +1269,36 @@ static int qmp_ev_connect(libxl__gc *gc, libxl__ev_q= mp *ev) if (rc) goto out; =20 + qmp_ev_set_state(gc, ev, qmp_state_waiting_lock); + + lock->ao =3D ev->ao; + lock->domid =3D ev->domid; + lock->callback =3D qmp_ev_lock_aquired; + libxl__ev_slowlock_lock(egc, &ev->lock); + + return 0; + +out: + return rc; +} + +static void qmp_ev_lock_aquired(libxl__egc *egc, libxl__ev_slowlock *lock, + int rc) + /* waiting_lock (with `lock' Acquired) -> connecting + * on error: broken */ +{ + libxl__ev_qmp *ev =3D 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 =3D libxl__qemu_qmp_path(gc, ev->domid); + + LOGD(DEBUG, ev->domid, "Connecting to %s", qmp_socket_path); + rc =3D libxl__prepare_sockaddr_un(gc, &un, qmp_socket_path, "QMP socket"); if (rc) @@ -1279,10 +1320,33 @@ static int qmp_ev_connect(libxl__gc *gc, libxl__ev_= qmp *ev) =20 qmp_ev_set_state(gc, ev, qmp_state_connecting); =20 - return 0; + return; =20 out: - return rc; + /* An error occurred and we need to let the caller know. At this + * point, we can only do so via the callback. Unfortunately, the + * callback of libxl__ev_slowlock_lock() might be called synchronously, + * but libxl__ev_qmp_send() promise that it will not call the callback + * synchronously. So we have to arrange to call the callback + * asynchronously. */ + ev->rc =3D rc; + ev->ei.callback =3D lock_error_callback; + libxl__ev_immediate_register(egc, &ev->ei); +} + +static void lock_error_callback(libxl__egc *egc, libxl__ev_immediate *ei) + /* broken -> disconnected */ +{ + EGC_GC; + libxl__ev_qmp *ev =3D CONTAINER_OF(ei, *ev, ei); + + int rc =3D ev->rc; + + /* On error, deallocate all private resources */ + libxl__ev_qmp_dispose(gc, ev); + + /* And tell libxl__ev_qmp user about the error */ + ev->callback(egc, ev, NULL, rc); /* must be last */ } =20 /* QMP FD callbacks */ @@ -1779,11 +1843,14 @@ void libxl__ev_qmp_init(libxl__ev_qmp *ev) ev->qemu_version.major =3D -1; ev->qemu_version.minor =3D -1; ev->qemu_version.micro =3D -1; + + libxl__ev_qmplock_init(&ev->lock); + ev->rc =3D 0; } =20 int libxl__ev_qmp_send(libxl__egc *egc, libxl__ev_qmp *ev, const char *cmd, libxl__json_object *args) - /* disconnected -> connecting + /* disconnected -> waiting_lock/connecting * connected -> waiting_reply (with msg set) * on error: disconnected */ { @@ -1798,7 +1865,7 @@ int libxl__ev_qmp_send(libxl__egc *egc, libxl__ev_qmp= *ev, =20 /* Connect to QEMU if not already connected */ if (ev->state =3D=3D qmp_state_disconnected) { - rc =3D qmp_ev_connect(gc, ev); + rc =3D qmp_ev_connect(egc, ev); if (rc) goto error; } @@ -1830,6 +1897,7 @@ void libxl__ev_qmp_dispose(libxl__gc *gc, libxl__ev_q= mp *ev) =20 libxl__ev_fd_deregister(gc, &ev->efd); libxl__carefd_close(ev->cfd); + libxl__ev_slowlock_dispose(gc, &ev->lock); =20 libxl__ev_qmp_init(ev); } --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel