ia64/xen-unstable

changeset 964:83c751260dea

bitkeeper revision 1.618 (3fbd0a59dVMNI4LJimKHSsxwsIEbLA)

Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno
author kaf24@scramble.cl.cam.ac.uk
date Thu Nov 20 18:39:21 2003 +0000 (2003-11-20)
parents 57093982ce20 3f16bb4c82c9
children 7a02d0bf8d11
files .rootkeys tools/xc/Makefile tools/xc/lib/libxc_domain.c tools/xc/lib/libxc_linux_build.c tools/xc/lib/libxc_misc.c tools/xc/lib/libxc_vbd.c tools/xc/lib/xc.h tools/xc/py/Makefile tools/xc/py/setup.py tools/xc/py/xc_py.c
line diff
     1.1 --- a/.rootkeys	Thu Nov 20 13:12:48 2003 +0000
     1.2 +++ b/.rootkeys	Thu Nov 20 18:39:21 2003 +0000
     1.3 @@ -212,6 +212,9 @@ 3fbba6dcoGq9hQlksrBUfC2P5F6sGg tools/xc/
     1.4  3fbba6dc38q-ioRlwSR_quw4G3qUeQ tools/xc/lib/libxc_vif.c
     1.5  3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/xc/lib/rpm.spec
     1.6  3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/xc/lib/xc.h
     1.7 +3fbd0a3dTwnDcfdw0-v46dPbX98zDw tools/xc/py/Makefile
     1.8 +3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/xc/py/setup.py
     1.9 +3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/xc/py/xc_py.c
    1.10  3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING
    1.11  3f841450eJvqAD1Dldc0_aOweGiglQ xen/GUEST_CHANGES
    1.12  3ddb79bcbOVHh38VJzc97-JEGD4dJQ xen/Makefile
     2.1 --- a/tools/xc/Makefile	Thu Nov 20 13:12:48 2003 +0000
     2.2 +++ b/tools/xc/Makefile	Thu Nov 20 18:39:21 2003 +0000
     2.3 @@ -1,9 +1,12 @@
     2.4  
     2.5  all:
     2.6  	$(MAKE) -C lib
     2.7 +	$(MAKE) -C py
     2.8  
     2.9  install:
    2.10  	$(MAKE) -C lib install
    2.11 +	$(MAKE) -C py  install
    2.12  
    2.13  clean:
    2.14 -	$(MAKE) -C lib xlean
    2.15 +	$(MAKE) -C lib clean
    2.16 +	$(MAKE) -C py  clean
     3.1 --- a/tools/xc/lib/libxc_domain.c	Thu Nov 20 13:12:48 2003 +0000
     3.2 +++ b/tools/xc/lib/libxc_domain.c	Thu Nov 20 18:39:21 2003 +0000
     3.3 @@ -81,6 +81,7 @@ int xc_domain_getinfo(int xc_handle,
     3.4          info->name[XC_DOMINFO_MAXNAME-1] = '\0';
     3.5  
     3.6          next_domid = op.u.getdomaininfo.domain + 1;
     3.7 +        info++;
     3.8      }
     3.9  
    3.10      return nr_doms;
     4.1 --- a/tools/xc/lib/libxc_linux_build.c	Thu Nov 20 13:12:48 2003 +0000
     4.2 +++ b/tools/xc/lib/libxc_linux_build.c	Thu Nov 20 18:39:21 2003 +0000
     4.3 @@ -317,11 +317,11 @@ static int setup_guestos(int xc_handle,
     4.4      return -1;
     4.5  }
     4.6  
     4.7 -int xc_domain_build(int xc_handle,
     4.8 -                    unsigned int domid,
     4.9 -                    const char *image_name,
    4.10 -                    const char *ramdisk_name,
    4.11 -                    const char *cmdline)
    4.12 +int xc_linux_build(int xc_handle,
    4.13 +                   unsigned int domid,
    4.14 +                   const char *image_name,
    4.15 +                   const char *ramdisk_name,
    4.16 +                   const char *cmdline)
    4.17  {
    4.18      dom0_op_t launch_op, op;
    4.19      unsigned long load_addr;
     5.1 --- a/tools/xc/lib/libxc_misc.c	Thu Nov 20 13:12:48 2003 +0000
     5.2 +++ b/tools/xc/lib/libxc_misc.c	Thu Nov 20 18:39:21 2003 +0000
     5.3 @@ -8,7 +8,10 @@
     5.4  
     5.5  int xc_interface_open(void)
     5.6  {
     5.7 -    return open("/proc/xeno/privcmd", O_RDWR);
     5.8 +    int fd = open("/proc/xeno/privcmd", O_RDWR);
     5.9 +    if ( fd == -1 )
    5.10 +        PERROR("Could not obtain handle on privileged command interface");
    5.11 +    return fd;
    5.12  }
    5.13  
    5.14  int xc_interface_close(int xc_handle)
     6.1 --- a/tools/xc/lib/libxc_vbd.c	Thu Nov 20 13:12:48 2003 +0000
     6.2 +++ b/tools/xc/lib/libxc_vbd.c	Thu Nov 20 18:39:21 2003 +0000
     6.3 @@ -73,7 +73,6 @@ int xc_vbd_delete_extent(int xc_handle,
     6.4  
     6.5  int xc_vbd_probe(int xc_handle,
     6.6                   unsigned int domid,
     6.7 -                 unsigned short vbdid,
     6.8                   unsigned int max_vbds,
     6.9                   xc_vbd_t *vbds)
    6.10  {
    6.11 @@ -82,7 +81,7 @@ int xc_vbd_probe(int xc_handle,
    6.12      int i, j, ret, allocsz = max_vbds * sizeof(xen_disk_t); 
    6.13  
    6.14      op.cmd = BLOCK_IO_OP_VBD_PROBE; 
    6.15 -    op.u.probe_params.domain    = domid; 
    6.16 +    op.u.probe_params.domain = domid; 
    6.17      
    6.18      xdi->max   = max_vbds;
    6.19      xdi->disks = malloc(allocsz);
     7.1 --- a/tools/xc/lib/xc.h	Thu Nov 20 13:12:48 2003 +0000
     7.2 +++ b/tools/xc/lib/xc.h	Thu Nov 20 18:39:21 2003 +0000
     7.3 @@ -44,7 +44,8 @@ int xc_linux_save(int xc_handle,
     7.4                    const char *state_file, 
     7.5                    int verbose);
     7.6  int xc_linux_restore(int xc_handle,
     7.7 -                     const char *state_file, int verbose);
     7.8 +                     const char *state_file, 
     7.9 +                     int verbose);
    7.10  int xc_linux_build(int xc_handle,
    7.11                     unsigned int domid,
    7.12                     const char *image_name,
    7.13 @@ -114,7 +115,6 @@ int xc_vbd_delete_extent(int xc_handle,
    7.14                           unsigned long nr_sectors);
    7.15  int xc_vbd_probe(int xc_handle,
    7.16                   unsigned int domid,
    7.17 -                 unsigned short vbdid,
    7.18                   unsigned int max_vbds,
    7.19                   xc_vbd_t *vbds);
    7.20  
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/xc/py/Makefile	Thu Nov 20 18:39:21 2003 +0000
     8.3 @@ -0,0 +1,9 @@
     8.4 +
     8.5 +all: ../lib/libxc.a
     8.6 +	python setup.py build
     8.7 +
     8.8 +install:
     8.9 +	# How to install Xc.so ??
    8.10 +
    8.11 +clean:
    8.12 +	rm -rf build
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/xc/py/setup.py	Thu Nov 20 18:39:21 2003 +0000
     9.3 @@ -0,0 +1,16 @@
     9.4 +
     9.5 +from distutils.core import setup, Extension
     9.6 +
     9.7 +module = Extension("Xc",
     9.8 +                   include_dirs         = ["../lib"],
     9.9 +                   library_dirs         = ["../lib"],
    9.10 +                   sources              = ["xc_py.c"])
    9.11 +
    9.12 +# Include the following line to link against shared libxc.so
    9.13 +#module.libraries = ["xc"]
    9.14 +
    9.15 +# Include the following lines to link against static libxc.a
    9.16 +module.extra_objects = ["../lib/libxc.a"]
    9.17 +module.libraries     = ["z"]
    9.18 +
    9.19 +setup(name = "Xc", version = "1.0", ext_modules = [module])
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/xc/py/xc_py.c	Thu Nov 20 18:39:21 2003 +0000
    10.3 @@ -0,0 +1,704 @@
    10.4 +/******************************************************************************
    10.5 + * xc_py.c
    10.6 + * 
    10.7 + * Copyright (c) 2003, K A Fraser
    10.8 + */
    10.9 +
   10.10 +#include <Python.h>
   10.11 +#include <xc.h>
   10.12 +
   10.13 +typedef struct {
   10.14 +    PyObject_HEAD;
   10.15 +    int xc_handle;
   10.16 +} XcObject;
   10.17 +
   10.18 +/*
   10.19 + * Definitions for the 'xc' object type.
   10.20 + */
   10.21 +
   10.22 +static PyObject *pyxc_domain_create(PyObject *self,
   10.23 +                                    PyObject *args,
   10.24 +                                    PyObject *kwds)
   10.25 +{
   10.26 +    XcObject *xc = (XcObject *)self;
   10.27 +
   10.28 +    unsigned int mem_kb = 65536;
   10.29 +    char        *name   = "(anon)";
   10.30 +    int          ret;
   10.31 +
   10.32 +    static char *kwd_list[] = { "mem_kb", "name" };
   10.33 +
   10.34 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|is", kwd_list, 
   10.35 +                                      &mem_kb, &name) )
   10.36 +        return NULL;
   10.37 +
   10.38 +    ret = xc_domain_create(xc->xc_handle, mem_kb, name);
   10.39 +    
   10.40 +    return PyInt_FromLong(ret);
   10.41 +}
   10.42 +
   10.43 +static PyObject *pyxc_domain_start(PyObject *self,
   10.44 +                                   PyObject *args,
   10.45 +                                   PyObject *kwds)
   10.46 +{
   10.47 +    XcObject *xc = (XcObject *)self;
   10.48 +
   10.49 +    unsigned int dom;
   10.50 +    int          ret;
   10.51 +
   10.52 +    static char *kwd_list[] = { "dom" };
   10.53 +
   10.54 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )
   10.55 +        return NULL;
   10.56 +
   10.57 +    ret = xc_domain_start(xc->xc_handle, dom);
   10.58 +    
   10.59 +    return PyInt_FromLong(ret);
   10.60 +}
   10.61 +
   10.62 +static PyObject *pyxc_domain_stop(PyObject *self,
   10.63 +                                  PyObject *args,
   10.64 +                                  PyObject *kwds)
   10.65 +{
   10.66 +    XcObject *xc = (XcObject *)self;
   10.67 +
   10.68 +    unsigned int dom;
   10.69 +    int          ret;
   10.70 +
   10.71 +    static char *kwd_list[] = { "dom" };
   10.72 +
   10.73 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )
   10.74 +        return NULL;
   10.75 +
   10.76 +    ret = xc_domain_stop(xc->xc_handle, dom);
   10.77 +    
   10.78 +    return PyInt_FromLong(ret);
   10.79 +}
   10.80 +
   10.81 +static PyObject *pyxc_domain_getinfo(PyObject *self,
   10.82 +                                     PyObject *args,
   10.83 +                                     PyObject *kwds)
   10.84 +{
   10.85 +    XcObject *xc = (XcObject *)self;
   10.86 +    PyObject *list;
   10.87 +
   10.88 +    unsigned int  first_dom = 0, max_doms = 1024;
   10.89 +    int           nr_doms, i;
   10.90 +    xc_dominfo_t *info;
   10.91 +
   10.92 +    static char *kwd_list[] = { "first_dom", "max_doms" };
   10.93 +    
   10.94 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list,
   10.95 +                                      &first_dom, &max_doms) )
   10.96 +        return NULL;
   10.97 +
   10.98 +    info = malloc(max_doms * sizeof(xc_dominfo_t));
   10.99 +    if ( info == NULL )
  10.100 +        nr_doms = 0;
  10.101 +    else
  10.102 +        nr_doms = xc_domain_getinfo(xc->xc_handle, first_dom, max_doms, info);
  10.103 +    
  10.104 +    list = PyList_New(nr_doms);
  10.105 +    for ( i = 0 ; i < nr_doms; i++ )
  10.106 +    {
  10.107 +        PyList_SetItem(
  10.108 +            list, i, 
  10.109 +            Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:L,s:s}",
  10.110 +                          "dom",      info[i].domid,
  10.111 +                          "cpu",      info[i].cpu,
  10.112 +                          "running",  info[i].has_cpu,
  10.113 +                          "stopped",  info[i].stopped,
  10.114 +                          "mem_kb",   info[i].nr_pages*4,
  10.115 +                          "cpu_time", info[i].cpu_time,
  10.116 +                          "name",     info[i].name));
  10.117 +    }
  10.118 +
  10.119 +    if ( info != NULL )
  10.120 +        free(info);
  10.121 +
  10.122 +    return list;
  10.123 +}
  10.124 +
  10.125 +static PyObject *pyxc_linux_save(PyObject *self,
  10.126 +                                 PyObject *args,
  10.127 +                                 PyObject *kwds)
  10.128 +{
  10.129 +    XcObject *xc = (XcObject *)self;
  10.130 +
  10.131 +    unsigned int dom;
  10.132 +    char        *state_file;
  10.133 +    int          progress = 1, ret;
  10.134 +
  10.135 +    static char *kwd_list[] = { "dom", "state_file", "progress" };
  10.136 +
  10.137 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is|i", kwd_list, 
  10.138 +                                      &dom, &state_file, &progress) )
  10.139 +        return NULL;
  10.140 +
  10.141 +    ret = xc_linux_save(xc->xc_handle, dom, state_file, progress);
  10.142 +    
  10.143 +    return PyInt_FromLong(ret);
  10.144 +}
  10.145 +
  10.146 +static PyObject *pyxc_linux_restore(PyObject *self,
  10.147 +                                    PyObject *args,
  10.148 +                                    PyObject *kwds)
  10.149 +{
  10.150 +    XcObject *xc = (XcObject *)self;
  10.151 +
  10.152 +    char        *state_file;
  10.153 +    int          progress = 1, ret;
  10.154 +
  10.155 +    static char *kwd_list[] = { "state_file", "progress" };
  10.156 +
  10.157 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwd_list, 
  10.158 +                                      &state_file, &progress) )
  10.159 +        return NULL;
  10.160 +
  10.161 +    ret = xc_linux_restore(xc->xc_handle, state_file, progress);
  10.162 +    
  10.163 +    return PyInt_FromLong(ret);
  10.164 +}
  10.165 +
  10.166 +static PyObject *pyxc_linux_build(PyObject *self,
  10.167 +                                  PyObject *args,
  10.168 +                                  PyObject *kwds)
  10.169 +{
  10.170 +    XcObject *xc = (XcObject *)self;
  10.171 +
  10.172 +    unsigned int dom;
  10.173 +    char        *image, *ramdisk = NULL, *cmdline = "";
  10.174 +    int          ret;
  10.175 +
  10.176 +    static char *kwd_list[] = { "dom", "image", "ramdisk", "cmdline" };
  10.177 +
  10.178 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is|ss", kwd_list, 
  10.179 +                                      &dom, &image, &ramdisk, &cmdline) )
  10.180 +        return NULL;
  10.181 +
  10.182 +    ret = xc_linux_build(xc->xc_handle, dom, image, ramdisk, cmdline);
  10.183 +    
  10.184 +    return PyInt_FromLong(ret);
  10.185 +}
  10.186 +
  10.187 +static PyObject *pyxc_bvtsched_global_set(PyObject *self,
  10.188 +                                          PyObject *args,
  10.189 +                                          PyObject *kwds)
  10.190 +{
  10.191 +    XcObject *xc = (XcObject *)self;
  10.192 +
  10.193 +    unsigned long ctx_allow;
  10.194 +    int           ret;
  10.195 +
  10.196 +    static char *kwd_list[] = { "ctx_allow" };
  10.197 +
  10.198 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "l", kwd_list, &ctx_allow) )
  10.199 +        return NULL;
  10.200 +
  10.201 +    ret = xc_bvtsched_global_set(xc->xc_handle, ctx_allow);
  10.202 +    
  10.203 +    return PyInt_FromLong(ret);
  10.204 +}
  10.205 +
  10.206 +static PyObject *pyxc_bvtsched_domain_set(PyObject *self,
  10.207 +                                          PyObject *args,
  10.208 +                                          PyObject *kwds)
  10.209 +{
  10.210 +    XcObject *xc = (XcObject *)self;
  10.211 +
  10.212 +    unsigned int  dom;
  10.213 +    unsigned long mcuadv, warp, warpl, warpu;
  10.214 +    int           ret;
  10.215 +
  10.216 +    static char *kwd_list[] = { "dom", "mcuadv", "warp", "warpl", "warpu" };
  10.217 +
  10.218 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illll", kwd_list, 
  10.219 +                                      &dom, &mcuadv, &warp, &warpl, &warpu) )
  10.220 +        return NULL;
  10.221 +
  10.222 +    ret = xc_bvtsched_domain_set(xc->xc_handle, dom, mcuadv, 
  10.223 +                                 warp, warpl, warpu);
  10.224 +    
  10.225 +    return PyInt_FromLong(ret);
  10.226 +}
  10.227 +
  10.228 +static PyObject *pyxc_vif_scheduler_set(PyObject *self,
  10.229 +                                        PyObject *args,
  10.230 +                                        PyObject *kwds)
  10.231 +{
  10.232 +    XcObject *xc = (XcObject *)self;
  10.233 +
  10.234 +    unsigned int  dom, vif;
  10.235 +    xc_vif_sched_params_t sched = { 0, 0 };
  10.236 +    int           ret;
  10.237 +
  10.238 +    static char *kwd_list[] = { "dom", "vif", "credit_bytes", "credit_usecs" };
  10.239 +
  10.240 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii|ll", kwd_list, 
  10.241 +                                      &dom, &vif, 
  10.242 +                                      &sched.credit_bytes, 
  10.243 +                                      &sched.credit_usec) )
  10.244 +        return NULL;
  10.245 +
  10.246 +    ret = xc_vif_scheduler_set(xc->xc_handle, dom, vif, &sched);
  10.247 +    
  10.248 +    return PyInt_FromLong(ret);
  10.249 +}
  10.250 +
  10.251 +static PyObject *pyxc_vif_scheduler_get(PyObject *self,
  10.252 +                                        PyObject *args,
  10.253 +                                        PyObject *kwds)
  10.254 +{
  10.255 +    XcObject *xc = (XcObject *)self;
  10.256 +    PyObject *dict;
  10.257 +
  10.258 +    unsigned int  dom, vif;
  10.259 +    xc_vif_sched_params_t sched;
  10.260 +    int           ret;
  10.261 +
  10.262 +    static char *kwd_list[] = { "dom", "vif" };
  10.263 +
  10.264 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
  10.265 +                                      &dom, &vif) )
  10.266 +        return NULL;
  10.267 +
  10.268 +    ret = xc_vif_scheduler_get(xc->xc_handle, dom, vif, &sched);
  10.269 +
  10.270 +    if ( ret < 0 )
  10.271 +        dict = Py_BuildValue("{}");
  10.272 +    else
  10.273 +        dict = Py_BuildValue("{s:l,s:l}", 
  10.274 +                             "credit_bytes", sched.credit_bytes,
  10.275 +                             "credit_usecs", sched.credit_usec);
  10.276 +    
  10.277 +    return dict;
  10.278 +}
  10.279 +
  10.280 +static PyObject *pyxc_vif_stats_get(PyObject *self,
  10.281 +                                    PyObject *args,
  10.282 +                                    PyObject *kwds)
  10.283 +{
  10.284 +    XcObject *xc = (XcObject *)self;
  10.285 +    PyObject *dict;
  10.286 +
  10.287 +    unsigned int  dom, vif;
  10.288 +    xc_vif_stats_t stats;
  10.289 +    int           ret;
  10.290 +
  10.291 +    static char *kwd_list[] = { "dom", "vif" };
  10.292 +
  10.293 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
  10.294 +                                      &dom, &vif) )
  10.295 +        return NULL;
  10.296 +
  10.297 +    ret = xc_vif_stats_get(xc->xc_handle, dom, vif, &stats);
  10.298 +
  10.299 +    if ( ret < 0 )
  10.300 +        dict = Py_BuildValue("{}");
  10.301 +    else
  10.302 +        dict = Py_BuildValue("{s:L,s:L,s:L,s:L}", 
  10.303 +                             "tx_bytes", stats.tx_bytes,
  10.304 +                             "tx_packets", stats.tx_pkts,
  10.305 +                             "rx_bytes", stats.rx_bytes,
  10.306 +                             "rx_packets", stats.rx_pkts);
  10.307 +    
  10.308 +    return dict;
  10.309 +}
  10.310 +
  10.311 +static PyObject *pyxc_vbd_create(PyObject *self,
  10.312 +                                 PyObject *args,
  10.313 +                                 PyObject *kwds)
  10.314 +{
  10.315 +    XcObject *xc = (XcObject *)self;
  10.316 +
  10.317 +    unsigned int dom, vbd;
  10.318 +    int          writeable, ret;
  10.319 +
  10.320 +    static char *kwd_list[] = { "dom", "vbd", "writeable" };
  10.321 +
  10.322 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list, 
  10.323 +                                      &dom, &vbd, &writeable) )
  10.324 +        return NULL;
  10.325 +
  10.326 +    ret = xc_vbd_create(xc->xc_handle, dom, vbd, writeable);
  10.327 +    
  10.328 +    return PyInt_FromLong(ret);
  10.329 +}
  10.330 +
  10.331 +static PyObject *pyxc_vbd_destroy(PyObject *self,
  10.332 +                                  PyObject *args,
  10.333 +                                  PyObject *kwds)
  10.334 +{
  10.335 +    XcObject *xc = (XcObject *)self;
  10.336 +
  10.337 +    unsigned int dom, vbd;
  10.338 +    int          ret;
  10.339 +
  10.340 +    static char *kwd_list[] = { "dom", "vbd" };
  10.341 +
  10.342 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
  10.343 +                                      &dom, &vbd) )
  10.344 +        return NULL;
  10.345 +
  10.346 +    ret = xc_vbd_destroy(xc->xc_handle, dom, vbd);
  10.347 +    
  10.348 +    return PyInt_FromLong(ret);
  10.349 +}
  10.350 +
  10.351 +static PyObject *pyxc_vbd_add_extent(PyObject *self,
  10.352 +                                     PyObject *args,
  10.353 +                                     PyObject *kwds)
  10.354 +{
  10.355 +    XcObject *xc = (XcObject *)self;
  10.356 +
  10.357 +    unsigned int  dom, vbd, device;
  10.358 +    unsigned long start_sector, nr_sectors;
  10.359 +    int           ret;
  10.360 +
  10.361 +    static char *kwd_list[] = { "dom", "vbd", "device", 
  10.362 +                                "start_sector", "nr_sectors" };
  10.363 +
  10.364 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiill", kwd_list, 
  10.365 +                                      &dom, &vbd, &device, 
  10.366 +                                      &start_sector, &nr_sectors) )
  10.367 +        return NULL;
  10.368 +
  10.369 +    ret = xc_vbd_add_extent(xc->xc_handle, dom, vbd, device, 
  10.370 +                            start_sector, nr_sectors);
  10.371 +    
  10.372 +    return PyInt_FromLong(ret);
  10.373 +}
  10.374 +
  10.375 +static PyObject *pyxc_vbd_delete_extent(PyObject *self,
  10.376 +                                        PyObject *args,
  10.377 +                                        PyObject *kwds)
  10.378 +{
  10.379 +    XcObject *xc = (XcObject *)self;
  10.380 +
  10.381 +    unsigned int  dom, vbd, device;
  10.382 +    unsigned long start_sector, nr_sectors;
  10.383 +    int           ret;
  10.384 +
  10.385 +    static char *kwd_list[] = { "dom", "vbd", "device", 
  10.386 +                                "start_sector", "nr_sectors" };
  10.387 +
  10.388 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiill", kwd_list, 
  10.389 +                                      &dom, &vbd, &device, 
  10.390 +                                      &start_sector, &nr_sectors) )
  10.391 +        return NULL;
  10.392 +
  10.393 +    ret = xc_vbd_delete_extent(xc->xc_handle, dom, vbd, device, 
  10.394 +                               start_sector, nr_sectors);
  10.395 +    
  10.396 +    return PyInt_FromLong(ret);
  10.397 +}
  10.398 +
  10.399 +static PyObject *pyxc_vbd_probe(PyObject *self,
  10.400 +                                PyObject *args,
  10.401 +                                PyObject *kwds)
  10.402 +{
  10.403 +    XcObject *xc = (XcObject *)self;
  10.404 +    PyObject *list;
  10.405 +
  10.406 +    unsigned int dom = XC_VBDDOM_PROBE_ALL, max_vbds = 1024;
  10.407 +    xc_vbd_t    *info;
  10.408 +    int          nr_vbds, i;
  10.409 +
  10.410 +    static char *kwd_list[] = { "dom", "max_vbds" };
  10.411 +
  10.412 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list, 
  10.413 +                                      &dom, &max_vbds) )
  10.414 +        return NULL;
  10.415 +
  10.416 +    info = malloc(max_vbds * sizeof(xc_vbd_t));
  10.417 +    if ( info == NULL )
  10.418 +        nr_vbds = 0;
  10.419 +    else
  10.420 +        nr_vbds = xc_vbd_probe(xc->xc_handle, dom, max_vbds, info);
  10.421 +
  10.422 +    list = PyList_New(nr_vbds);
  10.423 +    for ( i = 0; i < nr_vbds; i++ )
  10.424 +    {
  10.425 +        PyList_SetItem(
  10.426 +            list, i, 
  10.427 +            Py_BuildValue("{s:i,s:i,s:i,s:l}",
  10.428 +                          "dom",        info[i].domid,
  10.429 +                          "vbd",        info[i].vbdid,
  10.430 +                          "writeable",  !!(info[i].flags & XC_VBDF_WRITEABLE),
  10.431 +                          "nr_sectors", info[i].nr_sectors));
  10.432 +    }
  10.433 +
  10.434 +    if ( info != NULL )
  10.435 +        free(info);
  10.436 +
  10.437 +    return list;
  10.438 +}
  10.439 +
  10.440 +static PyObject *pyxc_readconsolering(PyObject *self,
  10.441 +                                      PyObject *args,
  10.442 +                                      PyObject *kwds)
  10.443 +{
  10.444 +    XcObject *xc = (XcObject *)self;
  10.445 +    PyObject *pystr = Py_None;
  10.446 +
  10.447 +    unsigned int clear = 0;
  10.448 +    char         str[32768];
  10.449 +    int          ret;
  10.450 +
  10.451 +    static char *kwd_list[] = { "clear" };
  10.452 +
  10.453 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &clear) )
  10.454 +        return NULL;
  10.455 +
  10.456 +    ret = xc_readconsolering(xc->xc_handle, str, sizeof(str), clear);
  10.457 +
  10.458 +    if ( ret > 0 )
  10.459 +        pystr = PyString_FromString(str);
  10.460 +    
  10.461 +    return pystr;
  10.462 +}
  10.463 +
  10.464 +static PyMethodDef pyxc_methods[] = {
  10.465 +    { "domain_create", 
  10.466 +      (PyCFunction)pyxc_domain_create, 
  10.467 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.468 +      "Create a new domain.\n"
  10.469 +      " mem_kb [int, 65536]:    Memory allocation, in kilobytes.\n"
  10.470 +      " name   [str, '(anon)']: Informative textual name.\n\n"
  10.471 +      "Returns: [int] new domain identifier; -1 on error.\n" },
  10.472 +
  10.473 +    { "domain_start", 
  10.474 +      (PyCFunction)pyxc_domain_start, 
  10.475 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.476 +      "Start execution of a domain.\n"
  10.477 +      " dom [int]: Identifier of domain to be started.\n\n"
  10.478 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.479 +
  10.480 +    { "domain_stop", 
  10.481 +      (PyCFunction)pyxc_domain_stop, 
  10.482 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.483 +      "Stop execution of a domain.\n"
  10.484 +      " dom [int]: Identifier of domain to be stopped.\n\n"
  10.485 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.486 +
  10.487 +    { "domain_getinfo", 
  10.488 +      (PyCFunction)pyxc_domain_getinfo, 
  10.489 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.490 +      "Get information regarding a set of domains, in increasing id order.\n"
  10.491 +      " first_dom [int, 0]:    First domain to retrieve info about.\n"
  10.492 +      " max_doms  [int, 1024]: Maximum number of domains to retrieve info"
  10.493 +      " about.\n\n"
  10.494 +      "Returns: [list of dicts] if list length is less than 'max_doms'\n"
  10.495 +      "         parameter then there was an error, or the end of the\n"
  10.496 +      "         domain-id space was reached.\n"
  10.497 +      " dom      [int]:  Identifier of domain to which this info pertains\n"
  10.498 +      " cpu      [int]:  CPU to which this domain is bound\n"
  10.499 +      " running  [int]:  Bool - is the domain currently running?\n"
  10.500 +      " stopped  [int]:  Bool - is the domain suspended?\n"
  10.501 +      " mem_kb   [int]:  Memory reservation, in kilobytes\n"
  10.502 +      " cpu_time [long]: CPU time consumed, in nanoseconds\n"
  10.503 +      " name     [str]:  Identifying name\n" },
  10.504 +
  10.505 +    { "linux_save", 
  10.506 +      (PyCFunction)pyxc_linux_save, 
  10.507 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.508 +      "Save the CPU and memory state of a Linux guest OS.\n"
  10.509 +      " dom        [int]:    Identifier of domain to be saved.\n"
  10.510 +      " state_file [str]:    Name of state file. Must not currently exist.\n"
  10.511 +      " progress   [int, 1]: Bool - display a running progress indication?\n\n"
  10.512 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.513 +
  10.514 +    { "linux_restore", 
  10.515 +      (PyCFunction)pyxc_linux_restore, 
  10.516 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.517 +      "Restore the CPU and memory state of a Linux guest OS.\n"
  10.518 +      " state_file [str]:    Name of state file. Must not currently exist.\n"
  10.519 +      " progress   [int, 1]: Bool - display a running progress indication?\n\n"
  10.520 +      "Returns: [int] new domain identifier on success; -1 on error.\n" },
  10.521 +
  10.522 +    { "linux_build", 
  10.523 +      (PyCFunction)pyxc_linux_build, 
  10.524 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.525 +      "Build a new Linux guest OS.\n"
  10.526 +      " dom     [int]:      Identifier of domain to build into.\n"
  10.527 +      " image   [str]:      Name of kernel image file. May be gzipped.\n"
  10.528 +      " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
  10.529 +      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
  10.530 +      "Returns: [int] new domain identifier on success; -1 on error.\n" },
  10.531 +
  10.532 +    { "bvtsched_global_set", 
  10.533 +      (PyCFunction)pyxc_bvtsched_global_set, 
  10.534 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.535 +      "Set global tuning parameters for Borrowed Virtual Time scheduler.\n"
  10.536 +      " ctx_allow [int]: Minimal guaranteed quantum (I think!).\n\n"
  10.537 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.538 +
  10.539 +    { "bvtsched_domain_set", 
  10.540 +      (PyCFunction)pyxc_bvtsched_domain_set, 
  10.541 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.542 +      "Set per-domain tuning parameters for Borrowed Virtual Time scheduler.\n"
  10.543 +      " dom    [int]: Identifier of domain to be tuned.\n"
  10.544 +      " mcuadv [int]: Internal BVT parameter.\n"
  10.545 +      " warp   [int]: Internal BVT parameter.\n"
  10.546 +      " warpl  [int]: Internal BVT parameter.\n"
  10.547 +      " warpu  [int]: Internal BVT parameter.\n\n"
  10.548 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.549 +
  10.550 +    { "vif_scheduler_set", 
  10.551 +      (PyCFunction)pyxc_vif_scheduler_set, 
  10.552 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.553 +      "Set per-network-interface scheduling parameters.\n"
  10.554 +      " dom          [int]:    Identifier of domain to be adjusted.\n"
  10.555 +      " vif          [int]:    Identifier of VIF to be adjusted.\n"
  10.556 +      " credit_bytes [int, 0]: Tx bytes permitted each interval.\n"
  10.557 +      " credit_usecs [int, 0]: Interval, in usecs. 0 == no scheduling.\n\n"
  10.558 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.559 +
  10.560 +    { "vif_scheduler_get", 
  10.561 +      (PyCFunction)pyxc_vif_scheduler_get, 
  10.562 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.563 +      "Query the per-network-interface scheduling parameters.\n"
  10.564 +      " dom          [int]:    Identifier of domain to be queried.\n"
  10.565 +      " vif          [int]:    Identifier of VIF to be queried.\n\n"
  10.566 +      "Returns: [dict] dictionary is empty on failure.\n"
  10.567 +      " credit_bytes [int]: Tx bytes permitted each interval.\n"
  10.568 +      " credit_usecs [int]: Interval, in usecs. 0 == no scheduling.\n" },
  10.569 +
  10.570 +    { "vif_stats_get", 
  10.571 +      (PyCFunction)pyxc_vif_stats_get, 
  10.572 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.573 +      "Query the per-network-interface statistics.\n"
  10.574 +      " dom          [int]: Identifier of domain to be queried.\n"
  10.575 +      " vif          [int]: Identifier of VIF to be queried.\n\n"
  10.576 +      "Returns: [dict] dictionary is empty on failure.\n"
  10.577 +      " tx_bytes   [long]: Bytes transmitted.\n"
  10.578 +      " tx_packets [long]: Packets transmitted.\n"
  10.579 +      " rx_bytes   [long]: Bytes received.\n"
  10.580 +      " rx_packets [long]: Packets received.\n" },
  10.581 +
  10.582 +    { "vbd_create", 
  10.583 +      (PyCFunction)pyxc_vbd_create, 
  10.584 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.585 +      "Create a new virtual block device associated with a given domain.\n"
  10.586 +      " dom       [int]: Identifier of domain to get a new VBD.\n"
  10.587 +      " vbd       [int]: Identifier for new VBD.\n"
  10.588 +      " writeable [int]: Bool - is the new VBD writeable?\n\n"
  10.589 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.590 +
  10.591 +    { "vbd_destroy", 
  10.592 +      (PyCFunction)pyxc_vbd_destroy, 
  10.593 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.594 +      "Destroy a virtual block device.\n"
  10.595 +      " dom       [int]: Identifier of domain containing the VBD.\n"
  10.596 +      " vbd       [int]: Identifier of the VBD.\n\n"
  10.597 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.598 +
  10.599 +    { "vbd_add_extent", 
  10.600 +      (PyCFunction)pyxc_vbd_add_extent, 
  10.601 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.602 +      "Add an extent to a virtual block device.\n"
  10.603 +      " dom          [int]: Identifier of domain containing the VBD.\n"
  10.604 +      " vbd          [int]: Identifier of the VBD.\n"
  10.605 +      " device       [int]: Identifier of the real underlying block device.\n"
  10.606 +      " start_sector [int]: Real start sector of this extent.\n"
  10.607 +      " nr_sectors   [int]: Length, in sectors, of this extent.\n\n"
  10.608 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.609 +
  10.610 +    { "vbd_delete_extent", 
  10.611 +      (PyCFunction)pyxc_vbd_delete_extent, 
  10.612 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.613 +      "Delete an extent from a virtual block device.\n"
  10.614 +      " dom          [int]: Identifier of domain containing the VBD.\n"
  10.615 +      " vbd          [int]: Identifier of the VBD.\n"
  10.616 +      " device       [int]: Identifier of the real underlying block device.\n"
  10.617 +      " start_sector [int]: Real start sector of the extent.\n"
  10.618 +      " nr_sectors   [int]: Length, in sectors, of the extent.\n\n"
  10.619 +      "Returns: [int] 0 on success; -1 on error.\n" },
  10.620 +
  10.621 +    { "vbd_probe", 
  10.622 +      (PyCFunction)pyxc_vbd_probe, 
  10.623 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.624 +      "Get information regarding extant virtual block devices.\n"
  10.625 +      " dom          [int, ALL]:  Domain to query (default is to query all).\n"
  10.626 +      " max_vbds     [int, 1024]: Maximum VBDs to query.\n\n"
  10.627 +      "Returns: [list of dicts] if list length is less than 'max_vbds'\n"
  10.628 +      "         parameter then there was an error, or there were fewer vbds.\n"
  10.629 +      " dom        [int]: Domain containing this VBD.\n"
  10.630 +      " vbd        [int]: Domain-specific identifier of this VBD.\n"
  10.631 +      " writeable  [int]: Bool - is this VBD writeable?\n"
  10.632 +      " nr_sectors [int]: Size of this VBD, in 512-byte sectors.\n" },
  10.633 +
  10.634 +    { "readconsolering", 
  10.635 +      (PyCFunction)pyxc_readconsolering, 
  10.636 +      METH_VARARGS | METH_KEYWORDS, "\n"
  10.637 +      "Read Xen's console ring.\n"
  10.638 +      " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
  10.639 +      "Returns: [str] string is empty on failure.\n" },
  10.640 +
  10.641 +    { NULL, NULL, 0, NULL }
  10.642 +};
  10.643 +
  10.644 +
  10.645 +/*
  10.646 + * Definitions for the 'Xc' module wrapper.
  10.647 + */
  10.648 +
  10.649 +staticforward PyTypeObject PyXcType;
  10.650 +
  10.651 +static PyObject *PyXc_new(PyObject *self, PyObject *args)
  10.652 +{
  10.653 +    XcObject *xc;
  10.654 +
  10.655 +    if ( !PyArg_ParseTuple(args, ":new") )
  10.656 +        return NULL;
  10.657 +
  10.658 +    xc = PyObject_New(XcObject, &PyXcType);
  10.659 +
  10.660 +    if ( (xc->xc_handle = xc_interface_open()) == -1 )
  10.661 +    {
  10.662 +        PyObject_Del((PyObject *)xc);
  10.663 +        return NULL;
  10.664 +    }
  10.665 +
  10.666 +    return (PyObject *)xc;
  10.667 +}
  10.668 +
  10.669 +static PyObject *PyXc_getattr(PyObject *obj, char *name)
  10.670 +{
  10.671 +    return Py_FindMethod(pyxc_methods, obj, name);
  10.672 +}
  10.673 +
  10.674 +static void PyXc_dealloc(PyObject *self)
  10.675 +{
  10.676 +    XcObject *xc = (XcObject *)self;
  10.677 +    (void)xc_interface_close(xc->xc_handle);
  10.678 +    PyObject_Del(self);
  10.679 +}
  10.680 +
  10.681 +static PyTypeObject PyXcType = {
  10.682 +    PyObject_HEAD_INIT(&PyType_Type)
  10.683 +    0,
  10.684 +    "Xc",
  10.685 +    sizeof(XcObject),
  10.686 +    0,
  10.687 +    PyXc_dealloc,    /* tp_dealloc     */
  10.688 +    NULL,            /* tp_print       */
  10.689 +    PyXc_getattr,    /* tp_getattr     */
  10.690 +    NULL,            /* tp_setattr     */
  10.691 +    NULL,            /* tp_compare     */
  10.692 +    NULL,            /* tp_repr        */
  10.693 +    NULL,            /* tp_as_number   */
  10.694 +    NULL,            /* tp_as_sequence */
  10.695 +    NULL,            /* tp_as_mapping  */
  10.696 +    NULL             /* tp_hash        */
  10.697 +};
  10.698 +
  10.699 +static PyMethodDef PyXc_methods[] = {
  10.700 +    { "new", PyXc_new, METH_VARARGS, "Craate a new Xc object." },
  10.701 +    { NULL, NULL, 0, NULL }
  10.702 +};
  10.703 +
  10.704 +DL_EXPORT(void) initXc(void)
  10.705 +{
  10.706 +    Py_InitModule("Xc", PyXc_methods);
  10.707 +}