xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Wei Liu <wei.liu2@citrix.com>, Jim Fehlig <jfehlig@suse.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Ian Campbell <Ian.Campbell@citrix.com>
Subject: [PATCH 2/9] libxl: poll: Use poller_get and poller_put for poller_app
Date: Thu, 9 Jul 2015 18:47:50 +0100	[thread overview]
Message-ID: <1436464077-2752-3-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1436464077-2752-1-git-send-email-ian.jackson@eu.citrix.com>

This makes the code more regular.  We are going to want to do some
more work in poller_get and poller_put, which work also wants to be
done for poller_app.

Two very minor functional changes:

 * We call malloc an extra time since poller_app is now a pointer

 * ERROR_FAIL on poller_get failing for poller_app is generated in
   libxl_ctx_init rather than passed through by libxl_poller_init
   from libxl__pipe_nonblock.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Jim Fehlig <jfehlig@suse.com>
---
 tools/libxl/libxl.c          |   11 ++++++++---
 tools/libxl/libxl_event.c    |    4 ++--
 tools/libxl/libxl_internal.h |    2 +-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index e9a2d26..97a60cf 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -59,6 +59,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
 
     ctx->osevent_hooks = 0;
 
+    ctx->poller_app = 0;
     LIBXL_LIST_INIT(&ctx->pollers_event);
     LIBXL_LIST_INIT(&ctx->pollers_idle);
 
@@ -103,8 +104,11 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
     rc = libxl__atfork_init(ctx);
     if (rc) goto out;
 
-    rc = libxl__poller_init(gc, &ctx->poller_app);
-    if (rc) goto out;
+    ctx->poller_app = libxl__poller_get(gc);
+    if (!ctx->poller_app) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
 
     ctx->xch = xc_interface_open(lg,lg,0);
     if (!ctx->xch) {
@@ -183,7 +187,8 @@ int libxl_ctx_free(libxl_ctx *ctx)
     if (ctx->xsh) xs_daemon_close(ctx->xsh);
     if (ctx->xce) xc_evtchn_close(ctx->xce);
 
-    libxl__poller_dispose(&ctx->poller_app);
+    libxl__poller_put(ctx, ctx->poller_app);
+    ctx->poller_app = NULL;
     assert(LIBXL_LIST_EMPTY(&ctx->pollers_event));
     libxl__poller *poller, *poller_tmp;
     LIBXL_LIST_FOREACH_SAFE(poller, &ctx->pollers_idle, entry, poller_tmp) {
diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c
index b332dd7..942e02c 100644
--- a/tools/libxl/libxl_event.c
+++ b/tools/libxl/libxl_event.c
@@ -1138,7 +1138,7 @@ int libxl_osevent_beforepoll(libxl_ctx *ctx, int *nfds_io,
 {
     EGC_INIT(ctx);
     CTX_LOCK;
-    int rc = beforepoll_internal(gc, &ctx->poller_app,
+    int rc = beforepoll_internal(gc, ctx->poller_app,
                                  nfds_io, fds, timeout_upd, now);
     CTX_UNLOCK;
     EGC_FREE;
@@ -1291,7 +1291,7 @@ void libxl_osevent_afterpoll(libxl_ctx *ctx, int nfds, const struct pollfd *fds,
 {
     EGC_INIT(ctx);
     CTX_LOCK;
-    afterpoll_internal(egc, &ctx->poller_app, nfds, fds, now);
+    afterpoll_internal(egc, ctx->poller_app, nfds, fds, now);
     CTX_UNLOCK;
     EGC_FREE;
 }
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index d52589e..a33725e 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -401,7 +401,7 @@ struct libxl__ctx {
       /* See the comment for OSEVENT_HOOK_INTERN in libxl_event.c
        * for restrictions on the use of the osevent fields. */
 
-    libxl__poller poller_app; /* libxl_osevent_beforepoll and _afterpoll */
+    libxl__poller *poller_app; /* libxl_osevent_beforepoll and _afterpoll */
     LIBXL_LIST_HEAD(, libxl__poller) pollers_event, pollers_idle;
 
     LIBXL_SLIST_HEAD(libxl__osevent_hook_nexi, libxl__osevent_hook_nexus)
-- 
1.7.10.4

  parent reply	other threads:[~2015-07-09 17:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09 17:47 [PATCH 0/9] libxl: poll: Avoid fd deregistration race POLLNVAL Ian Jackson
2015-07-09 17:47 ` [PATCH 1/9] libxl: poll: Make libxl__poller_get have only one success return path Ian Jackson
2015-07-10 10:39   ` Wei Liu
2015-07-09 17:47 ` Ian Jackson [this message]
2015-07-10 10:39   ` [PATCH 2/9] libxl: poll: Use poller_get and poller_put for poller_app Wei Liu
2015-07-09 17:47 ` [PATCH 3/9] libxl: poll: Avoid fd deregistration race POLLNVAL crash Ian Jackson
2015-07-10 10:41   ` Wei Liu
2015-07-09 17:47 ` [PATCH 4/9] libxl: event tests: Improve Makefile doc comment Ian Jackson
2015-07-10 10:41   ` Wei Liu
2015-07-09 17:47 ` [PATCH 5/9] libxl: event tests: Contemplate separate tests Ian Jackson
2015-07-10 10:42   ` Wei Liu
2015-07-09 17:47 ` [PATCH 6/9] libxl: event tests: Provide libxl_test_fdevent Ian Jackson
2015-07-10 10:43   ` Wei Liu
2015-07-09 17:47 ` [PATCH 7/9] libxl: event tests: Provide miniature poll machinery Ian Jackson
2015-07-10 10:44   ` Wei Liu
2015-07-09 17:47 ` [PATCH 8/9] libxl: event tests: Introduce `fdderegrace' test Ian Jackson
2015-07-10 10:45   ` Wei Liu
2015-07-09 17:47 ` [PATCH 9/9] libxl: event tests: test_timedereg: Fix rc handling Ian Jackson
2015-07-10 10:46   ` Wei Liu
2015-07-15 10:43     ` [PATCH 9/9] libxl: event tests: test_timedereg: Fix rc handling [and 1 more messages] Ian Jackson
2015-07-13 15:14 ` [PATCH 0/9] libxl: poll: Avoid fd deregistration race POLLNVAL Jim Fehlig
2015-07-13 15:54   ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436464077-2752-3-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=jfehlig@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).