Skip to contentSkip to conversation

XenStore difficulties.

DISCUSSION John McCullough 2 participants 3 messages Nov 14, 2006

lore
Share & tools
lore
#0 lore raw

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
% time sudo python commander.py > /dev/null #(in separate terminal) Traceback (most recent call last):
File "commander.py", line 9, in ?
xsbc = 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 <bound method xsblockingchannel.__del__ of <xsblockingchannel.xsblockingchannel instance at 0xb7ce448c>> ignored

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

#include "xs.h"
#include <unistd.h>
#include <sys/select.h>
#include <sys/types.h>

int main(void)

{
    const char path[] = "/tool/test";
    struct xs_handle *xs;
    xs_transaction_t th;
    int fd_q;
    int num, len;
    char **vec, *buf;
    fd_set set_q;

    xs = xs_daemon_open();
    printf("xs: %p\n", xs);
    th = 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 = xs_fileno(xs);

    while(1){
        struct timeval tv = {.tv_sec=1, .tv_usec=0};

    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 = xs_read_watch(xs, &num);
        if(vec != NULL){
            th = xs_transaction_start(xs);
            buf = 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 = 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);
            
            }
            free(buf);
            free(vec);
        }
    }
    }

    xs_unwatch(xs, path, "commandee");
}

import sys
import time
sys.path.append("/usr/lib/python")

import xsblockingchannel
from xen.xend.xenstore.xstransact import xstransact

while 1:

    xsbc = xsblockingchannel.xsblockingchannel("test")
    xsbc.write("hello")
    xsbc.waitFor("hello_done")
    xsbc.write("there")
    xsbc.waitFor("there_done")

import threading
import sys
from xen.xend.xenstore.xsutil import xshandle_new
from xen.xend.xenstore.xswatch import xswatch

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
"""
self.xs = xshandle_new()
self.path = "/tool/%s" % toolNode

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 = self.xs.transaction_start() self.xs.write(th, self.path, value)
res = self.xs.transaction_end(th) print("xsbc.write " + value + " res" + str(res))

def waitFor(self, waitValue, timeout=5):
"""
Perform a blocking wait for value on the fromNode. """

while True:
th = self.xs.transaction_start()
val = self.xs.read(th, self.path)
self.xs.transaction_end(th)

print("Got val %s want %s" % (val, waitValue)) if val == waitValue:
return True

self.we = None

watchThread = threading.Thread(target=readWatchThread,
args=[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" %
(self.path, timeout))
th = self.xs.transaction_start() self.xs.write(th, self.path, "timed out") self.xs.transaction_end(th)

return False

if self.we != None:
path = self.we[0]

if path == "@releaseDomain":
print("Got %s" % path)
return False

def cleanup(self):
"""
Remove the node from xenstore.
"""
th = self.xs.transaction_start()
self.xs.rm(th, self.path)
self.xs.transaction_end(th)

def readWatchThread(self):
we = self.xs.read_watch()
self.we = we

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 31 lines · John McCullough

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
% time sudo python commander.py > /dev/null #(in separate terminal) Traceback (most recent call last):
File "commander.py", line 9, in ?
xsbc = 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 <bound method xsblockingchannel.__del__ of <xsblockingchannel.xsblockingchannel instance at 0xb7ce448c>> ignored

Quoted 1 line

1.02s user 5.00s system 8% cpu 1:08.61 total

I can't remember the details, but I have vague recollection of a Xenstore-related problem where the error was ENOMEM, but that error was misleading.

One thing you can try is to run xenstore in trace mode: export XENSTORED_TRACE=1 before running xend, which will add "-T /var/log/xen/xenstored-trace.log" to the xenstore command line. This will give you a log of every operation on the store, which will tell us whether the error code is coming from xenstore.

Regarding the missing read -- that's probably because you are not handling EAGAIN when doing xs_transaction_end. You need to retry if xs_transaction_end fails with errno = EAGAIN, being careful not to allocate memory each retry. See xenstore_client.c for example.

Ewan.

#2 lore raw
Quoted 33 lines · Ewan Mellor
Quoted 31 lines · John McCullough

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
% time sudo python commander.py > /dev/null #(in separate terminal) Traceback (most recent call last):
File "commander.py", line 9, in ?
xsbc = 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 <bound method xsblockingchannel.__del__ of <xsblockingchannel.xsblockingchannel instance at 0xb7ce448c>> ignored

Quoted 5 lines
Quoted 1 line

1.02s user 5.00s system 8% cpu 1:08.61 total

I can't remember the details, but I have vague recollection of a Xenstore-related problem where the error was ENOMEM, but that error was misleading.

The problem I was thinking was a misleading ENOSPC, not a misleading ENOMEM (and we've since fixed the ENOSPC). It looks like your ENOMEM might be real.

Ewan.