From patchwork Mon Nov 18 18:10:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11250089 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 894C7109A for ; Mon, 18 Nov 2019 18:11:44 +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 65334222A3 for ; Mon, 18 Nov 2019 18:11:44 +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="HX1QAmt0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 65334222A3 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 1iWlTg-0004GY-Cz; Mon, 18 Nov 2019 18:10:20 +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 1iWlTe-0004GQ-IT for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 18:10:18 +0000 X-Inumbo-ID: acda9eec-0a2e-11ea-a2de-12813bfff9fa Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id acda9eec-0a2e-11ea-a2de-12813bfff9fa; Mon, 18 Nov 2019 18:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574100617; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kTuFvu2BbPHfp8dvWbx7uWxgQKcOYfIbMEjHLLe06aw=; b=HX1QAmt0e5y3Gn841aADLxArkmTSDSgcLKeWOh1Ge+0AudjK+ZmGBsns NDiPmZ3rdX/GzheYcfwvMpBrY/j/hsAPbiY7EVdicCOdvpm3s9CdodwIw 8VDYg+c1VwhRf4ZV+Fgeyg/2I3U4RWLSewu/b9l5XfblK7dG+YPOaiPhw k=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: erVQe32TJBbJlmpCd2cIAJp2dFm1A4cz7e+m4qGvNRokiMNVRnLkAo8UlXmDn48Cr0+/DZ9cLI dL3IFgNoocYhUH+qZBE/mfHQYvY/wQiQM6owZGk6PDepu7N4gdQ4Bm9B5l82mTqEW8VUSKDUpr KdQkPYfsaNd4TekcRkmtwvfKHo5X7xUfgyT0XukJP2t1ZNrhLqZcWLwx5vub4EgdpR9gXYCoBw aMDqIkrgKPZuTr0jOMg/kL11cTov4fhB8YPqevezEJOIR/sx/kLLRDE/pwc4vsCr4HE/P6j1wx IlI= X-SBRS: 2.7 X-MesageID: 8891838 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,321,1569297600"; d="scan'208";a="8891838" From: Anthony PERARD To: Date: Mon, 18 Nov 2019 18:10:14 +0000 Message-ID: <20191118181014.1472995-1-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118174956.GD1425@perard.uk.xensource.com> References: <20191118174956.GD1425@perard.uk.xensource.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v4 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 Acked-by: Ian Jackson --- Notes: v4: - rework foreach loop in egc_run_callbacks, to a safe alternative where the list is safe to be modified. - use STAILQ instead of TAILQ v3: - new patch tools/libxl/libxl_event.c | 20 ++++++++++++++++++++ tools/libxl/libxl_internal.h | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index 43155368de76..aa8b7d1945bd 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_STAILQ_INSERT_TAIL(&egc->ev_immediates, ei, entry); +} + /* * domain death/destruction */ @@ -1395,6 +1404,17 @@ 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; + + while (!LIBXL_STAILQ_EMPTY(&egc->ev_immediates)) { + ei = LIBXL_STAILQ_FIRST(&egc->ev_immediates); + LIBXL_STAILQ_REMOVE_HEAD(&egc->ev_immediates, 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..0b75eef2a22f 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_STAILQ_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_STAILQ_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_STAILQ_INIT(&(egc).ev_immediates); \ } while(0) _hidden void libxl__egc_cleanup(libxl__egc *egc);