From: John McCullough Subject: XenStore difficulties. Date: Mon, 13 Nov 2006 21:23:52 -0800 Message-ID: <20061114052351.GA30871@cs.ucsd.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0888531916==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============0888531916== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZoaI/ZTpAVc4A5k6" Content-Disposition: inline --ZoaI/ZTpAVc4A5k6 Content-Type: multipart/mixed; boundary="jI8keyz6grp/JLjh" Content-Disposition: inline --jI8keyz6grp/JLjh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, I am working on forking hvm domains and I have been using xenstore to send commands to qemu. I have noticed that occasionally qemu's watch is not read. I am using the qemu fd handler methods. I have been trying to duplicate the missed read outside of qemu and the rest of xend, but I haven't been able to. However, I think I may have discovered a memory leak in lowlevel/xs/xs.c. I am attaching: - commandee.c : consumer of "commands" - commander.py : issuer of commands - xsblockingchannel.py : com channel for the commander I am working against a changset from midsummer (11536:041be3f6b38e) since I'm trying to iron out some of my bugs before moving forward in the revisions. % gcc -o commandee commandee.c /usr/lib/libxenstore.a -lpthread % sudo ./commandee > /dev/null=20 % time sudo python commander.py > /dev/null #(in separate terminal) Traceback (most recent call last): File "commander.py", line 9, in ? xsbc =3D xsblockingchannel.xsblockingchannel("test") File "/net/xen/xsstress/xsblockingchannel.py", line 19, in __init__ self.xs.watch(self.path, self) xen.lowlevel.xs.Error: (12, 'Cannot allocate memory') Exception xen.lowlevel.xs.Error: (2, 'No such file or directory') in > ignor= ed 1.02s user 5.00s system 8% cpu 1:08.61 total Given that I am unwatching the watches in xsblockingchannel I don't think the memory leak would be due to me. As far as the lost watches are concerned, I would speculate that something is wrong with qemu's select/callback handling, or that xenstore is racing and dropping things. If the memory leak has already been fixed, I apologise for the noise. I am moving on to unix domain sockets for now, as I have been running into this problem for a while and I don't currently have the patience to debug it, but I thought I should mention it so that it is on the general radar. Once I finish with the domain sockets I should find out whether it is the qemu select handling. Regards, John McCullough --jI8keyz6grp/JLjh Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="commandee.c" Content-Transfer-Encoding: quoted-printable #include "xs.h" #include #include #include int main(void) { const char path[] =3D "/tool/test"; struct xs_handle *xs; xs_transaction_t th; int fd_q; int num, len; char **vec, *buf; fd_set set_q; xs =3D xs_daemon_open(); printf("xs: %p\n", xs); th =3D xs_transaction_start(xs); xs_write(xs, th, path, "init", strlen("init")); xs_transaction_end(xs, th, 0); xs_watch(xs, path, "commandee"); fd_q =3D xs_fileno(xs); while(1){ struct timeval tv =3D {.tv_sec=3D1, .tv_usec=3D0}; FD_ZERO(&set_q); FD_SET(fd_q, &set_q); if(select(fd_q + 1, &set_q, NULL, NULL, &tv) > 0 && FD_ISSET(fd_q, &set_q)) { vec =3D xs_read_watch(xs, &num); if(vec !=3D NULL){ th =3D xs_transaction_start(xs); buf =3D xs_read(xs, th, vec[XS_WATCH_PATH], &len); xs_transaction_end(xs, th, 0); printf("Got %s\n", buf); if(!strstr(buf, "_done")) { char *fu; printf("Wrote Response\n"); th =3D xs_transaction_start(xs); asprintf(&fu, "%s_done", buf); xs_write(xs, th, path, fu, strlen(fu)); free(fu); xs_transaction_end(xs, th, 0); =20 } free(buf); free(vec); } } } xs_unwatch(xs, path, "commandee"); } --jI8keyz6grp/JLjh Content-Type: text/x-python; charset=us-ascii Content-Disposition: attachment; filename="commander.py" Content-Transfer-Encoding: quoted-printable import sys import time sys.path.append("/usr/lib/python") import xsblockingchannel =66rom xen.xend.xenstore.xstransact import xstransact while 1: xsbc =3D xsblockingchannel.xsblockingchannel("test") xsbc.write("hello") xsbc.waitFor("hello_done") xsbc.write("there") xsbc.waitFor("there_done") --jI8keyz6grp/JLjh Content-Type: text/x-python; charset=us-ascii Content-Disposition: attachment; filename="xsblockingchannel.py" Content-Transfer-Encoding: quoted-printable import threading import sys =66rom xen.xend.xenstore.xsutil import xshandle_new =66rom xen.xend.xenstore.xswatch import xswatch=20 class xsblockingchannel: """ The XenStore Blocking Channel provides an interface into a communication channel that will block waiting for specific values. This is helpful for stateful communications across the XenStore. """ def __init__(self, toolNode): """ toolNode - The node within /tools=20 """ self.xs =3D xshandle_new()=20 self.path =3D "/tool/%s" % toolNode =20 self.xs.watch(self.path, self) self.xs.watch("@domainRelease", self) def __del__(self): self.xs.unwatch(self.path, self) self.xs.unwatch("@domainRelease", self) xs.dealloc() def write(self, value): """ value - A value to be written to the toNode """ th =3D self.xs.transaction_start() self.xs.write(th, self.path, value) res =3D self.xs.transaction_end(th) print("xsbc.write " + value + " res" + str(res)) =20 def waitFor(self, waitValue, timeout=3D5): """ Perform a blocking wait for value on the fromNode. """ while True: th =3D self.xs.transaction_start() val =3D self.xs.read(th, self.path) self.xs.transaction_end(th) print("Got val %s want %s" % (val, waitValue)) if val =3D=3D waitValue: return True self.we =3D None =20 watchThread =3D threading.Thread(target=3DreadWatchThread, args=3D[self]) watchThread.start() watchThread.run() try: watchThread.join(timeout) except: sys.exit(1) if watchThread.isAlive(): # Trigger the watch ourselves print("xsbc: wait on %s timed out after %ds" %=20 (self.path, timeout= )) th =3D self.xs.transaction_start() self.xs.write(th, self.path, "timed out") self.xs.transaction_end(th) return False if self.we !=3D None: path =3D self.we[0] =20 if path =3D=3D "@releaseDomain": print("Got %s" % path) return False =20 def cleanup(self): """ Remove the node from xenstore. """ th =3D self.xs.transaction_start() self.xs.rm(th, self.path) self.xs.transaction_end(th) def readWatchThread(self): we =3D self.xs.read_watch() self.we =3D we =20 --jI8keyz6grp/JLjh-- --ZoaI/ZTpAVc4A5k6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQFFWVLn48DoLwhCPR0RAqGJAJwPWQrGvaeN9SGZ0mwECGGP8ko38ACg1wti p0OEH9syPazst0aMjucuyaE= =DNfT -----END PGP SIGNATURE----- --ZoaI/ZTpAVc4A5k6-- --===============0888531916== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0888531916==--