ia64/xen-unstable

view tools/python/xen/lowlevel/xc/xc.c @ 12840:5aea6a32fc8b

[LIBXC] Python error extraction tweak.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Dec 07 11:46:07 2006 +0000 (2006-12-07)
parents 2dd4569e0640
children df5fa63490f4
line source
1 /******************************************************************************
2 * Xc.c
3 *
4 * Copyright (c) 2003-2004, K A Fraser (University of Cambridge)
5 */
7 #include <Python.h>
8 #include <xenctrl.h>
9 #include <xenguest.h>
10 #include <zlib.h>
11 #include <fcntl.h>
12 #include <netinet/in.h>
13 #include <netinet/tcp.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <sys/mman.h>
17 #include <netdb.h>
18 #include <arpa/inet.h>
20 #include "xenctrl.h"
21 #include <xen/hvm/hvm_info_table.h>
22 #include <xen/hvm/params.h>
24 /* Needed for Python versions earlier than 2.3. */
25 #ifndef PyMODINIT_FUNC
26 #define PyMODINIT_FUNC DL_EXPORT(void)
27 #endif
29 #define PKG "xen.lowlevel.xc"
30 #define CLS "xc"
32 static PyObject *xc_error_obj, *zero;
34 typedef struct {
35 PyObject_HEAD;
36 int xc_handle;
37 } XcObject;
40 static PyObject *dom_op(XcObject *self, PyObject *args,
41 int (*fn)(int, uint32_t));
43 static PyObject *pyxc_error_to_exception(void)
44 {
45 PyObject *pyerr;
46 const xc_error const *err = xc_get_last_error();
47 const char *desc = xc_error_code_to_desc(err->code);
49 if (err->code == XC_ERROR_NONE)
50 return PyErr_SetFromErrno(xc_error_obj);
52 if (err->message[0] != '\0')
53 pyerr = Py_BuildValue("(iss)", err->code, desc, err->message);
54 else
55 pyerr = Py_BuildValue("(is)", err->code, desc);
57 xc_clear_last_error();
59 PyErr_SetObject(xc_error_obj, pyerr);
61 return NULL;
62 }
64 static PyObject *pyxc_domain_dumpcore(XcObject *self, PyObject *args)
65 {
66 uint32_t dom;
67 char *corefile;
69 if (!PyArg_ParseTuple(args, "is", &dom, &corefile))
70 return NULL;
72 if ( (corefile == NULL) || (corefile[0] == '\0') )
73 return NULL;
75 if (xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0)
76 return pyxc_error_to_exception();
78 Py_INCREF(zero);
79 return zero;
80 }
82 static PyObject *pyxc_handle(XcObject *self)
83 {
84 return PyInt_FromLong(self->xc_handle);
85 }
87 static PyObject *pyxc_domain_create(XcObject *self,
88 PyObject *args,
89 PyObject *kwds)
90 {
91 uint32_t dom = 0, ssidref = 0, flags = 0;
92 int ret, i, hvm = 0;
93 PyObject *pyhandle = NULL;
94 xen_domain_handle_t handle = {
95 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
96 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef };
98 static char *kwd_list[] = { "domid", "ssidref", "handle", "hvm", NULL };
100 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOi", kwd_list,
101 &dom, &ssidref, &pyhandle, &hvm))
102 return NULL;
104 if ( pyhandle != NULL )
105 {
106 if ( !PyList_Check(pyhandle) ||
107 (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) )
108 goto out_exception;
110 for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
111 {
112 PyObject *p = PyList_GetItem(pyhandle, i);
113 if ( !PyInt_Check(p) )
114 goto out_exception;
115 handle[i] = (uint8_t)PyInt_AsLong(p);
116 }
117 }
119 if ( hvm )
120 flags |= XEN_DOMCTL_CDF_hvm_guest;
122 if ( (ret = xc_domain_create(self->xc_handle, ssidref,
123 handle, flags, &dom)) < 0 )
124 return pyxc_error_to_exception();
126 return PyInt_FromLong(dom);
128 out_exception:
129 errno = EINVAL;
130 PyErr_SetFromErrno(xc_error_obj);
131 return NULL;
132 }
134 static PyObject *pyxc_domain_max_vcpus(XcObject *self, PyObject *args)
135 {
136 uint32_t dom, max;
138 if (!PyArg_ParseTuple(args, "ii", &dom, &max))
139 return NULL;
141 if (xc_domain_max_vcpus(self->xc_handle, dom, max) != 0)
142 return pyxc_error_to_exception();
144 Py_INCREF(zero);
145 return zero;
146 }
148 static PyObject *pyxc_domain_pause(XcObject *self, PyObject *args)
149 {
150 return dom_op(self, args, xc_domain_pause);
151 }
153 static PyObject *pyxc_domain_unpause(XcObject *self, PyObject *args)
154 {
155 return dom_op(self, args, xc_domain_unpause);
156 }
158 static PyObject *pyxc_domain_destroy(XcObject *self, PyObject *args)
159 {
160 return dom_op(self, args, xc_domain_destroy);
161 }
164 static PyObject *pyxc_vcpu_setaffinity(XcObject *self,
165 PyObject *args,
166 PyObject *kwds)
167 {
168 uint32_t dom;
169 int vcpu = 0, i;
170 uint64_t cpumap = ~0ULL;
171 PyObject *cpulist = NULL;
173 static char *kwd_list[] = { "domid", "vcpu", "cpumap", NULL };
175 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|iO", kwd_list,
176 &dom, &vcpu, &cpulist) )
177 return NULL;
179 if ( (cpulist != NULL) && PyList_Check(cpulist) )
180 {
181 cpumap = 0ULL;
182 for ( i = 0; i < PyList_Size(cpulist); i++ )
183 cpumap |= (uint64_t)1 << PyInt_AsLong(PyList_GetItem(cpulist, i));
184 }
186 if ( xc_vcpu_setaffinity(self->xc_handle, dom, vcpu, cpumap) != 0 )
187 return pyxc_error_to_exception();
189 Py_INCREF(zero);
190 return zero;
191 }
193 static PyObject *pyxc_domain_setcpuweight(XcObject *self,
194 PyObject *args,
195 PyObject *kwds)
196 {
197 uint32_t dom;
198 float cpuweight = 1;
200 static char *kwd_list[] = { "domid", "cpuweight", NULL };
202 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|f", kwd_list,
203 &dom, &cpuweight) )
204 return NULL;
206 if ( xc_domain_setcpuweight(self->xc_handle, dom, cpuweight) != 0 )
207 return pyxc_error_to_exception();
209 Py_INCREF(zero);
210 return zero;
211 }
213 static PyObject *pyxc_domain_sethandle(XcObject *self, PyObject *args)
214 {
215 int i;
216 uint32_t dom;
217 PyObject *pyhandle;
218 xen_domain_handle_t handle;
220 if (!PyArg_ParseTuple(args, "iO", &dom, &pyhandle))
221 return NULL;
223 if ( !PyList_Check(pyhandle) ||
224 (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) )
225 {
226 goto out_exception;
227 }
229 for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
230 {
231 PyObject *p = PyList_GetItem(pyhandle, i);
232 if ( !PyInt_Check(p) )
233 goto out_exception;
234 handle[i] = (uint8_t)PyInt_AsLong(p);
235 }
237 if (xc_domain_sethandle(self->xc_handle, dom, handle) < 0)
238 return pyxc_error_to_exception();
240 Py_INCREF(zero);
241 return zero;
243 out_exception:
244 PyErr_SetFromErrno(xc_error_obj);
245 return NULL;
246 }
249 static PyObject *pyxc_domain_getinfo(XcObject *self,
250 PyObject *args,
251 PyObject *kwds)
252 {
253 PyObject *list, *info_dict;
255 uint32_t first_dom = 0;
256 int max_doms = 1024, nr_doms, i, j;
257 xc_dominfo_t *info;
259 static char *kwd_list[] = { "first_dom", "max_doms", NULL };
261 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list,
262 &first_dom, &max_doms) )
263 return NULL;
265 if ( (info = malloc(max_doms * sizeof(xc_dominfo_t))) == NULL )
266 return PyErr_NoMemory();
268 nr_doms = xc_domain_getinfo(self->xc_handle, first_dom, max_doms, info);
270 if (nr_doms < 0)
271 {
272 free(info);
273 return pyxc_error_to_exception();
274 }
276 list = PyList_New(nr_doms);
277 for ( i = 0 ; i < nr_doms; i++ )
278 {
279 PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
280 for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
281 PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
282 info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
283 ",s:l,s:L,s:l,s:i,s:i}",
284 "domid", info[i].domid,
285 "online_vcpus", info[i].nr_online_vcpus,
286 "max_vcpu_id", info[i].max_vcpu_id,
287 "hvm", info[i].hvm,
288 "dying", info[i].dying,
289 "crashed", info[i].crashed,
290 "shutdown", info[i].shutdown,
291 "paused", info[i].paused,
292 "blocked", info[i].blocked,
293 "running", info[i].running,
294 "mem_kb", info[i].nr_pages*(XC_PAGE_SIZE/1024),
295 "cpu_time", info[i].cpu_time,
296 "maxmem_kb", info[i].max_memkb,
297 "ssidref", info[i].ssidref,
298 "shutdown_reason", info[i].shutdown_reason);
299 PyDict_SetItemString(info_dict, "handle", pyhandle);
300 Py_DECREF(pyhandle);
301 PyList_SetItem(list, i, info_dict);
302 }
304 free(info);
306 return list;
307 }
309 static PyObject *pyxc_vcpu_getinfo(XcObject *self,
310 PyObject *args,
311 PyObject *kwds)
312 {
313 PyObject *info_dict, *cpulist;
315 uint32_t dom, vcpu = 0;
316 xc_vcpuinfo_t info;
317 int rc, i;
318 uint64_t cpumap;
320 static char *kwd_list[] = { "domid", "vcpu", NULL };
322 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
323 &dom, &vcpu) )
324 return NULL;
326 rc = xc_vcpu_getinfo(self->xc_handle, dom, vcpu, &info);
327 if ( rc < 0 )
328 return pyxc_error_to_exception();
329 rc = xc_vcpu_getaffinity(self->xc_handle, dom, vcpu, &cpumap);
330 if ( rc < 0 )
331 return pyxc_error_to_exception();
333 info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i}",
334 "online", info.online,
335 "blocked", info.blocked,
336 "running", info.running,
337 "cpu_time", info.cpu_time,
338 "cpu", info.cpu);
340 cpulist = PyList_New(0);
341 for ( i = 0; cpumap != 0; i++ )
342 {
343 if ( cpumap & 1 )
344 PyList_Append(cpulist, PyInt_FromLong(i));
345 cpumap >>= 1;
346 }
347 PyDict_SetItemString(info_dict, "cpumap", cpulist);
348 Py_DECREF(cpulist);
349 return info_dict;
350 }
352 static PyObject *pyxc_linux_build(XcObject *self,
353 PyObject *args,
354 PyObject *kwds)
355 {
356 uint32_t dom;
357 char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
358 int flags = 0;
359 int store_evtchn, console_evtchn;
360 unsigned int mem_mb;
361 unsigned long store_mfn = 0;
362 unsigned long console_mfn = 0;
364 static char *kwd_list[] = { "domid", "store_evtchn", "memsize",
365 "console_evtchn", "image",
366 /* optional */
367 "ramdisk", "cmdline", "flags",
368 "features", NULL };
370 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis", kwd_list,
371 &dom, &store_evtchn, &mem_mb,
372 &console_evtchn, &image,
373 /* optional */
374 &ramdisk, &cmdline, &flags,
375 &features) )
376 return NULL;
378 if ( xc_linux_build(self->xc_handle, dom, mem_mb, image,
379 ramdisk, cmdline, features, flags,
380 store_evtchn, &store_mfn,
381 console_evtchn, &console_mfn) != 0 ) {
382 return pyxc_error_to_exception();
383 }
384 return Py_BuildValue("{s:i,s:i}",
385 "store_mfn", store_mfn,
386 "console_mfn", console_mfn);
387 }
389 static PyObject *pyxc_hvm_build(XcObject *self,
390 PyObject *args,
391 PyObject *kwds)
392 {
393 uint32_t dom;
394 struct hvm_info_table *va_hvm;
395 uint8_t *va_map, sum;
396 char *image;
397 int i, store_evtchn, memsize, vcpus = 1, pae = 0, acpi = 0, apic = 1;
398 unsigned long store_mfn;
400 static char *kwd_list[] = { "domid", "store_evtchn",
401 "memsize", "image", "vcpus", "pae", "acpi",
402 "apic", NULL };
403 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|iiii", kwd_list,
404 &dom, &store_evtchn, &memsize,
405 &image, &vcpus, &pae, &acpi, &apic) )
406 return NULL;
408 if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )
409 return pyxc_error_to_exception();
411 /* Set up the HVM info table. */
412 va_map = xc_map_foreign_range(self->xc_handle, dom, XC_PAGE_SIZE,
413 PROT_READ | PROT_WRITE,
414 HVM_INFO_PFN);
415 if ( va_map == NULL )
416 return PyErr_SetFromErrno(xc_error_obj);
417 va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
418 memset(va_hvm, 0, sizeof(*va_hvm));
419 strncpy(va_hvm->signature, "HVM INFO", 8);
420 va_hvm->length = sizeof(struct hvm_info_table);
421 va_hvm->acpi_enabled = acpi;
422 va_hvm->apic_mode = apic;
423 va_hvm->nr_vcpus = vcpus;
424 for ( i = 0, sum = 0; i < va_hvm->length; i++ )
425 sum += ((uint8_t *)va_hvm)[i];
426 va_hvm->checksum = -sum;
427 munmap(va_map, XC_PAGE_SIZE);
429 xc_get_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_PFN, &store_mfn);
430 xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
431 xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_EVTCHN,
432 store_evtchn);
434 return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
435 }
437 static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,
438 PyObject *args,
439 PyObject *kwds)
440 {
441 uint32_t dom, remote_dom;
442 int port;
444 static char *kwd_list[] = { "domid", "remote_dom", NULL };
446 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
447 &dom, &remote_dom) )
448 return NULL;
450 if ( (port = xc_evtchn_alloc_unbound(self->xc_handle, dom, remote_dom)) < 0 )
451 return pyxc_error_to_exception();
453 return PyInt_FromLong(port);
454 }
456 static PyObject *pyxc_physdev_pci_access_modify(XcObject *self,
457 PyObject *args,
458 PyObject *kwds)
459 {
460 uint32_t dom;
461 int bus, dev, func, enable, ret;
463 static char *kwd_list[] = { "domid", "bus", "dev", "func", "enable", NULL };
465 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiii", kwd_list,
466 &dom, &bus, &dev, &func, &enable) )
467 return NULL;
469 ret = xc_physdev_pci_access_modify(
470 self->xc_handle, dom, bus, dev, func, enable);
471 if ( ret != 0 )
472 return pyxc_error_to_exception();
474 Py_INCREF(zero);
475 return zero;
476 }
478 static PyObject *pyxc_readconsolering(XcObject *self,
479 PyObject *args,
480 PyObject *kwds)
481 {
482 unsigned int clear = 0;
483 char _str[32768], *str = _str;
484 unsigned int count = 32768;
485 int ret;
487 static char *kwd_list[] = { "clear", NULL };
489 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &clear) )
490 return NULL;
492 ret = xc_readconsolering(self->xc_handle, &str, &count, clear);
493 if ( ret < 0 )
494 return pyxc_error_to_exception();
496 return PyString_FromStringAndSize(str, count);
497 }
500 static unsigned long pages_to_kib(unsigned long pages)
501 {
502 return pages * (XC_PAGE_SIZE / 1024);
503 }
506 static PyObject *pyxc_pages_to_kib(XcObject *self, PyObject *args)
507 {
508 unsigned long pages;
510 if (!PyArg_ParseTuple(args, "l", &pages))
511 return NULL;
513 return PyLong_FromUnsignedLong(pages_to_kib(pages));
514 }
517 static PyObject *pyxc_physinfo(XcObject *self)
518 {
519 xc_physinfo_t info;
520 char cpu_cap[128], *p=cpu_cap, *q=cpu_cap;
521 int i;
523 if ( xc_physinfo(self->xc_handle, &info) != 0 )
524 return pyxc_error_to_exception();
526 *q=0;
527 for(i=0;i<sizeof(info.hw_cap)/4;i++)
528 {
529 p+=sprintf(p,"%08x:",info.hw_cap[i]);
530 if(info.hw_cap[i])
531 q=p;
532 }
533 if(q>cpu_cap)
534 *(q-1)=0;
536 return Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s}",
537 "threads_per_core", info.threads_per_core,
538 "cores_per_socket", info.cores_per_socket,
539 "sockets_per_node", info.sockets_per_node,
540 "nr_nodes", info.nr_nodes,
541 "total_memory", pages_to_kib(info.total_pages),
542 "free_memory", pages_to_kib(info.free_pages),
543 "scrub_memory", pages_to_kib(info.scrub_pages),
544 "cpu_khz", info.cpu_khz,
545 "hw_caps", cpu_cap);
546 }
548 static PyObject *pyxc_xeninfo(XcObject *self)
549 {
550 xen_extraversion_t xen_extra;
551 xen_compile_info_t xen_cc;
552 xen_changeset_info_t xen_chgset;
553 xen_capabilities_info_t xen_caps;
554 xen_platform_parameters_t p_parms;
555 long xen_version;
556 long xen_pagesize;
557 char str[128];
559 xen_version = xc_version(self->xc_handle, XENVER_version, NULL);
561 if ( xc_version(self->xc_handle, XENVER_extraversion, &xen_extra) != 0 )
562 return pyxc_error_to_exception();
564 if ( xc_version(self->xc_handle, XENVER_compile_info, &xen_cc) != 0 )
565 return pyxc_error_to_exception();
567 if ( xc_version(self->xc_handle, XENVER_changeset, &xen_chgset) != 0 )
568 return pyxc_error_to_exception();
570 if ( xc_version(self->xc_handle, XENVER_capabilities, &xen_caps) != 0 )
571 return pyxc_error_to_exception();
573 if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 )
574 return pyxc_error_to_exception();
576 sprintf(str, "virt_start=0x%lx", p_parms.virt_start);
578 xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL);
579 if (xen_pagesize < 0 )
580 return pyxc_error_to_exception();
582 return Py_BuildValue("{s:i,s:i,s:s,s:s,s:i,s:s,s:s,s:s,s:s,s:s,s:s}",
583 "xen_major", xen_version >> 16,
584 "xen_minor", (xen_version & 0xffff),
585 "xen_extra", xen_extra,
586 "xen_caps", xen_caps,
587 "xen_pagesize", xen_pagesize,
588 "platform_params", str,
589 "xen_changeset", xen_chgset,
590 "cc_compiler", xen_cc.compiler,
591 "cc_compile_by", xen_cc.compile_by,
592 "cc_compile_domain", xen_cc.compile_domain,
593 "cc_compile_date", xen_cc.compile_date);
594 }
597 static PyObject *pyxc_sedf_domain_set(XcObject *self,
598 PyObject *args,
599 PyObject *kwds)
600 {
601 uint32_t domid;
602 uint64_t period, slice, latency;
603 uint16_t extratime, weight;
604 static char *kwd_list[] = { "domid", "period", "slice",
605 "latency", "extratime", "weight",NULL };
607 if( !PyArg_ParseTupleAndKeywords(args, kwds, "iLLLhh", kwd_list,
608 &domid, &period, &slice,
609 &latency, &extratime, &weight) )
610 return NULL;
611 if ( xc_sedf_domain_set(self->xc_handle, domid, period,
612 slice, latency, extratime,weight) != 0 )
613 return pyxc_error_to_exception();
615 Py_INCREF(zero);
616 return zero;
617 }
619 static PyObject *pyxc_sedf_domain_get(XcObject *self, PyObject *args)
620 {
621 uint32_t domid;
622 uint64_t period, slice,latency;
623 uint16_t weight, extratime;
625 if(!PyArg_ParseTuple(args, "i", &domid))
626 return NULL;
628 if (xc_sedf_domain_get(self->xc_handle, domid, &period,
629 &slice,&latency,&extratime,&weight))
630 return pyxc_error_to_exception();
632 return Py_BuildValue("{s:i,s:L,s:L,s:L,s:i,s:i}",
633 "domid", domid,
634 "period", period,
635 "slice", slice,
636 "latency", latency,
637 "extratime", extratime,
638 "weight", weight);
639 }
641 static PyObject *pyxc_shadow_control(PyObject *self,
642 PyObject *args,
643 PyObject *kwds)
644 {
645 XcObject *xc = (XcObject *)self;
647 uint32_t dom;
648 int op=0;
650 static char *kwd_list[] = { "dom", "op", NULL };
652 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
653 &dom, &op) )
654 return NULL;
656 if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, NULL, 0, NULL)
657 < 0 )
658 return pyxc_error_to_exception();
660 Py_INCREF(zero);
661 return zero;
662 }
664 static PyObject *pyxc_shadow_mem_control(PyObject *self,
665 PyObject *args,
666 PyObject *kwds)
667 {
668 XcObject *xc = (XcObject *)self;
669 int op;
670 uint32_t dom;
671 int mbarg = -1;
672 unsigned long mb;
674 static char *kwd_list[] = { "dom", "mb", NULL };
676 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
677 &dom, &mbarg) )
678 return NULL;
680 if ( mbarg < 0 )
681 op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
682 else
683 {
684 mb = mbarg;
685 op = XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION;
686 }
687 if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, &mb, 0, NULL) < 0 )
688 return pyxc_error_to_exception();
690 mbarg = mb;
691 return Py_BuildValue("i", mbarg);
692 }
694 static PyObject *pyxc_sched_id_get(XcObject *self) {
696 int sched_id;
697 if (xc_sched_id(self->xc_handle, &sched_id) != 0)
698 return PyErr_SetFromErrno(xc_error_obj);
700 return Py_BuildValue("i", sched_id);
701 }
703 static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
704 PyObject *args,
705 PyObject *kwds)
706 {
707 uint32_t domid;
708 uint16_t weight;
709 uint16_t cap;
710 static char *kwd_list[] = { "domid", "weight", "cap", NULL };
711 static char kwd_type[] = "I|HH";
712 struct xen_domctl_sched_credit sdom;
714 weight = 0;
715 cap = (uint16_t)~0U;
716 if( !PyArg_ParseTupleAndKeywords(args, kwds, kwd_type, kwd_list,
717 &domid, &weight, &cap) )
718 return NULL;
720 sdom.weight = weight;
721 sdom.cap = cap;
723 if ( xc_sched_credit_domain_set(self->xc_handle, domid, &sdom) != 0 )
724 return pyxc_error_to_exception();
726 Py_INCREF(zero);
727 return zero;
728 }
730 static PyObject *pyxc_sched_credit_domain_get(XcObject *self, PyObject *args)
731 {
732 uint32_t domid;
733 struct xen_domctl_sched_credit sdom;
735 if( !PyArg_ParseTuple(args, "I", &domid) )
736 return NULL;
738 if ( xc_sched_credit_domain_get(self->xc_handle, domid, &sdom) != 0 )
739 return pyxc_error_to_exception();
741 return Py_BuildValue("{s:H,s:H}",
742 "weight", sdom.weight,
743 "cap", sdom.cap);
744 }
746 static PyObject *pyxc_domain_setmaxmem(XcObject *self, PyObject *args)
747 {
748 uint32_t dom;
749 unsigned int maxmem_kb;
751 if (!PyArg_ParseTuple(args, "ii", &dom, &maxmem_kb))
752 return NULL;
754 if (xc_domain_setmaxmem(self->xc_handle, dom, maxmem_kb) != 0)
755 return pyxc_error_to_exception();
757 Py_INCREF(zero);
758 return zero;
759 }
761 static PyObject *pyxc_domain_memory_increase_reservation(XcObject *self,
762 PyObject *args,
763 PyObject *kwds)
764 {
765 uint32_t dom;
766 unsigned long mem_kb;
767 unsigned int extent_order = 0 , address_bits = 0;
768 unsigned long nr_extents;
770 static char *kwd_list[] = { "domid", "mem_kb", "extent_order", "address_bits", NULL };
772 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "il|ii", kwd_list,
773 &dom, &mem_kb, &extent_order, &address_bits) )
774 return NULL;
776 /* round down to nearest power of 2. Assume callers using extent_order>0
777 know what they are doing */
778 nr_extents = (mem_kb / (XC_PAGE_SIZE/1024)) >> extent_order;
779 if ( xc_domain_memory_increase_reservation(self->xc_handle, dom,
780 nr_extents, extent_order,
781 address_bits, NULL) )
782 return pyxc_error_to_exception();
784 Py_INCREF(zero);
785 return zero;
786 }
788 static PyObject *pyxc_domain_ioport_permission(XcObject *self,
789 PyObject *args,
790 PyObject *kwds)
791 {
792 uint32_t dom;
793 int first_port, nr_ports, allow_access, ret;
795 static char *kwd_list[] = { "domid", "first_port", "nr_ports", "allow_access", NULL };
797 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiii", kwd_list,
798 &dom, &first_port, &nr_ports, &allow_access) )
799 return NULL;
801 ret = xc_domain_ioport_permission(
802 self->xc_handle, dom, first_port, nr_ports, allow_access);
803 if ( ret != 0 )
804 return pyxc_error_to_exception();
806 Py_INCREF(zero);
807 return zero;
808 }
810 static PyObject *pyxc_domain_irq_permission(PyObject *self,
811 PyObject *args,
812 PyObject *kwds)
813 {
814 XcObject *xc = (XcObject *)self;
815 uint32_t dom;
816 int pirq, allow_access, ret;
818 static char *kwd_list[] = { "domid", "pirq", "allow_access", NULL };
820 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list,
821 &dom, &pirq, &allow_access) )
822 return NULL;
824 ret = xc_domain_irq_permission(
825 xc->xc_handle, dom, pirq, allow_access);
826 if ( ret != 0 )
827 return pyxc_error_to_exception();
829 Py_INCREF(zero);
830 return zero;
831 }
833 static PyObject *pyxc_domain_iomem_permission(PyObject *self,
834 PyObject *args,
835 PyObject *kwds)
836 {
837 XcObject *xc = (XcObject *)self;
838 uint32_t dom;
839 unsigned long first_pfn, nr_pfns, allow_access, ret;
841 static char *kwd_list[] = { "domid", "first_pfn", "nr_pfns", "allow_access", NULL };
843 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illi", kwd_list,
844 &dom, &first_pfn, &nr_pfns, &allow_access) )
845 return NULL;
847 ret = xc_domain_iomem_permission(
848 xc->xc_handle, dom, first_pfn, nr_pfns, allow_access);
849 if ( ret != 0 )
850 return pyxc_error_to_exception();
852 Py_INCREF(zero);
853 return zero;
854 }
856 static PyObject *pyxc_domain_set_time_offset(XcObject *self, PyObject *args)
857 {
858 uint32_t dom;
859 int32_t time_offset_seconds;
860 time_t calendar_time;
861 struct tm local_time;
862 struct tm utc_time;
864 if (!PyArg_ParseTuple(args, "i", &dom))
865 return NULL;
867 calendar_time = time(NULL);
868 localtime_r(&calendar_time, &local_time);
869 gmtime_r(&calendar_time, &utc_time);
870 /* set up to get calendar time based on utc_time, with local dst setting */
871 utc_time.tm_isdst = local_time.tm_isdst;
872 time_offset_seconds = (int32_t)difftime(calendar_time, mktime(&utc_time));
874 if (xc_domain_set_time_offset(self->xc_handle, dom, time_offset_seconds) != 0)
875 return NULL;
877 Py_INCREF(zero);
878 return zero;
879 }
881 static PyObject *dom_op(XcObject *self, PyObject *args,
882 int (*fn)(int, uint32_t))
883 {
884 uint32_t dom;
886 if (!PyArg_ParseTuple(args, "i", &dom))
887 return NULL;
889 if (fn(self->xc_handle, dom) != 0)
890 return pyxc_error_to_exception();
892 Py_INCREF(zero);
893 return zero;
894 }
897 static PyMethodDef pyxc_methods[] = {
898 { "handle",
899 (PyCFunction)pyxc_handle,
900 METH_NOARGS, "\n"
901 "Query the xc control interface file descriptor.\n\n"
902 "Returns: [int] file descriptor\n" },
904 { "domain_create",
905 (PyCFunction)pyxc_domain_create,
906 METH_VARARGS | METH_KEYWORDS, "\n"
907 "Create a new domain.\n"
908 " dom [int, 0]: Domain identifier to use (allocated if zero).\n"
909 "Returns: [int] new domain identifier; -1 on error.\n" },
911 { "domain_max_vcpus",
912 (PyCFunction)pyxc_domain_max_vcpus,
913 METH_VARARGS, "\n"
914 "Set the maximum number of VCPUs a domain may create.\n"
915 " dom [int, 0]: Domain identifier to use.\n"
916 " max [int, 0]: New maximum number of VCPUs in domain.\n"
917 "Returns: [int] 0 on success; -1 on error.\n" },
919 { "domain_dumpcore",
920 (PyCFunction)pyxc_domain_dumpcore,
921 METH_VARARGS, "\n"
922 "Dump core of a domain.\n"
923 " dom [int]: Identifier of domain to dump core of.\n"
924 " corefile [string]: Name of corefile to be created.\n\n"
925 "Returns: [int] 0 on success; -1 on error.\n" },
927 { "domain_pause",
928 (PyCFunction)pyxc_domain_pause,
929 METH_VARARGS, "\n"
930 "Temporarily pause execution of a domain.\n"
931 " dom [int]: Identifier of domain to be paused.\n\n"
932 "Returns: [int] 0 on success; -1 on error.\n" },
934 { "domain_unpause",
935 (PyCFunction)pyxc_domain_unpause,
936 METH_VARARGS, "\n"
937 "(Re)start execution of a domain.\n"
938 " dom [int]: Identifier of domain to be unpaused.\n\n"
939 "Returns: [int] 0 on success; -1 on error.\n" },
941 { "domain_destroy",
942 (PyCFunction)pyxc_domain_destroy,
943 METH_VARARGS, "\n"
944 "Destroy a domain.\n"
945 " dom [int]: Identifier of domain to be destroyed.\n\n"
946 "Returns: [int] 0 on success; -1 on error.\n" },
948 { "vcpu_setaffinity",
949 (PyCFunction)pyxc_vcpu_setaffinity,
950 METH_VARARGS | METH_KEYWORDS, "\n"
951 "Pin a VCPU to a specified set CPUs.\n"
952 " dom [int]: Identifier of domain to which VCPU belongs.\n"
953 " vcpu [int, 0]: VCPU being pinned.\n"
954 " cpumap [list, []]: list of usable CPUs.\n\n"
955 "Returns: [int] 0 on success; -1 on error.\n" },
957 { "domain_setcpuweight",
958 (PyCFunction)pyxc_domain_setcpuweight,
959 METH_VARARGS | METH_KEYWORDS, "\n"
960 "Set cpuweight scheduler parameter for domain.\n"
961 " dom [int]: Identifier of domain to be changed.\n"
962 " cpuweight [float, 1]: VCPU being pinned.\n"
963 "Returns: [int] 0 on success; -1 on error.\n" },
965 { "domain_sethandle",
966 (PyCFunction)pyxc_domain_sethandle,
967 METH_VARARGS, "\n"
968 "Set domain's opaque handle.\n"
969 " dom [int]: Identifier of domain.\n"
970 " handle [list of 16 ints]: New opaque handle.\n"
971 "Returns: [int] 0 on success; -1 on error.\n" },
973 { "domain_getinfo",
974 (PyCFunction)pyxc_domain_getinfo,
975 METH_VARARGS | METH_KEYWORDS, "\n"
976 "Get information regarding a set of domains, in increasing id order.\n"
977 " first_dom [int, 0]: First domain to retrieve info about.\n"
978 " max_doms [int, 1024]: Maximum number of domains to retrieve info"
979 " about.\n\n"
980 "Returns: [list of dicts] if list length is less than 'max_doms'\n"
981 " parameter then there was an error, or the end of the\n"
982 " domain-id space was reached.\n"
983 " dom [int]: Identifier of domain to which this info pertains\n"
984 " cpu [int]: CPU to which this domain is bound\n"
985 " vcpus [int]: Number of Virtual CPUS in this domain\n"
986 " dying [int]: Bool - is the domain dying?\n"
987 " crashed [int]: Bool - has the domain crashed?\n"
988 " shutdown [int]: Bool - has the domain shut itself down?\n"
989 " paused [int]: Bool - is the domain paused by control software?\n"
990 " blocked [int]: Bool - is the domain blocked waiting for an event?\n"
991 " running [int]: Bool - is the domain currently running?\n"
992 " mem_kb [int]: Memory reservation, in kilobytes\n"
993 " maxmem_kb [int]: Maximum memory limit, in kilobytes\n"
994 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
995 " shutdown_reason [int]: Numeric code from guest OS, explaining "
996 "reason why it shut itself down.\n" },
998 { "vcpu_getinfo",
999 (PyCFunction)pyxc_vcpu_getinfo,
1000 METH_VARARGS | METH_KEYWORDS, "\n"
1001 "Get information regarding a VCPU.\n"
1002 " dom [int]: Domain to retrieve info about.\n"
1003 " vcpu [int, 0]: VCPU to retrieve info about.\n\n"
1004 "Returns: [dict]\n"
1005 " online [int]: Bool - Is this VCPU currently online?\n"
1006 " blocked [int]: Bool - Is this VCPU blocked waiting for an event?\n"
1007 " running [int]: Bool - Is this VCPU currently running on a CPU?\n"
1008 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
1009 " cpumap [int]: Bitmap of CPUs this VCPU can run on\n"
1010 " cpu [int]: CPU that this VCPU is currently bound to\n" },
1012 { "linux_build",
1013 (PyCFunction)pyxc_linux_build,
1014 METH_VARARGS | METH_KEYWORDS, "\n"
1015 "Build a new Linux guest OS.\n"
1016 " dom [int]: Identifier of domain to build into.\n"
1017 " image [str]: Name of kernel image file. May be gzipped.\n"
1018 " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
1019 " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
1020 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
1021 "Returns: [int] 0 on success; -1 on error.\n" },
1023 { "hvm_build",
1024 (PyCFunction)pyxc_hvm_build,
1025 METH_VARARGS | METH_KEYWORDS, "\n"
1026 "Build a new HVM guest OS.\n"
1027 " dom [int]: Identifier of domain to build into.\n"
1028 " image [str]: Name of HVM loader image file.\n"
1029 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
1030 "Returns: [int] 0 on success; -1 on error.\n" },
1032 { "sched_id_get",
1033 (PyCFunction)pyxc_sched_id_get,
1034 METH_NOARGS, "\n"
1035 "Get the current scheduler type in use.\n"
1036 "Returns: [int] sched_id.\n" },
1038 { "sedf_domain_set",
1039 (PyCFunction)pyxc_sedf_domain_set,
1040 METH_KEYWORDS, "\n"
1041 "Set the scheduling parameters for a domain when running with Atropos.\n"
1042 " dom [int]: domain to set\n"
1043 " period [long]: domain's scheduling period\n"
1044 " slice [long]: domain's slice per period\n"
1045 " latency [long]: domain's wakeup latency hint\n"
1046 " extratime [int]: domain aware of extratime?\n"
1047 "Returns: [int] 0 on success; -1 on error.\n" },
1049 { "sedf_domain_get",
1050 (PyCFunction)pyxc_sedf_domain_get,
1051 METH_VARARGS, "\n"
1052 "Get the current scheduling parameters for a domain when running with\n"
1053 "the Atropos scheduler."
1054 " dom [int]: domain to query\n"
1055 "Returns: [dict]\n"
1056 " domain [int]: domain ID\n"
1057 " period [long]: scheduler period\n"
1058 " slice [long]: CPU reservation per period\n"
1059 " latency [long]: domain's wakeup latency hint\n"
1060 " extratime [int]: domain aware of extratime?\n"},
1062 { "sched_credit_domain_set",
1063 (PyCFunction)pyxc_sched_credit_domain_set,
1064 METH_KEYWORDS, "\n"
1065 "Set the scheduling parameters for a domain when running with the\n"
1066 "SMP credit scheduler.\n"
1067 " domid [int]: domain id to set\n"
1068 " weight [short]: domain's scheduling weight\n"
1069 "Returns: [int] 0 on success; -1 on error.\n" },
1071 { "sched_credit_domain_get",
1072 (PyCFunction)pyxc_sched_credit_domain_get,
1073 METH_VARARGS, "\n"
1074 "Get the scheduling parameters for a domain when running with the\n"
1075 "SMP credit scheduler.\n"
1076 " domid [int]: domain id to get\n"
1077 "Returns: [dict]\n"
1078 " weight [short]: domain's scheduling weight\n"},
1080 { "evtchn_alloc_unbound",
1081 (PyCFunction)pyxc_evtchn_alloc_unbound,
1082 METH_VARARGS | METH_KEYWORDS, "\n"
1083 "Allocate an unbound port that will await a remote connection.\n"
1084 " dom [int]: Domain whose port space to allocate from.\n"
1085 " remote_dom [int]: Remote domain to accept connections from.\n\n"
1086 "Returns: [int] Unbound event-channel port.\n" },
1088 { "physdev_pci_access_modify",
1089 (PyCFunction)pyxc_physdev_pci_access_modify,
1090 METH_VARARGS | METH_KEYWORDS, "\n"
1091 "Allow a domain access to a PCI device\n"
1092 " dom [int]: Identifier of domain to be allowed access.\n"
1093 " bus [int]: PCI bus\n"
1094 " dev [int]: PCI slot\n"
1095 " func [int]: PCI function\n"
1096 " enable [int]: Non-zero means enable access; else disable access\n\n"
1097 "Returns: [int] 0 on success; -1 on error.\n" },
1099 { "readconsolering",
1100 (PyCFunction)pyxc_readconsolering,
1101 METH_VARARGS | METH_KEYWORDS, "\n"
1102 "Read Xen's console ring.\n"
1103 " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
1104 "Returns: [str] string is empty on failure.\n" },
1106 { "physinfo",
1107 (PyCFunction)pyxc_physinfo,
1108 METH_NOARGS, "\n"
1109 "Get information about the physical host machine\n"
1110 "Returns [dict]: information about the hardware"
1111 " [None]: on failure.\n" },
1113 { "xeninfo",
1114 (PyCFunction)pyxc_xeninfo,
1115 METH_NOARGS, "\n"
1116 "Get information about the Xen host\n"
1117 "Returns [dict]: information about Xen"
1118 " [None]: on failure.\n" },
1120 { "shadow_control",
1121 (PyCFunction)pyxc_shadow_control,
1122 METH_VARARGS | METH_KEYWORDS, "\n"
1123 "Set parameter for shadow pagetable interface\n"
1124 " dom [int]: Identifier of domain.\n"
1125 " op [int, 0]: operation\n\n"
1126 "Returns: [int] 0 on success; -1 on error.\n" },
1128 { "shadow_mem_control",
1129 (PyCFunction)pyxc_shadow_mem_control,
1130 METH_VARARGS | METH_KEYWORDS, "\n"
1131 "Set or read shadow pagetable memory use\n"
1132 " dom [int]: Identifier of domain.\n"
1133 " mb [int, -1]: MB of shadow memory this domain should have.\n\n"
1134 "Returns: [int] MB of shadow memory in use by this domain.\n" },
1136 { "domain_setmaxmem",
1137 (PyCFunction)pyxc_domain_setmaxmem,
1138 METH_VARARGS, "\n"
1139 "Set a domain's memory limit\n"
1140 " dom [int]: Identifier of domain.\n"
1141 " maxmem_kb [int]: .\n"
1142 "Returns: [int] 0 on success; -1 on error.\n" },
1144 { "domain_memory_increase_reservation",
1145 (PyCFunction)pyxc_domain_memory_increase_reservation,
1146 METH_VARARGS | METH_KEYWORDS, "\n"
1147 "Increase a domain's memory reservation\n"
1148 " dom [int]: Identifier of domain.\n"
1149 " mem_kb [long]: .\n"
1150 "Returns: [int] 0 on success; -1 on error.\n" },
1152 { "domain_ioport_permission",
1153 (PyCFunction)pyxc_domain_ioport_permission,
1154 METH_VARARGS | METH_KEYWORDS, "\n"
1155 "Allow a domain access to a range of IO ports\n"
1156 " dom [int]: Identifier of domain to be allowed access.\n"
1157 " first_port [int]: First IO port\n"
1158 " nr_ports [int]: Number of IO ports\n"
1159 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1160 "Returns: [int] 0 on success; -1 on error.\n" },
1162 { "domain_irq_permission",
1163 (PyCFunction)pyxc_domain_irq_permission,
1164 METH_VARARGS | METH_KEYWORDS, "\n"
1165 "Allow a domain access to a physical IRQ\n"
1166 " dom [int]: Identifier of domain to be allowed access.\n"
1167 " pirq [int]: The Physical IRQ\n"
1168 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1169 "Returns: [int] 0 on success; -1 on error.\n" },
1171 { "domain_iomem_permission",
1172 (PyCFunction)pyxc_domain_iomem_permission,
1173 METH_VARARGS | METH_KEYWORDS, "\n"
1174 "Allow a domain access to a range of IO memory pages\n"
1175 " dom [int]: Identifier of domain to be allowed access.\n"
1176 " first_pfn [long]: First page of I/O Memory\n"
1177 " nr_pfns [long]: Number of pages of I/O Memory (>0)\n"
1178 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1179 "Returns: [int] 0 on success; -1 on error.\n" },
1181 { "pages_to_kib",
1182 (PyCFunction)pyxc_pages_to_kib,
1183 METH_VARARGS, "\n"
1184 "Returns: [int]: The size in KiB of memory spanning the given number "
1185 "of pages.\n" },
1187 { "domain_set_time_offset",
1188 (PyCFunction)pyxc_domain_set_time_offset,
1189 METH_VARARGS, "\n"
1190 "Set a domain's time offset to Dom0's localtime\n"
1191 " dom [int]: Domain whose time offset is being set.\n"
1192 "Returns: [int] 0 on success; -1 on error.\n" },
1194 { NULL, NULL, 0, NULL }
1195 };
1198 static PyObject *PyXc_getattr(PyObject *obj, char *name)
1200 return Py_FindMethod(pyxc_methods, obj, name);
1203 static PyObject *PyXc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1205 XcObject *self = (XcObject *)type->tp_alloc(type, 0);
1207 if (self == NULL)
1208 return NULL;
1210 self->xc_handle = -1;
1212 return (PyObject *)self;
1215 static int
1216 PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
1218 if ((self->xc_handle = xc_interface_open()) == -1) {
1219 pyxc_error_to_exception();
1220 return -1;
1223 return 0;
1226 static void PyXc_dealloc(XcObject *self)
1228 if (self->xc_handle != -1) {
1229 xc_interface_close(self->xc_handle);
1230 self->xc_handle = -1;
1233 self->ob_type->tp_free((PyObject *)self);
1236 static PyTypeObject PyXcType = {
1237 PyObject_HEAD_INIT(NULL)
1238 0,
1239 PKG "." CLS,
1240 sizeof(XcObject),
1241 0,
1242 (destructor)PyXc_dealloc, /* tp_dealloc */
1243 NULL, /* tp_print */
1244 PyXc_getattr, /* tp_getattr */
1245 NULL, /* tp_setattr */
1246 NULL, /* tp_compare */
1247 NULL, /* tp_repr */
1248 NULL, /* tp_as_number */
1249 NULL, /* tp_as_sequence */
1250 NULL, /* tp_as_mapping */
1251 NULL, /* tp_hash */
1252 NULL, /* tp_call */
1253 NULL, /* tp_str */
1254 NULL, /* tp_getattro */
1255 NULL, /* tp_setattro */
1256 NULL, /* tp_as_buffer */
1257 Py_TPFLAGS_DEFAULT, /* tp_flags */
1258 "Xen client connections", /* tp_doc */
1259 NULL, /* tp_traverse */
1260 NULL, /* tp_clear */
1261 NULL, /* tp_richcompare */
1262 0, /* tp_weaklistoffset */
1263 NULL, /* tp_iter */
1264 NULL, /* tp_iternext */
1265 pyxc_methods, /* tp_methods */
1266 NULL, /* tp_members */
1267 NULL, /* tp_getset */
1268 NULL, /* tp_base */
1269 NULL, /* tp_dict */
1270 NULL, /* tp_descr_get */
1271 NULL, /* tp_descr_set */
1272 0, /* tp_dictoffset */
1273 (initproc)PyXc_init, /* tp_init */
1274 NULL, /* tp_alloc */
1275 PyXc_new, /* tp_new */
1276 };
1278 static PyMethodDef xc_methods[] = { { NULL } };
1280 PyMODINIT_FUNC initxc(void)
1282 PyObject *m;
1284 if (PyType_Ready(&PyXcType) < 0)
1285 return;
1287 m = Py_InitModule(PKG, xc_methods);
1289 if (m == NULL)
1290 return;
1292 xc_error_obj = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
1293 zero = PyInt_FromLong(0);
1295 /* KAF: This ensures that we get debug output in a timely manner. */
1296 setbuf(stdout, NULL);
1297 setbuf(stderr, NULL);
1299 Py_INCREF(&PyXcType);
1300 PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
1302 Py_INCREF(xc_error_obj);
1303 PyModule_AddObject(m, "Error", xc_error_obj);
1305 /* Expose some libxc constants to Python */
1306 PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF);
1307 PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT);
1312 /*
1313 * Local variables:
1314 * c-indent-level: 4
1315 * c-basic-offset: 4
1316 * End:
1317 */