ia64/xen-unstable

view tools/python/xen/lowlevel/xc/xc.c @ 13931:3773af71a14b

[TOOLS][POWERPC] fixes for the prose builder.

Signed-off-by: Maria Butrico <butrico@watson.ibm.com>
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
author Jimi Xenidis <jimix@watson.ibm.com>
date Wed Jan 17 19:37:20 2007 -0500 (2007-01-17)
parents a23587ebcbf6
children 09b3fd488726
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 #if !defined(__ia64__)
395 struct hvm_info_table *va_hvm;
396 uint8_t *va_map, sum;
397 int i;
398 #endif
399 char *image;
400 int store_evtchn, memsize, vcpus = 1, pae = 0, acpi = 0, apic = 1;
401 unsigned long store_mfn;
403 static char *kwd_list[] = { "domid", "store_evtchn",
404 "memsize", "image", "vcpus", "pae", "acpi",
405 "apic", NULL };
406 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|iiii", kwd_list,
407 &dom, &store_evtchn, &memsize,
408 &image, &vcpus, &pae, &acpi, &apic) )
409 return NULL;
411 if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )
412 return pyxc_error_to_exception();
414 #if !defined(__ia64__)
415 /* Set up the HVM info table. */
416 va_map = xc_map_foreign_range(self->xc_handle, dom, XC_PAGE_SIZE,
417 PROT_READ | PROT_WRITE,
418 HVM_INFO_PFN);
419 if ( va_map == NULL )
420 return PyErr_SetFromErrno(xc_error_obj);
421 va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
422 memset(va_hvm, 0, sizeof(*va_hvm));
423 strncpy(va_hvm->signature, "HVM INFO", 8);
424 va_hvm->length = sizeof(struct hvm_info_table);
425 va_hvm->acpi_enabled = acpi;
426 va_hvm->apic_mode = apic;
427 va_hvm->nr_vcpus = vcpus;
428 for ( i = 0, sum = 0; i < va_hvm->length; i++ )
429 sum += ((uint8_t *)va_hvm)[i];
430 va_hvm->checksum = -sum;
431 munmap(va_map, XC_PAGE_SIZE);
432 #endif
434 xc_get_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_PFN, &store_mfn);
435 #if !defined(__ia64__)
436 xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
437 #endif
438 xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_EVTCHN,
439 store_evtchn);
441 return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
442 }
444 static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,
445 PyObject *args,
446 PyObject *kwds)
447 {
448 uint32_t dom, remote_dom;
449 int port;
451 static char *kwd_list[] = { "domid", "remote_dom", NULL };
453 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
454 &dom, &remote_dom) )
455 return NULL;
457 if ( (port = xc_evtchn_alloc_unbound(self->xc_handle, dom, remote_dom)) < 0 )
458 return pyxc_error_to_exception();
460 return PyInt_FromLong(port);
461 }
463 static PyObject *pyxc_physdev_pci_access_modify(XcObject *self,
464 PyObject *args,
465 PyObject *kwds)
466 {
467 uint32_t dom;
468 int bus, dev, func, enable, ret;
470 static char *kwd_list[] = { "domid", "bus", "dev", "func", "enable", NULL };
472 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiii", kwd_list,
473 &dom, &bus, &dev, &func, &enable) )
474 return NULL;
476 ret = xc_physdev_pci_access_modify(
477 self->xc_handle, dom, bus, dev, func, enable);
478 if ( ret != 0 )
479 return pyxc_error_to_exception();
481 Py_INCREF(zero);
482 return zero;
483 }
485 static PyObject *pyxc_readconsolering(XcObject *self,
486 PyObject *args,
487 PyObject *kwds)
488 {
489 unsigned int clear = 0;
490 char _str[32768], *str = _str;
491 unsigned int count = 32768;
492 int ret;
494 static char *kwd_list[] = { "clear", NULL };
496 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &clear) )
497 return NULL;
499 ret = xc_readconsolering(self->xc_handle, &str, &count, clear);
500 if ( ret < 0 )
501 return pyxc_error_to_exception();
503 return PyString_FromStringAndSize(str, count);
504 }
507 static unsigned long pages_to_kib(unsigned long pages)
508 {
509 return pages * (XC_PAGE_SIZE / 1024);
510 }
513 static PyObject *pyxc_pages_to_kib(XcObject *self, PyObject *args)
514 {
515 unsigned long pages;
517 if (!PyArg_ParseTuple(args, "l", &pages))
518 return NULL;
520 return PyLong_FromUnsignedLong(pages_to_kib(pages));
521 }
524 static PyObject *pyxc_physinfo(XcObject *self)
525 {
526 xc_physinfo_t info;
527 char cpu_cap[128], *p=cpu_cap, *q=cpu_cap;
528 int i;
530 if ( xc_physinfo(self->xc_handle, &info) != 0 )
531 return pyxc_error_to_exception();
533 *q=0;
534 for(i=0;i<sizeof(info.hw_cap)/4;i++)
535 {
536 p+=sprintf(p,"%08x:",info.hw_cap[i]);
537 if(info.hw_cap[i])
538 q=p;
539 }
540 if(q>cpu_cap)
541 *(q-1)=0;
543 return Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s}",
544 "threads_per_core", info.threads_per_core,
545 "cores_per_socket", info.cores_per_socket,
546 "sockets_per_node", info.sockets_per_node,
547 "nr_nodes", info.nr_nodes,
548 "total_memory", pages_to_kib(info.total_pages),
549 "free_memory", pages_to_kib(info.free_pages),
550 "scrub_memory", pages_to_kib(info.scrub_pages),
551 "cpu_khz", info.cpu_khz,
552 "hw_caps", cpu_cap);
553 }
555 static PyObject *pyxc_xeninfo(XcObject *self)
556 {
557 xen_extraversion_t xen_extra;
558 xen_compile_info_t xen_cc;
559 xen_changeset_info_t xen_chgset;
560 xen_capabilities_info_t xen_caps;
561 xen_platform_parameters_t p_parms;
562 long xen_version;
563 long xen_pagesize;
564 char str[128];
566 xen_version = xc_version(self->xc_handle, XENVER_version, NULL);
568 if ( xc_version(self->xc_handle, XENVER_extraversion, &xen_extra) != 0 )
569 return pyxc_error_to_exception();
571 if ( xc_version(self->xc_handle, XENVER_compile_info, &xen_cc) != 0 )
572 return pyxc_error_to_exception();
574 if ( xc_version(self->xc_handle, XENVER_changeset, &xen_chgset) != 0 )
575 return pyxc_error_to_exception();
577 if ( xc_version(self->xc_handle, XENVER_capabilities, &xen_caps) != 0 )
578 return pyxc_error_to_exception();
580 if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 )
581 return pyxc_error_to_exception();
583 sprintf(str, "virt_start=0x%lx", p_parms.virt_start);
585 xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL);
586 if (xen_pagesize < 0 )
587 return pyxc_error_to_exception();
589 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}",
590 "xen_major", xen_version >> 16,
591 "xen_minor", (xen_version & 0xffff),
592 "xen_extra", xen_extra,
593 "xen_caps", xen_caps,
594 "xen_pagesize", xen_pagesize,
595 "platform_params", str,
596 "xen_changeset", xen_chgset,
597 "cc_compiler", xen_cc.compiler,
598 "cc_compile_by", xen_cc.compile_by,
599 "cc_compile_domain", xen_cc.compile_domain,
600 "cc_compile_date", xen_cc.compile_date);
601 }
604 static PyObject *pyxc_sedf_domain_set(XcObject *self,
605 PyObject *args,
606 PyObject *kwds)
607 {
608 uint32_t domid;
609 uint64_t period, slice, latency;
610 uint16_t extratime, weight;
611 static char *kwd_list[] = { "domid", "period", "slice",
612 "latency", "extratime", "weight",NULL };
614 if( !PyArg_ParseTupleAndKeywords(args, kwds, "iLLLhh", kwd_list,
615 &domid, &period, &slice,
616 &latency, &extratime, &weight) )
617 return NULL;
618 if ( xc_sedf_domain_set(self->xc_handle, domid, period,
619 slice, latency, extratime,weight) != 0 )
620 return pyxc_error_to_exception();
622 Py_INCREF(zero);
623 return zero;
624 }
626 static PyObject *pyxc_sedf_domain_get(XcObject *self, PyObject *args)
627 {
628 uint32_t domid;
629 uint64_t period, slice,latency;
630 uint16_t weight, extratime;
632 if(!PyArg_ParseTuple(args, "i", &domid))
633 return NULL;
635 if (xc_sedf_domain_get(self->xc_handle, domid, &period,
636 &slice,&latency,&extratime,&weight))
637 return pyxc_error_to_exception();
639 return Py_BuildValue("{s:i,s:L,s:L,s:L,s:i,s:i}",
640 "domid", domid,
641 "period", period,
642 "slice", slice,
643 "latency", latency,
644 "extratime", extratime,
645 "weight", weight);
646 }
648 static PyObject *pyxc_shadow_control(PyObject *self,
649 PyObject *args,
650 PyObject *kwds)
651 {
652 XcObject *xc = (XcObject *)self;
654 uint32_t dom;
655 int op=0;
657 static char *kwd_list[] = { "dom", "op", NULL };
659 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
660 &dom, &op) )
661 return NULL;
663 if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, NULL, 0, NULL)
664 < 0 )
665 return pyxc_error_to_exception();
667 Py_INCREF(zero);
668 return zero;
669 }
671 static PyObject *pyxc_shadow_mem_control(PyObject *self,
672 PyObject *args,
673 PyObject *kwds)
674 {
675 XcObject *xc = (XcObject *)self;
676 int op;
677 uint32_t dom;
678 int mbarg = -1;
679 unsigned long mb;
681 static char *kwd_list[] = { "dom", "mb", NULL };
683 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
684 &dom, &mbarg) )
685 return NULL;
687 if ( mbarg < 0 )
688 op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
689 else
690 {
691 mb = mbarg;
692 op = XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION;
693 }
694 if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, &mb, 0, NULL) < 0 )
695 return pyxc_error_to_exception();
697 mbarg = mb;
698 return Py_BuildValue("i", mbarg);
699 }
701 static PyObject *pyxc_sched_id_get(XcObject *self) {
703 int sched_id;
704 if (xc_sched_id(self->xc_handle, &sched_id) != 0)
705 return PyErr_SetFromErrno(xc_error_obj);
707 return Py_BuildValue("i", sched_id);
708 }
710 static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
711 PyObject *args,
712 PyObject *kwds)
713 {
714 uint32_t domid;
715 uint16_t weight;
716 uint16_t cap;
717 static char *kwd_list[] = { "domid", "weight", "cap", NULL };
718 static char kwd_type[] = "I|HH";
719 struct xen_domctl_sched_credit sdom;
721 weight = 0;
722 cap = (uint16_t)~0U;
723 if( !PyArg_ParseTupleAndKeywords(args, kwds, kwd_type, kwd_list,
724 &domid, &weight, &cap) )
725 return NULL;
727 sdom.weight = weight;
728 sdom.cap = cap;
730 if ( xc_sched_credit_domain_set(self->xc_handle, domid, &sdom) != 0 )
731 return pyxc_error_to_exception();
733 Py_INCREF(zero);
734 return zero;
735 }
737 static PyObject *pyxc_sched_credit_domain_get(XcObject *self, PyObject *args)
738 {
739 uint32_t domid;
740 struct xen_domctl_sched_credit sdom;
742 if( !PyArg_ParseTuple(args, "I", &domid) )
743 return NULL;
745 if ( xc_sched_credit_domain_get(self->xc_handle, domid, &sdom) != 0 )
746 return pyxc_error_to_exception();
748 return Py_BuildValue("{s:H,s:H}",
749 "weight", sdom.weight,
750 "cap", sdom.cap);
751 }
753 static PyObject *pyxc_domain_setmaxmem(XcObject *self, PyObject *args)
754 {
755 uint32_t dom;
756 unsigned int maxmem_kb;
758 if (!PyArg_ParseTuple(args, "ii", &dom, &maxmem_kb))
759 return NULL;
761 if (xc_domain_setmaxmem(self->xc_handle, dom, maxmem_kb) != 0)
762 return pyxc_error_to_exception();
764 Py_INCREF(zero);
765 return zero;
766 }
768 static PyObject *pyxc_domain_set_memmap_limit(XcObject *self, PyObject *args)
769 {
770 uint32_t dom;
771 unsigned int maplimit_kb;
773 if ( !PyArg_ParseTuple(args, "ii", &dom, &maplimit_kb) )
774 return NULL;
776 if ( xc_domain_set_memmap_limit(self->xc_handle, dom, maplimit_kb) != 0 )
777 return pyxc_error_to_exception();
779 Py_INCREF(zero);
780 return zero;
781 }
783 static PyObject *pyxc_domain_memory_increase_reservation(XcObject *self,
784 PyObject *args,
785 PyObject *kwds)
786 {
787 uint32_t dom;
788 unsigned long mem_kb;
789 unsigned int extent_order = 0 , address_bits = 0;
790 unsigned long nr_extents;
792 static char *kwd_list[] = { "domid", "mem_kb", "extent_order", "address_bits", NULL };
794 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "il|ii", kwd_list,
795 &dom, &mem_kb, &extent_order, &address_bits) )
796 return NULL;
798 /* round down to nearest power of 2. Assume callers using extent_order>0
799 know what they are doing */
800 nr_extents = (mem_kb / (XC_PAGE_SIZE/1024)) >> extent_order;
801 if ( xc_domain_memory_increase_reservation(self->xc_handle, dom,
802 nr_extents, extent_order,
803 address_bits, NULL) )
804 return pyxc_error_to_exception();
806 Py_INCREF(zero);
807 return zero;
808 }
810 static PyObject *pyxc_domain_ioport_permission(XcObject *self,
811 PyObject *args,
812 PyObject *kwds)
813 {
814 uint32_t dom;
815 int first_port, nr_ports, allow_access, ret;
817 static char *kwd_list[] = { "domid", "first_port", "nr_ports", "allow_access", NULL };
819 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiii", kwd_list,
820 &dom, &first_port, &nr_ports, &allow_access) )
821 return NULL;
823 ret = xc_domain_ioport_permission(
824 self->xc_handle, dom, first_port, nr_ports, allow_access);
825 if ( ret != 0 )
826 return pyxc_error_to_exception();
828 Py_INCREF(zero);
829 return zero;
830 }
832 static PyObject *pyxc_domain_irq_permission(PyObject *self,
833 PyObject *args,
834 PyObject *kwds)
835 {
836 XcObject *xc = (XcObject *)self;
837 uint32_t dom;
838 int pirq, allow_access, ret;
840 static char *kwd_list[] = { "domid", "pirq", "allow_access", NULL };
842 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list,
843 &dom, &pirq, &allow_access) )
844 return NULL;
846 ret = xc_domain_irq_permission(
847 xc->xc_handle, dom, pirq, allow_access);
848 if ( ret != 0 )
849 return pyxc_error_to_exception();
851 Py_INCREF(zero);
852 return zero;
853 }
855 static PyObject *pyxc_domain_iomem_permission(PyObject *self,
856 PyObject *args,
857 PyObject *kwds)
858 {
859 XcObject *xc = (XcObject *)self;
860 uint32_t dom;
861 unsigned long first_pfn, nr_pfns, allow_access, ret;
863 static char *kwd_list[] = { "domid", "first_pfn", "nr_pfns", "allow_access", NULL };
865 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illi", kwd_list,
866 &dom, &first_pfn, &nr_pfns, &allow_access) )
867 return NULL;
869 ret = xc_domain_iomem_permission(
870 xc->xc_handle, dom, first_pfn, nr_pfns, allow_access);
871 if ( ret != 0 )
872 return pyxc_error_to_exception();
874 Py_INCREF(zero);
875 return zero;
876 }
878 static PyObject *pyxc_domain_set_time_offset(XcObject *self, PyObject *args)
879 {
880 uint32_t dom;
881 int32_t time_offset_seconds;
882 time_t calendar_time;
883 struct tm local_time;
884 struct tm utc_time;
886 if (!PyArg_ParseTuple(args, "i", &dom))
887 return NULL;
889 calendar_time = time(NULL);
890 localtime_r(&calendar_time, &local_time);
891 gmtime_r(&calendar_time, &utc_time);
892 /* set up to get calendar time based on utc_time, with local dst setting */
893 utc_time.tm_isdst = local_time.tm_isdst;
894 time_offset_seconds = (int32_t)difftime(calendar_time, mktime(&utc_time));
896 if (xc_domain_set_time_offset(self->xc_handle, dom, time_offset_seconds) != 0)
897 return NULL;
899 Py_INCREF(zero);
900 return zero;
901 }
903 static PyObject *dom_op(XcObject *self, PyObject *args,
904 int (*fn)(int, uint32_t))
905 {
906 uint32_t dom;
908 if (!PyArg_ParseTuple(args, "i", &dom))
909 return NULL;
911 if (fn(self->xc_handle, dom) != 0)
912 return pyxc_error_to_exception();
914 Py_INCREF(zero);
915 return zero;
916 }
918 #ifdef __powerpc__
919 static PyObject *pyxc_alloc_real_mode_area(XcObject *self,
920 PyObject *args,
921 PyObject *kwds)
922 {
923 uint32_t dom;
924 unsigned int log;
926 static char *kwd_list[] = { "dom", "log", NULL };
928 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
929 &dom, &log) )
930 return NULL;
932 if ( xc_alloc_real_mode_area(self->xc_handle, dom, log) )
933 return pyxc_error_to_exception();
935 Py_INCREF(zero);
936 return zero;
937 }
939 static PyObject *pyxc_prose_build(XcObject *self,
940 PyObject *args,
941 PyObject *kwds)
942 {
943 uint32_t dom;
944 char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
945 int flags = 0;
946 int store_evtchn, console_evtchn;
947 unsigned int mem_mb;
948 unsigned long store_mfn = 0;
949 unsigned long console_mfn = 0;
950 void *arch_args = NULL;
951 int unused;
953 static char *kwd_list[] = { "dom", "store_evtchn",
954 "console_evtchn", "image", "memsize",
955 /* optional */
956 "ramdisk", "cmdline", "flags",
957 "features", "arch_args", NULL };
959 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssiss#", kwd_list,
960 &dom, &store_evtchn, &mem_mb,
961 &console_evtchn, &image,
962 /* optional */
963 &ramdisk, &cmdline, &flags,
964 &features, &arch_args, &unused) )
965 return NULL;
967 if ( xc_prose_build(self->xc_handle, dom, mem_mb, image,
968 ramdisk, cmdline, features, flags,
969 store_evtchn, &store_mfn,
970 console_evtchn, &console_mfn,
971 arch_args) != 0 ) {
972 if (!errno)
973 errno = EINVAL;
974 return pyxc_error_to_exception();
975 }
976 return Py_BuildValue("{s:i,s:i}",
977 "store_mfn", store_mfn,
978 "console_mfn", console_mfn);
979 }
980 #endif /* powerpc */
982 static PyMethodDef pyxc_methods[] = {
983 { "handle",
984 (PyCFunction)pyxc_handle,
985 METH_NOARGS, "\n"
986 "Query the xc control interface file descriptor.\n\n"
987 "Returns: [int] file descriptor\n" },
989 { "domain_create",
990 (PyCFunction)pyxc_domain_create,
991 METH_VARARGS | METH_KEYWORDS, "\n"
992 "Create a new domain.\n"
993 " dom [int, 0]: Domain identifier to use (allocated if zero).\n"
994 "Returns: [int] new domain identifier; -1 on error.\n" },
996 { "domain_max_vcpus",
997 (PyCFunction)pyxc_domain_max_vcpus,
998 METH_VARARGS, "\n"
999 "Set the maximum number of VCPUs a domain may create.\n"
1000 " dom [int, 0]: Domain identifier to use.\n"
1001 " max [int, 0]: New maximum number of VCPUs in domain.\n"
1002 "Returns: [int] 0 on success; -1 on error.\n" },
1004 { "domain_dumpcore",
1005 (PyCFunction)pyxc_domain_dumpcore,
1006 METH_VARARGS, "\n"
1007 "Dump core of a domain.\n"
1008 " dom [int]: Identifier of domain to dump core of.\n"
1009 " corefile [string]: Name of corefile to be created.\n\n"
1010 "Returns: [int] 0 on success; -1 on error.\n" },
1012 { "domain_pause",
1013 (PyCFunction)pyxc_domain_pause,
1014 METH_VARARGS, "\n"
1015 "Temporarily pause execution of a domain.\n"
1016 " dom [int]: Identifier of domain to be paused.\n\n"
1017 "Returns: [int] 0 on success; -1 on error.\n" },
1019 { "domain_unpause",
1020 (PyCFunction)pyxc_domain_unpause,
1021 METH_VARARGS, "\n"
1022 "(Re)start execution of a domain.\n"
1023 " dom [int]: Identifier of domain to be unpaused.\n\n"
1024 "Returns: [int] 0 on success; -1 on error.\n" },
1026 { "domain_destroy",
1027 (PyCFunction)pyxc_domain_destroy,
1028 METH_VARARGS, "\n"
1029 "Destroy a domain.\n"
1030 " dom [int]: Identifier of domain to be destroyed.\n\n"
1031 "Returns: [int] 0 on success; -1 on error.\n" },
1033 { "vcpu_setaffinity",
1034 (PyCFunction)pyxc_vcpu_setaffinity,
1035 METH_VARARGS | METH_KEYWORDS, "\n"
1036 "Pin a VCPU to a specified set CPUs.\n"
1037 " dom [int]: Identifier of domain to which VCPU belongs.\n"
1038 " vcpu [int, 0]: VCPU being pinned.\n"
1039 " cpumap [list, []]: list of usable CPUs.\n\n"
1040 "Returns: [int] 0 on success; -1 on error.\n" },
1042 { "domain_setcpuweight",
1043 (PyCFunction)pyxc_domain_setcpuweight,
1044 METH_VARARGS | METH_KEYWORDS, "\n"
1045 "Set cpuweight scheduler parameter for domain.\n"
1046 " dom [int]: Identifier of domain to be changed.\n"
1047 " cpuweight [float, 1]: VCPU being pinned.\n"
1048 "Returns: [int] 0 on success; -1 on error.\n" },
1050 { "domain_sethandle",
1051 (PyCFunction)pyxc_domain_sethandle,
1052 METH_VARARGS, "\n"
1053 "Set domain's opaque handle.\n"
1054 " dom [int]: Identifier of domain.\n"
1055 " handle [list of 16 ints]: New opaque handle.\n"
1056 "Returns: [int] 0 on success; -1 on error.\n" },
1058 { "domain_getinfo",
1059 (PyCFunction)pyxc_domain_getinfo,
1060 METH_VARARGS | METH_KEYWORDS, "\n"
1061 "Get information regarding a set of domains, in increasing id order.\n"
1062 " first_dom [int, 0]: First domain to retrieve info about.\n"
1063 " max_doms [int, 1024]: Maximum number of domains to retrieve info"
1064 " about.\n\n"
1065 "Returns: [list of dicts] if list length is less than 'max_doms'\n"
1066 " parameter then there was an error, or the end of the\n"
1067 " domain-id space was reached.\n"
1068 " dom [int]: Identifier of domain to which this info pertains\n"
1069 " cpu [int]: CPU to which this domain is bound\n"
1070 " vcpus [int]: Number of Virtual CPUS in this domain\n"
1071 " dying [int]: Bool - is the domain dying?\n"
1072 " crashed [int]: Bool - has the domain crashed?\n"
1073 " shutdown [int]: Bool - has the domain shut itself down?\n"
1074 " paused [int]: Bool - is the domain paused by control software?\n"
1075 " blocked [int]: Bool - is the domain blocked waiting for an event?\n"
1076 " running [int]: Bool - is the domain currently running?\n"
1077 " mem_kb [int]: Memory reservation, in kilobytes\n"
1078 " maxmem_kb [int]: Maximum memory limit, in kilobytes\n"
1079 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
1080 " shutdown_reason [int]: Numeric code from guest OS, explaining "
1081 "reason why it shut itself down.\n" },
1083 { "vcpu_getinfo",
1084 (PyCFunction)pyxc_vcpu_getinfo,
1085 METH_VARARGS | METH_KEYWORDS, "\n"
1086 "Get information regarding a VCPU.\n"
1087 " dom [int]: Domain to retrieve info about.\n"
1088 " vcpu [int, 0]: VCPU to retrieve info about.\n\n"
1089 "Returns: [dict]\n"
1090 " online [int]: Bool - Is this VCPU currently online?\n"
1091 " blocked [int]: Bool - Is this VCPU blocked waiting for an event?\n"
1092 " running [int]: Bool - Is this VCPU currently running on a CPU?\n"
1093 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
1094 " cpumap [int]: Bitmap of CPUs this VCPU can run on\n"
1095 " cpu [int]: CPU that this VCPU is currently bound to\n" },
1097 { "linux_build",
1098 (PyCFunction)pyxc_linux_build,
1099 METH_VARARGS | METH_KEYWORDS, "\n"
1100 "Build a new Linux guest OS.\n"
1101 " dom [int]: Identifier of domain to build into.\n"
1102 " image [str]: Name of kernel image file. May be gzipped.\n"
1103 " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
1104 " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
1105 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
1106 "Returns: [int] 0 on success; -1 on error.\n" },
1108 { "hvm_build",
1109 (PyCFunction)pyxc_hvm_build,
1110 METH_VARARGS | METH_KEYWORDS, "\n"
1111 "Build a new HVM guest OS.\n"
1112 " dom [int]: Identifier of domain to build into.\n"
1113 " image [str]: Name of HVM loader image file.\n"
1114 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
1115 "Returns: [int] 0 on success; -1 on error.\n" },
1117 { "sched_id_get",
1118 (PyCFunction)pyxc_sched_id_get,
1119 METH_NOARGS, "\n"
1120 "Get the current scheduler type in use.\n"
1121 "Returns: [int] sched_id.\n" },
1123 { "sedf_domain_set",
1124 (PyCFunction)pyxc_sedf_domain_set,
1125 METH_KEYWORDS, "\n"
1126 "Set the scheduling parameters for a domain when running with Atropos.\n"
1127 " dom [int]: domain to set\n"
1128 " period [long]: domain's scheduling period\n"
1129 " slice [long]: domain's slice per period\n"
1130 " latency [long]: domain's wakeup latency hint\n"
1131 " extratime [int]: domain aware of extratime?\n"
1132 "Returns: [int] 0 on success; -1 on error.\n" },
1134 { "sedf_domain_get",
1135 (PyCFunction)pyxc_sedf_domain_get,
1136 METH_VARARGS, "\n"
1137 "Get the current scheduling parameters for a domain when running with\n"
1138 "the Atropos scheduler."
1139 " dom [int]: domain to query\n"
1140 "Returns: [dict]\n"
1141 " domain [int]: domain ID\n"
1142 " period [long]: scheduler period\n"
1143 " slice [long]: CPU reservation per period\n"
1144 " latency [long]: domain's wakeup latency hint\n"
1145 " extratime [int]: domain aware of extratime?\n"},
1147 { "sched_credit_domain_set",
1148 (PyCFunction)pyxc_sched_credit_domain_set,
1149 METH_KEYWORDS, "\n"
1150 "Set the scheduling parameters for a domain when running with the\n"
1151 "SMP credit scheduler.\n"
1152 " domid [int]: domain id to set\n"
1153 " weight [short]: domain's scheduling weight\n"
1154 "Returns: [int] 0 on success; -1 on error.\n" },
1156 { "sched_credit_domain_get",
1157 (PyCFunction)pyxc_sched_credit_domain_get,
1158 METH_VARARGS, "\n"
1159 "Get the scheduling parameters for a domain when running with the\n"
1160 "SMP credit scheduler.\n"
1161 " domid [int]: domain id to get\n"
1162 "Returns: [dict]\n"
1163 " weight [short]: domain's scheduling weight\n"},
1165 { "evtchn_alloc_unbound",
1166 (PyCFunction)pyxc_evtchn_alloc_unbound,
1167 METH_VARARGS | METH_KEYWORDS, "\n"
1168 "Allocate an unbound port that will await a remote connection.\n"
1169 " dom [int]: Domain whose port space to allocate from.\n"
1170 " remote_dom [int]: Remote domain to accept connections from.\n\n"
1171 "Returns: [int] Unbound event-channel port.\n" },
1173 { "physdev_pci_access_modify",
1174 (PyCFunction)pyxc_physdev_pci_access_modify,
1175 METH_VARARGS | METH_KEYWORDS, "\n"
1176 "Allow a domain access to a PCI device\n"
1177 " dom [int]: Identifier of domain to be allowed access.\n"
1178 " bus [int]: PCI bus\n"
1179 " dev [int]: PCI slot\n"
1180 " func [int]: PCI function\n"
1181 " enable [int]: Non-zero means enable access; else disable access\n\n"
1182 "Returns: [int] 0 on success; -1 on error.\n" },
1184 { "readconsolering",
1185 (PyCFunction)pyxc_readconsolering,
1186 METH_VARARGS | METH_KEYWORDS, "\n"
1187 "Read Xen's console ring.\n"
1188 " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
1189 "Returns: [str] string is empty on failure.\n" },
1191 { "physinfo",
1192 (PyCFunction)pyxc_physinfo,
1193 METH_NOARGS, "\n"
1194 "Get information about the physical host machine\n"
1195 "Returns [dict]: information about the hardware"
1196 " [None]: on failure.\n" },
1198 { "xeninfo",
1199 (PyCFunction)pyxc_xeninfo,
1200 METH_NOARGS, "\n"
1201 "Get information about the Xen host\n"
1202 "Returns [dict]: information about Xen"
1203 " [None]: on failure.\n" },
1205 { "shadow_control",
1206 (PyCFunction)pyxc_shadow_control,
1207 METH_VARARGS | METH_KEYWORDS, "\n"
1208 "Set parameter for shadow pagetable interface\n"
1209 " dom [int]: Identifier of domain.\n"
1210 " op [int, 0]: operation\n\n"
1211 "Returns: [int] 0 on success; -1 on error.\n" },
1213 { "shadow_mem_control",
1214 (PyCFunction)pyxc_shadow_mem_control,
1215 METH_VARARGS | METH_KEYWORDS, "\n"
1216 "Set or read shadow pagetable memory use\n"
1217 " dom [int]: Identifier of domain.\n"
1218 " mb [int, -1]: MB of shadow memory this domain should have.\n\n"
1219 "Returns: [int] MB of shadow memory in use by this domain.\n" },
1221 { "domain_setmaxmem",
1222 (PyCFunction)pyxc_domain_setmaxmem,
1223 METH_VARARGS, "\n"
1224 "Set a domain's memory limit\n"
1225 " dom [int]: Identifier of domain.\n"
1226 " maxmem_kb [int]: .\n"
1227 "Returns: [int] 0 on success; -1 on error.\n" },
1229 { "domain_set_memmap_limit",
1230 (PyCFunction)pyxc_domain_set_memmap_limit,
1231 METH_VARARGS, "\n"
1232 "Set a domain's physical memory mappping limit\n"
1233 " dom [int]: Identifier of domain.\n"
1234 " map_limitkb [int]: .\n"
1235 "Returns: [int] 0 on success; -1 on error.\n" },
1237 { "domain_memory_increase_reservation",
1238 (PyCFunction)pyxc_domain_memory_increase_reservation,
1239 METH_VARARGS | METH_KEYWORDS, "\n"
1240 "Increase a domain's memory reservation\n"
1241 " dom [int]: Identifier of domain.\n"
1242 " mem_kb [long]: .\n"
1243 "Returns: [int] 0 on success; -1 on error.\n" },
1245 { "domain_ioport_permission",
1246 (PyCFunction)pyxc_domain_ioport_permission,
1247 METH_VARARGS | METH_KEYWORDS, "\n"
1248 "Allow a domain access to a range of IO ports\n"
1249 " dom [int]: Identifier of domain to be allowed access.\n"
1250 " first_port [int]: First IO port\n"
1251 " nr_ports [int]: Number of IO ports\n"
1252 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1253 "Returns: [int] 0 on success; -1 on error.\n" },
1255 { "domain_irq_permission",
1256 (PyCFunction)pyxc_domain_irq_permission,
1257 METH_VARARGS | METH_KEYWORDS, "\n"
1258 "Allow a domain access to a physical IRQ\n"
1259 " dom [int]: Identifier of domain to be allowed access.\n"
1260 " pirq [int]: The Physical IRQ\n"
1261 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1262 "Returns: [int] 0 on success; -1 on error.\n" },
1264 { "domain_iomem_permission",
1265 (PyCFunction)pyxc_domain_iomem_permission,
1266 METH_VARARGS | METH_KEYWORDS, "\n"
1267 "Allow a domain access to a range of IO memory pages\n"
1268 " dom [int]: Identifier of domain to be allowed access.\n"
1269 " first_pfn [long]: First page of I/O Memory\n"
1270 " nr_pfns [long]: Number of pages of I/O Memory (>0)\n"
1271 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
1272 "Returns: [int] 0 on success; -1 on error.\n" },
1274 { "pages_to_kib",
1275 (PyCFunction)pyxc_pages_to_kib,
1276 METH_VARARGS, "\n"
1277 "Returns: [int]: The size in KiB of memory spanning the given number "
1278 "of pages.\n" },
1280 { "domain_set_time_offset",
1281 (PyCFunction)pyxc_domain_set_time_offset,
1282 METH_VARARGS, "\n"
1283 "Set a domain's time offset to Dom0's localtime\n"
1284 " dom [int]: Domain whose time offset is being set.\n"
1285 "Returns: [int] 0 on success; -1 on error.\n" },
1287 #ifdef __powerpc__
1288 { "arch_alloc_real_mode_area",
1289 (PyCFunction)pyxc_alloc_real_mode_area,
1290 METH_VARARGS | METH_KEYWORDS, "\n"
1291 "Allocate a domain's real mode area.\n"
1292 " dom [int]: Identifier of domain.\n"
1293 " log [int]: Specifies the area's size.\n"
1294 "Returns: [int] 0 on success; -1 on error.\n" },
1296 { "arch_prose_build",
1297 (PyCFunction)pyxc_prose_build,
1298 METH_VARARGS | METH_KEYWORDS, "\n"
1299 "Build a new Linux guest OS.\n"
1300 " dom [int]: Identifier of domain to build into.\n"
1301 " image [str]: Name of kernel image file. May be gzipped.\n"
1302 " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
1303 " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
1304 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
1305 "Returns: [int] 0 on success; -1 on error.\n" },
1306 #endif /* __powerpc */
1308 { NULL, NULL, 0, NULL }
1309 };
1312 static PyObject *PyXc_getattr(PyObject *obj, char *name)
1314 return Py_FindMethod(pyxc_methods, obj, name);
1317 static PyObject *PyXc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1319 XcObject *self = (XcObject *)type->tp_alloc(type, 0);
1321 if (self == NULL)
1322 return NULL;
1324 self->xc_handle = -1;
1326 return (PyObject *)self;
1329 static int
1330 PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
1332 if ((self->xc_handle = xc_interface_open()) == -1) {
1333 pyxc_error_to_exception();
1334 return -1;
1337 return 0;
1340 static void PyXc_dealloc(XcObject *self)
1342 if (self->xc_handle != -1) {
1343 xc_interface_close(self->xc_handle);
1344 self->xc_handle = -1;
1347 self->ob_type->tp_free((PyObject *)self);
1350 static PyTypeObject PyXcType = {
1351 PyObject_HEAD_INIT(NULL)
1352 0,
1353 PKG "." CLS,
1354 sizeof(XcObject),
1355 0,
1356 (destructor)PyXc_dealloc, /* tp_dealloc */
1357 NULL, /* tp_print */
1358 PyXc_getattr, /* tp_getattr */
1359 NULL, /* tp_setattr */
1360 NULL, /* tp_compare */
1361 NULL, /* tp_repr */
1362 NULL, /* tp_as_number */
1363 NULL, /* tp_as_sequence */
1364 NULL, /* tp_as_mapping */
1365 NULL, /* tp_hash */
1366 NULL, /* tp_call */
1367 NULL, /* tp_str */
1368 NULL, /* tp_getattro */
1369 NULL, /* tp_setattro */
1370 NULL, /* tp_as_buffer */
1371 Py_TPFLAGS_DEFAULT, /* tp_flags */
1372 "Xen client connections", /* tp_doc */
1373 NULL, /* tp_traverse */
1374 NULL, /* tp_clear */
1375 NULL, /* tp_richcompare */
1376 0, /* tp_weaklistoffset */
1377 NULL, /* tp_iter */
1378 NULL, /* tp_iternext */
1379 pyxc_methods, /* tp_methods */
1380 NULL, /* tp_members */
1381 NULL, /* tp_getset */
1382 NULL, /* tp_base */
1383 NULL, /* tp_dict */
1384 NULL, /* tp_descr_get */
1385 NULL, /* tp_descr_set */
1386 0, /* tp_dictoffset */
1387 (initproc)PyXc_init, /* tp_init */
1388 NULL, /* tp_alloc */
1389 PyXc_new, /* tp_new */
1390 };
1392 static PyMethodDef xc_methods[] = { { NULL } };
1394 PyMODINIT_FUNC initxc(void)
1396 PyObject *m;
1398 if (PyType_Ready(&PyXcType) < 0)
1399 return;
1401 m = Py_InitModule(PKG, xc_methods);
1403 if (m == NULL)
1404 return;
1406 xc_error_obj = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
1407 zero = PyInt_FromLong(0);
1409 /* KAF: This ensures that we get debug output in a timely manner. */
1410 setbuf(stdout, NULL);
1411 setbuf(stderr, NULL);
1413 Py_INCREF(&PyXcType);
1414 PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
1416 Py_INCREF(xc_error_obj);
1417 PyModule_AddObject(m, "Error", xc_error_obj);
1419 /* Expose some libxc constants to Python */
1420 PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF);
1421 PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT);
1426 /*
1427 * Local variables:
1428 * c-indent-level: 4
1429 * c-basic-offset: 4
1430 * End:
1431 */