ia64/xen-unstable

changeset 5359:fd8e5378d8ac

bitkeeper revision 1.1662.1.17 (42a59f62TbTw4kErDSfuOYh8iAzCuA)

setup.py:
Add xenstore python bindings.
xs.c:
new file
params.py:
XSDAEMON_DEBUG -> XENSTORED_DEBUG
Makefile:
xenstore is also a library -- build it before python.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Jun 07 13:21:38 2005 +0000 (2005-06-07)
parents 4ad402c55b9f
children 22daf37c41c8
files .rootkeys tools/Makefile tools/python/setup.py tools/python/xen/lowlevel/xs/xs.c tools/python/xen/xend/server/params.py
line diff
     1.1 --- a/.rootkeys	Tue Jun 07 12:54:45 2005 +0000
     1.2 +++ b/.rootkeys	Tue Jun 07 13:21:38 2005 +0000
     1.3 @@ -805,6 +805,7 @@ 40c9c469n2RRwCmjWdjdyyVRWKmgWg tools/pyt
     1.4  40dc4076hGpwa8-sWRN0jtXZeQJuKg tools/python/xen/__init__.py
     1.5  40dfd40aMOhnw_cQLve9462UR5yYxQ tools/python/xen/lowlevel/__init__.py
     1.6  3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/python/xen/lowlevel/xc/xc.c
     1.7 +42a59f20JpCmm9DsCoVZowGafnhBuw tools/python/xen/lowlevel/xs/xs.c
     1.8  40dc4076St6AmPTmQPrtQ6LGHPxGmw tools/python/xen/lowlevel/xu/__init__.py
     1.9  40dc4076CwBYRTUQDdbdU1L6KcLgSw tools/python/xen/lowlevel/xu/xu.c
    1.10  40d8915cyoVA0hJxiBFNymL7YvDaRg tools/python/xen/util/Brctl.py
     2.1 --- a/tools/Makefile	Tue Jun 07 12:54:45 2005 +0000
     2.2 +++ b/tools/Makefile	Tue Jun 07 13:21:38 2005 +0000
     2.3 @@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
     2.4  
     2.5  SUBDIRS :=
     2.6  SUBDIRS += libxc
     2.7 +SUBDIRS += xenstore
     2.8  SUBDIRS += misc
     2.9  SUBDIRS += examples
    2.10  SUBDIRS += xentrace
     3.1 --- a/tools/python/setup.py	Tue Jun 07 12:54:45 2005 +0000
     3.2 +++ b/tools/python/setup.py	Tue Jun 07 13:21:38 2005 +0000
     3.3 @@ -9,13 +9,15 @@ extra_compile_args  = [ "-fno-strict-ali
     3.4  
     3.5  include_dirs = [ XEN_ROOT + "/tools/python/xen/lowlevel/xu",
     3.6                   XEN_ROOT + "/tools/libxc",
     3.7 +                 XEN_ROOT + "/tools/xenstore",
     3.8                   XEN_ROOT + "/tools/xcs",
     3.9                   ]
    3.10  
    3.11  library_dirs = [ XEN_ROOT + "/tools/libxc",
    3.12 +                 XEN_ROOT + "/tools/xenstore",
    3.13                   ]
    3.14  
    3.15 -libraries = [ "xc" ]
    3.16 +libraries = [ "xc", "xenstore" ]
    3.17  
    3.18  xc = Extension("xc",
    3.19                 extra_compile_args = extra_compile_args,
    3.20 @@ -30,7 +32,14 @@ xu = Extension("xu",
    3.21                 library_dirs       = library_dirs,
    3.22                 libraries          = libraries,
    3.23                 sources            = [ "xen/lowlevel/xu/xu.c" ])
    3.24 -               
    3.25 +
    3.26 +xs = Extension("xs",
    3.27 +               extra_compile_args = extra_compile_args,
    3.28 +               include_dirs       = include_dirs + [ "xen/lowlevel/xs" ],
    3.29 +               library_dirs       = library_dirs,
    3.30 +               libraries          = libraries,
    3.31 +               sources            = [ "xen/lowlevel/xs/xs.c" ])
    3.32 +
    3.33  setup(name            = 'xen',
    3.34        version         = '2.0',
    3.35        description     = 'Xen',
    3.36 @@ -43,7 +52,7 @@ setup(name            = 'xen',
    3.37                           'xen.web',
    3.38                           ],
    3.39        ext_package = "xen.lowlevel",
    3.40 -      ext_modules = [ xc, xu ]
    3.41 +      ext_modules = [ xc, xu, xs ]
    3.42        )
    3.43  
    3.44  os.chdir('logging')
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Tue Jun 07 13:21:38 2005 +0000
     4.3 @@ -0,0 +1,617 @@
     4.4 +#include <Python.h>
     4.5 +
     4.6 +#include <stdio.h>
     4.7 +#include <stdlib.h>
     4.8 +#include <unistd.h>
     4.9 +#include <sys/types.h>
    4.10 +#include <sys/stat.h>
    4.11 +#include <fcntl.h>
    4.12 +
    4.13 +#include "xs.h"
    4.14 +
    4.15 +/** @file
    4.16 + * Python interface to the Xen Store Daemon (xs).
    4.17 + */
    4.18 +
    4.19 +/* Needed for Python versions earlier than 2.3. */
    4.20 +//#ifndef PyMODINIT_FUNC
    4.21 +//#define PyMODINIT_FUNC DL_EXPORT(void)
    4.22 +//#endif
    4.23 +
    4.24 +#define PYPKG    "xen.lowlevel.xs"
    4.25 +
    4.26 +/** Python wrapper round an xs handle.
    4.27 + */
    4.28 +typedef struct XsHandle {
    4.29 +    PyObject_HEAD;
    4.30 +    struct xs_handle *xh;
    4.31 +} XsHandle;
    4.32 +
    4.33 +static inline struct xs_handle *xshandle(PyObject *self)
    4.34 +{
    4.35 +    struct xs_handle *xh = ((XsHandle*)self)->xh;
    4.36 +    if (!xh)
    4.37 +        PyErr_SetString(PyExc_RuntimeError, "invalid xenstore daemon handle");
    4.38 +    return xh;
    4.39 +}
    4.40 +
    4.41 +static inline PyObject *pyvalue_int(int val) {
    4.42 +    return (val
    4.43 +            ? PyInt_FromLong(val)
    4.44 +            : PyErr_SetFromErrno(PyExc_RuntimeError));
    4.45 +}
    4.46 +
    4.47 +static inline PyObject *pyvalue_str(char *val) {
    4.48 +    return (val
    4.49 +            ? PyString_FromString(val)
    4.50 +            : PyErr_SetFromErrno(PyExc_RuntimeError));
    4.51 +}
    4.52 +
    4.53 +static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
    4.54 +{
    4.55 +    static char *kwd_spec[] = { "path", "data", "create", "excl", NULL };
    4.56 +    static char *arg_spec = "ss#|ii";
    4.57 +    char *path = NULL;
    4.58 +    char *data = NULL;
    4.59 +    int data_n = 0;
    4.60 +    int create = 0;
    4.61 +    int excl = 0;
    4.62 +
    4.63 +    struct xs_handle *xh = xshandle(self);
    4.64 +    PyObject *val = NULL;
    4.65 +    int flags = 0;
    4.66 +    int xsval = 0;
    4.67 +
    4.68 +    if (!xh)
    4.69 +	goto exit;
    4.70 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
    4.71 +                                     &path, &data, &data_n, &create, &excl))
    4.72 +        goto exit;
    4.73 +    if (create)
    4.74 +	flags |= O_CREAT;
    4.75 +    if (excl)
    4.76 +	flags |= O_EXCL;
    4.77 +    xsval = xs_write(xh, path, data, data_n, flags);
    4.78 +    val = pyvalue_int(xsval);
    4.79 + exit:
    4.80 +    return val;
    4.81 +}
    4.82 +
    4.83 +static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
    4.84 +{
    4.85 +    static char *kwd_spec[] = { "path", NULL };
    4.86 +    static char *arg_spec = "s|";
    4.87 +    char *path = NULL;
    4.88 +
    4.89 +    struct xs_handle *xh = xshandle(self);
    4.90 +    char *xsval = NULL;
    4.91 +    int xsval_n = 0;
    4.92 +    PyObject *val = NULL;
    4.93 +
    4.94 +    if (!xh)
    4.95 +	goto exit;
    4.96 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
    4.97 +                                     &path))
    4.98 +        goto exit;
    4.99 +    xsval = xs_read(xh, path, &xsval_n);
   4.100 +    if (!xsval) {
   4.101 +        val = pyvalue_int(0);
   4.102 +        goto exit;
   4.103 +    }
   4.104 +    val = PyString_FromStringAndSize(xsval, xsval_n);
   4.105 + exit:
   4.106 +    if (xsval)
   4.107 +	free(xsval);
   4.108 +    return val;
   4.109 +}
   4.110 +
   4.111 +static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
   4.112 +{
   4.113 +    static char *kwd_spec[] = { "path", NULL };
   4.114 +    static char *arg_spec = "s|";
   4.115 +    char *path = NULL;
   4.116 +
   4.117 +    struct xs_handle *xh = xshandle(self);
   4.118 +    PyObject *val = NULL;
   4.119 +    int xsval = 0;
   4.120 +
   4.121 +    if (!xh)
   4.122 +	goto exit;
   4.123 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   4.124 +        goto exit;
   4.125 +    xsval = xs_mkdir(xh, path);
   4.126 +    val = pyvalue_int(xsval);
   4.127 + exit:
   4.128 +    return val;
   4.129 +}
   4.130 +
   4.131 +static PyObject *xspy_ls(PyObject *self, PyObject *args, PyObject *kwds)
   4.132 +{
   4.133 +    static char *kwd_spec[] = { "path", NULL };
   4.134 +    static char *arg_spec = "s|";
   4.135 +    char *path = NULL;
   4.136 +
   4.137 +    struct xs_handle *xh = xshandle(self);
   4.138 +    PyObject *val = NULL;
   4.139 +    char **xsval = NULL;
   4.140 +    int xsval_n = 0;
   4.141 +    int i;
   4.142 +
   4.143 +    if (!xh)
   4.144 +	goto exit;
   4.145 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   4.146 +        goto exit;
   4.147 +    xsval = xs_directory(xh, path, &xsval_n);
   4.148 +    if (!xsval) {
   4.149 +        val = pyvalue_int(0);
   4.150 +        goto exit;
   4.151 +    }
   4.152 +    val = PyList_New(xsval_n);
   4.153 +    for (i = 0; i < xsval_n; i++)
   4.154 +        PyList_SetItem(val, i, PyString_FromString(xsval[i]));
   4.155 + exit:
   4.156 +    return val;
   4.157 +}
   4.158 +
   4.159 +static PyObject *xspy_rm(PyObject *self, PyObject *args, PyObject *kwds)
   4.160 +{
   4.161 +    static char *kwd_spec[] = { "path", NULL };
   4.162 +    static char *arg_spec = "s|";
   4.163 +    char *path = NULL;
   4.164 +
   4.165 +    struct xs_handle *xh = xshandle(self);
   4.166 +    PyObject *val = NULL;
   4.167 +    int xsval = 0;
   4.168 +
   4.169 +    if (!xh)
   4.170 +	goto exit;
   4.171 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   4.172 +        goto exit;
   4.173 +    xsval = xs_rm(xh, path);
   4.174 +    val = pyvalue_int(xsval);
   4.175 + exit:
   4.176 +    return val;
   4.177 +}
   4.178 +
   4.179 +static PyObject *xspy_get_permissions(PyObject *self, PyObject *args,
   4.180 +				      PyObject *kwds)
   4.181 +{
   4.182 +    static char *kwd_spec[] = { "path", NULL };
   4.183 +    static char *arg_spec = "s|";
   4.184 +    char *path = NULL;
   4.185 +
   4.186 +    struct xs_handle *xh = xshandle(self);
   4.187 +    PyObject *val = NULL;
   4.188 +    struct xs_permissions *perms;
   4.189 +    int perms_n = 0;
   4.190 +    int i;
   4.191 +
   4.192 +    if (!xh)
   4.193 +	goto exit;
   4.194 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   4.195 +        goto exit;
   4.196 +    perms = xs_get_permissions(xh, path, &perms_n);
   4.197 +    if (!perms) {
   4.198 +        PyErr_SetFromErrno(PyExc_RuntimeError);
   4.199 +        goto exit;
   4.200 +    }
   4.201 +    val = PyList_New(perms_n);
   4.202 +    for (i = 0; i < perms_n; i++, perms++) {
   4.203 +        PyObject *p = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i}",
   4.204 +                                    "dom",    perms->id,
   4.205 +                                    "read",   (perms->perms & XS_PERM_READ),
   4.206 +                                    "write",  (perms->perms & XS_PERM_WRITE),
   4.207 +                                    "create", (perms->perms & XS_PERM_CREATE),
   4.208 +                                    "owner",  (perms->perms & XS_PERM_OWNER));
   4.209 +        PyList_SetItem(val, i, p);
   4.210 +    }
   4.211 + exit:
   4.212 +    return val;
   4.213 +}
   4.214 +
   4.215 +static PyObject *xspy_set_permissions(PyObject *self, PyObject *args,
   4.216 +				      PyObject *kwds)
   4.217 +{
   4.218 +    static char *kwd_spec[] = { "path", "perms", NULL };
   4.219 +    static char *arg_spec = "sO";
   4.220 +    char *path = NULL;
   4.221 +    PyObject *perms = NULL;
   4.222 +    static char *perm_names[] = { "dom", "read", "write", "create", "owner",
   4.223 +				  NULL };
   4.224 +    static char *perm_spec = "i|iiii";
   4.225 +
   4.226 +    struct xs_handle *xh = xshandle(self);
   4.227 +    int i, xsval;
   4.228 +    struct xs_permissions *xsperms = NULL;
   4.229 +    int xsperms_n = 0;
   4.230 +    PyObject *tuple0 = NULL;
   4.231 +    PyObject *val = NULL;
   4.232 +
   4.233 +    if (!xh)
   4.234 +        goto exit;
   4.235 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   4.236 +                                     &path, &perms))
   4.237 +        goto exit;
   4.238 +    if (!PyList_Check(perms)) {
   4.239 +        PyErr_SetString(PyExc_RuntimeError, "perms must be a list");
   4.240 +        goto exit;
   4.241 +    }
   4.242 +    xsperms_n = PyList_Size(perms);
   4.243 +    xsperms = calloc(xsperms_n, sizeof(struct xs_permissions));
   4.244 +    if (!xsperms) {
   4.245 +        PyErr_SetString(PyExc_RuntimeError, "out of memory");
   4.246 +        goto exit;
   4.247 +    }
   4.248 +    tuple0 = PyTuple_New(0);
   4.249 +    if (!tuple0)
   4.250 +	goto exit;
   4.251 +    for (i = 0; i < xsperms_n; i++) {
   4.252 +        /* Domain the permissions apply to. */
   4.253 +        int dom = 0;
   4.254 +        /* Read/write perms. Set these. */
   4.255 +        int p_read = 0, p_write = 0;
   4.256 +        /* Create/owner perms. Ignore them.
   4.257 +         * This is so the output from get_permissions() can be used
   4.258 +         * as input to set_permissions().
   4.259 +         */
   4.260 +        int p_create = 0, p_owner = 0;
   4.261 +        PyObject *p = PyList_GetItem(perms, i);
   4.262 +        if (!PyArg_ParseTupleAndKeywords(tuple0, p, perm_spec, perm_names,
   4.263 +					 &dom, &p_read, &p_write, &p_create,
   4.264 +					 &p_owner))
   4.265 +            goto exit;
   4.266 +        xsperms[i].id = dom;
   4.267 +        if (p_read)
   4.268 +	    xsperms[i].perms |= XS_PERM_READ;
   4.269 +        if (p_write)
   4.270 +	    xsperms[i].perms |= XS_PERM_WRITE;
   4.271 +    }
   4.272 +    xsval = xs_set_permissions(xh, path, xsperms, xsperms_n);
   4.273 +    val = pyvalue_int(xsval);
   4.274 + exit:
   4.275 +    Py_XDECREF(tuple0);
   4.276 +    if (xsperms)
   4.277 +	free(xsperms);
   4.278 +    return val;
   4.279 +}
   4.280 +
   4.281 +static PyObject *xspy_watch(PyObject *self, PyObject *args, PyObject *kwds)
   4.282 +{
   4.283 +    static char *kwd_spec[] = { "path", "priority", NULL };
   4.284 +    static char *arg_spec = "s|i";
   4.285 +    char *path = NULL;
   4.286 +    int priority = 0;
   4.287 +
   4.288 +    struct xs_handle *xh = xshandle(self);
   4.289 +    PyObject *val = NULL;
   4.290 +    int xsval = 0;
   4.291 +
   4.292 +    if (!xh)
   4.293 +	goto exit;
   4.294 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, 
   4.295 +                                     &path, &priority))
   4.296 +        goto exit;
   4.297 +    xsval = xs_watch(xh, path, priority);
   4.298 +    val = pyvalue_int(xsval);
   4.299 + exit:
   4.300 +    return val;
   4.301 +}
   4.302 +
   4.303 +static PyObject *xspy_read_watch(PyObject *self, PyObject *args,
   4.304 +				 PyObject *kwds)
   4.305 +{
   4.306 +    static char *kwd_spec[] = { NULL };
   4.307 +    static char *arg_spec = "";
   4.308 +
   4.309 +    struct xs_handle *xh = xshandle(self);
   4.310 +    PyObject *val = NULL;
   4.311 +    char *xsval = NULL;
   4.312 +
   4.313 +    if (!xh)
   4.314 +	goto exit;
   4.315 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   4.316 +        goto exit;
   4.317 +    xsval = xs_read_watch(xh);
   4.318 +    val = pyvalue_str(xsval);
   4.319 + exit:
   4.320 +    if (xsval)
   4.321 +	free(xsval);
   4.322 +    return val;
   4.323 +}
   4.324 +
   4.325 +static PyObject *xspy_acknowledge_watch(PyObject *self, PyObject *args,
   4.326 +					PyObject *kwds)
   4.327 +{
   4.328 +    static char *kwd_spec[] = { NULL };
   4.329 +    static char *arg_spec = "";
   4.330 +
   4.331 +    struct xs_handle *xh = xshandle(self);
   4.332 +    PyObject *val = NULL;
   4.333 +    int xsval = 0;
   4.334 +
   4.335 +    if (!xh)
   4.336 +	goto exit;
   4.337 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   4.338 +        goto exit;
   4.339 +    xsval = xs_acknowledge_watch(xh);
   4.340 +    val = pyvalue_int(xsval);
   4.341 + exit:
   4.342 +    return val;
   4.343 +}
   4.344 +
   4.345 +static PyObject *xspy_unwatch(PyObject *self, PyObject *args, PyObject *kwds)
   4.346 +{
   4.347 +    static char *kwd_spec[] = { "path", NULL };
   4.348 +    static char *arg_spec = "s|";
   4.349 +    char *path = NULL;
   4.350 +
   4.351 +    struct xs_handle *xh = xshandle(self);
   4.352 +    PyObject *val = NULL;
   4.353 +    int xsval = 0;
   4.354 +
   4.355 +    if (!xh)
   4.356 +	goto exit;
   4.357 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   4.358 +        goto exit;
   4.359 +    xsval = xs_unwatch(xh, path);
   4.360 +    val = pyvalue_int(xsval);
   4.361 + exit:
   4.362 +    return val;
   4.363 +}
   4.364 +
   4.365 +static PyObject *xspy_transaction_start(PyObject *self, PyObject *args,
   4.366 +					PyObject *kwds)
   4.367 +{
   4.368 +    static char *kwd_spec[] = { "path", NULL };
   4.369 +    static char *arg_spec = "s|";
   4.370 +    char *path = NULL;
   4.371 +
   4.372 +    struct xs_handle *xh = xshandle(self);
   4.373 +    PyObject *val = NULL;
   4.374 +    int xsval = 0;
   4.375 +
   4.376 +    if (!xh)
   4.377 +	goto exit;
   4.378 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   4.379 +        goto exit;
   4.380 +    xsval = xs_transaction_start(xh, path);
   4.381 +    val = pyvalue_int(xsval);
   4.382 + exit:
   4.383 +    return val;
   4.384 +}
   4.385 +
   4.386 +static PyObject *xspy_transaction_end(PyObject *self, PyObject *args,
   4.387 +				      PyObject *kwds)
   4.388 +{
   4.389 +    static char *kwd_spec[] = { "abort", NULL };
   4.390 +    static char *arg_spec = "|i";
   4.391 +    int abort = 0;
   4.392 +
   4.393 +    struct xs_handle *xh = xshandle(self);
   4.394 +    PyObject *val = NULL;
   4.395 +    int xsval = 0;
   4.396 +
   4.397 +    if (!xh)
   4.398 +	goto exit;
   4.399 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &abort))
   4.400 +        goto exit;
   4.401 +    xsval = xs_transaction_end(xh, abort);
   4.402 +    val = pyvalue_int(xsval);
   4.403 + exit:
   4.404 +    return val;
   4.405 +}
   4.406 +
   4.407 +static PyObject *xspy_introduce_domain(PyObject *self, PyObject *args,
   4.408 +				       PyObject *kwds)
   4.409 +{
   4.410 +    static char *kwd_spec[] = { "dom", "page", "port", "path", NULL };
   4.411 +    static char *arg_spec = "iiis|";
   4.412 +    domid_t dom = 0;
   4.413 +    unsigned long page = 0;
   4.414 +    unsigned int port = 0;
   4.415 +    char *path = NULL;
   4.416 +
   4.417 +    struct xs_handle *xh = xshandle(self);
   4.418 +    PyObject *val = NULL;
   4.419 +    int xsval = 0;
   4.420 +
   4.421 +    if (!xh)
   4.422 +	goto exit;
   4.423 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   4.424 +                                     &dom, &page, &port, &path))
   4.425 +        goto exit;
   4.426 +    printf("%s> dom=%u page=0x%08lx port=%u path=%s\n", __FUNCTION__, dom,
   4.427 +	   page, port, path);
   4.428 +    xsval = xs_introduce_domain(xh, dom, page, port, path);
   4.429 +    printf("%s> xsval=%d\n", __FUNCTION__, xsval);
   4.430 +    val = pyvalue_int(xsval);
   4.431 + exit:
   4.432 +    return val;
   4.433 +}
   4.434 +
   4.435 +static PyObject *xspy_release_domain(PyObject *self, PyObject *args,
   4.436 +				     PyObject *kwds)
   4.437 +{
   4.438 +    static char *kwd_spec[] = { "dom", NULL };
   4.439 +    static char *arg_spec = "i|";
   4.440 +    domid_t dom;
   4.441 +
   4.442 +    struct xs_handle *xh = xshandle(self);
   4.443 +    PyObject *val = NULL;
   4.444 +    int xsval = 0;
   4.445 +
   4.446 +    if (!xh)
   4.447 +	goto exit;
   4.448 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   4.449 +                                     &dom))
   4.450 +        goto exit;
   4.451 +    printf("%s> dom=%u\n", __FUNCTION__, dom);
   4.452 +    xsval = xs_release_domain(xh, dom);
   4.453 +    printf("%s> xsval=%d\n", __FUNCTION__, xsval);
   4.454 +    val = pyvalue_int(xsval);
   4.455 + exit:
   4.456 +    return val;
   4.457 +}
   4.458 +
   4.459 +static PyObject *xspy_close(PyObject *self, PyObject *args, PyObject *kwds)
   4.460 +{
   4.461 +    static char *kwd_spec[] = { NULL };
   4.462 +    static char *arg_spec = "";
   4.463 +
   4.464 +    struct xs_handle *xh = xshandle(self);
   4.465 +    PyObject *val = NULL;
   4.466 +    int xsval = 1;
   4.467 +
   4.468 +    if (!xh)
   4.469 +	goto exit;
   4.470 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   4.471 +        goto exit;
   4.472 +    xs_daemon_close(xh);
   4.473 +    ((XsHandle*)self)->xh = NULL;
   4.474 +    val = pyvalue_int(xsval);
   4.475 + exit:
   4.476 +    return val;
   4.477 +}
   4.478 +
   4.479 +static PyObject *xspy_shutdown(PyObject *self, PyObject *args, PyObject *kwds)
   4.480 +{
   4.481 +    static char *kwd_spec[] = { NULL };
   4.482 +    static char *arg_spec = "";
   4.483 +
   4.484 +    struct xs_handle *xh = xshandle(self);
   4.485 +    PyObject *val = NULL;
   4.486 +    int xsval = 0;
   4.487 +
   4.488 +    if (!xh)
   4.489 +	goto exit;
   4.490 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   4.491 +        goto exit;
   4.492 +    xsval = xs_shutdown(xh);
   4.493 +    val = pyvalue_int(xsval);
   4.494 + exit:
   4.495 +    return val;
   4.496 +}
   4.497 +
   4.498 +#define XSPY_METH(_name) \
   4.499 +    #_name, \
   4.500 +    (PyCFunction) xspy_ ## _name, \
   4.501 +    (METH_VARARGS | METH_KEYWORDS)
   4.502 +// mtime
   4.503 +// ctime
   4.504 +
   4.505 +static PyMethodDef xshandle_methods[] = {
   4.506 +    { XSPY_METH(read), 
   4.507 +      "read(path) : read data\n" },
   4.508 +    { XSPY_METH(write), 
   4.509 +      "write(path, data, [creat], [excl]): write data\n" },
   4.510 +    { XSPY_METH(ls), 
   4.511 +      "ls(path): list directory.\n" },
   4.512 +    { XSPY_METH(mkdir), 
   4.513 +      "mkdir(path): make a directory.\n" },
   4.514 +    { XSPY_METH(rm),
   4.515 +      "rm(path): remove a path (dir must be empty).\n" },
   4.516 +    { XSPY_METH(get_permissions),
   4.517 +      "get_permissions(path)\n" },
   4.518 +    { XSPY_METH(set_permissions),
   4.519 +      "set_permissions(path)\n" },
   4.520 +    { XSPY_METH(watch), 
   4.521 +      "watch(path)\n" },
   4.522 +    { XSPY_METH(read_watch), 
   4.523 +      "read_watch()\n" },
   4.524 +    { XSPY_METH(acknowledge_watch), 
   4.525 +      "acknowledge_watch()\n" },
   4.526 +    { XSPY_METH(unwatch), 
   4.527 +      "unwatch()\n" },
   4.528 +    { XSPY_METH(transaction_start), 
   4.529 +      "transaction_start()\n" },
   4.530 +    { XSPY_METH(transaction_end), 
   4.531 +      "transaction_end([abort])\n" },
   4.532 +    { XSPY_METH(introduce_domain), 
   4.533 +      "introduce_domain(dom, page, port)\n" },
   4.534 +    { XSPY_METH(release_domain), 
   4.535 +      "release_domain(dom)\n" },
   4.536 +    { XSPY_METH(close), 
   4.537 +      "close()\n" },
   4.538 +    { XSPY_METH(shutdown), 
   4.539 +      "shutdown()\n" },
   4.540 +    { NULL, NULL, 0, NULL }
   4.541 +};
   4.542 +
   4.543 +static PyObject *xshandle_getattr(PyObject *self, char *name)
   4.544 +{
   4.545 +    PyObject *val = NULL;
   4.546 +    if (strcmp(name, "fileno") == 0) {
   4.547 +        struct xs_handle *xh = xshandle(self);
   4.548 +        val = PyInt_FromLong((xh ? xs_fileno(xh) : -1));
   4.549 +    } else
   4.550 +        val = Py_FindMethod(xshandle_methods, self, name);
   4.551 +    return val;
   4.552 +}
   4.553 +
   4.554 +static void xshandle_dealloc(PyObject *self)
   4.555 +{
   4.556 +    XsHandle *xh = (XsHandle*)self;
   4.557 +    if (xh->xh) {
   4.558 +        xs_daemon_close(xh->xh);
   4.559 +        xh->xh = NULL;
   4.560 +    }
   4.561 +    PyObject_Del(self);
   4.562 +}
   4.563 +
   4.564 +static PyTypeObject xshandle_type = {
   4.565 +    PyObject_HEAD_INIT(&PyType_Type)
   4.566 +    0,
   4.567 +    "xshandle",
   4.568 +    sizeof(XsHandle),
   4.569 +    0,
   4.570 +    xshandle_dealloc,   /* tp_dealloc     */
   4.571 +    NULL,               /* tp_print       */
   4.572 +    xshandle_getattr,   /* tp_getattr     */
   4.573 +    NULL,               /* tp_setattr     */
   4.574 +    NULL,               /* tp_compare     */
   4.575 +    NULL,               /* tp_repr        */
   4.576 +    NULL,               /* tp_as_number   */
   4.577 +    NULL,               /* tp_as_sequence */
   4.578 +    NULL,               /* tp_as_mapping  */
   4.579 +    NULL                /* tp_hash        */
   4.580 +};
   4.581 +
   4.582 +static PyObject *xshandle_open(PyObject *self, PyObject *args, PyObject *kwds)
   4.583 +{
   4.584 +    static char *kwd_spec[] = { "readonly", NULL };
   4.585 +    static char *arg_spec = "|i";
   4.586 +    int readonly = 0;
   4.587 +
   4.588 +    XsHandle *xsh = NULL;
   4.589 +    PyObject *val = NULL;
   4.590 +
   4.591 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   4.592 +                                     &readonly))
   4.593 +        goto exit;
   4.594 +
   4.595 +    xsh = PyObject_New(XsHandle, &xshandle_type);
   4.596 +    if (!xsh)
   4.597 +	goto exit;
   4.598 +    xsh->xh = (readonly ? xs_daemon_open_readonly() : xs_daemon_open());
   4.599 +    if (!xsh->xh) {
   4.600 +        PyObject_Del(xsh);
   4.601 +        val = pyvalue_int(0);
   4.602 +        goto exit;
   4.603 +    }
   4.604 +    val = (PyObject *)xsh;
   4.605 + exit:
   4.606 +    return val;
   4.607 +}
   4.608 +
   4.609 +static PyMethodDef xs_methods[] = {
   4.610 +    { "open", (PyCFunction)xshandle_open, (METH_VARARGS | METH_KEYWORDS), 
   4.611 +      "Open a connection to the xenstore daemon.\n" },
   4.612 +    { NULL, NULL, 0, NULL }
   4.613 +};
   4.614 +
   4.615 +PyMODINIT_FUNC initxs (void)
   4.616 +{
   4.617 +    PyObject *module;
   4.618 +
   4.619 +    module = Py_InitModule(PYPKG, xs_methods);
   4.620 +}
     5.1 --- a/tools/python/xen/xend/server/params.py	Tue Jun 07 12:54:45 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/params.py	Tue Jun 07 13:21:38 2005 +0000
     5.3 @@ -31,4 +31,4 @@ XEND_DAEMONIZE     = getenv("XEND_DAEMON
     5.4  XENSTORED_PID_FILE = '/var/run/xenstored.pid'
     5.5  XENSTORED_RUN_DIR  = '/var/run/xenstored'
     5.6  XENSTORED_LIB_DIR  = '/var/lib/xenstored'
     5.7 -XENSTORED_DEBUG    = getenv("XSDAEMON_DEBUG", 0, conv=int)
     5.8 +XENSTORED_DEBUG    = getenv("XENSTORED_DEBUG", 0, conv=int)