debuggers.hg

changeset 22776:aa3d665e3bb7

tools/python/pyxl: Export PCI passthrough related libxl functions

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Gianni Tedesco <gianni.tedesco@citrix.com>
date Tue Jan 11 18:57:37 2011 +0000 (2011-01-11)
parents 659ffaf66e88
children ea6f92a479da
files tools/python/xen/lowlevel/xl/xl.c
line diff
     1.1 --- a/tools/python/xen/lowlevel/xl/xl.c	Tue Jan 11 18:57:16 2011 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xl/xl.c	Tue Jan 11 18:57:37 2011 +0000
     1.3 @@ -537,6 +537,75 @@ static PyObject *pyxl_pci_parse(XlObject
     1.4      return (PyObject *)pci;
     1.5  }
     1.6  
     1.7 +static PyObject *pyxl_pci_list_assignable(XlObject *self, PyObject *args)
     1.8 +{
     1.9 +    libxl_device_pci *dev;
    1.10 +    PyObject *list;
    1.11 +    int nr_dev, i;
    1.12 +
    1.13 +    if ( libxl_device_pci_list_assignable(&self->ctx, &dev, &nr_dev) ) {
    1.14 +        PyErr_SetString(xl_error_obj, "Cannot list assignable devices");
    1.15 +        return NULL;
    1.16 +    }
    1.17 +
    1.18 +    list = PyList_New(nr_dev);
    1.19 +    if ( NULL == list )
    1.20 +        return NULL;
    1.21 +
    1.22 +    for(i = 0; i < nr_dev; i++) {
    1.23 +        Py_device_pci *pd;
    1.24 +        pd = Pydevice_pci_New();
    1.25 +        if ( NULL == pd )
    1.26 +            goto err_mem;
    1.27 +        memcpy(&pd->obj, &dev[i], sizeof(pd->obj));
    1.28 +        /* SetItem steals a reference */
    1.29 +        PyList_SetItem(list, i, (PyObject *)pd);
    1.30 +    }
    1.31 +
    1.32 +    free(dev);
    1.33 +    return list;
    1.34 +err_mem:
    1.35 +    Py_DECREF(list);
    1.36 +    PyErr_SetString(PyExc_MemoryError, "Allocating PCI device list");
    1.37 +    return NULL;
    1.38 +}
    1.39 +
    1.40 +static PyObject *pyxl_pci_list(XlObject *self, PyObject *args)
    1.41 +{
    1.42 +    libxl_device_pci *dev;
    1.43 +    PyObject *list;
    1.44 +    int nr_dev, i, domid;
    1.45 +
    1.46 +    if ( !PyArg_ParseTuple(args, "i", &domid) )
    1.47 +        return NULL;
    1.48 +
    1.49 +    if ( libxl_device_pci_list_assigned(&self->ctx, &dev, domid, &nr_dev) ) {
    1.50 +        PyErr_SetString(xl_error_obj, "Cannot list assignable devices");
    1.51 +        return NULL;
    1.52 +    }
    1.53 +
    1.54 +    list = PyList_New(nr_dev);
    1.55 +    if ( NULL == list )
    1.56 +        return NULL;
    1.57 +
    1.58 +    for(i = 0; i < nr_dev; i++) {
    1.59 +        Py_device_pci *pd;
    1.60 +        pd = Pydevice_pci_New();
    1.61 +        if ( NULL == pd )
    1.62 +            goto err_mem;
    1.63 +        memcpy(&pd->obj, &dev[i], sizeof(pd->obj));
    1.64 +        /* SetItem steals a reference */
    1.65 +        PyList_SetItem(list, i, (PyObject *)pd);
    1.66 +    }
    1.67 +
    1.68 +    free(dev);
    1.69 +    return list;
    1.70 +err_mem:
    1.71 +    Py_DECREF(list);
    1.72 +    PyErr_SetString(PyExc_MemoryError, "Allocating PCI device list");
    1.73 +    return NULL;
    1.74 +}
    1.75 +
    1.76  static PyMethodDef pyxl_methods[] = {
    1.77      {"list_domains", (PyCFunction)pyxl_list_domains, METH_NOARGS,
    1.78           "List domains"},
    1.79 @@ -558,6 +627,11 @@ static PyMethodDef pyxl_methods[] = {
    1.80           "Remove a pass-through PCI device"},
    1.81      {"device_pci_parse_bdf", (PyCFunction)pyxl_pci_parse, METH_VARARGS,
    1.82           "Parse pass-through PCI device spec (BDF)"},
    1.83 +    {"device_pci_list", (PyCFunction)pyxl_pci_list, METH_VARARGS,
    1.84 +        "List PCI devices assigned to a domain"},
    1.85 +    {"device_pci_list_assignable",
    1.86 +        (PyCFunction)pyxl_pci_list_assignable, METH_NOARGS,
    1.87 +        "List assignable PCI devices"},
    1.88      { NULL, NULL, 0, NULL }
    1.89  };
    1.90