All of lore.kernel.org
 help / color / mirror / Atom feed
From: Euan Harris <euan.harris@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Euan Harris <euan.harris@citrix.com>, marmarek@invisiblethingslab.com
Subject: [PATCH v2 2/3] python: Extract registered watch search logic from xspy_read_watch()
Date: Thu, 21 Sep 2017 17:47:07 +0100	[thread overview]
Message-ID: <1506012428-59769-3-git-send-email-euan.harris@citrix.com> (raw)
In-Reply-To: <1506012428-59769-1-git-send-email-euan.harris@citrix.com>

When a watch fires, xspy_read_watch() checks whether the client has
registered interest in the path which changed and, if so, returns the
path and a client-supplied token.   The binding for xs_check_watch()
needs to do the same, so this patch extracts the search code into a
separate function.

Signed-off-by: Euan Harris <euan.harris@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
---
Changed since v1:
 * Remove stray newline
 * Fix indentation

 tools/python/xen/lowlevel/xs/xs.c | 60 ++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 23 deletions(-)

diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c
index 9f1b916..2af5e07 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -77,6 +77,8 @@ static inline struct xs_handle *xshandle(XsHandle *self)
 
 static void remove_watch(XsHandle *xsh, PyObject *token);
 
+static PyObject *match_watch_by_token(XsHandle *self, char **xsval);
+
 static PyObject *none(bool result);
 
 static int parse_transaction_path(XsHandle *self, PyObject *args,
@@ -484,8 +486,6 @@ static PyObject *xspy_read_watch(XsHandle *self, PyObject *args)
     struct xs_handle *xh = xshandle(self);
     PyObject *val = NULL;
     char **xsval;
-    PyObject *token;
-    int i;
     unsigned int num;
 
     if (!xh)
@@ -497,29 +497,16 @@ again:
     Py_END_ALLOW_THREADS
     if (!xsval) {
         PyErr_SetFromErrno(xs_error);
-        goto exit;
-    }
-    if (sscanf(xsval[XS_WATCH_TOKEN], "%li", (unsigned long *)&token) != 1) {
-	xs_set_error(EINVAL);
-        goto exit;
-    }
-    for (i = 0; i < PyList_Size(self->watches); i++) {
-        if (token == PyList_GetItem(self->watches, i))
-            break;
-    }
-    if (i == PyList_Size(self->watches)) {
-      /* We do not have a registered watch for the one that has just fired.
-         Ignore this -- a watch that has been recently deregistered can still
-         have watches in transit.  This is a blocking method, so go back to
-         read again.
-      */
-      free(xsval);
-      goto again;
+        return val;
     }
-    /* Create tuple (path, token). */
-    val = Py_BuildValue("(sO)", xsval[XS_WATCH_PATH], token);
- exit:
+
+    val = match_watch_by_token(self, xsval);
     free(xsval);
+
+    if (!val && errno == EAGAIN) {
+        goto again;
+    }
+
     return val;
 }
 
@@ -868,6 +855,33 @@ static int parse_transaction_path(XsHandle *self, PyObject *args,
 }
 
 
+static PyObject *match_watch_by_token(XsHandle *self, char **xsval)
+{
+    PyObject *token;
+    int i;
+
+    if (sscanf(xsval[XS_WATCH_TOKEN], "%li", (unsigned long *)&token) != 1) {
+        xs_set_error(EINVAL);
+        return NULL;
+    }
+    for (i = 0; i < PyList_Size(self->watches); i++) {
+        if (token == PyList_GetItem(self->watches, i))
+            break;
+    }
+    if (i == PyList_Size(self->watches)) {
+        /* We do not have a registered watch for the one that has just fired.
+           Ignore this -- a watch that has been recently deregistered can still
+           have watches in transit.
+        */
+        xs_set_error(EAGAIN);
+        return NULL;
+    }
+
+    /* Create tuple (path, token). */
+    return Py_BuildValue("(sO)", xsval[XS_WATCH_PATH], token);
+}
+
+
 static PyObject *none(bool result)
 {
     if (result) {
-- 
1.8.3.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-09-21 16:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-21 16:47 [PATCH v2 0/3] python: Add non-blocking Xenstore watch bindings Euan Harris
2017-09-21 16:47 ` [PATCH v2 1/3] python: Add binding for xs_fileno() Euan Harris
2017-09-21 18:04   ` Marek Marczykowski-Górecki
2017-09-21 16:47 ` Euan Harris [this message]
2017-09-21 18:07   ` [PATCH v2 2/3] python: Extract registered watch search logic from xspy_read_watch() Marek Marczykowski-Górecki
2017-09-21 16:47 ` [PATCH v2 3/3] python: Add binding for non-blocking xs_check_watch() Euan Harris
2017-09-21 18:09   ` Marek Marczykowski-Górecki

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=1506012428-59769-3-git-send-email-euan.harris@citrix.com \
    --to=euan.harris@citrix.com \
    --cc=marmarek@invisiblethingslab.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.