ia64/xen-unstable

changeset 7905:5c954929bb0d

Merged.
author emellor@leeni.uk.xensource.com
date Fri Nov 18 16:32:04 2005 +0100 (2005-11-18)
parents 049dee79c76d 0dd531d4af46
children 69ea493e415a 1e3042a93904
files
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Fri Nov 18 16:31:50 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Fri Nov 18 16:32:04 2005 +0100
     1.3 @@ -199,6 +199,7 @@ static void *xs_talkv(struct xenbus_tran
     1.4  	int err;
     1.5  
     1.6  	msg.tx_id = (u32)(unsigned long)t;
     1.7 +	msg.req_id = 0;
     1.8  	msg.type = type;
     1.9  	msg.len = 0;
    1.10  	for (i = 0; i < num_vecs; i++)
     2.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Fri Nov 18 16:31:50 2005 +0100
     2.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Fri Nov 18 16:32:04 2005 +0100
     2.3 @@ -49,19 +49,16 @@ static PyObject *pyxc_domain_dumpcore(Py
     2.4  
     2.5      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
     2.6                                        &dom, &corefile) )
     2.7 -        goto exit;
     2.8 +        return NULL;
     2.9  
    2.10      if ( (corefile == NULL) || (corefile[0] == '\0') )
    2.11 -        goto exit;
    2.12 +        return NULL;
    2.13  
    2.14      if ( xc_domain_dumpcore(xc->xc_handle, dom, corefile) != 0 )
    2.15          return PyErr_SetFromErrno(xc_error);
    2.16      
    2.17      Py_INCREF(zero);
    2.18      return zero;
    2.19 -
    2.20 - exit:
    2.21 -    return NULL;
    2.22  }
    2.23  
    2.24  static PyObject *pyxc_handle(PyObject *self)
    2.25 @@ -95,12 +92,7 @@ static PyObject *pyxc_domain_create(PyOb
    2.26      {
    2.27          if ( !PyList_Check(pyhandle) || 
    2.28               (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) )
    2.29 -        {
    2.30 -        out_exception:
    2.31 -            errno = EINVAL;
    2.32 -            PyErr_SetFromErrno(xc_error);
    2.33 -            return NULL;
    2.34 -        }
    2.35 +            goto out_exception;
    2.36  
    2.37          for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
    2.38          {
    2.39 @@ -115,6 +107,11 @@ static PyObject *pyxc_domain_create(PyOb
    2.40          return PyErr_SetFromErrno(xc_error);
    2.41  
    2.42      return PyInt_FromLong(dom);
    2.43 +
    2.44 +out_exception:
    2.45 +    errno = EINVAL;
    2.46 +    PyErr_SetFromErrno(xc_error);
    2.47 +    return NULL;
    2.48  }
    2.49  
    2.50  static PyObject *pyxc_domain_max_vcpus(PyObject *self,
    2.51 @@ -270,10 +267,7 @@ static PyObject *pyxc_domain_sethandle(P
    2.52      if ( !PyList_Check(pyhandle) || 
    2.53           (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) )
    2.54      {
    2.55 -    out_exception:
    2.56 -        errno = EINVAL;
    2.57 -        PyErr_SetFromErrno(xc_error);
    2.58 -        return NULL;
    2.59 +        goto out_exception;
    2.60      }
    2.61  
    2.62      for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
    2.63 @@ -289,8 +283,14 @@ static PyObject *pyxc_domain_sethandle(P
    2.64      
    2.65      Py_INCREF(zero);
    2.66      return zero;
    2.67 +
    2.68 +out_exception:
    2.69 +    errno = EINVAL;
    2.70 +    PyErr_SetFromErrno(xc_error);
    2.71 +    return NULL;
    2.72  }
    2.73  
    2.74 +
    2.75  static PyObject *pyxc_domain_getinfo(PyObject *self,
    2.76                                       PyObject *args,
    2.77                                       PyObject *kwds)
     3.1 --- a/tools/python/xen/lowlevel/xs/xs.c	Fri Nov 18 16:31:50 2005 +0100
     3.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Fri Nov 18 16:32:04 2005 +0100
     3.3 @@ -21,6 +21,7 @@
     3.4  
     3.5  #include <Python.h>
     3.6  
     3.7 +#include <stdbool.h>
     3.8  #include <stdio.h>
     3.9  #include <stdlib.h>
    3.10  #include <unistd.h>
    3.11 @@ -70,6 +71,17 @@ static inline PyObject *pyvalue_str(char
    3.12              : PyErr_SetFromErrno(PyExc_RuntimeError));
    3.13  }
    3.14  
    3.15 +static void remove_watch(XsHandle *xsh, PyObject *token);
    3.16 +
    3.17 +static PyObject *none(bool result);
    3.18 +
    3.19 +static int parse_transaction_path(PyObject *self, PyObject *args,
    3.20 +                                  PyObject *kwds,
    3.21 +                                  struct xs_handle **xh,
    3.22 +                                  struct xs_transaction_handle **th,
    3.23 +                                  char **path);
    3.24 +
    3.25 +
    3.26  #define xspy_read_doc "\n"			\
    3.27  	"Read data from a path.\n"		\
    3.28  	" path [string]: xenstore path\n"	\
    3.29 @@ -81,43 +93,30 @@ static inline PyObject *pyvalue_str(char
    3.30  
    3.31  static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
    3.32  {
    3.33 -    static char *kwd_spec[] = { "transaction", "path", NULL };
    3.34 -    static char *arg_spec = "ss";
    3.35 -    char *path = NULL;
    3.36 -
    3.37 -    struct xs_handle *xh = xshandle(self);
    3.38 -    char *xsval = NULL;
    3.39 -    unsigned int xsval_n = 0;
    3.40 -    PyObject *val = NULL;
    3.41 -
    3.42 +    struct xs_handle *xh;
    3.43      struct xs_transaction_handle *th;
    3.44 -    char *thstr;
    3.45 +    char *path;
    3.46  
    3.47 -    if (!xh)
    3.48 -        goto exit;
    3.49 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
    3.50 -                                     &thstr, &path))
    3.51 -        goto exit;
    3.52 +    char *xsval;
    3.53 +    unsigned int xsval_n;
    3.54  
    3.55 -    th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
    3.56 +    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
    3.57 +        return NULL;
    3.58  
    3.59      Py_BEGIN_ALLOW_THREADS
    3.60      xsval = xs_read(xh, th, path, &xsval_n);
    3.61      Py_END_ALLOW_THREADS
    3.62 -    if (!xsval) {
    3.63 -        if (errno == ENOENT) {
    3.64 -            Py_INCREF(Py_None);
    3.65 -            val = Py_None;
    3.66 -        } else
    3.67 -            PyErr_SetFromErrno(PyExc_RuntimeError);
    3.68 -        goto exit;
    3.69 +    if (xsval) {
    3.70 +        PyObject *val = PyString_FromStringAndSize(xsval, xsval_n);
    3.71 +        free(xsval);
    3.72 +        return val;
    3.73      }
    3.74 -    val = PyString_FromStringAndSize(xsval, xsval_n);
    3.75 - exit:
    3.76 -    free(xsval);
    3.77 -    return val;
    3.78 +    else {
    3.79 +        return none(errno == ENOENT);
    3.80 +    }
    3.81  }
    3.82  
    3.83 +
    3.84  #define xspy_write_doc "\n"					\
    3.85  	"Write data to a path.\n"				\
    3.86  	" path   [string] : xenstore path to write to\n."	\
    3.87 @@ -136,33 +135,27 @@ static PyObject *xspy_write(PyObject *se
    3.88      int data_n = 0;
    3.89  
    3.90      struct xs_handle *xh = xshandle(self);
    3.91 -    PyObject *val = NULL;
    3.92 -    int xsval = 0;
    3.93 +    bool result;
    3.94  
    3.95      struct xs_transaction_handle *th;
    3.96      char *thstr;
    3.97  
    3.98      if (!xh)
    3.99 -        goto exit;
   3.100 +        return NULL;
   3.101      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.102                                       &thstr, &path, &data, &data_n))
   3.103 -        goto exit;
   3.104 +        return NULL;
   3.105  
   3.106      th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   3.107  
   3.108      Py_BEGIN_ALLOW_THREADS
   3.109 -    xsval = xs_write(xh, th, path, data, data_n);
   3.110 +    result = xs_write(xh, th, path, data, data_n);
   3.111      Py_END_ALLOW_THREADS
   3.112 -    if (!xsval) {
   3.113 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.114 -        goto exit;
   3.115 -    }
   3.116 -    Py_INCREF(Py_None);
   3.117 -    val = Py_None;
   3.118 - exit:
   3.119 -    return val;
   3.120 +
   3.121 +    return none(result);
   3.122  }
   3.123  
   3.124 +
   3.125  #define xspy_ls_doc "\n"					\
   3.126  	"List a directory.\n"					\
   3.127  	" path [string]: path to list.\n"			\
   3.128 @@ -174,47 +167,34 @@ static PyObject *xspy_write(PyObject *se
   3.129  
   3.130  static PyObject *xspy_ls(PyObject *self, PyObject *args, PyObject *kwds)
   3.131  {
   3.132 -    static char *kwd_spec[] = { "transaction", "path", NULL };
   3.133 -    static char *arg_spec = "ss";
   3.134 -    char *path = NULL;
   3.135 -
   3.136 -    struct xs_handle *xh = xshandle(self);
   3.137 -    PyObject *val = NULL;
   3.138 -    char **xsval = NULL;
   3.139 -    unsigned int xsval_n = 0;
   3.140 -    int i;
   3.141 -
   3.142 +    struct xs_handle *xh;
   3.143      struct xs_transaction_handle *th;
   3.144 -    char *thstr;
   3.145 +    char *path;
   3.146  
   3.147 -    if (!xh)
   3.148 -        goto exit;
   3.149 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.150 -                                     &thstr, &path))
   3.151 -        goto exit;
   3.152 +    char **xsval;
   3.153 +    int xsval_n;
   3.154  
   3.155 -
   3.156 -    th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   3.157 +    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
   3.158 +        return NULL;
   3.159  
   3.160      Py_BEGIN_ALLOW_THREADS
   3.161      xsval = xs_directory(xh, th, path, &xsval_n);
   3.162      Py_END_ALLOW_THREADS
   3.163 -    if (!xsval) {
   3.164 -        if (errno == ENOENT) {
   3.165 -            Py_INCREF(Py_None);
   3.166 -            val = Py_None;
   3.167 -        } else
   3.168 -            PyErr_SetFromErrno(PyExc_RuntimeError);
   3.169 -	goto exit;
   3.170 +
   3.171 +    if (xsval) {
   3.172 +        int i;
   3.173 +        PyObject *val = PyList_New(xsval_n);
   3.174 +        for (i = 0; i < xsval_n; i++)
   3.175 +            PyList_SetItem(val, i, PyString_FromString(xsval[i]));
   3.176 +        free(xsval);
   3.177 +        return val;
   3.178      }
   3.179 -    val = PyList_New(xsval_n);
   3.180 -    for (i = 0; i < xsval_n; i++)
   3.181 -        PyList_SetItem(val, i, PyString_FromString(xsval[i]));
   3.182 -    free(xsval);
   3.183 - exit:
   3.184 -    return val;
   3.185 +    else {
   3.186 +        return none(errno == ENOENT);
   3.187 +    }
   3.188  }
   3.189  
   3.190 +
   3.191  #define xspy_mkdir_doc "\n"					\
   3.192  	"Make a directory.\n"					\
   3.193  	" path [string]: path to directory to create.\n"	\
   3.194 @@ -225,38 +205,23 @@ static PyObject *xspy_ls(PyObject *self,
   3.195  
   3.196  static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
   3.197  {
   3.198 -    static char *kwd_spec[] = { "transaction", "path", NULL };
   3.199 -    static char *arg_spec = "ss";
   3.200 -    char *path = NULL;
   3.201 -
   3.202 -    struct xs_handle *xh = xshandle(self);
   3.203 -    PyObject *val = NULL;
   3.204 -    int xsval = 0;
   3.205 -
   3.206 +    struct xs_handle *xh;
   3.207      struct xs_transaction_handle *th;
   3.208 -    char *thstr;
   3.209 +    char *path;
   3.210  
   3.211 -    if (!xh)
   3.212 -        goto exit;
   3.213 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.214 -                                     &thstr, &path))
   3.215 -        goto exit;
   3.216 +    bool result;
   3.217  
   3.218 -    th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   3.219 +    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
   3.220 +        return NULL;
   3.221  
   3.222      Py_BEGIN_ALLOW_THREADS
   3.223 -    xsval = xs_mkdir(xh, th, path);
   3.224 +    result = xs_mkdir(xh, th, path);
   3.225      Py_END_ALLOW_THREADS
   3.226 -    if (!xsval) {
   3.227 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.228 -        goto exit;
   3.229 -    }
   3.230 -    Py_INCREF(Py_None);
   3.231 -    val = Py_None;
   3.232 - exit:
   3.233 -    return val;
   3.234 +
   3.235 +    return none(result);
   3.236  }
   3.237  
   3.238 +
   3.239  #define xspy_rm_doc "\n"			\
   3.240  	"Remove a path.\n"			\
   3.241  	" path [string] : path to remove\n"	\
   3.242 @@ -267,38 +232,23 @@ static PyObject *xspy_mkdir(PyObject *se
   3.243  
   3.244  static PyObject *xspy_rm(PyObject *self, PyObject *args, PyObject *kwds)
   3.245  {
   3.246 -    static char *kwd_spec[] = { "transaction", "path", NULL };
   3.247 -    static char *arg_spec = "ss";
   3.248 -    char *path = NULL;
   3.249 -
   3.250 -    struct xs_handle *xh = xshandle(self);
   3.251 -    PyObject *val = NULL;
   3.252 -    int xsval = 0;
   3.253 -
   3.254 +    struct xs_handle *xh;
   3.255      struct xs_transaction_handle *th;
   3.256 -    char *thstr;
   3.257 +    char *path;
   3.258  
   3.259 -    if (!xh)
   3.260 -        goto exit;
   3.261 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.262 -                                     &thstr, &path))
   3.263 -        goto exit;
   3.264 +    bool result;
   3.265  
   3.266 -    th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   3.267 +    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
   3.268 +        return NULL;
   3.269  
   3.270      Py_BEGIN_ALLOW_THREADS
   3.271 -    xsval = xs_rm(xh, th, path);
   3.272 +    result = xs_rm(xh, th, path);
   3.273      Py_END_ALLOW_THREADS
   3.274 -    if (!xsval && errno != ENOENT) {
   3.275 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.276 -        goto exit;
   3.277 -    }
   3.278 -    Py_INCREF(Py_None);
   3.279 -    val = Py_None;
   3.280 - exit:
   3.281 -    return val;
   3.282 +
   3.283 +    return none(result || errno == ENOENT);
   3.284  }
   3.285  
   3.286 +
   3.287  #define xspy_get_permissions_doc "\n"		\
   3.288  	"Get the permissions for a path\n"	\
   3.289  	" path [string]: xenstore path.\n"	\
   3.290 @@ -315,7 +265,6 @@ static PyObject *xspy_get_permissions(Py
   3.291      char *path = NULL;
   3.292  
   3.293      struct xs_handle *xh = xshandle(self);
   3.294 -    PyObject *val = NULL;
   3.295      struct xs_permissions *perms;
   3.296      unsigned int perms_n = 0;
   3.297      int i;
   3.298 @@ -324,30 +273,34 @@ static PyObject *xspy_get_permissions(Py
   3.299      char *thstr;
   3.300  
   3.301      if (!xh)
   3.302 -        goto exit;
   3.303 +        return NULL;
   3.304      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.305                                       &thstr, &path))
   3.306 -        goto exit;
   3.307 +        return NULL;
   3.308  
   3.309      th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   3.310  
   3.311      Py_BEGIN_ALLOW_THREADS
   3.312      perms = xs_get_permissions(xh, th, path, &perms_n);
   3.313      Py_END_ALLOW_THREADS
   3.314 -    if (!perms) {
   3.315 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.316 -        goto exit;
   3.317 +
   3.318 +    if (perms) {
   3.319 +        PyObject *val = PyList_New(perms_n);
   3.320 +        for (i = 0; i < perms_n; i++, perms++) {
   3.321 +            PyObject *p = Py_BuildValue("{s:i,s:i,s:i}",
   3.322 +                                        "dom",  perms->id,
   3.323 +                                        "read", perms->perms & XS_PERM_READ,
   3.324 +                                        "write",perms->perms & XS_PERM_WRITE);
   3.325 +            PyList_SetItem(val, i, p);
   3.326 +        }
   3.327 +
   3.328 +        free(perms);
   3.329 +        return val;
   3.330      }
   3.331 -    val = PyList_New(perms_n);
   3.332 -    for (i = 0; i < perms_n; i++, perms++) {
   3.333 -        PyObject *p = Py_BuildValue("{s:i,s:i,s:i}",
   3.334 -                                    "dom",   perms->id,
   3.335 -                                    "read",  (perms->perms & XS_PERM_READ),
   3.336 -                                    "write",  (perms->perms & XS_PERM_WRITE));
   3.337 -        PyList_SetItem(val, i, p);
   3.338 +    else {
   3.339 +        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.340 +        return NULL;
   3.341      }
   3.342 - exit:
   3.343 -    return val;
   3.344  }
   3.345  
   3.346  #define xspy_set_permissions_doc "\n"		\
   3.347 @@ -370,7 +323,7 @@ static PyObject *xspy_set_permissions(Py
   3.348      static char *perm_spec = "i|iiii";
   3.349  
   3.350      struct xs_handle *xh = xshandle(self);
   3.351 -    int i, xsval;
   3.352 +    int i, result;
   3.353      struct xs_permissions *xsperms = NULL;
   3.354      int xsperms_n = 0;
   3.355      PyObject *tuple0 = NULL;
   3.356 @@ -416,9 +369,9 @@ static PyObject *xspy_set_permissions(Py
   3.357              xsperms[i].perms |= XS_PERM_WRITE;
   3.358      }
   3.359      Py_BEGIN_ALLOW_THREADS
   3.360 -    xsval = xs_set_permissions(xh, th, path, xsperms, xsperms_n);
   3.361 +    result = xs_set_permissions(xh, th, path, xsperms, xsperms_n);
   3.362      Py_END_ALLOW_THREADS
   3.363 -    if (!xsval) {
   3.364 +    if (!result) {
   3.365          PyErr_SetFromErrno(PyExc_RuntimeError);
   3.366          goto exit;
   3.367      }
   3.368 @@ -453,7 +406,7 @@ static PyObject *xspy_watch(PyObject *se
   3.369  
   3.370      XsHandle *xsh = (XsHandle *)self;
   3.371      struct xs_handle *xh = xshandle(self);
   3.372 -    int xsval = 0;
   3.373 +    int result = 0;
   3.374  
   3.375      if (!xh)
   3.376          return NULL;
   3.377 @@ -466,10 +419,9 @@ static PyObject *xspy_watch(PyObject *se
   3.378         races with xs_read_watch.
   3.379      */
   3.380  
   3.381 -    Py_INCREF(token);
   3.382      for (i = 0; i < PyList_Size(xsh->watches); i++) {
   3.383          if (PyList_GetItem(xsh->watches, i) == Py_None) {
   3.384 -            PyList_SetItem(xsh->watches, i, token);
   3.385 +            PySequence_SetItem(xsh->watches, i, token);
   3.386              break;
   3.387          }
   3.388      }
   3.389 @@ -478,24 +430,15 @@ static PyObject *xspy_watch(PyObject *se
   3.390  
   3.391      sprintf(token_str, "%li", (unsigned long)token);
   3.392      Py_BEGIN_ALLOW_THREADS
   3.393 -    xsval = xs_watch(xh, path, token_str);
   3.394 +    result = xs_watch(xh, path, token_str);
   3.395      Py_END_ALLOW_THREADS
   3.396 -    if (!xsval) {
   3.397 -        for (i = 0; i < PyList_Size(xsh->watches); i++) {
   3.398 -            if (PyList_GetItem(xsh->watches, i) == token) {
   3.399 -                Py_INCREF(Py_None);
   3.400 -                PyList_SetItem(xsh->watches, i,  Py_None);
   3.401 -                break;
   3.402 -            }
   3.403 -        }
   3.404 +
   3.405 +    if (!result)
   3.406 +        remove_watch(xsh, token);
   3.407  
   3.408 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.409 -        return NULL;
   3.410 -    }
   3.411 +    return none(result);
   3.412 +}
   3.413  
   3.414 -    Py_INCREF(Py_None);
   3.415 -    return Py_None;
   3.416 -}
   3.417  
   3.418  #define xspy_read_watch_doc "\n"				\
   3.419  	"Read a watch notification.\n"				\
   3.420 @@ -519,9 +462,10 @@ static PyObject *xspy_read_watch(PyObjec
   3.421      unsigned int num;
   3.422  
   3.423      if (!xh)
   3.424 -        goto exit;
   3.425 +        return NULL;
   3.426      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   3.427 -        goto exit;
   3.428 +        return NULL;
   3.429 +
   3.430  again:
   3.431      Py_BEGIN_ALLOW_THREADS
   3.432      xsval = xs_read_watch(xh, &num);
   3.433 @@ -570,37 +514,25 @@ static PyObject *xspy_unwatch(PyObject *
   3.434      char *path = NULL;
   3.435      PyObject *token;
   3.436      char token_str[MAX_STRLEN(unsigned long) + 1];
   3.437 -    int i;
   3.438  
   3.439      XsHandle *xsh = (XsHandle *)self;
   3.440      struct xs_handle *xh = xshandle(self);
   3.441 -    PyObject *val = NULL;
   3.442 -    int xsval = 0;
   3.443 +    int result = 0;
   3.444  
   3.445      if (!xh)
   3.446 -        goto exit;
   3.447 +        return NULL;
   3.448      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path,
   3.449                                       &token))
   3.450 -        goto exit;
   3.451 +        return NULL;
   3.452 +
   3.453      sprintf(token_str, "%li", (unsigned long)token);
   3.454      Py_BEGIN_ALLOW_THREADS
   3.455 -    xsval = xs_unwatch(xh, path, token_str);
   3.456 +    result = xs_unwatch(xh, path, token_str);
   3.457      Py_END_ALLOW_THREADS
   3.458 -    if (!xsval)
   3.459 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.460 -    else {
   3.461 -        Py_INCREF(Py_None);
   3.462 -        val = Py_None;
   3.463 -    }
   3.464 -    for (i = 0; i < PyList_Size(xsh->watches); i++) {
   3.465 -        if (token == PyList_GetItem(xsh->watches, i)) {
   3.466 -            Py_INCREF(Py_None);
   3.467 -            PyList_SetItem(xsh->watches, i, Py_None);
   3.468 -            break;
   3.469 -        }
   3.470 -    }
   3.471 - exit:
   3.472 -    return val;
   3.473 +
   3.474 +    remove_watch(xsh, token);
   3.475 +
   3.476 +    return none(result);
   3.477  }
   3.478  
   3.479  #define xspy_transaction_start_doc "\n"				\
   3.480 @@ -618,26 +550,25 @@ static PyObject *xspy_transaction_start(
   3.481      char *path = NULL;
   3.482  
   3.483      struct xs_handle *xh = xshandle(self);
   3.484 -    PyObject *val = NULL;
   3.485      struct xs_transaction_handle *th;
   3.486      char thstr[20];
   3.487  
   3.488      if (!xh)
   3.489 -        goto exit;
   3.490 +        return NULL;
   3.491      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   3.492 -        goto exit;
   3.493 +        return NULL;
   3.494 +
   3.495      Py_BEGIN_ALLOW_THREADS
   3.496      th = xs_transaction_start(xh);
   3.497      Py_END_ALLOW_THREADS
   3.498 +
   3.499      if (th == NULL) {
   3.500          PyErr_SetFromErrno(PyExc_RuntimeError);
   3.501 -        goto exit;
   3.502 +        return NULL;
   3.503      }
   3.504  
   3.505      sprintf(thstr, "%lX", (unsigned long)th);
   3.506 -    val = PyString_FromString(thstr);
   3.507 - exit:
   3.508 -    return val;
   3.509 +    return PyString_FromString(thstr);
   3.510  }
   3.511  
   3.512  #define xspy_transaction_end_doc "\n"					\
   3.513 @@ -657,38 +588,38 @@ static PyObject *xspy_transaction_end(Py
   3.514      int abort = 0;
   3.515  
   3.516      struct xs_handle *xh = xshandle(self);
   3.517 -    PyObject *val = NULL;
   3.518 -    int xsval = 0;
   3.519 +    bool result;
   3.520  
   3.521      struct xs_transaction_handle *th;
   3.522      char *thstr;
   3.523  
   3.524      if (!xh)
   3.525 -        goto exit;
   3.526 +        return NULL;
   3.527      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.528                                       &thstr, &abort))
   3.529 -        goto exit;
   3.530 +        return NULL;
   3.531  
   3.532      th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   3.533  
   3.534      Py_BEGIN_ALLOW_THREADS
   3.535 -    xsval = xs_transaction_end(xh, th, abort);
   3.536 +    result = xs_transaction_end(xh, th, abort);
   3.537      Py_END_ALLOW_THREADS
   3.538 -    if (!xsval) {
   3.539 -	if (errno == EAGAIN) {
   3.540 -	    Py_INCREF(Py_False);
   3.541 -	    val = Py_False;
   3.542 -	    goto exit;
   3.543 -	}
   3.544 +
   3.545 +    if (result) {
   3.546 +        Py_INCREF(Py_True);
   3.547 +        return Py_True;
   3.548 +    }
   3.549 +    else if (errno == EAGAIN) {
   3.550 +        Py_INCREF(Py_False);
   3.551 +        return Py_False;
   3.552 +    }
   3.553 +    else {
   3.554          PyErr_SetFromErrno(PyExc_RuntimeError);
   3.555 -        goto exit;
   3.556 +        return NULL;
   3.557      }
   3.558 -    Py_INCREF(Py_True);
   3.559 -    val = Py_True;
   3.560 - exit:
   3.561 -    return val;
   3.562  }
   3.563  
   3.564 +
   3.565  #define xspy_introduce_domain_doc "\n"					\
   3.566  	"Tell xenstore about a domain so it can talk to it.\n"		\
   3.567  	" dom  [int]   : domain id\n"					\
   3.568 @@ -709,27 +640,22 @@ static PyObject *xspy_introduce_domain(P
   3.569      unsigned int port = 0;
   3.570  
   3.571      struct xs_handle *xh = xshandle(self);
   3.572 -    PyObject *val = NULL;
   3.573 -    int xsval = 0;
   3.574 +    bool result = 0;
   3.575  
   3.576      if (!xh)
   3.577 -        goto exit;
   3.578 +        return NULL;
   3.579      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.580                                       &dom, &page, &port))
   3.581 -        goto exit;
   3.582 +        return NULL;
   3.583 +
   3.584      Py_BEGIN_ALLOW_THREADS
   3.585 -    xsval = xs_introduce_domain(xh, dom, page, port);
   3.586 +    result = xs_introduce_domain(xh, dom, page, port);
   3.587      Py_END_ALLOW_THREADS
   3.588 -    if (!xsval) {
   3.589 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.590 -        goto exit;
   3.591 -    }
   3.592 -    Py_INCREF(Py_None);
   3.593 -    val = Py_None;
   3.594 - exit:
   3.595 -    return val;
   3.596 +
   3.597 +    return none(result);
   3.598  }
   3.599  
   3.600 +
   3.601  #define xspy_release_domain_doc "\n"					\
   3.602  	"Tell xenstore to release its channel to a domain.\n"		\
   3.603  	"Unless this is done the domain will not be released.\n"	\
   3.604 @@ -743,31 +669,26 @@ static PyObject *xspy_release_domain(PyO
   3.605                                       PyObject *kwds)
   3.606  {
   3.607      static char *kwd_spec[] = { "dom", NULL };
   3.608 -    static char *arg_spec = "i|";
   3.609 +    static char *arg_spec = "i";
   3.610      domid_t dom;
   3.611  
   3.612      struct xs_handle *xh = xshandle(self);
   3.613 -    PyObject *val = NULL;
   3.614 -    int xsval = 0;
   3.615 +    bool result = 0;
   3.616  
   3.617      if (!xh)
   3.618 -        goto exit;
   3.619 +        return NULL;
   3.620      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.621                                       &dom))
   3.622 -        goto exit;
   3.623 +        return NULL;
   3.624 +
   3.625      Py_BEGIN_ALLOW_THREADS
   3.626 -    xsval = xs_release_domain(xh, dom);
   3.627 +    result = xs_release_domain(xh, dom);
   3.628      Py_END_ALLOW_THREADS
   3.629 -    if (!xsval) {
   3.630 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.631 -        goto exit;
   3.632 -    }
   3.633 -    Py_INCREF(Py_None);
   3.634 -    val = Py_None;
   3.635 - exit:
   3.636 -    return val;
   3.637 +
   3.638 +    return none(result);
   3.639  }
   3.640  
   3.641 +
   3.642  #define xspy_close_doc "\n"			\
   3.643  	"Close the connection to xenstore.\n"	\
   3.644  	"\n"					\
   3.645 @@ -783,25 +704,25 @@ static PyObject *xspy_close(PyObject *se
   3.646  
   3.647      XsHandle *xsh = (XsHandle *)self;
   3.648      struct xs_handle *xh = xshandle(self);
   3.649 -    PyObject *val = NULL;
   3.650  
   3.651      if (!xh)
   3.652 -        goto exit;
   3.653 +        return NULL;
   3.654      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   3.655 -        goto exit;
   3.656 +        return NULL;
   3.657 +
   3.658      for (i = 0; i < PyList_Size(xsh->watches); i++) {
   3.659          /* TODO: xs_unwatch watches */
   3.660 -        Py_INCREF(Py_None);
   3.661 -        PyList_SetItem(xsh->watches, i, Py_None);
   3.662 +        PySequence_SetItem(xsh->watches, i, Py_None);
   3.663      }
   3.664 +
   3.665      xs_daemon_close(xh);
   3.666      xsh->xh = NULL;
   3.667 +
   3.668      Py_INCREF(Py_None);
   3.669 -    val = Py_None;
   3.670 - exit:
   3.671 -    return val;
   3.672 +    return Py_None;
   3.673  }
   3.674  
   3.675 +
   3.676  #define xspy_get_domain_path_doc "\n"			\
   3.677  	"Return store path of domain, whether or not the domain exists.\n" \
   3.678  	" domid [int]: domain id\n"			\
   3.679 @@ -819,30 +740,91 @@ static PyObject *xspy_get_domain_path(Py
   3.680  
   3.681      struct xs_handle *xh = xshandle(self);
   3.682      char *xsval = NULL;
   3.683 -    PyObject *val = NULL;
   3.684  
   3.685      if (!xh)
   3.686 -        goto exit;
   3.687 +        return NULL;
   3.688      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.689                                       &domid))
   3.690 -        goto exit;
   3.691 +        return NULL;
   3.692 +
   3.693      Py_BEGIN_ALLOW_THREADS
   3.694      xsval = xs_get_domain_path(xh, domid);
   3.695      Py_END_ALLOW_THREADS
   3.696 -    if (!xsval) {
   3.697 -        if (errno == ENOENT) {
   3.698 -            Py_INCREF(Py_None);
   3.699 -            val = Py_None;
   3.700 -        } else
   3.701 -            PyErr_SetFromErrno(PyExc_RuntimeError);
   3.702 -        goto exit;
   3.703 +
   3.704 +    if (xsval) {
   3.705 +        PyObject *val = PyString_FromString(xsval);
   3.706 +        free(xsval);
   3.707 +        return val;
   3.708 +    }
   3.709 +    else {
   3.710 +        return none(errno == ENOENT);
   3.711 +    }
   3.712 +}
   3.713 +
   3.714 +
   3.715 +/**
   3.716 + * Remove the given token from the watches list belonging to the given
   3.717 + * XsHandle, if present.
   3.718 + */
   3.719 +static void remove_watch(XsHandle *xsh, PyObject *token)
   3.720 +{
   3.721 +    int i;
   3.722 +
   3.723 +    for (i = 0; i < PyList_Size(xsh->watches); i++) {
   3.724 +        if (PyList_GetItem(xsh->watches, i) == token) {
   3.725 +            PySequence_SetItem(xsh->watches, i, Py_None);
   3.726 +            return;
   3.727 +        }
   3.728      }
   3.729 -    val = PyString_FromString(xsval);
   3.730 -    free(xsval);
   3.731 - exit:
   3.732 -    return val;
   3.733  }
   3.734  
   3.735 +
   3.736 +/**
   3.737 + * Parse transaction and path arguments from the given args and kwds,
   3.738 + * convert the given self value to an xs_handle, and return all three by
   3.739 + * reference.
   3.740 + * 
   3.741 + * @return 1 on success, in which case *xh, *th, and *path are valid, or 0 on
   3.742 + * failure.
   3.743 + */
   3.744 +static int parse_transaction_path(PyObject *self, PyObject *args,
   3.745 +                                  PyObject *kwds,
   3.746 +                                  struct xs_handle **xh,
   3.747 +                                  struct xs_transaction_handle **th,
   3.748 +                                  char **path)
   3.749 +{
   3.750 +    static char *arg_spec = "ss";
   3.751 +    static char *kwd_spec[] = { "transaction", "path", NULL };
   3.752 +    char *thstr;
   3.753 +
   3.754 +    *xh = xshandle(self);
   3.755 +
   3.756 +    if (!xh)
   3.757 +        return 0;
   3.758 +
   3.759 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   3.760 +                                     &thstr, path))
   3.761 +        return 0;
   3.762 +
   3.763 +    *th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   3.764 +
   3.765 +    return 1;
   3.766 +}
   3.767 +
   3.768 +
   3.769 +static PyObject *none(bool result)
   3.770 +{
   3.771 +    if (result) {
   3.772 +        Py_INCREF(Py_None);
   3.773 +        return Py_None;
   3.774 +    }
   3.775 +    else {
   3.776 +        PyErr_SetFromErrno(PyExc_RuntimeError);
   3.777 +        return NULL;
   3.778 +    }
   3.779 +}
   3.780 +
   3.781 +
   3.782  #define XSPY_METH(_name) {			\
   3.783      .ml_name  = #_name,				\
   3.784      .ml_meth  = (PyCFunction) xspy_ ## _name,	\
   3.785 @@ -871,9 +853,7 @@ static PyMethodDef xshandle_methods[] = 
   3.786  
   3.787  static PyObject *xshandle_getattr(PyObject *self, char *name)
   3.788  {
   3.789 -    PyObject *val = NULL;
   3.790 -    val = Py_FindMethod(xshandle_methods, self, name);
   3.791 -    return val;
   3.792 +    return Py_FindMethod(xshandle_methods, self, name);
   3.793  }
   3.794  
   3.795  static void xshandle_dealloc(PyObject *self)
     4.1 --- a/tools/xenstore/xs.c	Fri Nov 18 16:31:50 2005 +0100
     4.2 +++ b/tools/xenstore/xs.c	Fri Nov 18 16:32:04 2005 +0100
     4.3 @@ -305,6 +305,7 @@ static void *xs_talkv(struct xs_handle *
     4.4  	struct sigaction ignorepipe, oldact;
     4.5  
     4.6  	msg.tx_id = (uint32_t)(unsigned long)t;
     4.7 +	msg.req_id = 0;
     4.8  	msg.type = type;
     4.9  	msg.len = 0;
    4.10  	for (i = 0; i < num_vecs; i++)