From patchwork Mon Nov 18 17:13:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11250055 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 EA9C41599 for ; Mon, 18 Nov 2019 17:14:52 +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 C6AB621D7F for ; Mon, 18 Nov 2019 17:14:52 +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="I4wW6oDV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6AB621D7F 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 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 X-Inumbo-ID: b5ab0ba5-0a26-11ea-a2db-12813bfff9fa 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) 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 (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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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_devstate *ds, return rc; } +/* + * 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; + } 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; 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; }; +/* 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; }; struct libxl__aop_occurred { @@ -2322,6 +2338,7 @@ _hidden libxl_device_model_version libxl__default_device_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) _hidden void libxl__egc_cleanup(libxl__egc *egc);