From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 10/14] libxl: ao: Record ultimate parent of a nested ao Date: Fri, 20 Dec 2013 18:45:48 +0000 Message-ID: <1387565152-5642-11-git-send-email-ian.jackson@eu.citrix.com> References: <21172.35652.484647.666791@mariner.uk.xensource.com> <1387565152-5642-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1387565152-5642-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org This will be used by the cancellation machinery. Signed-off-by: Ian Jackson --- tools/libxl/libxl_event.c | 25 +++++++++++++++---------- tools/libxl/libxl_internal.h | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index 28b134a..8eb3483 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -31,6 +31,9 @@ #define DBG(args, ...) LIBXL__DBG_LOG(CTX, args, __VA_ARGS__) +static libxl__ao *ao_nested_root(libxl__ao *ao); + + /* * The counter osevent_in_hook is used to ensure that the application * honours the reentrancy restriction documented in libxl_event.h. @@ -1700,7 +1703,7 @@ void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc) LOG(DEBUG,"ao %p: complete, rc=%d",ao,rc); assert(ao->magic == LIBXL__AO_MAGIC); assert(!ao->complete); - assert(!ao->nested); + assert(!ao->nested_root); ao->complete = 1; ao->rc = rc; @@ -1865,7 +1868,7 @@ void libxl__ao_progress_report(libxl__egc *egc, libxl__ao *ao, const libxl_asyncprogress_how *how, libxl_event *ev) { AO_GC; - assert(!ao->nested); + assert(!ao->nested_root); if (how->callback == dummy_asyncprogress_callback_ignore) { LOG(DEBUG,"ao %p: progress report: ignored",ao); libxl_event_free(CTX,ev); @@ -1888,21 +1891,23 @@ void libxl__ao_progress_report(libxl__egc *egc, libxl__ao *ao, /* nested ao */ +static libxl__ao *ao_nested_root(libxl__ao *ao) { + libxl__ao *root = ao->nested_root ? : ao; + assert(!root->nested_root); + return root; +} + _hidden libxl__ao *libxl__nested_ao_create(libxl__ao *parent) { - /* We only use the parent to get the ctx. However, we require the - * caller to provide us with an ao, not just a ctx, to prove that - * they are already in an asynchronous operation. That will avoid - * people using this to (for example) make an ao in a non-ao_how - * function somewhere in the middle of libxl. */ - libxl__ao *child = NULL; + libxl__ao *child = NULL, *root; libxl_ctx *ctx = libxl__gc_owner(&parent->gc); assert(parent->magic == LIBXL__AO_MAGIC); + root = ao_nested_root(parent); child = libxl__zalloc(&ctx->nogc_gc, sizeof(*child)); child->magic = LIBXL__AO_MAGIC; - child->nested = 1; + child->nested_root = root; LIBXL_INIT_GC(child->gc, ctx); libxl__gc *gc = &child->gc; @@ -1913,7 +1918,7 @@ _hidden libxl__ao *libxl__nested_ao_create(libxl__ao *parent) _hidden void libxl__nested_ao_free(libxl__ao *child) { assert(child->magic == LIBXL__AO_MAGIC); - assert(child->nested); + assert(child->nested_root); libxl_ctx *ctx = libxl__gc_owner(&child->gc); libxl__ao__destroy(ctx, child); } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index b2109ea..3213d73 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -443,7 +443,8 @@ struct libxl__ao { * only in libxl__ao_complete.) */ uint32_t magic; - unsigned constructing:1, in_initiator:1, complete:1, notified:1, nested:1; + unsigned constructing:1, in_initiator:1, complete:1, notified:1; + libxl__ao *nested_root; int progress_reports_outstanding; int rc; libxl__gc gc; -- 1.7.10.4