From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 06/23] libxl: init: libxl__poller_init and _get take gc Date: Tue, 17 Dec 2013 18:35:20 +0000 Message-ID: <1387305337-15355-7-git-send-email-ian.jackson@eu.citrix.com> References: <1387305337-15355-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: <1387305337-15355-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: Shriram Rajagopalan , George Dunlap , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Change libxl__poller_init and libxl__poller__get to take a libxl__gc* rather than a libxl_ctx*. The gc is not used for memory allocation but simply to provide the standard local variable "gc" expected by the convenience macros. Doing this makes the error logging more convenient. Hence, convert the logging calls to use the LOG* convenience macros. And consequently, change the call sites, and the function bodies to use CTX rather than ctx. Also convert a call to malloc() (with error check) in libxl__poller_get, to libxl__zalloc (no error check needed). Signed-off-by: Ian Jackson CC: Stefano Stabellini CC: Ian Campbell --- tools/libxl/libxl.c | 2 +- tools/libxl/libxl_event.c | 25 ++++++++++--------------- tools/libxl/libxl_internal.h | 4 ++-- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index cfd1435..85b56a9 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -87,7 +87,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, rc = libxl__atfork_init(ctx); if (rc) goto out; - rc = libxl__poller_init(ctx, &ctx->poller_app); + rc = libxl__poller_init(gc, &ctx->poller_app); if (rc) goto out; ctx->xch = xc_interface_open(lg,lg,0); diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index bdef7ac..9c4fe1c 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -1274,7 +1274,7 @@ int libxl_event_check(libxl_ctx *ctx, libxl_event **event_r, * Manipulation of pollers */ -int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p) +int libxl__poller_init(libxl__gc *gc, libxl__poller *p) { int r, rc; p->fd_polls = 0; @@ -1282,15 +1282,15 @@ int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p) r = pipe(p->wakeup_pipe); if (r) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot create poller pipe"); + LOGE(ERROR, "cannot create poller pipe"); rc = ERROR_FAIL; goto out; } - rc = libxl_fd_set_nonblock(ctx, p->wakeup_pipe[0], 1); + rc = libxl_fd_set_nonblock(CTX, p->wakeup_pipe[0], 1); if (rc) goto out; - rc = libxl_fd_set_nonblock(ctx, p->wakeup_pipe[1], 1); + rc = libxl_fd_set_nonblock(CTX, p->wakeup_pipe[1], 1); if (rc) goto out; return 0; @@ -1308,25 +1308,20 @@ void libxl__poller_dispose(libxl__poller *p) free(p->fd_rindices); } -libxl__poller *libxl__poller_get(libxl_ctx *ctx) +libxl__poller *libxl__poller_get(libxl__gc *gc) { /* must be called with ctx locked */ int rc; - libxl__poller *p = LIBXL_LIST_FIRST(&ctx->pollers_idle); + libxl__poller *p = LIBXL_LIST_FIRST(&CTX->pollers_idle); if (p) { LIBXL_LIST_REMOVE(p, entry); return p; } - p = malloc(sizeof(*p)); - if (!p) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot allocate poller"); - return 0; - } - memset(p, 0, sizeof(*p)); + p = libxl__zalloc(NOGC, sizeof(*p)); - rc = libxl__poller_init(ctx, p); + rc = libxl__poller_init(gc, p); if (rc) { free(p); return NULL; @@ -1446,7 +1441,7 @@ int libxl_event_wait(libxl_ctx *ctx, libxl_event **event_r, EGC_INIT(ctx); CTX_LOCK; - poller = libxl__poller_get(ctx); + poller = libxl__poller_get(gc); if (!poller) { rc = ERROR_FAIL; goto out; } for (;;) { @@ -1622,7 +1617,7 @@ libxl__ao *libxl__ao_create(libxl_ctx *ctx, uint32_t domid, if (how) { ao->how = *how; } else { - ao->poller = libxl__poller_get(ctx); + ao->poller = libxl__poller_get(&ao->gc); if (!ao->poller) goto out; } libxl__log(ctx,XTL_DEBUG,-1,file,line,func, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 1bd23ff..2712005 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -823,13 +823,13 @@ _hidden void libxl__event_disaster(libxl__egc*, const char *msg, int errnoval, /* Fills in, or disposes of, the resources held by, a poller whose * space the caller has allocated. ctx must be locked. */ -_hidden int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p); +_hidden int libxl__poller_init(libxl__gc *gc, libxl__poller *p); _hidden void libxl__poller_dispose(libxl__poller *p); /* Obtain a fresh poller from malloc or the idle list, and put it * away again afterwards. _get can fail, returning NULL. * ctx must be locked. */ -_hidden libxl__poller *libxl__poller_get(libxl_ctx *ctx); +_hidden libxl__poller *libxl__poller_get(libxl__gc *gc); _hidden void libxl__poller_put(libxl_ctx*, libxl__poller *p /* may be NULL */); /* Notifies whoever is polling using p that they should wake up. -- 1.7.10.4