ia64/xen-unstable

changeset 969:65538950807b

bitkeeper revision 1.623 (3fbdf485H5kKnNF4DoXW42KlCsxXWw)

setup.py, Xc.c:
Name change to Python file.
Xc.c:
Rename: tools/xc/py/xc_py.c -> tools/xc/py/Xc.c
author kaf24@scramble.cl.cam.ac.uk
date Fri Nov 21 11:18:29 2003 +0000 (2003-11-21)
parents bc77f7e0e1ec
children ea0572c4bc9f
files .rootkeys tools/xc/py/Xc.c tools/xc/py/setup.py tools/xc/py/xc_py.c
line diff
     1.1 --- a/.rootkeys	Thu Nov 20 23:19:07 2003 +0000
     1.2 +++ b/.rootkeys	Fri Nov 21 11:18:29 2003 +0000
     1.3 @@ -213,9 +213,9 @@ 3fbba6dc38q-ioRlwSR_quw4G3qUeQ tools/xc/
     1.4  3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/xc/lib/rpm.spec
     1.5  3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/xc/lib/xc.h
     1.6  3fbd0a3dTwnDcfdw0-v46dPbX98zDw tools/xc/py/Makefile
     1.7 +3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/xc/py/Xc.c
     1.8  3fbd4bd6GtGwZGxYUJPOheYIR7bPaA tools/xc/py/XenoUtil.py
     1.9  3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/xc/py/setup.py
    1.10 -3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/xc/py/xc_py.c
    1.11  3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING
    1.12  3f841450eJvqAD1Dldc0_aOweGiglQ xen/GUEST_CHANGES
    1.13  3ddb79bcbOVHh38VJzc97-JEGD4dJQ xen/Makefile
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/xc/py/Xc.c	Fri Nov 21 11:18:29 2003 +0000
     2.3 @@ -0,0 +1,700 @@
     2.4 +/******************************************************************************
     2.5 + * Xc.c
     2.6 + * 
     2.7 + * Copyright (c) 2003, K A Fraser
     2.8 + */
     2.9 +
    2.10 +#include <Python.h>
    2.11 +#include <xc.h>
    2.12 +
    2.13 +typedef struct {
    2.14 +    PyObject_HEAD;
    2.15 +    int xc_handle;
    2.16 +} XcObject;
    2.17 +
    2.18 +/*
    2.19 + * Definitions for the 'xc' object type.
    2.20 + */
    2.21 +
    2.22 +static PyObject *pyxc_domain_create(PyObject *self,
    2.23 +                                    PyObject *args,
    2.24 +                                    PyObject *kwds)
    2.25 +{
    2.26 +    XcObject *xc = (XcObject *)self;
    2.27 +
    2.28 +    unsigned int mem_kb = 65536;
    2.29 +    char        *name   = "(anon)";
    2.30 +    int          ret;
    2.31 +
    2.32 +    static char *kwd_list[] = { "mem_kb", "name" };
    2.33 +
    2.34 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|is", kwd_list, 
    2.35 +                                      &mem_kb, &name) )
    2.36 +        return NULL;
    2.37 +
    2.38 +    ret = xc_domain_create(xc->xc_handle, mem_kb, name);
    2.39 +    
    2.40 +    return PyInt_FromLong(ret);
    2.41 +}
    2.42 +
    2.43 +static PyObject *pyxc_domain_start(PyObject *self,
    2.44 +                                   PyObject *args,
    2.45 +                                   PyObject *kwds)
    2.46 +{
    2.47 +    XcObject *xc = (XcObject *)self;
    2.48 +
    2.49 +    unsigned int dom;
    2.50 +    int          ret;
    2.51 +
    2.52 +    static char *kwd_list[] = { "dom" };
    2.53 +
    2.54 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )
    2.55 +        return NULL;
    2.56 +
    2.57 +    ret = xc_domain_start(xc->xc_handle, dom);
    2.58 +    
    2.59 +    return PyInt_FromLong(ret);
    2.60 +}
    2.61 +
    2.62 +static PyObject *pyxc_domain_stop(PyObject *self,
    2.63 +                                  PyObject *args,
    2.64 +                                  PyObject *kwds)
    2.65 +{
    2.66 +    XcObject *xc = (XcObject *)self;
    2.67 +
    2.68 +    unsigned int dom;
    2.69 +    int          ret;
    2.70 +
    2.71 +    static char *kwd_list[] = { "dom" };
    2.72 +
    2.73 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )
    2.74 +        return NULL;
    2.75 +
    2.76 +    ret = xc_domain_stop(xc->xc_handle, dom);
    2.77 +    
    2.78 +    return PyInt_FromLong(ret);
    2.79 +}
    2.80 +
    2.81 +static PyObject *pyxc_domain_getinfo(PyObject *self,
    2.82 +                                     PyObject *args,
    2.83 +                                     PyObject *kwds)
    2.84 +{
    2.85 +    XcObject *xc = (XcObject *)self;
    2.86 +    PyObject *list;
    2.87 +
    2.88 +    unsigned int  first_dom = 0, max_doms = 1024;
    2.89 +    int           nr_doms, i;
    2.90 +    xc_dominfo_t *info;
    2.91 +
    2.92 +    static char *kwd_list[] = { "first_dom", "max_doms" };
    2.93 +    
    2.94 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list,
    2.95 +                                      &first_dom, &max_doms) )
    2.96 +        return NULL;
    2.97 +
    2.98 +    info = malloc(max_doms * sizeof(xc_dominfo_t));
    2.99 +    if ( info == NULL )
   2.100 +        nr_doms = 0;
   2.101 +    else
   2.102 +        nr_doms = xc_domain_getinfo(xc->xc_handle, first_dom, max_doms, info);
   2.103 +    
   2.104 +    list = PyList_New(nr_doms);
   2.105 +    for ( i = 0 ; i < nr_doms; i++ )
   2.106 +    {
   2.107 +        PyList_SetItem(
   2.108 +            list, i, 
   2.109 +            Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:L,s:s}",
   2.110 +                          "dom",      info[i].domid,
   2.111 +                          "cpu",      info[i].cpu,
   2.112 +                          "running",  info[i].has_cpu,
   2.113 +                          "stopped",  info[i].stopped,
   2.114 +                          "mem_kb",   info[i].nr_pages*4,
   2.115 +                          "cpu_time", info[i].cpu_time,
   2.116 +                          "name",     info[i].name));
   2.117 +    }
   2.118 +
   2.119 +    if ( info != NULL )
   2.120 +        free(info);
   2.121 +
   2.122 +    return list;
   2.123 +}
   2.124 +
   2.125 +static PyObject *pyxc_linux_save(PyObject *self,
   2.126 +                                 PyObject *args,
   2.127 +                                 PyObject *kwds)
   2.128 +{
   2.129 +    XcObject *xc = (XcObject *)self;
   2.130 +
   2.131 +    unsigned int dom;
   2.132 +    char        *state_file;
   2.133 +    int          progress = 1, ret;
   2.134 +
   2.135 +    static char *kwd_list[] = { "dom", "state_file", "progress" };
   2.136 +
   2.137 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is|i", kwd_list, 
   2.138 +                                      &dom, &state_file, &progress) )
   2.139 +        return NULL;
   2.140 +
   2.141 +    ret = xc_linux_save(xc->xc_handle, dom, state_file, progress);
   2.142 +    
   2.143 +    return PyInt_FromLong(ret);
   2.144 +}
   2.145 +
   2.146 +static PyObject *pyxc_linux_restore(PyObject *self,
   2.147 +                                    PyObject *args,
   2.148 +                                    PyObject *kwds)
   2.149 +{
   2.150 +    XcObject *xc = (XcObject *)self;
   2.151 +
   2.152 +    char        *state_file;
   2.153 +    int          progress = 1, ret;
   2.154 +
   2.155 +    static char *kwd_list[] = { "state_file", "progress" };
   2.156 +
   2.157 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwd_list, 
   2.158 +                                      &state_file, &progress) )
   2.159 +        return NULL;
   2.160 +
   2.161 +    ret = xc_linux_restore(xc->xc_handle, state_file, progress);
   2.162 +    
   2.163 +    return PyInt_FromLong(ret);
   2.164 +}
   2.165 +
   2.166 +static PyObject *pyxc_linux_build(PyObject *self,
   2.167 +                                  PyObject *args,
   2.168 +                                  PyObject *kwds)
   2.169 +{
   2.170 +    XcObject *xc = (XcObject *)self;
   2.171 +
   2.172 +    unsigned int dom;
   2.173 +    char        *image, *ramdisk = NULL, *cmdline = "";
   2.174 +    int          ret;
   2.175 +
   2.176 +    static char *kwd_list[] = { "dom", "image", "ramdisk", "cmdline" };
   2.177 +
   2.178 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is|ss", kwd_list, 
   2.179 +                                      &dom, &image, &ramdisk, &cmdline) )
   2.180 +        return NULL;
   2.181 +
   2.182 +    ret = xc_linux_build(xc->xc_handle, dom, image, ramdisk, cmdline);
   2.183 +    
   2.184 +    return PyInt_FromLong(ret);
   2.185 +}
   2.186 +
   2.187 +static PyObject *pyxc_bvtsched_global_set(PyObject *self,
   2.188 +                                          PyObject *args,
   2.189 +                                          PyObject *kwds)
   2.190 +{
   2.191 +    XcObject *xc = (XcObject *)self;
   2.192 +
   2.193 +    unsigned long ctx_allow;
   2.194 +    int           ret;
   2.195 +
   2.196 +    static char *kwd_list[] = { "ctx_allow" };
   2.197 +
   2.198 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "l", kwd_list, &ctx_allow) )
   2.199 +        return NULL;
   2.200 +
   2.201 +    ret = xc_bvtsched_global_set(xc->xc_handle, ctx_allow);
   2.202 +    
   2.203 +    return PyInt_FromLong(ret);
   2.204 +}
   2.205 +
   2.206 +static PyObject *pyxc_bvtsched_domain_set(PyObject *self,
   2.207 +                                          PyObject *args,
   2.208 +                                          PyObject *kwds)
   2.209 +{
   2.210 +    XcObject *xc = (XcObject *)self;
   2.211 +
   2.212 +    unsigned int  dom;
   2.213 +    unsigned long mcuadv, warp, warpl, warpu;
   2.214 +    int           ret;
   2.215 +
   2.216 +    static char *kwd_list[] = { "dom", "mcuadv", "warp", "warpl", "warpu" };
   2.217 +
   2.218 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illll", kwd_list, 
   2.219 +                                      &dom, &mcuadv, &warp, &warpl, &warpu) )
   2.220 +        return NULL;
   2.221 +
   2.222 +    ret = xc_bvtsched_domain_set(xc->xc_handle, dom, mcuadv, 
   2.223 +                                 warp, warpl, warpu);
   2.224 +    
   2.225 +    return PyInt_FromLong(ret);
   2.226 +}
   2.227 +
   2.228 +static PyObject *pyxc_vif_scheduler_set(PyObject *self,
   2.229 +                                        PyObject *args,
   2.230 +                                        PyObject *kwds)
   2.231 +{
   2.232 +    XcObject *xc = (XcObject *)self;
   2.233 +
   2.234 +    unsigned int  dom, vif;
   2.235 +    xc_vif_sched_params_t sched = { 0, 0 };
   2.236 +    int           ret;
   2.237 +
   2.238 +    static char *kwd_list[] = { "dom", "vif", "credit_bytes", "credit_usecs" };
   2.239 +
   2.240 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii|ll", kwd_list, 
   2.241 +                                      &dom, &vif, 
   2.242 +                                      &sched.credit_bytes, 
   2.243 +                                      &sched.credit_usec) )
   2.244 +        return NULL;
   2.245 +
   2.246 +    ret = xc_vif_scheduler_set(xc->xc_handle, dom, vif, &sched);
   2.247 +    
   2.248 +    return PyInt_FromLong(ret);
   2.249 +}
   2.250 +
   2.251 +static PyObject *pyxc_vif_scheduler_get(PyObject *self,
   2.252 +                                        PyObject *args,
   2.253 +                                        PyObject *kwds)
   2.254 +{
   2.255 +    XcObject *xc = (XcObject *)self;
   2.256 +    PyObject *dict;
   2.257 +
   2.258 +    unsigned int  dom, vif;
   2.259 +    xc_vif_sched_params_t sched;
   2.260 +    int           ret;
   2.261 +
   2.262 +    static char *kwd_list[] = { "dom", "vif" };
   2.263 +
   2.264 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
   2.265 +                                      &dom, &vif) )
   2.266 +        return NULL;
   2.267 +
   2.268 +    ret = xc_vif_scheduler_get(xc->xc_handle, dom, vif, &sched);
   2.269 +
   2.270 +    if ( ret < 0 )
   2.271 +        dict = Py_BuildValue("{}");
   2.272 +    else
   2.273 +        dict = Py_BuildValue("{s:l,s:l}", 
   2.274 +                             "credit_bytes", sched.credit_bytes,
   2.275 +                             "credit_usecs", sched.credit_usec);
   2.276 +    
   2.277 +    return dict;
   2.278 +}
   2.279 +
   2.280 +static PyObject *pyxc_vif_stats_get(PyObject *self,
   2.281 +                                    PyObject *args,
   2.282 +                                    PyObject *kwds)
   2.283 +{
   2.284 +    XcObject *xc = (XcObject *)self;
   2.285 +    PyObject *dict;
   2.286 +
   2.287 +    unsigned int  dom, vif;
   2.288 +    xc_vif_stats_t stats;
   2.289 +    int           ret;
   2.290 +
   2.291 +    static char *kwd_list[] = { "dom", "vif" };
   2.292 +
   2.293 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
   2.294 +                                      &dom, &vif) )
   2.295 +        return NULL;
   2.296 +
   2.297 +    ret = xc_vif_stats_get(xc->xc_handle, dom, vif, &stats);
   2.298 +
   2.299 +    if ( ret < 0 )
   2.300 +        dict = Py_BuildValue("{}");
   2.301 +    else
   2.302 +        dict = Py_BuildValue("{s:L,s:L,s:L,s:L}", 
   2.303 +                             "tx_bytes", stats.tx_bytes,
   2.304 +                             "tx_packets", stats.tx_pkts,
   2.305 +                             "rx_bytes", stats.rx_bytes,
   2.306 +                             "rx_packets", stats.rx_pkts);
   2.307 +    
   2.308 +    return dict;
   2.309 +}
   2.310 +
   2.311 +static PyObject *pyxc_vbd_create(PyObject *self,
   2.312 +                                 PyObject *args,
   2.313 +                                 PyObject *kwds)
   2.314 +{
   2.315 +    XcObject *xc = (XcObject *)self;
   2.316 +
   2.317 +    unsigned int dom, vbd;
   2.318 +    int          writeable, ret;
   2.319 +
   2.320 +    static char *kwd_list[] = { "dom", "vbd", "writeable" };
   2.321 +
   2.322 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list, 
   2.323 +                                      &dom, &vbd, &writeable) )
   2.324 +        return NULL;
   2.325 +
   2.326 +    ret = xc_vbd_create(xc->xc_handle, dom, vbd, writeable);
   2.327 +    
   2.328 +    return PyInt_FromLong(ret);
   2.329 +}
   2.330 +
   2.331 +static PyObject *pyxc_vbd_destroy(PyObject *self,
   2.332 +                                  PyObject *args,
   2.333 +                                  PyObject *kwds)
   2.334 +{
   2.335 +    XcObject *xc = (XcObject *)self;
   2.336 +
   2.337 +    unsigned int dom, vbd;
   2.338 +    int          ret;
   2.339 +
   2.340 +    static char *kwd_list[] = { "dom", "vbd" };
   2.341 +
   2.342 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
   2.343 +                                      &dom, &vbd) )
   2.344 +        return NULL;
   2.345 +
   2.346 +    ret = xc_vbd_destroy(xc->xc_handle, dom, vbd);
   2.347 +    
   2.348 +    return PyInt_FromLong(ret);
   2.349 +}
   2.350 +
   2.351 +static PyObject *pyxc_vbd_add_extent(PyObject *self,
   2.352 +                                     PyObject *args,
   2.353 +                                     PyObject *kwds)
   2.354 +{
   2.355 +    XcObject *xc = (XcObject *)self;
   2.356 +
   2.357 +    unsigned int  dom, vbd, device;
   2.358 +    unsigned long start_sector, nr_sectors;
   2.359 +    int           ret;
   2.360 +
   2.361 +    static char *kwd_list[] = { "dom", "vbd", "device", 
   2.362 +                                "start_sector", "nr_sectors" };
   2.363 +
   2.364 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiill", kwd_list, 
   2.365 +                                      &dom, &vbd, &device, 
   2.366 +                                      &start_sector, &nr_sectors) )
   2.367 +        return NULL;
   2.368 +
   2.369 +    ret = xc_vbd_add_extent(xc->xc_handle, dom, vbd, device, 
   2.370 +                            start_sector, nr_sectors);
   2.371 +    
   2.372 +    return PyInt_FromLong(ret);
   2.373 +}
   2.374 +
   2.375 +static PyObject *pyxc_vbd_delete_extent(PyObject *self,
   2.376 +                                        PyObject *args,
   2.377 +                                        PyObject *kwds)
   2.378 +{
   2.379 +    XcObject *xc = (XcObject *)self;
   2.380 +
   2.381 +    unsigned int  dom, vbd, device;
   2.382 +    unsigned long start_sector, nr_sectors;
   2.383 +    int           ret;
   2.384 +
   2.385 +    static char *kwd_list[] = { "dom", "vbd", "device", 
   2.386 +                                "start_sector", "nr_sectors" };
   2.387 +
   2.388 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiill", kwd_list, 
   2.389 +                                      &dom, &vbd, &device, 
   2.390 +                                      &start_sector, &nr_sectors) )
   2.391 +        return NULL;
   2.392 +
   2.393 +    ret = xc_vbd_delete_extent(xc->xc_handle, dom, vbd, device, 
   2.394 +                               start_sector, nr_sectors);
   2.395 +    
   2.396 +    return PyInt_FromLong(ret);
   2.397 +}
   2.398 +
   2.399 +static PyObject *pyxc_vbd_probe(PyObject *self,
   2.400 +                                PyObject *args,
   2.401 +                                PyObject *kwds)
   2.402 +{
   2.403 +    XcObject *xc = (XcObject *)self;
   2.404 +    PyObject *list;
   2.405 +
   2.406 +    unsigned int dom = XC_VBDDOM_PROBE_ALL, max_vbds = 1024;
   2.407 +    xc_vbd_t    *info;
   2.408 +    int          nr_vbds, i;
   2.409 +
   2.410 +    static char *kwd_list[] = { "dom", "max_vbds" };
   2.411 +
   2.412 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list, 
   2.413 +                                      &dom, &max_vbds) )
   2.414 +        return NULL;
   2.415 +
   2.416 +    info = malloc(max_vbds * sizeof(xc_vbd_t));
   2.417 +    if ( info == NULL )
   2.418 +        nr_vbds = 0;
   2.419 +    else
   2.420 +        nr_vbds = xc_vbd_probe(xc->xc_handle, dom, max_vbds, info);
   2.421 +
   2.422 +    list = PyList_New(nr_vbds);
   2.423 +    for ( i = 0; i < nr_vbds; i++ )
   2.424 +    {
   2.425 +        PyList_SetItem(
   2.426 +            list, i, 
   2.427 +            Py_BuildValue("{s:i,s:i,s:i,s:l}",
   2.428 +                          "dom",        info[i].domid,
   2.429 +                          "vbd",        info[i].vbdid,
   2.430 +                          "writeable",  !!(info[i].flags & XC_VBDF_WRITEABLE),
   2.431 +                          "nr_sectors", info[i].nr_sectors));
   2.432 +    }
   2.433 +
   2.434 +    if ( info != NULL )
   2.435 +        free(info);
   2.436 +
   2.437 +    return list;
   2.438 +}
   2.439 +
   2.440 +static PyObject *pyxc_readconsolering(PyObject *self,
   2.441 +                                      PyObject *args,
   2.442 +                                      PyObject *kwds)
   2.443 +{
   2.444 +    XcObject *xc = (XcObject *)self;
   2.445 +
   2.446 +    unsigned int clear = 0;
   2.447 +    char         str[32768];
   2.448 +    int          ret;
   2.449 +
   2.450 +    static char *kwd_list[] = { "clear" };
   2.451 +
   2.452 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &clear) )
   2.453 +        return NULL;
   2.454 +
   2.455 +    ret = xc_readconsolering(xc->xc_handle, str, sizeof(str), clear);
   2.456 +
   2.457 +    return PyString_FromStringAndSize(str, (ret < 0) ? 0 : ret);
   2.458 +}
   2.459 +
   2.460 +static PyMethodDef pyxc_methods[] = {
   2.461 +    { "domain_create", 
   2.462 +      (PyCFunction)pyxc_domain_create, 
   2.463 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.464 +      "Create a new domain.\n"
   2.465 +      " mem_kb [int, 65536]:    Memory allocation, in kilobytes.\n"
   2.466 +      " name   [str, '(anon)']: Informative textual name.\n\n"
   2.467 +      "Returns: [int] new domain identifier; -1 on error.\n" },
   2.468 +
   2.469 +    { "domain_start", 
   2.470 +      (PyCFunction)pyxc_domain_start, 
   2.471 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.472 +      "Start execution of a domain.\n"
   2.473 +      " dom [int]: Identifier of domain to be started.\n\n"
   2.474 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.475 +
   2.476 +    { "domain_stop", 
   2.477 +      (PyCFunction)pyxc_domain_stop, 
   2.478 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.479 +      "Stop execution of a domain.\n"
   2.480 +      " dom [int]: Identifier of domain to be stopped.\n\n"
   2.481 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.482 +
   2.483 +    { "domain_getinfo", 
   2.484 +      (PyCFunction)pyxc_domain_getinfo, 
   2.485 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.486 +      "Get information regarding a set of domains, in increasing id order.\n"
   2.487 +      " first_dom [int, 0]:    First domain to retrieve info about.\n"
   2.488 +      " max_doms  [int, 1024]: Maximum number of domains to retrieve info"
   2.489 +      " about.\n\n"
   2.490 +      "Returns: [list of dicts] if list length is less than 'max_doms'\n"
   2.491 +      "         parameter then there was an error, or the end of the\n"
   2.492 +      "         domain-id space was reached.\n"
   2.493 +      " dom      [int]:  Identifier of domain to which this info pertains\n"
   2.494 +      " cpu      [int]:  CPU to which this domain is bound\n"
   2.495 +      " running  [int]:  Bool - is the domain currently running?\n"
   2.496 +      " stopped  [int]:  Bool - is the domain suspended?\n"
   2.497 +      " mem_kb   [int]:  Memory reservation, in kilobytes\n"
   2.498 +      " cpu_time [long]: CPU time consumed, in nanoseconds\n"
   2.499 +      " name     [str]:  Identifying name\n" },
   2.500 +
   2.501 +    { "linux_save", 
   2.502 +      (PyCFunction)pyxc_linux_save, 
   2.503 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.504 +      "Save the CPU and memory state of a Linux guest OS.\n"
   2.505 +      " dom        [int]:    Identifier of domain to be saved.\n"
   2.506 +      " state_file [str]:    Name of state file. Must not currently exist.\n"
   2.507 +      " progress   [int, 1]: Bool - display a running progress indication?\n\n"
   2.508 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.509 +
   2.510 +    { "linux_restore", 
   2.511 +      (PyCFunction)pyxc_linux_restore, 
   2.512 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.513 +      "Restore the CPU and memory state of a Linux guest OS.\n"
   2.514 +      " state_file [str]:    Name of state file. Must not currently exist.\n"
   2.515 +      " progress   [int, 1]: Bool - display a running progress indication?\n\n"
   2.516 +      "Returns: [int] new domain identifier on success; -1 on error.\n" },
   2.517 +
   2.518 +    { "linux_build", 
   2.519 +      (PyCFunction)pyxc_linux_build, 
   2.520 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.521 +      "Build a new Linux guest OS.\n"
   2.522 +      " dom     [int]:      Identifier of domain to build into.\n"
   2.523 +      " image   [str]:      Name of kernel image file. May be gzipped.\n"
   2.524 +      " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
   2.525 +      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
   2.526 +      "Returns: [int] new domain identifier on success; -1 on error.\n" },
   2.527 +
   2.528 +    { "bvtsched_global_set", 
   2.529 +      (PyCFunction)pyxc_bvtsched_global_set, 
   2.530 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.531 +      "Set global tuning parameters for Borrowed Virtual Time scheduler.\n"
   2.532 +      " ctx_allow [int]: Minimal guaranteed quantum (I think!).\n\n"
   2.533 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.534 +
   2.535 +    { "bvtsched_domain_set", 
   2.536 +      (PyCFunction)pyxc_bvtsched_domain_set, 
   2.537 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.538 +      "Set per-domain tuning parameters for Borrowed Virtual Time scheduler.\n"
   2.539 +      " dom    [int]: Identifier of domain to be tuned.\n"
   2.540 +      " mcuadv [int]: Internal BVT parameter.\n"
   2.541 +      " warp   [int]: Internal BVT parameter.\n"
   2.542 +      " warpl  [int]: Internal BVT parameter.\n"
   2.543 +      " warpu  [int]: Internal BVT parameter.\n\n"
   2.544 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.545 +
   2.546 +    { "vif_scheduler_set", 
   2.547 +      (PyCFunction)pyxc_vif_scheduler_set, 
   2.548 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.549 +      "Set per-network-interface scheduling parameters.\n"
   2.550 +      " dom          [int]:    Identifier of domain to be adjusted.\n"
   2.551 +      " vif          [int]:    Identifier of VIF to be adjusted.\n"
   2.552 +      " credit_bytes [int, 0]: Tx bytes permitted each interval.\n"
   2.553 +      " credit_usecs [int, 0]: Interval, in usecs. 0 == no scheduling.\n\n"
   2.554 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.555 +
   2.556 +    { "vif_scheduler_get", 
   2.557 +      (PyCFunction)pyxc_vif_scheduler_get, 
   2.558 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.559 +      "Query the per-network-interface scheduling parameters.\n"
   2.560 +      " dom          [int]:    Identifier of domain to be queried.\n"
   2.561 +      " vif          [int]:    Identifier of VIF to be queried.\n\n"
   2.562 +      "Returns: [dict] dictionary is empty on failure.\n"
   2.563 +      " credit_bytes [int]: Tx bytes permitted each interval.\n"
   2.564 +      " credit_usecs [int]: Interval, in usecs. 0 == no scheduling.\n" },
   2.565 +
   2.566 +    { "vif_stats_get", 
   2.567 +      (PyCFunction)pyxc_vif_stats_get, 
   2.568 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.569 +      "Query the per-network-interface statistics.\n"
   2.570 +      " dom          [int]: Identifier of domain to be queried.\n"
   2.571 +      " vif          [int]: Identifier of VIF to be queried.\n\n"
   2.572 +      "Returns: [dict] dictionary is empty on failure.\n"
   2.573 +      " tx_bytes   [long]: Bytes transmitted.\n"
   2.574 +      " tx_packets [long]: Packets transmitted.\n"
   2.575 +      " rx_bytes   [long]: Bytes received.\n"
   2.576 +      " rx_packets [long]: Packets received.\n" },
   2.577 +
   2.578 +    { "vbd_create", 
   2.579 +      (PyCFunction)pyxc_vbd_create, 
   2.580 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.581 +      "Create a new virtual block device associated with a given domain.\n"
   2.582 +      " dom       [int]: Identifier of domain to get a new VBD.\n"
   2.583 +      " vbd       [int]: Identifier for new VBD.\n"
   2.584 +      " writeable [int]: Bool - is the new VBD writeable?\n\n"
   2.585 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.586 +
   2.587 +    { "vbd_destroy", 
   2.588 +      (PyCFunction)pyxc_vbd_destroy, 
   2.589 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.590 +      "Destroy a virtual block device.\n"
   2.591 +      " dom       [int]: Identifier of domain containing the VBD.\n"
   2.592 +      " vbd       [int]: Identifier of the VBD.\n\n"
   2.593 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.594 +
   2.595 +    { "vbd_add_extent", 
   2.596 +      (PyCFunction)pyxc_vbd_add_extent, 
   2.597 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.598 +      "Add an extent to a virtual block device.\n"
   2.599 +      " dom          [int]: Identifier of domain containing the VBD.\n"
   2.600 +      " vbd          [int]: Identifier of the VBD.\n"
   2.601 +      " device       [int]: Identifier of the real underlying block device.\n"
   2.602 +      " start_sector [int]: Real start sector of this extent.\n"
   2.603 +      " nr_sectors   [int]: Length, in sectors, of this extent.\n\n"
   2.604 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.605 +
   2.606 +    { "vbd_delete_extent", 
   2.607 +      (PyCFunction)pyxc_vbd_delete_extent, 
   2.608 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.609 +      "Delete an extent from a virtual block device.\n"
   2.610 +      " dom          [int]: Identifier of domain containing the VBD.\n"
   2.611 +      " vbd          [int]: Identifier of the VBD.\n"
   2.612 +      " device       [int]: Identifier of the real underlying block device.\n"
   2.613 +      " start_sector [int]: Real start sector of the extent.\n"
   2.614 +      " nr_sectors   [int]: Length, in sectors, of the extent.\n\n"
   2.615 +      "Returns: [int] 0 on success; -1 on error.\n" },
   2.616 +
   2.617 +    { "vbd_probe", 
   2.618 +      (PyCFunction)pyxc_vbd_probe, 
   2.619 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.620 +      "Get information regarding extant virtual block devices.\n"
   2.621 +      " dom          [int, ALL]:  Domain to query (default is to query all).\n"
   2.622 +      " max_vbds     [int, 1024]: Maximum VBDs to query.\n\n"
   2.623 +      "Returns: [list of dicts] if list length is less than 'max_vbds'\n"
   2.624 +      "         parameter then there was an error, or there were fewer vbds.\n"
   2.625 +      " dom        [int]: Domain containing this VBD.\n"
   2.626 +      " vbd        [int]: Domain-specific identifier of this VBD.\n"
   2.627 +      " writeable  [int]: Bool - is this VBD writeable?\n"
   2.628 +      " nr_sectors [int]: Size of this VBD, in 512-byte sectors.\n" },
   2.629 +
   2.630 +    { "readconsolering", 
   2.631 +      (PyCFunction)pyxc_readconsolering, 
   2.632 +      METH_VARARGS | METH_KEYWORDS, "\n"
   2.633 +      "Read Xen's console ring.\n"
   2.634 +      " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
   2.635 +      "Returns: [str] string is empty on failure.\n" },
   2.636 +
   2.637 +    { NULL, NULL, 0, NULL }
   2.638 +};
   2.639 +
   2.640 +
   2.641 +/*
   2.642 + * Definitions for the 'Xc' module wrapper.
   2.643 + */
   2.644 +
   2.645 +staticforward PyTypeObject PyXcType;
   2.646 +
   2.647 +static PyObject *PyXc_new(PyObject *self, PyObject *args)
   2.648 +{
   2.649 +    XcObject *xc;
   2.650 +
   2.651 +    if ( !PyArg_ParseTuple(args, ":new") )
   2.652 +        return NULL;
   2.653 +
   2.654 +    xc = PyObject_New(XcObject, &PyXcType);
   2.655 +
   2.656 +    if ( (xc->xc_handle = xc_interface_open()) == -1 )
   2.657 +    {
   2.658 +        PyObject_Del((PyObject *)xc);
   2.659 +        return NULL;
   2.660 +    }
   2.661 +
   2.662 +    return (PyObject *)xc;
   2.663 +}
   2.664 +
   2.665 +static PyObject *PyXc_getattr(PyObject *obj, char *name)
   2.666 +{
   2.667 +    return Py_FindMethod(pyxc_methods, obj, name);
   2.668 +}
   2.669 +
   2.670 +static void PyXc_dealloc(PyObject *self)
   2.671 +{
   2.672 +    XcObject *xc = (XcObject *)self;
   2.673 +    (void)xc_interface_close(xc->xc_handle);
   2.674 +    PyObject_Del(self);
   2.675 +}
   2.676 +
   2.677 +static PyTypeObject PyXcType = {
   2.678 +    PyObject_HEAD_INIT(&PyType_Type)
   2.679 +    0,
   2.680 +    "Xc",
   2.681 +    sizeof(XcObject),
   2.682 +    0,
   2.683 +    PyXc_dealloc,    /* tp_dealloc     */
   2.684 +    NULL,            /* tp_print       */
   2.685 +    PyXc_getattr,    /* tp_getattr     */
   2.686 +    NULL,            /* tp_setattr     */
   2.687 +    NULL,            /* tp_compare     */
   2.688 +    NULL,            /* tp_repr        */
   2.689 +    NULL,            /* tp_as_number   */
   2.690 +    NULL,            /* tp_as_sequence */
   2.691 +    NULL,            /* tp_as_mapping  */
   2.692 +    NULL             /* tp_hash        */
   2.693 +};
   2.694 +
   2.695 +static PyMethodDef PyXc_methods[] = {
   2.696 +    { "new", PyXc_new, METH_VARARGS, "Create a new Xc object." },
   2.697 +    { NULL, NULL, 0, NULL }
   2.698 +};
   2.699 +
   2.700 +DL_EXPORT(void) initXc(void)
   2.701 +{
   2.702 +    Py_InitModule("Xc", PyXc_methods);
   2.703 +}
     3.1 --- a/tools/xc/py/setup.py	Thu Nov 20 23:19:07 2003 +0000
     3.2 +++ b/tools/xc/py/setup.py	Fri Nov 21 11:18:29 2003 +0000
     3.3 @@ -4,7 +4,7 @@ from distutils.core import setup, Extens
     3.4  module = Extension("Xc",
     3.5                     include_dirs         = ["../lib"],
     3.6                     library_dirs         = ["../lib"],
     3.7 -                   sources              = ["xc_py.c"])
     3.8 +                   sources              = ["Xc.c"])
     3.9  
    3.10  # Include the following line to link against shared libxc.so
    3.11  #module.libraries = ["xc"]
     4.1 --- a/tools/xc/py/xc_py.c	Thu Nov 20 23:19:07 2003 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,700 +0,0 @@
     4.4 -/******************************************************************************
     4.5 - * xc_py.c
     4.6 - * 
     4.7 - * Copyright (c) 2003, K A Fraser
     4.8 - */
     4.9 -
    4.10 -#include <Python.h>
    4.11 -#include <xc.h>
    4.12 -
    4.13 -typedef struct {
    4.14 -    PyObject_HEAD;
    4.15 -    int xc_handle;
    4.16 -} XcObject;
    4.17 -
    4.18 -/*
    4.19 - * Definitions for the 'xc' object type.
    4.20 - */
    4.21 -
    4.22 -static PyObject *pyxc_domain_create(PyObject *self,
    4.23 -                                    PyObject *args,
    4.24 -                                    PyObject *kwds)
    4.25 -{
    4.26 -    XcObject *xc = (XcObject *)self;
    4.27 -
    4.28 -    unsigned int mem_kb = 65536;
    4.29 -    char        *name   = "(anon)";
    4.30 -    int          ret;
    4.31 -
    4.32 -    static char *kwd_list[] = { "mem_kb", "name" };
    4.33 -
    4.34 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|is", kwd_list, 
    4.35 -                                      &mem_kb, &name) )
    4.36 -        return NULL;
    4.37 -
    4.38 -    ret = xc_domain_create(xc->xc_handle, mem_kb, name);
    4.39 -    
    4.40 -    return PyInt_FromLong(ret);
    4.41 -}
    4.42 -
    4.43 -static PyObject *pyxc_domain_start(PyObject *self,
    4.44 -                                   PyObject *args,
    4.45 -                                   PyObject *kwds)
    4.46 -{
    4.47 -    XcObject *xc = (XcObject *)self;
    4.48 -
    4.49 -    unsigned int dom;
    4.50 -    int          ret;
    4.51 -
    4.52 -    static char *kwd_list[] = { "dom" };
    4.53 -
    4.54 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )
    4.55 -        return NULL;
    4.56 -
    4.57 -    ret = xc_domain_start(xc->xc_handle, dom);
    4.58 -    
    4.59 -    return PyInt_FromLong(ret);
    4.60 -}
    4.61 -
    4.62 -static PyObject *pyxc_domain_stop(PyObject *self,
    4.63 -                                  PyObject *args,
    4.64 -                                  PyObject *kwds)
    4.65 -{
    4.66 -    XcObject *xc = (XcObject *)self;
    4.67 -
    4.68 -    unsigned int dom;
    4.69 -    int          ret;
    4.70 -
    4.71 -    static char *kwd_list[] = { "dom" };
    4.72 -
    4.73 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )
    4.74 -        return NULL;
    4.75 -
    4.76 -    ret = xc_domain_stop(xc->xc_handle, dom);
    4.77 -    
    4.78 -    return PyInt_FromLong(ret);
    4.79 -}
    4.80 -
    4.81 -static PyObject *pyxc_domain_getinfo(PyObject *self,
    4.82 -                                     PyObject *args,
    4.83 -                                     PyObject *kwds)
    4.84 -{
    4.85 -    XcObject *xc = (XcObject *)self;
    4.86 -    PyObject *list;
    4.87 -
    4.88 -    unsigned int  first_dom = 0, max_doms = 1024;
    4.89 -    int           nr_doms, i;
    4.90 -    xc_dominfo_t *info;
    4.91 -
    4.92 -    static char *kwd_list[] = { "first_dom", "max_doms" };
    4.93 -    
    4.94 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list,
    4.95 -                                      &first_dom, &max_doms) )
    4.96 -        return NULL;
    4.97 -
    4.98 -    info = malloc(max_doms * sizeof(xc_dominfo_t));
    4.99 -    if ( info == NULL )
   4.100 -        nr_doms = 0;
   4.101 -    else
   4.102 -        nr_doms = xc_domain_getinfo(xc->xc_handle, first_dom, max_doms, info);
   4.103 -    
   4.104 -    list = PyList_New(nr_doms);
   4.105 -    for ( i = 0 ; i < nr_doms; i++ )
   4.106 -    {
   4.107 -        PyList_SetItem(
   4.108 -            list, i, 
   4.109 -            Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:L,s:s}",
   4.110 -                          "dom",      info[i].domid,
   4.111 -                          "cpu",      info[i].cpu,
   4.112 -                          "running",  info[i].has_cpu,
   4.113 -                          "stopped",  info[i].stopped,
   4.114 -                          "mem_kb",   info[i].nr_pages*4,
   4.115 -                          "cpu_time", info[i].cpu_time,
   4.116 -                          "name",     info[i].name));
   4.117 -    }
   4.118 -
   4.119 -    if ( info != NULL )
   4.120 -        free(info);
   4.121 -
   4.122 -    return list;
   4.123 -}
   4.124 -
   4.125 -static PyObject *pyxc_linux_save(PyObject *self,
   4.126 -                                 PyObject *args,
   4.127 -                                 PyObject *kwds)
   4.128 -{
   4.129 -    XcObject *xc = (XcObject *)self;
   4.130 -
   4.131 -    unsigned int dom;
   4.132 -    char        *state_file;
   4.133 -    int          progress = 1, ret;
   4.134 -
   4.135 -    static char *kwd_list[] = { "dom", "state_file", "progress" };
   4.136 -
   4.137 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is|i", kwd_list, 
   4.138 -                                      &dom, &state_file, &progress) )
   4.139 -        return NULL;
   4.140 -
   4.141 -    ret = xc_linux_save(xc->xc_handle, dom, state_file, progress);
   4.142 -    
   4.143 -    return PyInt_FromLong(ret);
   4.144 -}
   4.145 -
   4.146 -static PyObject *pyxc_linux_restore(PyObject *self,
   4.147 -                                    PyObject *args,
   4.148 -                                    PyObject *kwds)
   4.149 -{
   4.150 -    XcObject *xc = (XcObject *)self;
   4.151 -
   4.152 -    char        *state_file;
   4.153 -    int          progress = 1, ret;
   4.154 -
   4.155 -    static char *kwd_list[] = { "state_file", "progress" };
   4.156 -
   4.157 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwd_list, 
   4.158 -                                      &state_file, &progress) )
   4.159 -        return NULL;
   4.160 -
   4.161 -    ret = xc_linux_restore(xc->xc_handle, state_file, progress);
   4.162 -    
   4.163 -    return PyInt_FromLong(ret);
   4.164 -}
   4.165 -
   4.166 -static PyObject *pyxc_linux_build(PyObject *self,
   4.167 -                                  PyObject *args,
   4.168 -                                  PyObject *kwds)
   4.169 -{
   4.170 -    XcObject *xc = (XcObject *)self;
   4.171 -
   4.172 -    unsigned int dom;
   4.173 -    char        *image, *ramdisk = NULL, *cmdline = "";
   4.174 -    int          ret;
   4.175 -
   4.176 -    static char *kwd_list[] = { "dom", "image", "ramdisk", "cmdline" };
   4.177 -
   4.178 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is|ss", kwd_list, 
   4.179 -                                      &dom, &image, &ramdisk, &cmdline) )
   4.180 -        return NULL;
   4.181 -
   4.182 -    ret = xc_linux_build(xc->xc_handle, dom, image, ramdisk, cmdline);
   4.183 -    
   4.184 -    return PyInt_FromLong(ret);
   4.185 -}
   4.186 -
   4.187 -static PyObject *pyxc_bvtsched_global_set(PyObject *self,
   4.188 -                                          PyObject *args,
   4.189 -                                          PyObject *kwds)
   4.190 -{
   4.191 -    XcObject *xc = (XcObject *)self;
   4.192 -
   4.193 -    unsigned long ctx_allow;
   4.194 -    int           ret;
   4.195 -
   4.196 -    static char *kwd_list[] = { "ctx_allow" };
   4.197 -
   4.198 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "l", kwd_list, &ctx_allow) )
   4.199 -        return NULL;
   4.200 -
   4.201 -    ret = xc_bvtsched_global_set(xc->xc_handle, ctx_allow);
   4.202 -    
   4.203 -    return PyInt_FromLong(ret);
   4.204 -}
   4.205 -
   4.206 -static PyObject *pyxc_bvtsched_domain_set(PyObject *self,
   4.207 -                                          PyObject *args,
   4.208 -                                          PyObject *kwds)
   4.209 -{
   4.210 -    XcObject *xc = (XcObject *)self;
   4.211 -
   4.212 -    unsigned int  dom;
   4.213 -    unsigned long mcuadv, warp, warpl, warpu;
   4.214 -    int           ret;
   4.215 -
   4.216 -    static char *kwd_list[] = { "dom", "mcuadv", "warp", "warpl", "warpu" };
   4.217 -
   4.218 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illll", kwd_list, 
   4.219 -                                      &dom, &mcuadv, &warp, &warpl, &warpu) )
   4.220 -        return NULL;
   4.221 -
   4.222 -    ret = xc_bvtsched_domain_set(xc->xc_handle, dom, mcuadv, 
   4.223 -                                 warp, warpl, warpu);
   4.224 -    
   4.225 -    return PyInt_FromLong(ret);
   4.226 -}
   4.227 -
   4.228 -static PyObject *pyxc_vif_scheduler_set(PyObject *self,
   4.229 -                                        PyObject *args,
   4.230 -                                        PyObject *kwds)
   4.231 -{
   4.232 -    XcObject *xc = (XcObject *)self;
   4.233 -
   4.234 -    unsigned int  dom, vif;
   4.235 -    xc_vif_sched_params_t sched = { 0, 0 };
   4.236 -    int           ret;
   4.237 -
   4.238 -    static char *kwd_list[] = { "dom", "vif", "credit_bytes", "credit_usecs" };
   4.239 -
   4.240 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii|ll", kwd_list, 
   4.241 -                                      &dom, &vif, 
   4.242 -                                      &sched.credit_bytes, 
   4.243 -                                      &sched.credit_usec) )
   4.244 -        return NULL;
   4.245 -
   4.246 -    ret = xc_vif_scheduler_set(xc->xc_handle, dom, vif, &sched);
   4.247 -    
   4.248 -    return PyInt_FromLong(ret);
   4.249 -}
   4.250 -
   4.251 -static PyObject *pyxc_vif_scheduler_get(PyObject *self,
   4.252 -                                        PyObject *args,
   4.253 -                                        PyObject *kwds)
   4.254 -{
   4.255 -    XcObject *xc = (XcObject *)self;
   4.256 -    PyObject *dict;
   4.257 -
   4.258 -    unsigned int  dom, vif;
   4.259 -    xc_vif_sched_params_t sched;
   4.260 -    int           ret;
   4.261 -
   4.262 -    static char *kwd_list[] = { "dom", "vif" };
   4.263 -
   4.264 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
   4.265 -                                      &dom, &vif) )
   4.266 -        return NULL;
   4.267 -
   4.268 -    ret = xc_vif_scheduler_get(xc->xc_handle, dom, vif, &sched);
   4.269 -
   4.270 -    if ( ret < 0 )
   4.271 -        dict = Py_BuildValue("{}");
   4.272 -    else
   4.273 -        dict = Py_BuildValue("{s:l,s:l}", 
   4.274 -                             "credit_bytes", sched.credit_bytes,
   4.275 -                             "credit_usecs", sched.credit_usec);
   4.276 -    
   4.277 -    return dict;
   4.278 -}
   4.279 -
   4.280 -static PyObject *pyxc_vif_stats_get(PyObject *self,
   4.281 -                                    PyObject *args,
   4.282 -                                    PyObject *kwds)
   4.283 -{
   4.284 -    XcObject *xc = (XcObject *)self;
   4.285 -    PyObject *dict;
   4.286 -
   4.287 -    unsigned int  dom, vif;
   4.288 -    xc_vif_stats_t stats;
   4.289 -    int           ret;
   4.290 -
   4.291 -    static char *kwd_list[] = { "dom", "vif" };
   4.292 -
   4.293 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
   4.294 -                                      &dom, &vif) )
   4.295 -        return NULL;
   4.296 -
   4.297 -    ret = xc_vif_stats_get(xc->xc_handle, dom, vif, &stats);
   4.298 -
   4.299 -    if ( ret < 0 )
   4.300 -        dict = Py_BuildValue("{}");
   4.301 -    else
   4.302 -        dict = Py_BuildValue("{s:L,s:L,s:L,s:L}", 
   4.303 -                             "tx_bytes", stats.tx_bytes,
   4.304 -                             "tx_packets", stats.tx_pkts,
   4.305 -                             "rx_bytes", stats.rx_bytes,
   4.306 -                             "rx_packets", stats.rx_pkts);
   4.307 -    
   4.308 -    return dict;
   4.309 -}
   4.310 -
   4.311 -static PyObject *pyxc_vbd_create(PyObject *self,
   4.312 -                                 PyObject *args,
   4.313 -                                 PyObject *kwds)
   4.314 -{
   4.315 -    XcObject *xc = (XcObject *)self;
   4.316 -
   4.317 -    unsigned int dom, vbd;
   4.318 -    int          writeable, ret;
   4.319 -
   4.320 -    static char *kwd_list[] = { "dom", "vbd", "writeable" };
   4.321 -
   4.322 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list, 
   4.323 -                                      &dom, &vbd, &writeable) )
   4.324 -        return NULL;
   4.325 -
   4.326 -    ret = xc_vbd_create(xc->xc_handle, dom, vbd, writeable);
   4.327 -    
   4.328 -    return PyInt_FromLong(ret);
   4.329 -}
   4.330 -
   4.331 -static PyObject *pyxc_vbd_destroy(PyObject *self,
   4.332 -                                  PyObject *args,
   4.333 -                                  PyObject *kwds)
   4.334 -{
   4.335 -    XcObject *xc = (XcObject *)self;
   4.336 -
   4.337 -    unsigned int dom, vbd;
   4.338 -    int          ret;
   4.339 -
   4.340 -    static char *kwd_list[] = { "dom", "vbd" };
   4.341 -
   4.342 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
   4.343 -                                      &dom, &vbd) )
   4.344 -        return NULL;
   4.345 -
   4.346 -    ret = xc_vbd_destroy(xc->xc_handle, dom, vbd);
   4.347 -    
   4.348 -    return PyInt_FromLong(ret);
   4.349 -}
   4.350 -
   4.351 -static PyObject *pyxc_vbd_add_extent(PyObject *self,
   4.352 -                                     PyObject *args,
   4.353 -                                     PyObject *kwds)
   4.354 -{
   4.355 -    XcObject *xc = (XcObject *)self;
   4.356 -
   4.357 -    unsigned int  dom, vbd, device;
   4.358 -    unsigned long start_sector, nr_sectors;
   4.359 -    int           ret;
   4.360 -
   4.361 -    static char *kwd_list[] = { "dom", "vbd", "device", 
   4.362 -                                "start_sector", "nr_sectors" };
   4.363 -
   4.364 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiill", kwd_list, 
   4.365 -                                      &dom, &vbd, &device, 
   4.366 -                                      &start_sector, &nr_sectors) )
   4.367 -        return NULL;
   4.368 -
   4.369 -    ret = xc_vbd_add_extent(xc->xc_handle, dom, vbd, device, 
   4.370 -                            start_sector, nr_sectors);
   4.371 -    
   4.372 -    return PyInt_FromLong(ret);
   4.373 -}
   4.374 -
   4.375 -static PyObject *pyxc_vbd_delete_extent(PyObject *self,
   4.376 -                                        PyObject *args,
   4.377 -                                        PyObject *kwds)
   4.378 -{
   4.379 -    XcObject *xc = (XcObject *)self;
   4.380 -
   4.381 -    unsigned int  dom, vbd, device;
   4.382 -    unsigned long start_sector, nr_sectors;
   4.383 -    int           ret;
   4.384 -
   4.385 -    static char *kwd_list[] = { "dom", "vbd", "device", 
   4.386 -                                "start_sector", "nr_sectors" };
   4.387 -
   4.388 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiill", kwd_list, 
   4.389 -                                      &dom, &vbd, &device, 
   4.390 -                                      &start_sector, &nr_sectors) )
   4.391 -        return NULL;
   4.392 -
   4.393 -    ret = xc_vbd_delete_extent(xc->xc_handle, dom, vbd, device, 
   4.394 -                               start_sector, nr_sectors);
   4.395 -    
   4.396 -    return PyInt_FromLong(ret);
   4.397 -}
   4.398 -
   4.399 -static PyObject *pyxc_vbd_probe(PyObject *self,
   4.400 -                                PyObject *args,
   4.401 -                                PyObject *kwds)
   4.402 -{
   4.403 -    XcObject *xc = (XcObject *)self;
   4.404 -    PyObject *list;
   4.405 -
   4.406 -    unsigned int dom = XC_VBDDOM_PROBE_ALL, max_vbds = 1024;
   4.407 -    xc_vbd_t    *info;
   4.408 -    int          nr_vbds, i;
   4.409 -
   4.410 -    static char *kwd_list[] = { "dom", "max_vbds" };
   4.411 -
   4.412 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list, 
   4.413 -                                      &dom, &max_vbds) )
   4.414 -        return NULL;
   4.415 -
   4.416 -    info = malloc(max_vbds * sizeof(xc_vbd_t));
   4.417 -    if ( info == NULL )
   4.418 -        nr_vbds = 0;
   4.419 -    else
   4.420 -        nr_vbds = xc_vbd_probe(xc->xc_handle, dom, max_vbds, info);
   4.421 -
   4.422 -    list = PyList_New(nr_vbds);
   4.423 -    for ( i = 0; i < nr_vbds; i++ )
   4.424 -    {
   4.425 -        PyList_SetItem(
   4.426 -            list, i, 
   4.427 -            Py_BuildValue("{s:i,s:i,s:i,s:l}",
   4.428 -                          "dom",        info[i].domid,
   4.429 -                          "vbd",        info[i].vbdid,
   4.430 -                          "writeable",  !!(info[i].flags & XC_VBDF_WRITEABLE),
   4.431 -                          "nr_sectors", info[i].nr_sectors));
   4.432 -    }
   4.433 -
   4.434 -    if ( info != NULL )
   4.435 -        free(info);
   4.436 -
   4.437 -    return list;
   4.438 -}
   4.439 -
   4.440 -static PyObject *pyxc_readconsolering(PyObject *self,
   4.441 -                                      PyObject *args,
   4.442 -                                      PyObject *kwds)
   4.443 -{
   4.444 -    XcObject *xc = (XcObject *)self;
   4.445 -
   4.446 -    unsigned int clear = 0;
   4.447 -    char         str[32768];
   4.448 -    int          ret;
   4.449 -
   4.450 -    static char *kwd_list[] = { "clear" };
   4.451 -
   4.452 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &clear) )
   4.453 -        return NULL;
   4.454 -
   4.455 -    ret = xc_readconsolering(xc->xc_handle, str, sizeof(str), clear);
   4.456 -
   4.457 -    return PyString_FromStringAndSize(str, (ret < 0) ? 0 : ret);
   4.458 -}
   4.459 -
   4.460 -static PyMethodDef pyxc_methods[] = {
   4.461 -    { "domain_create", 
   4.462 -      (PyCFunction)pyxc_domain_create, 
   4.463 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.464 -      "Create a new domain.\n"
   4.465 -      " mem_kb [int, 65536]:    Memory allocation, in kilobytes.\n"
   4.466 -      " name   [str, '(anon)']: Informative textual name.\n\n"
   4.467 -      "Returns: [int] new domain identifier; -1 on error.\n" },
   4.468 -
   4.469 -    { "domain_start", 
   4.470 -      (PyCFunction)pyxc_domain_start, 
   4.471 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.472 -      "Start execution of a domain.\n"
   4.473 -      " dom [int]: Identifier of domain to be started.\n\n"
   4.474 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.475 -
   4.476 -    { "domain_stop", 
   4.477 -      (PyCFunction)pyxc_domain_stop, 
   4.478 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.479 -      "Stop execution of a domain.\n"
   4.480 -      " dom [int]: Identifier of domain to be stopped.\n\n"
   4.481 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.482 -
   4.483 -    { "domain_getinfo", 
   4.484 -      (PyCFunction)pyxc_domain_getinfo, 
   4.485 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.486 -      "Get information regarding a set of domains, in increasing id order.\n"
   4.487 -      " first_dom [int, 0]:    First domain to retrieve info about.\n"
   4.488 -      " max_doms  [int, 1024]: Maximum number of domains to retrieve info"
   4.489 -      " about.\n\n"
   4.490 -      "Returns: [list of dicts] if list length is less than 'max_doms'\n"
   4.491 -      "         parameter then there was an error, or the end of the\n"
   4.492 -      "         domain-id space was reached.\n"
   4.493 -      " dom      [int]:  Identifier of domain to which this info pertains\n"
   4.494 -      " cpu      [int]:  CPU to which this domain is bound\n"
   4.495 -      " running  [int]:  Bool - is the domain currently running?\n"
   4.496 -      " stopped  [int]:  Bool - is the domain suspended?\n"
   4.497 -      " mem_kb   [int]:  Memory reservation, in kilobytes\n"
   4.498 -      " cpu_time [long]: CPU time consumed, in nanoseconds\n"
   4.499 -      " name     [str]:  Identifying name\n" },
   4.500 -
   4.501 -    { "linux_save", 
   4.502 -      (PyCFunction)pyxc_linux_save, 
   4.503 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.504 -      "Save the CPU and memory state of a Linux guest OS.\n"
   4.505 -      " dom        [int]:    Identifier of domain to be saved.\n"
   4.506 -      " state_file [str]:    Name of state file. Must not currently exist.\n"
   4.507 -      " progress   [int, 1]: Bool - display a running progress indication?\n\n"
   4.508 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.509 -
   4.510 -    { "linux_restore", 
   4.511 -      (PyCFunction)pyxc_linux_restore, 
   4.512 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.513 -      "Restore the CPU and memory state of a Linux guest OS.\n"
   4.514 -      " state_file [str]:    Name of state file. Must not currently exist.\n"
   4.515 -      " progress   [int, 1]: Bool - display a running progress indication?\n\n"
   4.516 -      "Returns: [int] new domain identifier on success; -1 on error.\n" },
   4.517 -
   4.518 -    { "linux_build", 
   4.519 -      (PyCFunction)pyxc_linux_build, 
   4.520 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.521 -      "Build a new Linux guest OS.\n"
   4.522 -      " dom     [int]:      Identifier of domain to build into.\n"
   4.523 -      " image   [str]:      Name of kernel image file. May be gzipped.\n"
   4.524 -      " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
   4.525 -      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
   4.526 -      "Returns: [int] new domain identifier on success; -1 on error.\n" },
   4.527 -
   4.528 -    { "bvtsched_global_set", 
   4.529 -      (PyCFunction)pyxc_bvtsched_global_set, 
   4.530 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.531 -      "Set global tuning parameters for Borrowed Virtual Time scheduler.\n"
   4.532 -      " ctx_allow [int]: Minimal guaranteed quantum (I think!).\n\n"
   4.533 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.534 -
   4.535 -    { "bvtsched_domain_set", 
   4.536 -      (PyCFunction)pyxc_bvtsched_domain_set, 
   4.537 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.538 -      "Set per-domain tuning parameters for Borrowed Virtual Time scheduler.\n"
   4.539 -      " dom    [int]: Identifier of domain to be tuned.\n"
   4.540 -      " mcuadv [int]: Internal BVT parameter.\n"
   4.541 -      " warp   [int]: Internal BVT parameter.\n"
   4.542 -      " warpl  [int]: Internal BVT parameter.\n"
   4.543 -      " warpu  [int]: Internal BVT parameter.\n\n"
   4.544 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.545 -
   4.546 -    { "vif_scheduler_set", 
   4.547 -      (PyCFunction)pyxc_vif_scheduler_set, 
   4.548 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.549 -      "Set per-network-interface scheduling parameters.\n"
   4.550 -      " dom          [int]:    Identifier of domain to be adjusted.\n"
   4.551 -      " vif          [int]:    Identifier of VIF to be adjusted.\n"
   4.552 -      " credit_bytes [int, 0]: Tx bytes permitted each interval.\n"
   4.553 -      " credit_usecs [int, 0]: Interval, in usecs. 0 == no scheduling.\n\n"
   4.554 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.555 -
   4.556 -    { "vif_scheduler_get", 
   4.557 -      (PyCFunction)pyxc_vif_scheduler_get, 
   4.558 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.559 -      "Query the per-network-interface scheduling parameters.\n"
   4.560 -      " dom          [int]:    Identifier of domain to be queried.\n"
   4.561 -      " vif          [int]:    Identifier of VIF to be queried.\n\n"
   4.562 -      "Returns: [dict] dictionary is empty on failure.\n"
   4.563 -      " credit_bytes [int]: Tx bytes permitted each interval.\n"
   4.564 -      " credit_usecs [int]: Interval, in usecs. 0 == no scheduling.\n" },
   4.565 -
   4.566 -    { "vif_stats_get", 
   4.567 -      (PyCFunction)pyxc_vif_stats_get, 
   4.568 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.569 -      "Query the per-network-interface statistics.\n"
   4.570 -      " dom          [int]: Identifier of domain to be queried.\n"
   4.571 -      " vif          [int]: Identifier of VIF to be queried.\n\n"
   4.572 -      "Returns: [dict] dictionary is empty on failure.\n"
   4.573 -      " tx_bytes   [long]: Bytes transmitted.\n"
   4.574 -      " tx_packets [long]: Packets transmitted.\n"
   4.575 -      " rx_bytes   [long]: Bytes received.\n"
   4.576 -      " rx_packets [long]: Packets received.\n" },
   4.577 -
   4.578 -    { "vbd_create", 
   4.579 -      (PyCFunction)pyxc_vbd_create, 
   4.580 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.581 -      "Create a new virtual block device associated with a given domain.\n"
   4.582 -      " dom       [int]: Identifier of domain to get a new VBD.\n"
   4.583 -      " vbd       [int]: Identifier for new VBD.\n"
   4.584 -      " writeable [int]: Bool - is the new VBD writeable?\n\n"
   4.585 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.586 -
   4.587 -    { "vbd_destroy", 
   4.588 -      (PyCFunction)pyxc_vbd_destroy, 
   4.589 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.590 -      "Destroy a virtual block device.\n"
   4.591 -      " dom       [int]: Identifier of domain containing the VBD.\n"
   4.592 -      " vbd       [int]: Identifier of the VBD.\n\n"
   4.593 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.594 -
   4.595 -    { "vbd_add_extent", 
   4.596 -      (PyCFunction)pyxc_vbd_add_extent, 
   4.597 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.598 -      "Add an extent to a virtual block device.\n"
   4.599 -      " dom          [int]: Identifier of domain containing the VBD.\n"
   4.600 -      " vbd          [int]: Identifier of the VBD.\n"
   4.601 -      " device       [int]: Identifier of the real underlying block device.\n"
   4.602 -      " start_sector [int]: Real start sector of this extent.\n"
   4.603 -      " nr_sectors   [int]: Length, in sectors, of this extent.\n\n"
   4.604 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.605 -
   4.606 -    { "vbd_delete_extent", 
   4.607 -      (PyCFunction)pyxc_vbd_delete_extent, 
   4.608 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.609 -      "Delete an extent from a virtual block device.\n"
   4.610 -      " dom          [int]: Identifier of domain containing the VBD.\n"
   4.611 -      " vbd          [int]: Identifier of the VBD.\n"
   4.612 -      " device       [int]: Identifier of the real underlying block device.\n"
   4.613 -      " start_sector [int]: Real start sector of the extent.\n"
   4.614 -      " nr_sectors   [int]: Length, in sectors, of the extent.\n\n"
   4.615 -      "Returns: [int] 0 on success; -1 on error.\n" },
   4.616 -
   4.617 -    { "vbd_probe", 
   4.618 -      (PyCFunction)pyxc_vbd_probe, 
   4.619 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.620 -      "Get information regarding extant virtual block devices.\n"
   4.621 -      " dom          [int, ALL]:  Domain to query (default is to query all).\n"
   4.622 -      " max_vbds     [int, 1024]: Maximum VBDs to query.\n\n"
   4.623 -      "Returns: [list of dicts] if list length is less than 'max_vbds'\n"
   4.624 -      "         parameter then there was an error, or there were fewer vbds.\n"
   4.625 -      " dom        [int]: Domain containing this VBD.\n"
   4.626 -      " vbd        [int]: Domain-specific identifier of this VBD.\n"
   4.627 -      " writeable  [int]: Bool - is this VBD writeable?\n"
   4.628 -      " nr_sectors [int]: Size of this VBD, in 512-byte sectors.\n" },
   4.629 -
   4.630 -    { "readconsolering", 
   4.631 -      (PyCFunction)pyxc_readconsolering, 
   4.632 -      METH_VARARGS | METH_KEYWORDS, "\n"
   4.633 -      "Read Xen's console ring.\n"
   4.634 -      " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
   4.635 -      "Returns: [str] string is empty on failure.\n" },
   4.636 -
   4.637 -    { NULL, NULL, 0, NULL }
   4.638 -};
   4.639 -
   4.640 -
   4.641 -/*
   4.642 - * Definitions for the 'Xc' module wrapper.
   4.643 - */
   4.644 -
   4.645 -staticforward PyTypeObject PyXcType;
   4.646 -
   4.647 -static PyObject *PyXc_new(PyObject *self, PyObject *args)
   4.648 -{
   4.649 -    XcObject *xc;
   4.650 -
   4.651 -    if ( !PyArg_ParseTuple(args, ":new") )
   4.652 -        return NULL;
   4.653 -
   4.654 -    xc = PyObject_New(XcObject, &PyXcType);
   4.655 -
   4.656 -    if ( (xc->xc_handle = xc_interface_open()) == -1 )
   4.657 -    {
   4.658 -        PyObject_Del((PyObject *)xc);
   4.659 -        return NULL;
   4.660 -    }
   4.661 -
   4.662 -    return (PyObject *)xc;
   4.663 -}
   4.664 -
   4.665 -static PyObject *PyXc_getattr(PyObject *obj, char *name)
   4.666 -{
   4.667 -    return Py_FindMethod(pyxc_methods, obj, name);
   4.668 -}
   4.669 -
   4.670 -static void PyXc_dealloc(PyObject *self)
   4.671 -{
   4.672 -    XcObject *xc = (XcObject *)self;
   4.673 -    (void)xc_interface_close(xc->xc_handle);
   4.674 -    PyObject_Del(self);
   4.675 -}
   4.676 -
   4.677 -static PyTypeObject PyXcType = {
   4.678 -    PyObject_HEAD_INIT(&PyType_Type)
   4.679 -    0,
   4.680 -    "Xc",
   4.681 -    sizeof(XcObject),
   4.682 -    0,
   4.683 -    PyXc_dealloc,    /* tp_dealloc     */
   4.684 -    NULL,            /* tp_print       */
   4.685 -    PyXc_getattr,    /* tp_getattr     */
   4.686 -    NULL,            /* tp_setattr     */
   4.687 -    NULL,            /* tp_compare     */
   4.688 -    NULL,            /* tp_repr        */
   4.689 -    NULL,            /* tp_as_number   */
   4.690 -    NULL,            /* tp_as_sequence */
   4.691 -    NULL,            /* tp_as_mapping  */
   4.692 -    NULL             /* tp_hash        */
   4.693 -};
   4.694 -
   4.695 -static PyMethodDef PyXc_methods[] = {
   4.696 -    { "new", PyXc_new, METH_VARARGS, "Craate a new Xc object." },
   4.697 -    { NULL, NULL, 0, NULL }
   4.698 -};
   4.699 -
   4.700 -DL_EXPORT(void) initXc(void)
   4.701 -{
   4.702 -    Py_InitModule("Xc", PyXc_methods);
   4.703 -}