From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek =?utf-8?Q?Marczykowski-G=C3=B3recki?= Subject: Re: [PATCH v2 2/3] python: Extract registered watch search logic from xspy_read_watch() Date: Thu, 21 Sep 2017 20:07:23 +0200 Message-ID: <20170921180723.GG1116@mail-itl> References: <1506012428-59769-1-git-send-email-euan.harris@citrix.com> <1506012428-59769-3-git-send-email-euan.harris@citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1296722818795145363==" Return-path: Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv5sq-0007sL-Es for xen-devel@lists.xenproject.org; Thu, 21 Sep 2017 18:07:32 +0000 In-Reply-To: <1506012428-59769-3-git-send-email-euan.harris@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: Euan Harris Cc: xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org --===============1296722818795145363== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0PQOkvCAw33/u/bm" Content-Disposition: inline --0PQOkvCAw33/u/bm Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 21, 2017 at 05:47:07PM +0100, Euan Harris wrote: > 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. >=20 > Signed-off-by: Euan Harris > Reviewed-by: Wei Liu Acked-by: Marek Marczykowski-G=C3=B3recki > --- > Changed since v1: > * Remove stray newline > * Fix indentation >=20 > tools/python/xen/lowlevel/xs/xs.c | 60 ++++++++++++++++++++++++---------= ------ > 1 file changed, 37 insertions(+), 23 deletions(-) >=20 > diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowleve= l/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) > =20 > static void remove_watch(XsHandle *xsh, PyObject *token); > =20 > +static PyObject *match_watch_by_token(XsHandle *self, char **xsval); > + > static PyObject *none(bool result); > =20 > static int parse_transaction_path(XsHandle *self, PyObject *args, > @@ -484,8 +486,6 @@ static PyObject *xspy_read_watch(XsHandle *self, PyOb= ject *args) > struct xs_handle *xh =3D xshandle(self); > PyObject *val =3D NULL; > char **xsval; > - PyObject *token; > - int i; > unsigned int num; > =20 > 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) != =3D 1) { > - xs_set_error(EINVAL); > - goto exit; > - } > - for (i =3D 0; i < PyList_Size(self->watches); i++) { > - if (token =3D=3D PyList_GetItem(self->watches, i)) > - break; > - } > - if (i =3D=3D PyList_Size(self->watches)) { > - /* We do not have a registered watch for the one that has just fir= ed. > - 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 =3D Py_BuildValue("(sO)", xsval[XS_WATCH_PATH], token); > - exit: > + > + val =3D match_watch_by_token(self, xsval); > free(xsval); > + > + if (!val && errno =3D=3D EAGAIN) { > + goto again; > + } > + > return val; > } > =20 > @@ -868,6 +855,33 @@ static int parse_transaction_path(XsHandle *self, Py= Object *args, > } > =20 > =20 > +static PyObject *match_watch_by_token(XsHandle *self, char **xsval) > +{ > + PyObject *token; > + int i; > + > + if (sscanf(xsval[XS_WATCH_TOKEN], "%li", (unsigned long *)&token) != =3D 1) { > + xs_set_error(EINVAL); > + return NULL; > + } > + for (i =3D 0; i < PyList_Size(self->watches); i++) { > + if (token =3D=3D PyList_GetItem(self->watches, i)) > + break; > + } > + if (i =3D=3D PyList_Size(self->watches)) { > + /* We do not have a registered watch for the one that has just f= ired. > + Ignore this -- a watch that has been recently deregistered ca= n 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) { --=20 Best Regards, Marek Marczykowski-G=C3=B3recki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? --0PQOkvCAw33/u/bm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZw//eAAoJENuP0xzK19csjlsIAIJPEXuboDHjZzPmZ+8WXOyx cItzrjoWO1o0B8ubPKl5+XVpXh21cJhJnAT5idW7ewKK6R9XneP16aaejLToZqo4 DZ8By3gxFc6W7AZH6Cg/Yl0Tiqsaf16A3ItweigMsQUkbanG/NEzlPBDmBjRBhan 4rZMeR3i2QN7D/KZqpUCD/FVau8osv3mIKXIdwLs8mETKdzLuQ5BuBe4SLRffy5w xisVFff7anJb1HYMP3eSUt1sCQt7+nH5CTaIMzwlo8qeSkh8cIyIROH4M4nR6Igc TEzIPuWV34DTJJpJAtsM3Ymrfsrt9fFpakR/7ZVxU9qz4/FKuwS6+elpF/p0ghg= =0wcY -----END PGP SIGNATURE----- --0PQOkvCAw33/u/bm-- --===============1296722818795145363== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --===============1296722818795145363==--