As with xs.c, change the module interface to match the current Python/C

tutorial, simplifying the interface here, and making it more conventional.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
emellor@leeni.uk.xensource.com committed 2005-11-21 18:46:09 +01:00
1 parent 2b2f00d237
commit aecd7580d4
11 files changed
+93 -64

No files matched your search

+80 -51
View File
@@ -23,7 +23,8 @@
#define PyMODINIT_FUNC DL_EXPORT(void)
#endif
#define XENPKG "xen.lowlevel.xc"
#define PKG "xen.lowlevel.xc"
#define CLS "xc"
static PyObject *xc_error, *zero;
@@ -1055,81 +1056,109 @@ static PyMethodDef pyxc_methods[] = {
};
/*
* Definitions for the 'Xc' module wrapper.
*/
staticforward PyTypeObject PyXcType;
static PyObject *PyXc_new(PyObject *self, PyObject *args)
{
XcObject *xc;
if ( !PyArg_ParseTuple(args, ":new") )
return NULL;
xc = PyObject_New(XcObject, &PyXcType);
if ( (xc->xc_handle = xc_interface_open()) == -1 )
{
PyObject_Del((PyObject *)xc);
return PyErr_SetFromErrno(xc_error);
}
return (PyObject *)xc;
}
static PyObject *PyXc_getattr(PyObject *obj, char *name)
{
return Py_FindMethod(pyxc_methods, obj, name);
}
static void PyXc_dealloc(PyObject *self)
static PyObject *PyXc_new(PyTypeObject *type, PyObject *args)
{
XcObject *xc = (XcObject *)self;
(void)xc_interface_close(xc->xc_handle);
PyObject_Del(self);
XcObject *self = (XcObject *)type->tp_alloc(type, 0);
if (self == NULL)
return NULL;
self->xc_handle = NULL;
return (PyObject *)self;
}
static int
PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
{
if ((self->xc_handle = xc_interface_open()) == -1) {
PyErr_SetFromErrno(PyExc_RuntimeError);
return -1;
}
return 0;
}
static void PyXc_dealloc(XcObject *self)
{
if (self->xc_handle) {
xc_interface_close(self->xc_handle);
self->xc_handle = NULL;
}
self->ob_type->tp_free((PyObject *)self);
}
static PyTypeObject PyXcType = {
PyObject_HEAD_INIT(&PyType_Type)
PyObject_HEAD_INIT(NULL)
0,
"Xc",
PKG "." CLS,
sizeof(XcObject),
0,
PyXc_dealloc, /* tp_dealloc */
NULL, /* tp_print */
PyXc_getattr, /* tp_getattr */
NULL, /* tp_setattr */
NULL, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
NULL, /* tp_as_mapping */
NULL /* tp_hash */
(destructor)PyXc_dealloc, /* tp_dealloc */
NULL, /* tp_print */
PyXc_getattr, /* tp_getattr */
NULL, /* tp_setattr */
NULL, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
NULL, /* tp_as_mapping */
NULL, /* tp_hash */
NULL, /* tp_call */
NULL, /* tp_str */
NULL, /* tp_getattro */
NULL, /* tp_setattro */
NULL, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Xen client connections", /* tp_doc */
NULL, /* tp_traverse */
NULL, /* tp_clear */
NULL, /* tp_richcompare */
0, /* tp_weaklistoffset */
NULL, /* tp_iter */
NULL, /* tp_iternext */
pyxc_methods, /* tp_methods */
NULL, /* tp_members */
NULL, /* tp_getset */
NULL, /* tp_base */
NULL, /* tp_dict */
NULL, /* tp_descr_get */
NULL, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)PyXc_init, /* tp_init */
NULL, /* tp_alloc */
PyXc_new, /* tp_new */
};
static PyMethodDef PyXc_methods[] = {
{ "new", PyXc_new, METH_VARARGS, "Create a new " XENPKG " object." },
{ NULL, NULL, 0, NULL }
};
static PyMethodDef xc_methods[] = { { NULL } };
PyMODINIT_FUNC initxc(void)
{
PyObject *m, *d;
PyObject *m;
m = Py_InitModule(XENPKG, PyXc_methods);
if (PyType_Ready(&PyXcType) < 0)
return;
d = PyModule_GetDict(m);
xc_error = PyErr_NewException(XENPKG ".error", NULL, NULL);
PyDict_SetItemString(d, "error", xc_error);
PyDict_SetItemString(d, "VIRQ_DOM_EXC", PyInt_FromLong(VIRQ_DOM_EXC));
m = Py_InitModule(PKG, PyXc_methods);
if (m == NULL)
return;
xc_error = PyErr_NewException(PKG ".error", NULL, NULL);
zero = PyInt_FromLong(0);
/* KAF: This ensures that we get debug output in a timely manner. */
setbuf(stdout, NULL);
setbuf(stderr, NULL);
Py_INCREF(&PyXcType);
PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
}
+1 -1
View File
@@ -33,7 +33,7 @@ sizeof_int = calcsize("i")
sizeof_unsigned_long = calcsize("L")
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
def write_exact(fd, buf, errmsg):
+1 -1
View File
@@ -22,7 +22,7 @@ import xen.lowlevel.xc
class XendDmesg:
def __init__(self):
self.xc = xen.lowlevel.xc.new()
self.xc = xen.lowlevel.xc.xc()
def info(self):
return self.xc.readconsolering()
+3 -3
View File
@@ -39,7 +39,7 @@ from xen.xend.server import relocate
from xen.xend.xenstore.xswatch import xswatch
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
xroot = XendRoot.instance()
@@ -201,7 +201,7 @@ class XendDomain:
"%d. Destroying it in the hope of "
"recovery.", d)
try:
xc.domain_destroy(dom = d)
xc.domain_destroy(d)
except:
log.exception('Destruction of %d failed.', d)
@@ -378,7 +378,7 @@ class XendDomain:
val = dominfo.destroy()
else:
try:
val = xc.domain_destroy(dom=domid)
val = xc.domain_destroy(domid)
except Exception, ex:
raise XendError(str(ex))
return val
+1 -1
View File
@@ -93,7 +93,7 @@ MINIMUM_RESTART_TIME = 20
RESTART_IN_PROGRESS = 'xend/restart_in_progress'
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
xroot = XendRoot.instance()
log = logging.getLogger("xend.XendDomainInfo")
+2 -2
View File
@@ -28,7 +28,7 @@ import xen.lowlevel.xc
class XendNode:
def __init__(self):
self.xc = xen.lowlevel.xc.new()
self.xc = xen.lowlevel.xc.xc()
def shutdown(self):
return 0
@@ -40,7 +40,7 @@ class XendNode:
return 0
def cpu_bvt_slice_set(self, ctx_allow):
return self.xc.bvtsched_global_set(ctx_allow=ctx_allow)
return self.xc.bvtsched_global_set(ctx_allow)
def cpu_bvt_slice_get(self):
return self.xc.bvtsched_global_get()
+1 -1
View File
@@ -27,7 +27,7 @@ from xen.xend.XendLogging import log
from xen.xend.server.netif import randomMAC
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
MAX_GUEST_CMDLINE = 1024
+1 -1
View File
@@ -267,7 +267,7 @@ class Daemon:
try:
log.info("Xend Daemon started")
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
xinfo = xc.xeninfo()
log.info("Xend changeset: %s.", xinfo['xen_changeset'])
del xc
+1 -1
View File
@@ -28,7 +28,7 @@ from xen.xend.XendError import VmError
from xen.xend.server.DevController import DevController
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
def parse_ioport(val):
+1 -1
View File
@@ -27,7 +27,7 @@ from xen.xend.XendError import VmError
from xen.xend.server.DevController import DevController
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
def parse_pci(val):
+1 -1
View File
@@ -849,7 +849,7 @@ def balloon_out(dom0_min_mem, opts):
timeout = 20 # 2s
ret = 1
xc = xen.lowlevel.xc.new()
xc = xen.lowlevel.xc.xc()
free_mem = xc.physinfo()['free_pages'] / 256
domU_need_mem = opts.vals.memory + SLACK
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.