ia64/xen-unstable

changeset 1094:8a531b79be75

bitkeeper revision 1.726.1.1 (4030a057RR6WnkCC27Nn6Qs9vtjvJg)

Xc.c:
Robust arg handling, and debug tracing, in Xc.
author kaf24@scramble.cl.cam.ac.uk
date Mon Feb 16 10:49:59 2004 +0000 (2004-02-16)
parents 53b906cc1cba
children b3ff2e06510e
files tools/xc/py/Xc.c
line diff
     1.1 --- a/tools/xc/py/Xc.c	Fri Feb 13 20:50:45 2004 +0000
     1.2 +++ b/tools/xc/py/Xc.c	Mon Feb 16 10:49:59 2004 +0000
     1.3 @@ -7,6 +7,14 @@
     1.4  #include <Python.h>
     1.5  #include <xc.h>
     1.6  
     1.7 +#if 1
     1.8 +#define DPRINTF(_f, _a...)                  \
     1.9 +    fprintf(stderr, "%s:%s:%d:: " _f "\n" , \
    1.10 +            __FILE__ , __FUNCTION__ , __LINE__ , ## _a)
    1.11 +#else
    1.12 +#define DPRINTF(_f, _a...) ((void)0)
    1.13 +#endif
    1.14 +
    1.15  typedef struct {
    1.16      PyObject_HEAD;
    1.17      int xc_handle;
    1.18 @@ -31,7 +39,10 @@ static PyObject *pyxc_domain_create(PyOb
    1.19  
    1.20      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|is", kwd_list, 
    1.21                                        &mem_kb, &name) )
    1.22 +    {
    1.23 +        DPRINTF("could not parse parameter list.");
    1.24          return NULL;
    1.25 +    }
    1.26  
    1.27      if ( (ret = xc_domain_create(xc->xc_handle, mem_kb, name, &dom)) < 0 )
    1.28          return PyLong_FromLong(ret);
    1.29 @@ -51,7 +62,10 @@ static PyObject *pyxc_domain_start(PyObj
    1.30      static char *kwd_list[] = { "dom", NULL };
    1.31  
    1.32      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "L", kwd_list, &dom) )
    1.33 +    {
    1.34 +        DPRINTF("could not parse parameter list.");
    1.35          return NULL;
    1.36 +    }
    1.37  
    1.38      ret = xc_domain_start(xc->xc_handle, dom);
    1.39      
    1.40 @@ -70,7 +84,10 @@ static PyObject *pyxc_domain_stop(PyObje
    1.41      static char *kwd_list[] = { "dom", NULL };
    1.42  
    1.43      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "L", kwd_list, &dom) )
    1.44 +    {
    1.45 +        DPRINTF("could not parse parameter list.");
    1.46          return NULL;
    1.47 +    }
    1.48  
    1.49      ret = xc_domain_stop(xc->xc_handle, dom);
    1.50      
    1.51 @@ -90,7 +107,10 @@ static PyObject *pyxc_domain_destroy(PyO
    1.52  
    1.53      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "L|i", kwd_list, 
    1.54                                        &dom, &force) )
    1.55 +    {
    1.56 +        DPRINTF("could not parse parameter list.");
    1.57          return NULL;
    1.58 +    }
    1.59  
    1.60      ret = xc_domain_destroy(xc->xc_handle, dom, force);
    1.61      
    1.62 @@ -110,7 +130,10 @@ static PyObject *pyxc_domain_pincpu(PyOb
    1.63  
    1.64      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "L|i", kwd_list, 
    1.65                                        &dom, &cpu) )
    1.66 +    {
    1.67 +        DPRINTF("could not parse parameter list.");
    1.68          return NULL;
    1.69 +    }
    1.70  
    1.71      ret = xc_domain_pincpu(xc->xc_handle, dom, cpu);
    1.72      
    1.73 @@ -132,13 +155,20 @@ static PyObject *pyxc_domain_getinfo(PyO
    1.74      
    1.75      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|Li", kwd_list,
    1.76                                        &first_dom, &max_doms) )
    1.77 +    {
    1.78 +        DPRINTF("could not parse parameter list.");
    1.79          return NULL;
    1.80 +    }
    1.81  
    1.82 -    info = malloc(max_doms * sizeof(xc_dominfo_t));
    1.83 -    if ( info == NULL )
    1.84 +    if ( (info = malloc(max_doms * sizeof(xc_dominfo_t))) == NULL )
    1.85 +    {
    1.86 +        DPRINTF("out of memory.");
    1.87          nr_doms = 0;
    1.88 +    }
    1.89      else
    1.90 +    {
    1.91          nr_doms = xc_domain_getinfo(xc->xc_handle, first_dom, max_doms, info);
    1.92 +    }
    1.93      
    1.94      list = PyList_New(nr_doms);
    1.95      for ( i = 0 ; i < nr_doms; i++ )
    1.96 @@ -175,7 +205,10 @@ static PyObject *pyxc_linux_save(PyObjec
    1.97  
    1.98      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Ls|i", kwd_list, 
    1.99                                        &dom, &state_file, &progress) )
   1.100 +    {
   1.101 +        DPRINTF("could not parse parameter list.");
   1.102          return NULL;
   1.103 +    }
   1.104  
   1.105      ret = xc_linux_save(xc->xc_handle, dom, state_file, progress);
   1.106      
   1.107 @@ -196,7 +229,10 @@ static PyObject *pyxc_linux_restore(PyOb
   1.108  
   1.109      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwd_list, 
   1.110                                        &state_file, &progress) )
   1.111 +    {
   1.112 +        DPRINTF("could not parse parameter list.");
   1.113          return NULL;
   1.114 +    }
   1.115  
   1.116      ret = xc_linux_restore(xc->xc_handle, state_file, progress, &dom);
   1.117      if ( ret < 0 )
   1.118 @@ -219,7 +255,10 @@ static PyObject *pyxc_linux_build(PyObje
   1.119  
   1.120      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Ls|ss", kwd_list, 
   1.121                                        &dom, &image, &ramdisk, &cmdline) )
   1.122 +    {
   1.123 +        DPRINTF("could not parse parameter list.");
   1.124          return NULL;
   1.125 +    }
   1.126  
   1.127      ret = xc_linux_build(xc->xc_handle, dom, image, ramdisk, cmdline);
   1.128      
   1.129 @@ -240,7 +279,10 @@ static PyObject *pyxc_netbsd_build(PyObj
   1.130  
   1.131      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Ls|ss", kwd_list, 
   1.132                                        &dom, &image, &ramdisk, &cmdline) )
   1.133 +    {
   1.134 +        DPRINTF("could not parse parameter list.");
   1.135          return NULL;
   1.136 +    }
   1.137  
   1.138      ret = xc_netbsd_build(xc->xc_handle, dom, image, cmdline);
   1.139      
   1.140 @@ -259,7 +301,10 @@ static PyObject *pyxc_bvtsched_global_se
   1.141      static char *kwd_list[] = { "ctx_allow", NULL };
   1.142  
   1.143      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "l", kwd_list, &ctx_allow) )
   1.144 +    {
   1.145 +        DPRINTF("could not parse parameter list.");
   1.146          return NULL;
   1.147 +    }
   1.148  
   1.149      ret = xc_bvtsched_global_set(xc->xc_handle, ctx_allow);
   1.150      
   1.151 @@ -281,7 +326,10 @@ static PyObject *pyxc_bvtsched_domain_se
   1.152  
   1.153      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Lllll", kwd_list, 
   1.154                                        &dom, &mcuadv, &warp, &warpl, &warpu) )
   1.155 +    {
   1.156 +        DPRINTF("could not parse parameter list.");
   1.157          return NULL;
   1.158 +    }
   1.159  
   1.160      ret = xc_bvtsched_domain_set(xc->xc_handle, dom, mcuadv, 
   1.161                                   warp, warpl, warpu);
   1.162 @@ -307,7 +355,10 @@ static PyObject *pyxc_vif_scheduler_set(
   1.163                                        &dom, &vif, 
   1.164                                        &sched.credit_bytes, 
   1.165                                        &sched.credit_usec) )
   1.166 +    {
   1.167 +        DPRINTF("could not parse parameter list.");
   1.168          return NULL;
   1.169 +    }
   1.170  
   1.171      ret = xc_vif_scheduler_set(xc->xc_handle, dom, vif, &sched);
   1.172      
   1.173 @@ -330,7 +381,10 @@ static PyObject *pyxc_vif_scheduler_get(
   1.174  
   1.175      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Li", kwd_list, 
   1.176                                        &dom, &vif) )
   1.177 +    {
   1.178 +        DPRINTF("could not parse parameter list.");
   1.179          return NULL;
   1.180 +    }
   1.181  
   1.182      ret = xc_vif_scheduler_get(xc->xc_handle, dom, vif, &sched);
   1.183  
   1.184 @@ -360,7 +414,10 @@ static PyObject *pyxc_vif_stats_get(PyOb
   1.185  
   1.186      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Li", kwd_list, 
   1.187                                        &dom, &vif) )
   1.188 +    {
   1.189 +        DPRINTF("could not parse parameter list.");
   1.190          return NULL;
   1.191 +    }
   1.192  
   1.193      ret = xc_vif_stats_get(xc->xc_handle, dom, vif, &stats);
   1.194  
   1.195 @@ -390,7 +447,10 @@ static PyObject *pyxc_vbd_create(PyObjec
   1.196  
   1.197      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Lii", kwd_list, 
   1.198                                        &dom, &vbd, &writeable) )
   1.199 +    {
   1.200 +        DPRINTF("could not parse parameter list.");
   1.201          return NULL;
   1.202 +    }
   1.203  
   1.204      ret = xc_vbd_create(xc->xc_handle, dom, vbd, writeable);
   1.205      
   1.206 @@ -411,7 +471,10 @@ static PyObject *pyxc_vbd_destroy(PyObje
   1.207  
   1.208      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Li", kwd_list, 
   1.209                                        &dom, &vbd) )
   1.210 +    {
   1.211 +        DPRINTF("could not parse parameter list.");
   1.212          return NULL;
   1.213 +    }
   1.214  
   1.215      ret = xc_vbd_destroy(xc->xc_handle, dom, vbd);
   1.216      
   1.217 @@ -437,7 +500,10 @@ static PyObject *pyxc_vbd_grow(PyObject 
   1.218                                        &extent.real_device, 
   1.219                                        &extent.start_sector, 
   1.220                                        &extent.nr_sectors) )
   1.221 +    {
   1.222 +        DPRINTF("could not parse parameter list.");
   1.223          return NULL;
   1.224 +    }
   1.225  
   1.226      ret = xc_vbd_grow(xc->xc_handle, dom, vbd, &extent);
   1.227      
   1.228 @@ -458,7 +524,10 @@ static PyObject *pyxc_vbd_shrink(PyObjec
   1.229  
   1.230      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Li", kwd_list, 
   1.231                                        &dom, &vbd) )
   1.232 +    {
   1.233 +        DPRINTF("could not parse parameter list.");
   1.234          return NULL;
   1.235 +    }
   1.236  
   1.237      ret = xc_vbd_shrink(xc->xc_handle, dom, vbd);
   1.238      
   1.239 @@ -481,34 +550,95 @@ static PyObject *pyxc_vbd_setextents(PyO
   1.240  
   1.241      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "LiO", kwd_list, 
   1.242                                        &dom, &vbd, &list) )
   1.243 +    {
   1.244 +        DPRINTF("could not parse parameter list.");
   1.245          goto fail;
   1.246 +    }
   1.247  
   1.248      if ( (nr_extents = PyList_Size(list)) < 0 )
   1.249 +    {
   1.250 +        DPRINTF("parameter 'extents' is not a list.");
   1.251          goto fail;
   1.252 +    }
   1.253  
   1.254      if ( nr_extents != 0 )
   1.255      {
   1.256          extents = malloc(nr_extents * sizeof(xc_vbdextent_t));
   1.257          if ( extents == NULL )
   1.258 +        {
   1.259 +            DPRINTF("out of memory.");
   1.260              goto fail;
   1.261 +        }
   1.262  
   1.263          for ( i = 0; i < nr_extents; i++ )
   1.264          {
   1.265              dict = PyList_GetItem(list, i);
   1.266              if ( !PyDict_Check(dict) )
   1.267 +            {
   1.268 +                DPRINTF("extent %d -- extent is not a dictionary.", i);
   1.269                  goto fail;
   1.270 -            if ( ((obj = PyDict_GetItemString(dict, "device")) == NULL) ||
   1.271 -                 !PyInt_Check(obj) )
   1.272 +            }
   1.273 +
   1.274 +            if ( (obj = PyDict_GetItemString(dict, "device")) == NULL )
   1.275 +            {
   1.276 +                DPRINTF("extent %d -- 'device' is not in the dictionary.", i);
   1.277 +                goto fail;
   1.278 +            }
   1.279 +            if ( PyInt_Check(obj) )
   1.280 +            {
   1.281 +                extents[i].real_device = (unsigned short)PyInt_AsLong(obj);
   1.282 +            }
   1.283 +            else if ( PyLong_Check(obj) )
   1.284 +            {
   1.285 +                extents[i].real_device = (unsigned short)PyLong_AsLong(obj);
   1.286 +            }
   1.287 +            else
   1.288 +            {
   1.289 +                DPRINTF("extent %d -- 'device' is not an int or long.", i);
   1.290 +                goto fail;
   1.291 +            }
   1.292 +
   1.293 +            if ( (obj = PyDict_GetItemString(dict, "start_sector")) == NULL )
   1.294 +            {
   1.295 +                DPRINTF("extent %d -- 'start_sector' is not "
   1.296 +                        "in the dictionary.", i);
   1.297                  goto fail;
   1.298 -            extents[i].real_device = (unsigned short)PyInt_AsLong(obj);
   1.299 -            if ( ((obj = PyDict_GetItemString(dict,"start_sector")) == NULL) ||
   1.300 -                 !PyLong_Check(obj) )
   1.301 +            }
   1.302 +            if ( PyInt_Check(obj) )
   1.303 +            {
   1.304 +                extents[i].start_sector = PyInt_AsLong(obj);
   1.305 +            }
   1.306 +            else if ( PyLong_Check(obj) )
   1.307 +            {
   1.308 +                extents[i].start_sector = PyLong_AsUnsignedLongLong(obj);
   1.309 +            }
   1.310 +            else
   1.311 +            {
   1.312 +                DPRINTF("extent %d -- 'start_sector' is not "
   1.313 +                        "an int or long.", i);
   1.314                  goto fail;
   1.315 -            extents[i].start_sector = PyLong_AsUnsignedLongLong(obj);
   1.316 -            if ( ((obj = PyDict_GetItemString(dict, "nr_sectors")) == NULL) ||
   1.317 -                 !PyLong_Check(obj) )
   1.318 +            }
   1.319 +
   1.320 +            if ( (obj = PyDict_GetItemString(dict, "nr_sectors")) == NULL )
   1.321 +            {
   1.322 +                DPRINTF("extent %d -- 'nr_sectors' is not "
   1.323 +                        "in the dictionary.", i);
   1.324                  goto fail;
   1.325 -            extents[i].nr_sectors = PyLong_AsUnsignedLongLong(obj);        
   1.326 +            }
   1.327 +            if ( PyInt_Check(obj) )
   1.328 +            {
   1.329 +                extents[i].nr_sectors = PyInt_AsLong(obj);
   1.330 +            }
   1.331 +            else if ( PyLong_Check(obj) )
   1.332 +            {
   1.333 +                extents[i].nr_sectors = PyLong_AsUnsignedLongLong(obj);
   1.334 +            }
   1.335 +            else
   1.336 +            {
   1.337 +                DPRINTF("extent %d -- 'nr_sectors' is not "
   1.338 +                        "an int or long.", i);
   1.339 +                goto fail;
   1.340 +            }
   1.341          }
   1.342      }
   1.343  
   1.344 @@ -542,13 +672,21 @@ static PyObject *pyxc_vbd_getextents(PyO
   1.345  
   1.346      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Li", kwd_list, 
   1.347                                        &dom, &vbd) )
   1.348 +    {
   1.349 +        DPRINTF("could not parse parameter list.");
   1.350          return NULL;
   1.351 +    }
   1.352  
   1.353      extents = malloc(MAX_EXTENTS * sizeof(xc_vbdextent_t));
   1.354      if ( extents == NULL )
   1.355 +    {
   1.356 +        DPRINTF("out of memory.");
   1.357          max_extents = 0;
   1.358 +    }
   1.359      else
   1.360 +    {
   1.361          max_extents = MAX_EXTENTS;
   1.362 +    }
   1.363  
   1.364      nr_extents = xc_vbd_getextents(xc->xc_handle, dom, vbd, max_extents,
   1.365                                     extents, NULL);
   1.366 @@ -593,13 +731,21 @@ static PyObject *pyxc_vbd_probe(PyObject
   1.367  
   1.368      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|Li", kwd_list, 
   1.369                                        &dom, &max_vbds) )
   1.370 +    {
   1.371 +        DPRINTF("could not parse parameter list.");
   1.372          return NULL;
   1.373 +    }
   1.374  
   1.375      info = malloc(max_vbds * sizeof(xc_vbd_t));
   1.376      if ( info == NULL )
   1.377 +    {
   1.378 +        DPRINTF("out of memory.");
   1.379          nr_vbds = 0;
   1.380 +    }
   1.381      else
   1.382 +    {
   1.383          nr_vbds = xc_vbd_probe(xc->xc_handle, dom, max_vbds, info);
   1.384 +    }
   1.385  
   1.386      list = PyList_New(nr_vbds);
   1.387      for ( i = 0; i < nr_vbds; i++ )
   1.388 @@ -632,7 +778,10 @@ static PyObject *pyxc_readconsolering(Py
   1.389      static char *kwd_list[] = { "clear", NULL };
   1.390  
   1.391      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &clear) )
   1.392 +    {
   1.393 +        DPRINTF("could not parse parameter list.");
   1.394          return NULL;
   1.395 +    }
   1.396  
   1.397      ret = xc_readconsolering(xc->xc_handle, str, sizeof(str), clear);
   1.398