From: Sergei Lebedev Subject: Re: Xen 4.4, xenstored and WATCH requests Date: Fri, 26 Feb 2016 15:10:10 +0300 Message-ID: References: <20160226112650.GC644@citrix.com> Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) Content-Type: multipart/mixed; boundary="===============2614402653989723423==" Return-path: In-Reply-To: <20160226112650.GC644@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: Wei Liu Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org --===============2614402653989723423== Content-Type: multipart/alternative; boundary="Apple-Mail=_0FB1B7A7-5DAC-4E77-92D4-3C653105098A" --Apple-Mail=_0FB1B7A7-5DAC-4E77-92D4-3C653105098A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Wei, Yes, the Unix socket interface works okay. Here=E2=80=99s a relevant = part of the script changed to use the socket: import socket sock =3D socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect("/var/run/xenstored/socket") fd =3D os.dup(sock.fileno()) try: send_packet(fd, WRITE, 24, 0, b"/foo\x00bar\x00") print_reply(fd) # Responds with rq_id =3D 24. send_packet(fd, WATCH, 42, 0, b"/foo\x00token\x00") print_reply(fd) # ACK for WATCH with rq_id =3D 42. finally: os.close(fd) > BTW can you paste in the result of >=20 > $ ps aux | grep xenstored >=20 > here? $ ps aux | grep xenstored root 807 0.0 0.2 10932 2132 ? S 00:34 0:01 = /usr/lib/xen-4.4/bin/xenstored --p id-file=3D/var/run/xenstore.pid Sergei > On 26 Feb 2016, at 14:26, Wei Liu wrote: >=20 > Hello >=20 > On Thu, Feb 25, 2016 at 03:54:14PM +0300, Sergei Lebedev wrote: >> Hello list, >>=20 >> I=E2=80=99m working on a Python client library for XenStore [1]. The = library >> implements two ways to access XenStore: via Unix socket and via /dev. >> The /dev interface turned out to be a bit problematic, because it >> ignores the req_id field for WATCH requests. >>=20 >=20 > So the unix socket interface worked fine for you? >=20 >> The spec [2] requires all responses (except WATCH_EVENT) to copy >> req_id from request. So I wonder if it=E2=80=99s possible that the = behaviour I >> observe is in fact a bug in xenstored? >>=20 >> Below is a Python script demonstrating the issue: >>=20 >> import os >> import struct >>=20 >> WATCH =3D 4 >> WRITE =3D 11 >>=20 >> def send_packet(fd, op, rq_id, tx_id, payload): >> data =3D struct.pack(b"IIII", op, rq_id, tx_id, len(payload)) = + payload >> os.write(fd, data) >>=20 >>=20 >> def print_reply(fd): >> op, rq_id, tx_id, size =3D struct.unpack(b"IIII", os.read(fd, = 16)) >> payload =3D os.read(fd, size) if size else b"" >> print(op, rq_id, tx_id, payload) >>=20 >>=20 >> fd =3D os.open("/dev/xen/xenbus", os.O_RDWR) >> try: >> send_packet(fd, WRITE, 24, 0, b"/foo\x00bar\x00") >> print_reply(fd) # ACK for WRITE with rq_id =3D 24. >> send_packet(fd, WATCH, 42, 0, b"/foo\x00token\x00") >> print_reply(fd) # Spurious (?) WATCH_EVENT. >> print_reply(fd) # ACK for WATCH with rq_id =3D 0. >> finally: >> os.close(fd) >>=20 >=20 >> Example output: >>=20 >> (11, 24, 0, 'OK\x00') >> (15, 4294967295, 892960384, '/foo\x00token\x00') >> (4, 0, 0, 'OK\x00') >>=20 >> I=E2=80=99m running Xen 4.4 on Ubuntu 14.04 inside VirtualBox. >>=20 >> $ uname -a >> Linux xen-devel 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 = 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux >>=20 >=20 > FWIW I tried you program in my own testbox running xen-unstable with > Debian's stock 3.16 kernel, the result is the same. >=20 > And in xen.git >=20 > $ git diff origin/stable-4.4..origin/staging -- = docs/misc/xenstore.txt >=20 > shows nothing. >=20 > So this is not a problem in 4.4 only. >=20 > Wei. >=20 >> Regards, >> Sergei >>=20 >> [1]: http://github.com/selectel/pyxs = >> [2]: http://xenbits.xen.org/docs/4.4-testing/misc/xenstore.txt = >>=20 >>=20 >> _______________________________________________ >> Xen-devel mailing list >> Xen-devel@lists.xen.org >> http://lists.xen.org/xen-devel --Apple-Mail=_0FB1B7A7-5DAC-4E77-92D4-3C653105098A Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi Wei,

