direct-io.hg

view tools/python/xen/lowlevel/xc/xc.c @ 12803:df5fa63490f4

[XEN] Implement XENMEM_set_memory_map, which specifies memory map to
be returned by XENMEM_memory_map. Hook this into the domain builder.

Based on a patch by Glauber de Oliveira Costa <gcosta@redhat.com>

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Dec 08 11:30:30 2006 +0000 (2006-12-08)
parents 5aea6a32fc8b
children 970ff2ba748f
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_set_memmap_limit(XcObject *self, PyObject *args)
762 {
763 uint32_t dom;
764 unsigned int maplimit_kb;
766 if ( !PyArg_ParseTuple(args, "ii", &dom, &maplimit_kb) )
767 return NULL;
769 if ( xc_domain_set_memmap_limit(self->xc_handle, dom, maplimit_kb) != 0 )
770 return pyxc_error_to_exception();
772 Py_INCREF(zero);
773 return zero;
774 }
776 static PyObject *pyxc_domain_memory_increase_reservation(XcObject *self,
777 PyObject *args,
778 PyObject *kwds)
779 {
780 uint32_t dom;
781 unsigned long mem_kb;
782 unsigned int extent_order = 0 , address_bits = 0;
783 unsigned long nr_extents;
785 static char *kwd_list[] = { "domid", "mem_kb", "extent_order", "address_bits", NULL };
787 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "il|ii", kwd_list,
788 &dom, &mem_kb, &extent_order, &address_bits) )
789 return NULL;
791 /* round down to nearest power of 2. Assume callers using extent_order>0
792 know what they are doing */
793 nr_extents = (mem_kb / (XC_PAGE_SIZE/1024)) >> extent_order;
794 if ( xc_domain_memory_increase_reservation(self->xc_handle, dom,
795 nr_extents, extent_order,
796 address_bits, NULL) )
797 return pyxc_error_to_exception();
799 Py_INCREF(zero);
800 return zero;
801 }
803 static PyObject *pyxc_domain_ioport_permission(XcObject *self,
804 PyObject *args,
805 PyObject *kwds)
806 {
807 uint32_t dom;
808 int first_port, nr_ports, allow_access, ret;
810 static char *kwd_list[] = { "domid", "first_port", "nr_ports", "allow_access", NULL };
812 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiii", kwd_list,
813 &dom, &first_port, &nr_ports, &allow_access) )
814 return NULL;
816 ret = xc_domain_ioport_permission(
817 self->xc_handle, dom, first_port, nr_ports, allow_access);
818 if ( ret != 0 )
819 return pyxc_error_to_exception();
821 Py_INCREF(zero);
822 return zero;
823 }
825 static PyObject *pyxc_domain_irq_permission(PyObject *self,
826 PyObject *args,
827 PyObject *kwds)
828 {
829 XcObject *xc = (XcObject *)self;
830 uint32_t dom;
831 int pirq, allow_access, ret;
833 static char *kwd_list[] = { "domid", "pirq", "allow_access", NULL };
835 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list,
836 &dom, &pirq, &allow_access) )
837 return NULL;
839 ret = xc_domain_irq_permission(
840 xc->xc_handle, dom, pirq, allow_access);
841 if ( ret != 0 )
842 return pyxc_error_to_exception();
844 Py_INCREF(zero);
845 return zero;
846 }
848 static PyObject *pyxc_domain_iomem_permission(PyObject *self,
849 PyObject *args,
850 PyObject *kwds)
851 {
852 XcObject *xc = (XcObject *)self;
853 uint32_t dom;
854 unsigned long first_pfn, nr_pfns, allow_access, ret;
856 static char *kwd_list[] = { "domid", "first_pfn", "nr_pfns", "allow_access", NULL };
858 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illi", kwd_list,
859 &dom, &first_pfn, &nr_pfns, &allow_access) )
860 return NULL;
862 ret = xc_domain_iomem_permission(
863 xc->xc_handle, dom, first_pfn, nr_pfns, allow_access);
864 if ( ret != 0 )
865 return pyxc_error_to_exception();
867 Py_INCREF(zero);
868 return zero;
869 }
871 static PyObject *pyxc_domain_set_time_offset(XcObject *self, PyObject *args)
872 {
873 uint32_t dom;
874 int32_t time_offset_seconds;
875 time_t calendar_time;
876 struct tm local_time;
877 struct tm utc_time;
879 if (!PyArg_ParseTuple(args, "i", &dom))
880 return NULL;
882 calendar_time = time(NULL);
883 localtime_r(&calendar_time, &local_time);
884 gmtime_r(&calendar_time, &utc_time);
885 /* set up to get calendar time based on utc_time, with local dst setting */
886 utc_time.tm_isdst = local_time.tm_isdst;
887 time_offset_seconds = (int32_t)difftime(calendar_time, mktime(&utc_time));
889 if (xc_domain_set_time_offset(self->xc_handle, dom, time_offset_seconds) != 0)
890 return NULL;
892 Py_INCREF(zero);
893 return zero;
894 }
896 static PyObject *dom_op(XcObject *self, PyObject *args,
897 int (*fn)(int, uint32_t))
898 {
899 uint32_t dom;
901 if (!PyArg_ParseTuple(args, "i", &dom))
902 return NULL;
904 if (fn(self->xc_handle, dom) != 0)
905 return pyxc_error_to_exception();
907 Py_INCREF(zero);
908 return zero;
909 }
912 static PyMethodDef pyxc_methods[] = {
913 { "handle",
914 (PyCFunction)pyxc_handle,
915 METH_NOARGS, "\n"
916 "Query the xc control interface file descriptor.\n\n"
917 "Returns: [int] file descriptor\n" },
919 { "domain_create",
920 (PyCFunction)pyxc_domain_create,
921 METH_VARARGS | METH_KEYWORDS, "\n"
922 "Create a new domain.\n"
923 " dom [int, 0]: Domain identifier to use (allocated if zero).\n"
924 "Returns: [int] new domain identifier; -1 on error.\n" },
926 { "domain_max_vcpus",
927 (PyCFunction)pyxc_domain_max_vcpus,
928 METH_VARARGS, "\n"
929 "Set the maximum number of VCPUs a domain may create.\n"
930 " dom [int, 0]: Domain identifier to use.\n"
931 " max [int, 0]: New maximum number of VCPUs in domain.\n"
932 "Returns: [int] 0 on success; -1 on error.\n" },
934 { "domain_dumpcore",
935 (PyCFunction)pyxc_domain_dumpcore,
936 METH_VARARGS, "\n"
937 "Dump core of a domain.\n"
938 " dom [int]: Identifier of domain to dump core of.\n"
939 " corefile [string]: Name of corefile to be created.\n\n"
940 "Returns: [int] 0 on success; -1 on error.\n" },
942 { "domain_pause",
943 (PyCFunction)pyxc_domain_pause,
944 METH_VARARGS, "\n"
945 "Temporarily pause execution of a domain.\n"
946 " dom [int]: Identifier of domain to be paused.\n\n"
947 "Returns: [int] 0 on success; -1 on error.\n" },
949 { "domain_unpause",
950 (PyCFunction)pyxc_domain_unpause,
951 METH_VARARGS, "\n"
952 "(Re)start execution of a domain.\n"
953 " dom [int]: Identifier of domain to be unpaused.\n\n"
954 "Returns: [int] 0 on success; -1 on error.\n" },
956 { "domain_destroy",
957 (PyCFunction)pyxc_domain_destroy,
958 METH_VARARGS, "\n"
959 "Destroy a domain.\n"
960 " dom [int]: Identifier of domain to be destroyed.\n\n"
961 "Returns: [int] 0 on success; -1 on error.\n" },
963 { "vcpu_setaffinity",
964 (PyCFunction)pyxc_vcpu_setaffinity,
965 METH_VARARGS | METH_KEYWORDS, "\n"
966 "Pin a VCPU to a specified set CPUs.\n"
967 " dom [int]: Identifier of domain to which VCPU belongs.\n"
968 " vcpu [int, 0]: VCPU being pinned.\n"
969 " cpumap [list, []]: list of usable CPUs.\n\n"
970 "Returns: [int] 0 on success; -1 on error.\n" },
972 { "domain_setcpuweight",
973 (PyCFunction)pyxc_domain_setcpuweight,
974 METH_VARARGS | METH_KEYWORDS, "\n"
975 "Set cpuweight scheduler parameter for domain.\n"
976 " dom [int]: Identifier of domain to be changed.\n"
977 " cpuweight [float, 1]: VCPU being pinned.\n"
978 "Returns: [int] 0 on success; -1 on error.\n" },
980 { "domain_sethandle",
981 (PyCFunction)pyxc_domain_sethandle,
982 METH_VARARGS, "\n"
983 "Set domain's opaque handle.\n"
984 " dom [int]: Identifier of domain.\n"
985 " handle [list of 16 ints]: New opaque handle.\n"
986 "Returns: [int] 0 on success; -1 on error.\n" },
988 { "domain_getinfo",
989 (PyCFunction)pyxc_domain_getinfo,
990 METH_VARARGS | METH_KEYWORDS, "\n"
991 "Get information regarding a set of domains, in increasing id order.\n"
992 " first_dom [int, 0]: First domain to retrieve info about.\n"
993 " max_doms [int, 1024]: Maximum number of domains to retrieve info"
994 " about.\n\n"
995 "Returns: [list of dicts] if list length is less than 'max_doms'\n"
996 " parameter then there was an error, or the end of the\n"
997 " domain-id space was reached.\n"
998 " dom [int]: Identifier of domain to which this info pertains\n"
999 " cpu [int]: CPU to which this domain is bound\n"
1000 " vcpus [int]: Number of Virtual CPUS in this domain\n"
1001 " dying [int]: Bool - is the domain dying?\n"
1002 " crashed [int]: Bool - has the domain crashed?\n"
1003 " shutdown [int]: Bool - has the domain shut itself down?\n"
1004 " paused [int]: Bool - is the domain paused by control software?\n"
1005 " blocked [int]: Bool - is the domain blocked waiting for an event?\n"
1006 " running [int]: Bool - is the domain currently running?\n"
1007 " mem_kb [int]: Memory reservation, in kilobytes\n"
1008 " maxmem_kb [int]: Maximum memory limit, in kilobytes\n"
1009 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
1010 " shutdown_reason [int]: Numeric code from guest OS, explaining "
1011 "reason why it shut itself down.\n" },
1013 { "vcpu_getinfo",
1014 (PyCFunction)pyxc_vcpu_getinfo,
1015 METH_VARARGS | METH_KEYWORDS, "\n"
1016 "Get information regarding a VCPU.\n"
1017 " dom [int]: Domain to retrieve info about.\n"
1018 " vcpu [int, 0]: VCPU to retrieve info about.\n\n"
1019 "Returns: [dict]\n"
1020 " online [int]: Bool - Is this VCPU currently online?\n"
1021 " blocked [int]: Bool - Is this VCPU blocked waiting for an event?\n"
1022 " running [int]: Bool - Is this VCPU currently running on a CPU?\n"
1023 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
1024 " cpumap [int]: Bitmap of CPUs this VCPU can run on\n"
1025 " cpu [int]: CPU that this VCPU is currently bound to\n" },
1027 { "linux_build",
1028 (PyCFunction)pyxc_linux_build,
1029 METH_VARARGS | METH_KEYWORDS, "\n"
1030 "Build a new Linux guest OS.\n"
1031 " dom [int]: Identifier of domain to build into.\n"
1032 " image [str]: Name of kernel image file. May be gzipped.\n"
1033 " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
1034 " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
1035 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
1036 "Returns: [int] 0 on success; -1 on error.\n" },
1038 { "hvm_build",
1039 (PyCFunction)pyxc_hvm_build,
1040 METH_VARARGS | METH_KEYWORDS, "\n"
1041 "Build a new HVM guest OS.\n"
1042 " dom [int]: Identifier of domain to build into.\n"
1043 " image [str]: Name of HVM loader image file.\n"
1044 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
1045 "Returns: [int] 0 on success; -1 on error.\n" },
1047 { "sched_id_get",
1048 (PyCFunction)pyxc_sched_id_get,
1049 METH_NOARGS, "\n"
1050 "Get the current scheduler type in use.\n"
1051 "Returns: [int] sched_id.\n" },
1053 { "sedf_domain_set",
1054 (PyCFunction)pyxc_sedf_domain_set,
1055 METH_KEYWORDS, "\n"
1056 "Set the scheduling parameters for a domain when running with Atropos.\n"
1057 " dom [int]: domain to set\n"
1058 " period [long]: domain's scheduling period\n"
1059 " slice [long]: domain's slice per period\n"
1060 " latency [long]: domain's wakeup latency hint\n"
1061 " extratime [int]: domain aware of extratime?\n"
1062 "Returns: [int] 0 on success; -1 on error.\n" },
1064 { "sedf_domain_get",
1065 (PyCFunction)pyxc_sedf_domain_get,
1066 METH_VARARGS, "\n"
1067 "Get the current scheduling parameters for a domain when running with\n"
1068 "the Atropos scheduler."
1069 " dom [int]: domain to query\n"
1070 "Returns: [dict]\n"
1071 " domain [int]: domain ID\n"
1072 " period [long]: scheduler period\n"
1073 " slice [long]: CPU reservation per period\n"
1074 " latency [long]: domain's wakeup latency hint\n"
1075 " extratime [int]: domain aware of extratime?\n"},
1077 { "sched_credit_domain_set",
1078 (PyCFunction)pyxc_sched_credit_domain_set,
1079 METH_KEYWORDS, "\n"
1080 "Set the scheduling parameters for a domain when running with the\n"
1081 "SMP credit scheduler.\n"
1082 " domid [int]: domain id to set\n"
1083 " weight [short]: domain's scheduling weight\n"
1084 "Returns: [int] 0 on success; -1 on error.\n" },
1086 { "sched_credit_domain_get",
1087 (PyCFunction)pyxc_sched_credit_domain_get,
1088 METH_VARARGS, "\n"
1089 "Get the scheduling parameters for a domain when running with the\n"
1090 "SMP credit scheduler.\n"
1091 " domid [int]: domain id to get\n"
1092 "Returns: [dict]\n"
1093 " weight [short]: domain's scheduling weight\n"},
1095 { "evtchn_alloc_unbound",
1096 (PyCFunction)pyxc_evtchn_alloc_unbound,
1097 METH_VARARGS | METH_KEYWORDS, "\n"
1098 "Allocate an unbound port that will await a remote connection.\n"
1099 " dom [int]: Domain whose port space to allocate from.\n"
1100 " remote_dom [int]: Remote domain to accept connections from.\n\n"
1101 "Returns: [int] Unbound event-channel port.\n" },
1103 { "physdev_pci_access_modify",
1104 (PyCFunction)pyxc_physdev_pci_access_modify,
1105 METH_VARARGS | METH_KEYWORDS, "\n"
1106 "Allow a domain access to a PCI device\n"
1107 " dom [int]: Identifier of domain to be allowed access.\n"
1108 " bus [int]: PCI bus\n"
1109 " dev [int]: PCI slot\n"
1110 " func [int]: PCI function\n"
1111 " enable [int]: Non-zero means enable access; else disable access\n\n"
1112 "Returns: [int] 0 on success; -1 on error.\n" },
1114 { "readconsolering",
1115 (PyCFunction)pyxc_readconsolering,
1116 METH_VARARGS | METH_KEYWORDS, "\n"
1117 "Read Xen's console ring.\n"
1118 " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
1119 "Returns: [str] string is empty on failure.\n" },
1121 { "physinfo",
1122 (PyCFunction)pyxc_physinfo,
1123 METH_NOARGS, "\n"
1124 "Get information about the physical host machine\n"
1125 "Returns [dict]: information about the hardware"
1126 " [None]: on failure.\n" },
1128 { "xeninfo",
1129 (PyCFunction)pyxc_xeninfo,
1130 METH_NOARGS, "\n"
1131 "Get information about the Xen host\n"
1132 "Returns [dict]: information about Xen"
1133 " [None]: on failure.\n" },
1135 { "shadow_control",
1136 (PyCFunction)pyxc_shadow_control,
1137 METH_VARARGS | METH_KEYWORDS, "\n"
1138 "Set parameter for shadow pagetable interface\n"
1139 " dom [int]: Identifier of domain.\n"
1140 " op [int, 0]: operation\n\n"
1141 "Returns: [int] 0 on success; -1 on error.\n" },
1143 { "shadow_mem_control",
1144 (PyCFunction)pyxc_shadow_mem_control,
1145 METH_VARARGS | METH_KEYWORDS, "\n"
1146 "Set or read shadow pagetable memory use\n"
1147 " dom [int]: Identifier of domain.\n"
1148 " mb [int, -1]: MB of shadow memory this domain should have.\n\n"
1149 "Returns: [int] MB of shadow memory in use by this domain.\n" },
1151 { "domain_setmaxmem",
1152 (PyCFunction)pyxc_domain_setmaxmem,
1153 METH_VARARGS, "\n"
1154 "Set a domain's memory limit\n"
1155 " dom [int]: Identifier of domain.\n"
1156 " maxmem_kb [int]: .\n"
1157 "Returns: [int] 0 on success; -1 on error.\n" },
1159 { "domain_set_memmap_limit",
1160 (PyCFunction)pyxc_domain_set_memmap_limit,
1161 METH_VARARGS, "\n"
1162 "Set a domain's physical memory mappping limit\n"
1163 " dom [int]: Identifier of domain.\n"
1164 " map_limitkb [int]: .\n"
1165 "Returns: [int] 0 on success; -1 on error.\n" },
1167 { "domain_memory_increase_reservation",
1168 (PyCFunction)pyxc_domain_memory_increase_reservation,
1169 METH_VARARGS | METH_KEYWORDS, "\n"
1170 "Increase a domain's memory reservation\n"
1171 " dom [int]: Identifier of domain.\n"
1172 " mem_kb [long]: .\n"
1173 "Returns: [int] 0 on success; -1 on error.\n" },
1175 { "domain_ioport_permission",
1176 (PyCFunction)pyxc_domain_ioport_permission,
1177 METH_VARARGS | METH_KEYWORDS, "\n"
1178 "Allow a domain access to a range of IO ports\n"
1179 " dom [int]: Identifier of domain to be allowed access.\n"
1180 " first_port [int]: First IO port\n"
1181 " nr_ports [int]: Number of IO ports\n"
1182 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1183 "Returns: [int] 0 on success; -1 on error.\n" },
1185 { "domain_irq_permission",
1186 (PyCFunction)pyxc_domain_irq_permission,
1187 METH_VARARGS | METH_KEYWORDS, "\n"
1188 "Allow a domain access to a physical IRQ\n"
1189 " dom [int]: Identifier of domain to be allowed access.\n"
1190 " pirq [int]: The Physical IRQ\n"
1191 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1192 "Returns: [int] 0 on success; -1 on error.\n" },
1194 { "domain_iomem_permission",
1195 (PyCFunction)pyxc_domain_iomem_permission,
1196 METH_VARARGS | METH_KEYWORDS, "\n"
1197 "Allow a domain access to a range of IO memory pages\n"
1198 " dom [int]: Identifier of domain to be allowed access.\n"
1199 " first_pfn [long]: First page of I/O Memory\n"
1200 " nr_pfns [long]: Number of pages of I/O Memory (>0)\n"
1201 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1202 "Returns: [int] 0 on success; -1 on error.\n" },
1204 { "pages_to_kib",
1205 (PyCFunction)pyxc_pages_to_kib,
1206 METH_VARARGS, "\n"
1207 "Returns: [int]: The size in KiB of memory spanning the given number "
1208 "of pages.\n" },
1210 { "domain_set_time_offset",
1211 (PyCFunction)pyxc_domain_set_time_offset,
1212 METH_VARARGS, "\n"
1213 "Set a domain's time offset to Dom0's localtime\n"
1214 " dom [int]: Domain whose time offset is being set.\n"
1215 "Returns: [int] 0 on success; -1 on error.\n" },
1217 { NULL, NULL, 0, NULL }
1218 };
1221 static PyObject *PyXc_getattr(PyObject *obj, char *name)
1223 return Py_FindMethod(pyxc_methods, obj, name);
1226 static PyObject *PyXc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1228 XcObject *self = (XcObject *)type->tp_alloc(type, 0);
1230 if (self == NULL)
1231 return NULL;
1233 self->xc_handle = -1;
1235 return (PyObject *)self;
1238 static int
1239 PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
1241 if ((self->xc_handle = xc_interface_open()) == -1) {
1242 pyxc_error_to_exception();
1243 return -1;
1246 return 0;
1249 static void PyXc_dealloc(XcObject *self)
1251 if (self->xc_handle != -1) {
1252 xc_interface_close(self->xc_handle);
1253 self->xc_handle = -1;
1256 self->ob_type->tp_free((PyObject *)self);
1259 static PyTypeObject PyXcType = {
1260 PyObject_HEAD_INIT(NULL)
1261 0,
1262 PKG "." CLS,
1263 sizeof(XcObject),
1264 0,
1265 (destructor)PyXc_dealloc, /* tp_dealloc */
1266 NULL, /* tp_print */
1267 PyXc_getattr, /* tp_getattr */
1268 NULL, /* tp_setattr */
1269 NULL, /* tp_compare */
1270 NULL, /* tp_repr */
1271 NULL, /* tp_as_number */
1272 NULL, /* tp_as_sequence */
1273 NULL, /* tp_as_mapping */
1274 NULL, /* tp_hash */
1275 NULL, /* tp_call */
1276 NULL, /* tp_str */
1277 NULL, /* tp_getattro */
1278 NULL, /* tp_setattro */
1279 NULL, /* tp_as_buffer */
1280 Py_TPFLAGS_DEFAULT, /* tp_flags */
1281 "Xen client connections", /* tp_doc */
1282 NULL, /* tp_traverse */
1283 NULL, /* tp_clear */
1284 NULL, /* tp_richcompare */
1285 0, /* tp_weaklistoffset */
1286 NULL, /* tp_iter */
1287 NULL, /* tp_iternext */
1288 pyxc_methods, /* tp_methods */
1289 NULL, /* tp_members */
1290 NULL, /* tp_getset */
1291 NULL, /* tp_base */
1292 NULL, /* tp_dict */
1293 NULL, /* tp_descr_get */
1294 NULL, /* tp_descr_set */
1295 0, /* tp_dictoffset */
1296 (initproc)PyXc_init, /* tp_init */
1297 NULL, /* tp_alloc */
1298 PyXc_new, /* tp_new */
1299 };
1301 static PyMethodDef xc_methods[] = { { NULL } };
1303 PyMODINIT_FUNC initxc(void)
1305 PyObject *m;
1307 if (PyType_Ready(&PyXcType) < 0)
1308 return;
1310 m = Py_InitModule(PKG, xc_methods);
1312 if (m == NULL)
1313 return;
1315 xc_error_obj = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
1316 zero = PyInt_FromLong(0);
1318 /* KAF: This ensures that we get debug output in a timely manner. */
1319 setbuf(stdout, NULL);
1320 setbuf(stderr, NULL);
1322 Py_INCREF(&PyXcType);
1323 PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
1325 Py_INCREF(xc_error_obj);
1326 PyModule_AddObject(m, "Error", xc_error_obj);
1328 /* Expose some libxc constants to Python */
1329 PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF);
1330 PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT);
1335 /*
1336 * Local variables:
1337 * c-indent-level: 4
1338 * c-basic-offset: 4
1339 * End:
1340 */