direct-io.hg

changeset 5490:fd4eac035037

bitkeeper revision 1.1713.3.12 (42b30f09wgYSRV9tHZUjq2JpreIozQ)

xs.c:
Fix some oversights in watch/token code.
Cleanup whitespace.
Move method documentation next to method definition.
Reorder functions in file.
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 Fri Jun 17 17:57:29 2005 +0000 (2005-06-17)
parents 3e54d8803974
children c3f4626710c4
files tools/python/xen/lowlevel/xs/xs.c
line diff
     1.1 --- a/tools/python/xen/lowlevel/xs/xs.c	Fri Jun 17 17:36:02 2005 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Fri Jun 17 17:57:29 2005 +0000
     1.3 @@ -52,6 +52,53 @@ static inline PyObject *pyvalue_str(char
     1.4              : PyErr_SetFromErrno(PyExc_RuntimeError));
     1.5  }
     1.6  
     1.7 +#define xspy_read_doc "\n"			\
     1.8 +	"Read data from a path.\n"		\
     1.9 +	" path [string]: xenstore path\n"	\
    1.10 +	"\n"					\
    1.11 +	"Returns: [string] data read.\n"	\
    1.12 +	"Raises RuntimeError on error.\n"	\
    1.13 +	"\n"
    1.14 +
    1.15 +static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
    1.16 +{
    1.17 +    static char *kwd_spec[] = { "path", NULL };
    1.18 +    static char *arg_spec = "s|";
    1.19 +    char *path = NULL;
    1.20 +
    1.21 +    struct xs_handle *xh = xshandle(self);
    1.22 +    char *xsval = NULL;
    1.23 +    unsigned int xsval_n = 0;
    1.24 +    PyObject *val = NULL;
    1.25 +
    1.26 +    if (!xh)
    1.27 +	goto exit;
    1.28 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
    1.29 +                                     &path))
    1.30 +        goto exit;
    1.31 +    xsval = xs_read(xh, path, &xsval_n);
    1.32 +    if (!xsval) {
    1.33 +        val = pyvalue_int(0);
    1.34 +        goto exit;
    1.35 +    }
    1.36 +    val = PyString_FromStringAndSize(xsval, xsval_n);
    1.37 + exit:
    1.38 +    if (xsval)
    1.39 +	free(xsval);
    1.40 +    return val;
    1.41 +}
    1.42 +
    1.43 +#define xspy_write_doc "\n"					\
    1.44 +	"Write data to a path.\n"				\
    1.45 +	" path   [string] : xenstore path to write to\n."	\
    1.46 +	" data   [string] : data to write.\n"			\
    1.47 +	" create [int]    : create flag, default 0.\n"		\
    1.48 +	" excl   [int]    : exclusive flag, default 0.\n"	\
    1.49 +	"\n"							\
    1.50 +	"Returns: [int] 0 on success.\n"			\
    1.51 +	"Raises RuntimeError on error.\n"			\
    1.52 +	"\n"
    1.53 +
    1.54  static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
    1.55  {
    1.56      static char *kwd_spec[] = { "path", "data", "create", "excl", NULL };
    1.57 @@ -82,53 +129,13 @@ static PyObject *xspy_write(PyObject *se
    1.58      return val;
    1.59  }
    1.60  
    1.61 -static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
    1.62 -{
    1.63 -    static char *kwd_spec[] = { "path", NULL };
    1.64 -    static char *arg_spec = "s|";
    1.65 -    char *path = NULL;
    1.66 -
    1.67 -    struct xs_handle *xh = xshandle(self);
    1.68 -    char *xsval = NULL;
    1.69 -    unsigned int xsval_n = 0;
    1.70 -    PyObject *val = NULL;
    1.71 -
    1.72 -    if (!xh)
    1.73 -	goto exit;
    1.74 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
    1.75 -                                     &path))
    1.76 -        goto exit;
    1.77 -    xsval = xs_read(xh, path, &xsval_n);
    1.78 -    if (!xsval) {
    1.79 -        val = pyvalue_int(0);
    1.80 -        goto exit;
    1.81 -    }
    1.82 -    val = PyString_FromStringAndSize(xsval, xsval_n);
    1.83 - exit:
    1.84 -    if (xsval)
    1.85 -	free(xsval);
    1.86 -    return val;
    1.87 -}
    1.88 -
    1.89 -static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
    1.90 -{
    1.91 -    static char *kwd_spec[] = { "path", NULL };
    1.92 -    static char *arg_spec = "s|";
    1.93 -    char *path = NULL;
    1.94 -
    1.95 -    struct xs_handle *xh = xshandle(self);
    1.96 -    PyObject *val = NULL;
    1.97 -    int xsval = 0;
    1.98 -
    1.99 -    if (!xh)
   1.100 -	goto exit;
   1.101 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   1.102 -        goto exit;
   1.103 -    xsval = xs_mkdir(xh, path);
   1.104 -    val = pyvalue_int(xsval);
   1.105 - exit:
   1.106 -    return val;
   1.107 -}
   1.108 +#define xspy_ls_doc "\n"					\
   1.109 +	"List a directory.\n"					\
   1.110 +	" path [string]: path to list.\n"			\
   1.111 +	"\n"							\
   1.112 +	"Returns: [string array] list of subdirectory names.\n"	\
   1.113 +	"Raises RuntimeError on error.\n"			\
   1.114 +	"\n"
   1.115  
   1.116  static PyObject *xspy_ls(PyObject *self, PyObject *args, PyObject *kwds)
   1.117  {
   1.118 @@ -158,6 +165,41 @@ static PyObject *xspy_ls(PyObject *self,
   1.119      return val;
   1.120  }
   1.121  
   1.122 +#define xspy_mkdir_doc "\n"					\
   1.123 +	"Make a directory.\n"					\
   1.124 +	" path [string]: path to directory to create.\n"	\
   1.125 +	"\n"							\
   1.126 +	"Returns: [int] 0 on success.\n"			\
   1.127 +	"Raises RuntimeError on error.\n"			\
   1.128 +	"\n"
   1.129 +
   1.130 +static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
   1.131 +{
   1.132 +    static char *kwd_spec[] = { "path", NULL };
   1.133 +    static char *arg_spec = "s|";
   1.134 +    char *path = NULL;
   1.135 +
   1.136 +    struct xs_handle *xh = xshandle(self);
   1.137 +    PyObject *val = NULL;
   1.138 +    int xsval = 0;
   1.139 +
   1.140 +    if (!xh)
   1.141 +	goto exit;
   1.142 +    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   1.143 +        goto exit;
   1.144 +    xsval = xs_mkdir(xh, path);
   1.145 +    val = pyvalue_int(xsval);
   1.146 + exit:
   1.147 +    return val;
   1.148 +}
   1.149 +
   1.150 +#define xspy_rm_doc "\n"			\
   1.151 +	"Remove a path.\n"			\
   1.152 +	" path [string] : path to remove\n"	\
   1.153 +	"Returns: [int] 0 on success.\n"	\
   1.154 +	"Raises RuntimeError on error.\n"	\
   1.155 +	"\n"
   1.156 +
   1.157  static PyObject *xspy_rm(PyObject *self, PyObject *args, PyObject *kwds)
   1.158  {
   1.159      static char *kwd_spec[] = { "path", NULL };
   1.160 @@ -178,6 +220,14 @@ static PyObject *xspy_rm(PyObject *self,
   1.161      return val;
   1.162  }
   1.163  
   1.164 +#define xspy_get_permissions_doc "\n"		\
   1.165 +	"Get the permissions for a path\n"	\
   1.166 +	" path [string]: xenstore path.\n"	\
   1.167 +	"\n"					\
   1.168 +	"Returns: permissions array.\n"		\
   1.169 +	"Raises RuntimeError on error.\n"	\
   1.170 +	"\n"
   1.171 +
   1.172  static PyObject *xspy_get_permissions(PyObject *self, PyObject *args,
   1.173  				      PyObject *kwds)
   1.174  {
   1.175 @@ -214,6 +264,15 @@ static PyObject *xspy_get_permissions(Py
   1.176      return val;
   1.177  }
   1.178  
   1.179 +#define xspy_set_permissions_doc "\n"		\
   1.180 +	"Set the permissions for a path\n"	\
   1.181 +	" path  [string] : xenstore path.\n"	\
   1.182 +	" perms          : permissions.\n"	\
   1.183 +	"\n"					\
   1.184 +	"Returns: [int] 0 on success.\n"	\
   1.185 +	"Raises RuntimeError on error.\n"	\
   1.186 +	"\n"
   1.187 +
   1.188  static PyObject *xspy_set_permissions(PyObject *self, PyObject *args,
   1.189  				      PyObject *kwds)
   1.190  {
   1.191 @@ -280,13 +339,22 @@ static PyObject *xspy_set_permissions(Py
   1.192      return val;
   1.193  }
   1.194  
   1.195 +#define xspy_watch_doc "\n"					\
   1.196 +	"Watch a path, get notifications when it changes.\n"	\
   1.197 +	" path  [string] : xenstore path.\n"			\
   1.198 +	" token [string] : returned in watch notification\n"	\
   1.199 +	"\n"							\
   1.200 +	"Returns: [int] 0 on success.\n"			\
   1.201 +	"Raises RuntimeError on error.\n"			\
   1.202 +	"\n"
   1.203 +
   1.204  static PyObject *xspy_watch(PyObject *self, PyObject *args, PyObject *kwds)
   1.205  {
   1.206      static char *kwd_spec[] = { "path", "priority", "token", NULL };
   1.207      static char *arg_spec = "s|is";
   1.208      char *path = NULL;
   1.209      int priority = 0;
   1.210 -    char *token;
   1.211 +    char *token = "";
   1.212  
   1.213      struct xs_handle *xh = xshandle(self);
   1.214      PyObject *val = NULL;
   1.215 @@ -303,6 +371,14 @@ static PyObject *xspy_watch(PyObject *se
   1.216      return val;
   1.217  }
   1.218  
   1.219 +#define xspy_read_watch_doc "\n"		\
   1.220 +	"Read a watch notification.\n"		\
   1.221 +	" path [string]: xenstore path.\n"	\
   1.222 +	"\n"					\
   1.223 +	"Returns: [tuple] (path, token).\n"	\
   1.224 +	"Raises RuntimeError on error.\n"	\
   1.225 +	"\n"
   1.226 +
   1.227  static PyObject *xspy_read_watch(PyObject *self, PyObject *args,
   1.228  				 PyObject *kwds)
   1.229  {
   1.230 @@ -318,7 +394,7 @@ static PyObject *xspy_read_watch(PyObjec
   1.231      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   1.232          goto exit;
   1.233      xsval = xs_read_watch(xh);
   1.234 -    if(!xsval){
   1.235 +    if (!xsval) {
   1.236              val = PyErr_SetFromErrno(PyExc_RuntimeError);
   1.237              goto exit;
   1.238      }
   1.239 @@ -330,12 +406,20 @@ static PyObject *xspy_read_watch(PyObjec
   1.240      return val;
   1.241  }
   1.242  
   1.243 +#define xspy_acknowledge_watch_doc "\n"					\
   1.244 +	"Acknowledge a watch notification that has been read.\n"	\
   1.245 +	" token [string] : returned in watch notification\n"		\
   1.246 +	"\n"								\
   1.247 +	"Returns: [int] 0 on success.\n"				\
   1.248 +	"Raises RuntimeError on error.\n"				\
   1.249 +	"\n"
   1.250 +
   1.251  static PyObject *xspy_acknowledge_watch(PyObject *self, PyObject *args,
   1.252  					PyObject *kwds)
   1.253  {
   1.254 -    static char *kwd_spec[] = { NULL };
   1.255 +    static char *kwd_spec[] = { "token", NULL };
   1.256      static char *arg_spec = "s";
   1.257 -    char *token = "";
   1.258 +    char *token;
   1.259  
   1.260      struct xs_handle *xh = xshandle(self);
   1.261      PyObject *val = NULL;
   1.262 @@ -351,6 +435,15 @@ static PyObject *xspy_acknowledge_watch(
   1.263      return val;
   1.264  }
   1.265  
   1.266 +#define xspy_unwatch_doc "\n"				\
   1.267 +	"Stop watching a path.\n"			\
   1.268 +	" path  [string] : xenstore path.\n"		\
   1.269 +	" token [string] : token from the watch.\n"	\
   1.270 +	"\n"						\
   1.271 +	"Returns: [int] 0 on success.\n"		\
   1.272 +	"Raises RuntimeError on error.\n"		\
   1.273 +	"\n"
   1.274 +
   1.275  static PyObject *xspy_unwatch(PyObject *self, PyObject *args, PyObject *kwds)
   1.276  {
   1.277      static char *kwd_spec[] = { "path", "token", NULL };
   1.278 @@ -373,6 +466,15 @@ static PyObject *xspy_unwatch(PyObject *
   1.279      return val;
   1.280  }
   1.281  
   1.282 +#define xspy_transaction_start_doc "\n"				\
   1.283 +	"Start a transaction on a path.\n"			\
   1.284 +	"Only one transaction can be active at a time.\n"	\
   1.285 +	" path [string]: xenstore path.\n"			\
   1.286 +	"\n"							\
   1.287 +	"Returns: [int] 0 on success.\n"			\
   1.288 +	"Raises RuntimeError on error.\n"			\
   1.289 +	"\n"
   1.290 +
   1.291  static PyObject *xspy_transaction_start(PyObject *self, PyObject *args,
   1.292  					PyObject *kwds)
   1.293  {
   1.294 @@ -394,6 +496,15 @@ static PyObject *xspy_transaction_start(
   1.295      return val;
   1.296  }
   1.297  
   1.298 +#define xspy_transaction_end_doc "\n"					\
   1.299 +	"End the current transaction.\n"				\
   1.300 +	"Attempts to commit the transaction unless abort is true.\n"	\
   1.301 +	" abort [int]: Abort flag..\n"					\
   1.302 +	"\n"								\
   1.303 +	"Returns: [int] 0 on success.\n"				\
   1.304 +	"Raises RuntimeError on error.\n"				\
   1.305 +	"\n"
   1.306 +
   1.307  static PyObject *xspy_transaction_end(PyObject *self, PyObject *args,
   1.308  				      PyObject *kwds)
   1.309  {
   1.310 @@ -415,6 +526,17 @@ static PyObject *xspy_transaction_end(Py
   1.311      return val;
   1.312  }
   1.313  
   1.314 +#define xspy_introduce_domain_doc "\n"					\
   1.315 +	"Tell xenstore about a domain so it can talk to it.\n"		\
   1.316 +	" dom  [int]   : domain id\n"					\
   1.317 +	" page [long]  : address of domain's xenstore page\n"		\
   1.318 +	" port [int]   : port the domain is using for xenstore\n"	\
   1.319 +	" path [string]: path to the domain's data in xenstore\n"	\
   1.320 +	"\n"								\
   1.321 +	"Returns: [int] 0 on success.\n"				\
   1.322 +	"Raises RuntimeError on error.\n"				\
   1.323 +	"\n"
   1.324 +
   1.325  static PyObject *xspy_introduce_domain(PyObject *self, PyObject *args,
   1.326  				       PyObject *kwds)
   1.327  {
   1.328 @@ -443,6 +565,15 @@ static PyObject *xspy_introduce_domain(P
   1.329      return val;
   1.330  }
   1.331  
   1.332 +#define xspy_release_domain_doc "\n"					\
   1.333 +	"Tell xenstore to release its channel to a domain.\n"		\
   1.334 +	"Unless this is done the domain will not be released.\n"	\
   1.335 +	" dom [int]: domain id\n"					\
   1.336 +	"\n"								\
   1.337 +	"Returns: [int] 0 on success.\n"				\
   1.338 +	"Raises RuntimeError on error.\n"				\
   1.339 +	"\n"
   1.340 +
   1.341  static PyObject *xspy_release_domain(PyObject *self, PyObject *args,
   1.342  				     PyObject *kwds)
   1.343  {
   1.344 @@ -467,6 +598,13 @@ static PyObject *xspy_release_domain(PyO
   1.345      return val;
   1.346  }
   1.347  
   1.348 +#define xspy_close_doc "\n"			\
   1.349 +	"Close the connection to xenstore.\n"	\
   1.350 +	"\n"					\
   1.351 +	"Returns: [int] 0 on success.\n"	\
   1.352 +	"Raises RuntimeError on error.\n"	\
   1.353 +	"\n"
   1.354 +
   1.355  static PyObject *xspy_close(PyObject *self, PyObject *args, PyObject *kwds)
   1.356  {
   1.357      static char *kwd_spec[] = { NULL };
   1.358 @@ -487,6 +625,13 @@ static PyObject *xspy_close(PyObject *se
   1.359      return val;
   1.360  }
   1.361  
   1.362 +#define xspy_shutdown_doc "\n"				\
   1.363 +	"Shutdown the xenstore daemon (xsdaemon).\n"	\
   1.364 +	"\n"						\
   1.365 +	"Returns: [int] 0 on success.\n"		\
   1.366 +	"Raises RuntimeError on error.\n"		\
   1.367 +	"\n"
   1.368 +
   1.369  static PyObject *xspy_shutdown(PyObject *self, PyObject *args, PyObject *kwds)
   1.370  {
   1.371      static char *kwd_spec[] = { NULL };
   1.372 @@ -506,49 +651,31 @@ static PyObject *xspy_shutdown(PyObject 
   1.373      return val;
   1.374  }
   1.375  
   1.376 -#define XSPY_METH(_name) \
   1.377 -    #_name, \
   1.378 -    (PyCFunction) xspy_ ## _name, \
   1.379 -    (METH_VARARGS | METH_KEYWORDS)
   1.380 -// mtime
   1.381 -// ctime
   1.382 +#define XSPY_METH(_name) {			\
   1.383 +    .ml_name  = #_name,				\
   1.384 +    .ml_meth  = (PyCFunction) xspy_ ## _name,	\
   1.385 +    .ml_flags = (METH_VARARGS | METH_KEYWORDS),	\
   1.386 +    .ml_doc   = xspy_ ## _name ## _doc }
   1.387  
   1.388  static PyMethodDef xshandle_methods[] = {
   1.389 -    { XSPY_METH(read), 
   1.390 -      "read(path) : read data\n" },
   1.391 -    { XSPY_METH(write), 
   1.392 -      "write(path, data, [creat], [excl]): write data\n" },
   1.393 -    { XSPY_METH(ls), 
   1.394 -      "ls(path): list directory.\n" },
   1.395 -    { XSPY_METH(mkdir), 
   1.396 -      "mkdir(path): make a directory.\n" },
   1.397 -    { XSPY_METH(rm),
   1.398 -      "rm(path): remove a path (dir must be empty).\n" },
   1.399 -    { XSPY_METH(get_permissions),
   1.400 -      "get_permissions(path)\n" },
   1.401 -    { XSPY_METH(set_permissions),
   1.402 -      "set_permissions(path)\n" },
   1.403 -    { XSPY_METH(watch), 
   1.404 -      "watch(path)\n" },
   1.405 -    { XSPY_METH(read_watch), 
   1.406 -      "read_watch()\n" },
   1.407 -    { XSPY_METH(acknowledge_watch), 
   1.408 -      "acknowledge_watch()\n" },
   1.409 -    { XSPY_METH(unwatch), 
   1.410 -      "unwatch()\n" },
   1.411 -    { XSPY_METH(transaction_start), 
   1.412 -      "transaction_start()\n" },
   1.413 -    { XSPY_METH(transaction_end), 
   1.414 -      "transaction_end([abort])\n" },
   1.415 -    { XSPY_METH(introduce_domain), 
   1.416 -      "introduce_domain(dom, page, port)\n" },
   1.417 -    { XSPY_METH(release_domain), 
   1.418 -      "release_domain(dom)\n" },
   1.419 -    { XSPY_METH(close), 
   1.420 -      "close()\n" },
   1.421 -    { XSPY_METH(shutdown), 
   1.422 -      "shutdown()\n" },
   1.423 -    { NULL, NULL, 0, NULL }
   1.424 +     XSPY_METH(read),
   1.425 +     XSPY_METH(write),
   1.426 +     XSPY_METH(ls),
   1.427 +     XSPY_METH(mkdir),
   1.428 +     XSPY_METH(rm),
   1.429 +     XSPY_METH(get_permissions),
   1.430 +     XSPY_METH(set_permissions),
   1.431 +     XSPY_METH(watch),
   1.432 +     XSPY_METH(read_watch),
   1.433 +     XSPY_METH(acknowledge_watch),
   1.434 +     XSPY_METH(unwatch),
   1.435 +     XSPY_METH(transaction_start),
   1.436 +     XSPY_METH(transaction_end),
   1.437 +     XSPY_METH(introduce_domain),
   1.438 +     XSPY_METH(release_domain),
   1.439 +     XSPY_METH(close),
   1.440 +     XSPY_METH(shutdown),
   1.441 +     { /* Terminator. */ },
   1.442  };
   1.443  
   1.444  static PyObject *xshandle_getattr(PyObject *self, char *name)
   1.445 @@ -618,8 +745,15 @@ static PyObject *xshandle_open(PyObject 
   1.446  }
   1.447  
   1.448  static PyMethodDef xs_methods[] = {
   1.449 -    { "open", (PyCFunction)xshandle_open, (METH_VARARGS | METH_KEYWORDS), 
   1.450 -      "Open a connection to the xenstore daemon.\n" },
   1.451 +    { .ml_name  = "open",
   1.452 +      .ml_meth  = (PyCFunction)xshandle_open,
   1.453 +      .ml_flags = (METH_VARARGS | METH_KEYWORDS), 
   1.454 +      .ml_doc   = "\n"
   1.455 +      "Open a connection to the xenstore daemon.\n"
   1.456 +      "Returns: xs connection object.\n"
   1.457 +      "Raises RuntimeError on error.\n"
   1.458 +      "\n"
   1.459 +    },
   1.460      { NULL, NULL, 0, NULL }
   1.461  };
   1.462