Yes, the Unix socket interface works okay. Here=E2=80=99s a = relevant part of the script changed to use the socket:

    import socket
  =   sock =3D socket.socket(socket.AF_UNIX, = socket.SOCK_STREAM)
    = sock.connect("/var/run/xenstored/socket")
  =   fd =3D os.dup(sock.fileno())
    = try:
        send_packet(fd, = WRITE, 24, 0, b"/foo\x00bar\x00")
    =     print_reply(fd)  # Responds with rq_id =3D = 24.
        send_packet(fd, = WATCH, 42, 0, b"/foo\x00token\x00")
    =     print_reply(fd)  # ACK for WATCH with rq_id =3D = 42.
    finally:
        = os.close(fd)

BTW can you paste in = the result of

 $ ps aux | grep = xenstored

here?

$ ps aux | grep = xenstored
root       807  0.0 =  0.2  10932  2132 ?        S   =  00:34   0:01 /usr/lib/xen-4.4/bin/xenstored --p
id-file=3D/var/run/xenstore.pid

Sergei


On = 26 Feb 2016, at 14:26, Wei Liu <wei.liu2@citrix.com> wrote:

Hello

On Thu, Feb 25, 2016 at 03:54:14PM +0300, Sergei = Lebedev wrote:
Hello list,

I=E2=80=99m = working on a Python client library for XenStore [1]. The library
implements two ways to access XenStore: via Unix socket and = via /dev.
The /dev interface turned out to be a bit = problematic, because it
ignores the req_id field for WATCH = requests.


So the unix socket interface worked fine for = you?

The spec [2] requires = all responses (except WATCH_EVENT) to copy
req_id from = request. So I wonder if it=E2=80=99s possible that the behaviour I
observe is in fact a bug in xenstored?

Below is a Python script demonstrating the issue:

   import os
   import struct

   WATCH =3D 4
   WRITE =3D 11

   def send_packet(fd, op, rq_id, tx_id, = payload):
       data =3D= struct.pack(b"IIII", op, rq_id, tx_id, len(payload)) + payload
       os.write(fd, = data)


   def = print_reply(fd):
       op, rq_id, tx_id, = size =3D struct.unpack(b"IIII", os.read(fd, 16))
       payload =3D = os.read(fd, size) if size else b""
       print(op, rq_id, = tx_id, payload)


   fd =3D os.open("/dev/xen/xenbus", = os.O_RDWR)
   try:
       send_packet(fd, = WRITE, 24, 0, b"/foo\x00bar\x00")
       print_reply(fd) =  # ACK for WRITE with rq_id =3D 24.
       send_packet(fd, = WATCH, 42, 0, b"/foo\x00token\x00")
       print_reply(fd) =  # Spurious (?) WATCH_EVENT.
       print_reply(fd) =  # ACK for WATCH with rq_id =3D 0.
   finally:
       os.close(fd)


Example output:

   (11, 24, 0, 'OK\x00')
   (15, 4294967295, 892960384, = '/foo\x00token\x00')
   (4, 0, 0, = 'OK\x00')

I=E2=80=99m running Xen 4.4 on = Ubuntu 14.04 inside VirtualBox.

$ uname = -a
Linux xen-devel 3.19.0-25-generic #26~14.04.1-Ubuntu = SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


FWIW I tried you program in my own = testbox running xen-unstable with
Debian's stock 3.16 kernel, the result is = the same.

And in xen.git

 $ git diff = origin/stable-4.4..origin/staging -- docs/misc/xenstore.txt

shows nothing.

So this is not a problem in 4.4 = only.

Wei.

Regards,Sergei

[1]: http://github.com/selectel/pyxs
[2]: http://xenbits.xen.org/docs/4.4-testing/misc/xenstore.txt

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

= --Apple-Mail=_0FB1B7A7-5DAC-4E77-92D4-3C653105098A-- --===============2614402653989723423== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --===============2614402653989723423==--