ia64/xen-unstable

annotate tools/python/xen/lowlevel/xc/xc.c @ 13939:09b3fd488726

[XEND][POWERPC] Remove FlatDeviceTree.py, eliminate devtree from prose builder.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
author Jimi Xenidis <jimix@watson.ibm.com>
date Sun Jan 21 08:15:39 2007 -0500 (2007-01-21)
parents 3773af71a14b
children 978ff6fad81f
rev   line source
mjw@1629 1 /******************************************************************************
mjw@1629 2 * Xc.c
mjw@1629 3 *
mjw@1629 4 * Copyright (c) 2003-2004, K A Fraser (University of Cambridge)
mjw@1629 5 */
mjw@1629 6
mjw@1629 7 #include <Python.h>
cl349@6403 8 #include <xenctrl.h>
cl349@6404 9 #include <xenguest.h>
mjw@1629 10 #include <zlib.h>
mjw@1629 11 #include <fcntl.h>
mjw@1629 12 #include <netinet/in.h>
mjw@1629 13 #include <netinet/tcp.h>
mjw@1629 14 #include <sys/types.h>
mjw@1629 15 #include <sys/socket.h>
kfraser@12600 16 #include <sys/mman.h>
mjw@1629 17 #include <netdb.h>
mjw@1629 18 #include <arpa/inet.h>
cl349@5304 19
emellor@8522 20 #include "xenctrl.h"
kfraser@12600 21 #include <xen/hvm/hvm_info_table.h>
kfraser@12600 22 #include <xen/hvm/params.h>
mjw@1629 23
mjw@1629 24 /* Needed for Python versions earlier than 2.3. */
mjw@1629 25 #ifndef PyMODINIT_FUNC
mjw@1629 26 #define PyMODINIT_FUNC DL_EXPORT(void)
mjw@1629 27 #endif
mjw@1629 28
emellor@7973 29 #define PKG "xen.lowlevel.xc"
emellor@7973 30 #define CLS "xc"
mjw@1629 31
kfraser@12834 32 static PyObject *xc_error_obj, *zero;
mjw@1629 33
mjw@1629 34 typedef struct {
mjw@1629 35 PyObject_HEAD;
mjw@1629 36 int xc_handle;
mjw@1629 37 } XcObject;
mjw@1629 38
mjw@1629 39
emellor@7971 40 static PyObject *dom_op(XcObject *self, PyObject *args,
emellor@7971 41 int (*fn)(int, uint32_t));
emellor@7971 42
kfraser@12834 43 static PyObject *pyxc_error_to_exception(void)
kfraser@12834 44 {
kfraser@12834 45 PyObject *pyerr;
kfraser@12834 46 const xc_error const *err = xc_get_last_error();
kfraser@12834 47 const char *desc = xc_error_code_to_desc(err->code);
kfraser@12834 48
kfraser@12840 49 if (err->code == XC_ERROR_NONE)
kfraser@12840 50 return PyErr_SetFromErrno(xc_error_obj);
kfraser@12840 51
kfraser@12840 52 if (err->message[0] != '\0')
kfraser@12834 53 pyerr = Py_BuildValue("(iss)", err->code, desc, err->message);
kfraser@12834 54 else
kfraser@12834 55 pyerr = Py_BuildValue("(is)", err->code, desc);
kfraser@12834 56
kfraser@12834 57 xc_clear_last_error();
kfraser@12834 58
kfraser@12834 59 PyErr_SetObject(xc_error_obj, pyerr);
kfraser@12834 60
kfraser@12834 61 return NULL;
kfraser@12834 62 }
emellor@7971 63
emellor@7971 64 static PyObject *pyxc_domain_dumpcore(XcObject *self, PyObject *args)
kaf24@4719 65 {
kaf24@7349 66 uint32_t dom;
kaf24@4719 67 char *corefile;
kaf24@4719 68
emellor@7971 69 if (!PyArg_ParseTuple(args, "is", &dom, &corefile))
emellor@7902 70 return NULL;
kaf24@4719 71
kaf24@4719 72 if ( (corefile == NULL) || (corefile[0] == '\0') )
emellor@7902 73 return NULL;
kaf24@4719 74
emellor@7971 75 if (xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0)
kfraser@12834 76 return pyxc_error_to_exception();
kaf24@4719 77
kaf24@4719 78 Py_INCREF(zero);
kaf24@4719 79 return zero;
kaf24@4719 80 }
kaf24@4719 81
emellor@7971 82 static PyObject *pyxc_handle(XcObject *self)
cl349@5099 83 {
emellor@7971 84 return PyInt_FromLong(self->xc_handle);
cl349@5099 85 }
cl349@5099 86
emellor@7971 87 static PyObject *pyxc_domain_create(XcObject *self,
mjw@1629 88 PyObject *args,
mjw@1629 89 PyObject *kwds)
mjw@1629 90 {
kfraser@12210 91 uint32_t dom = 0, ssidref = 0, flags = 0;
kfraser@12210 92 int ret, i, hvm = 0;
kaf24@7388 93 PyObject *pyhandle = NULL;
kaf24@7388 94 xen_domain_handle_t handle = {
kaf24@7388 95 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
kaf24@7388 96 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef };
mjw@1629 97
kfraser@12210 98 static char *kwd_list[] = { "domid", "ssidref", "handle", "hvm", NULL };
mjw@1629 99
kfraser@12210 100 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOi", kwd_list,
kfraser@12210 101 &dom, &ssidref, &pyhandle, &hvm))
mjw@1629 102 return NULL;
kaf24@2179 103
kaf24@7388 104 if ( pyhandle != NULL )
kaf24@7388 105 {
kaf24@7388 106 if ( !PyList_Check(pyhandle) ||
kaf24@7388 107 (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) )
emellor@7902 108 goto out_exception;
kaf24@7388 109
kaf24@7388 110 for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
kaf24@7388 111 {
kaf24@7388 112 PyObject *p = PyList_GetItem(pyhandle, i);
kaf24@7388 113 if ( !PyInt_Check(p) )
kaf24@7388 114 goto out_exception;
kaf24@7388 115 handle[i] = (uint8_t)PyInt_AsLong(p);
kaf24@7388 116 }
kaf24@7388 117 }
kaf24@7388 118
kfraser@12210 119 if ( hvm )
kfraser@12210 120 flags |= XEN_DOMCTL_CDF_hvm_guest;
kfraser@12210 121
kfraser@12210 122 if ( (ret = xc_domain_create(self->xc_handle, ssidref,
kfraser@12210 123 handle, flags, &dom)) < 0 )
kfraser@12834 124 return pyxc_error_to_exception();
mjw@1629 125
mjw@1629 126 return PyInt_FromLong(dom);
emellor@7902 127
emellor@7902 128 out_exception:
emellor@7902 129 errno = EINVAL;
kfraser@12834 130 PyErr_SetFromErrno(xc_error_obj);
emellor@7902 131 return NULL;
mjw@1629 132 }
mjw@1629 133
emellor@7971 134 static PyObject *pyxc_domain_max_vcpus(XcObject *self, PyObject *args)
kaf24@7364 135 {
kaf24@7364 136 uint32_t dom, max;
kaf24@7364 137
emellor@7971 138 if (!PyArg_ParseTuple(args, "ii", &dom, &max))
emellor@7971 139 return NULL;
kaf24@7364 140
emellor@7971 141 if (xc_domain_max_vcpus(self->xc_handle, dom, max) != 0)
kfraser@12834 142 return pyxc_error_to_exception();
mjw@1629 143
mjw@1629 144 Py_INCREF(zero);
mjw@1629 145 return zero;
mjw@1629 146 }
mjw@1629 147
emellor@7971 148 static PyObject *pyxc_domain_pause(XcObject *self, PyObject *args)
mjw@1629 149 {
emellor@7971 150 return dom_op(self, args, xc_domain_pause);
mjw@1629 151 }
mjw@1629 152
emellor@7971 153 static PyObject *pyxc_domain_unpause(XcObject *self, PyObject *args)
mjw@1629 154 {
emellor@7971 155 return dom_op(self, args, xc_domain_unpause);
mjw@1629 156 }
mjw@1629 157
emellor@7971 158 static PyObject *pyxc_domain_destroy(XcObject *self, PyObject *args)
emellor@7971 159 {
emellor@7971 160 return dom_op(self, args, xc_domain_destroy);
emellor@7971 161 }
emellor@7971 162
emellor@7971 163
kaf24@8508 164 static PyObject *pyxc_vcpu_setaffinity(XcObject *self,
kaf24@8508 165 PyObject *args,
kaf24@8508 166 PyObject *kwds)
mjw@1629 167 {
kaf24@7349 168 uint32_t dom;
kaf24@7483 169 int vcpu = 0, i;
kfraser@11296 170 uint64_t cpumap = ~0ULL;
kaf24@7483 171 PyObject *cpulist = NULL;
mjw@1629 172
acnt2@12073 173 static char *kwd_list[] = { "domid", "vcpu", "cpumap", NULL };
mjw@1629 174
kaf24@7483 175 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|iO", kwd_list,
kaf24@7483 176 &dom, &vcpu, &cpulist) )
mjw@1629 177 return NULL;
mjw@1629 178
kaf24@7483 179 if ( (cpulist != NULL) && PyList_Check(cpulist) )
kaf24@7483 180 {
kaf24@7483 181 cpumap = 0ULL;
kaf24@7483 182 for ( i = 0; i < PyList_Size(cpulist); i++ )
kfraser@11296 183 cpumap |= (uint64_t)1 << PyInt_AsLong(PyList_GetItem(cpulist, i));
kaf24@7483 184 }
kaf24@7483 185
kaf24@8508 186 if ( xc_vcpu_setaffinity(self->xc_handle, dom, vcpu, cpumap) != 0 )
kfraser@12834 187 return pyxc_error_to_exception();
mjw@1629 188
mjw@1629 189 Py_INCREF(zero);
mjw@1629 190 return zero;
mjw@1629 191 }
mjw@1629 192
emellor@7971 193 static PyObject *pyxc_domain_setcpuweight(XcObject *self,
kfraser@11076 194 PyObject *args,
kfraser@11076 195 PyObject *kwds)
cl349@5045 196 {
kaf24@7349 197 uint32_t dom;
cl349@5045 198 float cpuweight = 1;
cl349@5045 199
acnt2@12073 200 static char *kwd_list[] = { "domid", "cpuweight", NULL };
cl349@5045 201
cl349@5045 202 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|f", kwd_list,
cl349@5045 203 &dom, &cpuweight) )
cl349@5045 204 return NULL;
cl349@5045 205
emellor@7971 206 if ( xc_domain_setcpuweight(self->xc_handle, dom, cpuweight) != 0 )
kfraser@12834 207 return pyxc_error_to_exception();
cl349@5045 208
cl349@5045 209 Py_INCREF(zero);
cl349@5045 210 return zero;
cl349@5045 211 }
cl349@5045 212
emellor@7971 213 static PyObject *pyxc_domain_sethandle(XcObject *self, PyObject *args)
kaf24@7389 214 {
kaf24@7389 215 int i;
kaf24@7389 216 uint32_t dom;
kaf24@7389 217 PyObject *pyhandle;
kaf24@7389 218 xen_domain_handle_t handle;
kaf24@7389 219
emellor@7971 220 if (!PyArg_ParseTuple(args, "iO", &dom, &pyhandle))
kaf24@7389 221 return NULL;
kaf24@7389 222
kaf24@7389 223 if ( !PyList_Check(pyhandle) ||
kaf24@7389 224 (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) )
kaf24@7389 225 {
emellor@7902 226 goto out_exception;
kaf24@7389 227 }
kaf24@7389 228
kaf24@7389 229 for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
kaf24@7389 230 {
kaf24@7389 231 PyObject *p = PyList_GetItem(pyhandle, i);
kaf24@7389 232 if ( !PyInt_Check(p) )
kaf24@7389 233 goto out_exception;
kaf24@7389 234 handle[i] = (uint8_t)PyInt_AsLong(p);
kaf24@7389 235 }
kaf24@7389 236
emellor@7971 237 if (xc_domain_sethandle(self->xc_handle, dom, handle) < 0)
kfraser@12834 238 return pyxc_error_to_exception();
kaf24@7389 239
kaf24@7389 240 Py_INCREF(zero);
kaf24@7389 241 return zero;
emellor@7902 242
emellor@7902 243 out_exception:
kfraser@12834 244 PyErr_SetFromErrno(xc_error_obj);
emellor@7902 245 return NULL;
kaf24@7389 246 }
kaf24@7389 247
emellor@7902 248
emellor@7971 249 static PyObject *pyxc_domain_getinfo(XcObject *self,
mjw@1629 250 PyObject *args,
mjw@1629 251 PyObject *kwds)
mjw@1629 252 {
kaf24@7388 253 PyObject *list, *info_dict;
mjw@1629 254
kaf24@7349 255 uint32_t first_dom = 0;
cl349@4845 256 int max_doms = 1024, nr_doms, i, j;
mjw@1629 257 xc_dominfo_t *info;
mjw@1629 258
mjw@1629 259 static char *kwd_list[] = { "first_dom", "max_doms", NULL };
mjw@1629 260
mjw@1629 261 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwd_list,
mjw@1629 262 &first_dom, &max_doms) )
mjw@1629 263 return NULL;
mjw@1629 264
mjw@1629 265 if ( (info = malloc(max_doms * sizeof(xc_dominfo_t))) == NULL )
mjw@1629 266 return PyErr_NoMemory();
mjw@1629 267
emellor@7971 268 nr_doms = xc_domain_getinfo(self->xc_handle, first_dom, max_doms, info);
shand@6880 269
shand@6880 270 if (nr_doms < 0)
emellor@6999 271 {
emellor@6999 272 free(info);
kfraser@12834 273 return pyxc_error_to_exception();
emellor@6999 274 }
emellor@6999 275
mjw@1629 276 list = PyList_New(nr_doms);
mjw@1629 277 for ( i = 0 ; i < nr_doms; i++ )
mjw@1629 278 {
kaf24@7388 279 PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
kaf24@7388 280 for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
kaf24@7388 281 PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
kfraser@12238 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"
smh22@5514 283 ",s:l,s:L,s:l,s:i,s:i}",
acnt2@12073 284 "domid", info[i].domid,
kaf24@7407 285 "online_vcpus", info[i].nr_online_vcpus,
kaf24@7407 286 "max_vcpu_id", info[i].max_vcpu_id,
kfraser@12238 287 "hvm", info[i].hvm,
cl349@4845 288 "dying", info[i].dying,
cl349@4845 289 "crashed", info[i].crashed,
cl349@4845 290 "shutdown", info[i].shutdown,
cl349@4845 291 "paused", info[i].paused,
cl349@4845 292 "blocked", info[i].blocked,
cl349@4845 293 "running", info[i].running,
kaf24@5930 294 "mem_kb", info[i].nr_pages*(XC_PAGE_SIZE/1024),
cl349@4845 295 "cpu_time", info[i].cpu_time,
cl349@4845 296 "maxmem_kb", info[i].max_memkb,
smh22@5514 297 "ssidref", info[i].ssidref,
cl349@4845 298 "shutdown_reason", info[i].shutdown_reason);
kaf24@7388 299 PyDict_SetItemString(info_dict, "handle", pyhandle);
emellor@7704 300 Py_DECREF(pyhandle);
kaf24@7388 301 PyList_SetItem(list, i, info_dict);
mjw@1629 302 }
mjw@1629 303
mjw@1629 304 free(info);
mjw@1629 305
mjw@1629 306 return list;
mjw@1629 307 }
mjw@1629 308
emellor@7971 309 static PyObject *pyxc_vcpu_getinfo(XcObject *self,
kaf24@7407 310 PyObject *args,
kaf24@7407 311 PyObject *kwds)
kaf24@7407 312 {
kaf24@7483 313 PyObject *info_dict, *cpulist;
kaf24@7407 314
kaf24@7407 315 uint32_t dom, vcpu = 0;
kaf24@7407 316 xc_vcpuinfo_t info;
kaf24@7483 317 int rc, i;
kfraser@11296 318 uint64_t cpumap;
kaf24@7407 319
acnt2@12073 320 static char *kwd_list[] = { "domid", "vcpu", NULL };
kaf24@7407 321
kaf24@7407 322 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
kaf24@7407 323 &dom, &vcpu) )
kaf24@7407 324 return NULL;
kaf24@7407 325
kaf24@8508 326 rc = xc_vcpu_getinfo(self->xc_handle, dom, vcpu, &info);
kaf24@7407 327 if ( rc < 0 )
kfraser@12834 328 return pyxc_error_to_exception();
kfraser@11296 329 rc = xc_vcpu_getaffinity(self->xc_handle, dom, vcpu, &cpumap);
kfraser@11296 330 if ( rc < 0 )
kfraser@12834 331 return pyxc_error_to_exception();
kaf24@7407 332
kaf24@7483 333 info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i}",
kaf24@7407 334 "online", info.online,
kaf24@7407 335 "blocked", info.blocked,
kaf24@7407 336 "running", info.running,
kaf24@7407 337 "cpu_time", info.cpu_time,
kaf24@7483 338 "cpu", info.cpu);
kaf24@7483 339
kaf24@7483 340 cpulist = PyList_New(0);
kaf24@7483 341 for ( i = 0; cpumap != 0; i++ )
kaf24@7483 342 {
kaf24@7483 343 if ( cpumap & 1 )
kaf24@7483 344 PyList_Append(cpulist, PyInt_FromLong(i));
kaf24@7483 345 cpumap >>= 1;
kaf24@7483 346 }
kaf24@7483 347 PyDict_SetItemString(info_dict, "cpumap", cpulist);
emellor@7704 348 Py_DECREF(cpulist);
kaf24@7407 349 return info_dict;
kaf24@7407 350 }
kaf24@7407 351
emellor@7971 352 static PyObject *pyxc_linux_build(XcObject *self,
mjw@1629 353 PyObject *args,
mjw@1629 354 PyObject *kwds)
mjw@1629 355 {
kaf24@7349 356 uint32_t dom;
Ian@9054 357 char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
kaf24@7429 358 int flags = 0;
cl349@6685 359 int store_evtchn, console_evtchn;
kfraser@12218 360 unsigned int mem_mb;
cl349@5349 361 unsigned long store_mfn = 0;
cl349@6492 362 unsigned long console_mfn = 0;
mjw@1629 363
kfraser@12218 364 static char *kwd_list[] = { "domid", "store_evtchn", "memsize",
Ian@9054 365 "console_evtchn", "image",
kfraser@11076 366 /* optional */
kfraser@11076 367 "ramdisk", "cmdline", "flags",
emellor@11080 368 "features", NULL };
mjw@1629 369
kfraser@12218 370 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis", kwd_list,
kfraser@12218 371 &dom, &store_evtchn, &mem_mb,
kfraser@11076 372 &console_evtchn, &image,
kfraser@11076 373 /* optional */
kfraser@11076 374 &ramdisk, &cmdline, &flags,
kfraser@11076 375 &features) )
mjw@1629 376 return NULL;
mjw@1629 377
kfraser@12218 378 if ( xc_linux_build(self->xc_handle, dom, mem_mb, image,
Ian@9054 379 ramdisk, cmdline, features, flags,
Ian@9054 380 store_evtchn, &store_mfn,
kfraser@11076 381 console_evtchn, &console_mfn) != 0 ) {
kfraser@12834 382 return pyxc_error_to_exception();
vhanquez@8869 383 }
cl349@6492 384 return Py_BuildValue("{s:i,s:i}",
kfraser@11076 385 "store_mfn", store_mfn,
kfraser@11076 386 "console_mfn", console_mfn);
mjw@1629 387 }
mjw@1629 388
kaf24@8708 389 static PyObject *pyxc_hvm_build(XcObject *self,
kaf24@7486 390 PyObject *args,
kaf24@7486 391 PyObject *kwds)
iap10@3390 392 {
kaf24@7486 393 uint32_t dom;
awilliam@12780 394 #if !defined(__ia64__)
kfraser@12600 395 struct hvm_info_table *va_hvm;
kfraser@12600 396 uint8_t *va_map, sum;
awilliam@12780 397 int i;
awilliam@12780 398 #endif
kaf24@7036 399 char *image;
awilliam@12780 400 int store_evtchn, memsize, vcpus = 1, pae = 0, acpi = 0, apic = 1;
kfraser@12600 401 unsigned long store_mfn;
iap10@3390 402
acnt2@12073 403 static char *kwd_list[] = { "domid", "store_evtchn",
kaf24@12257 404 "memsize", "image", "vcpus", "pae", "acpi",
kfraser@12600 405 "apic", NULL };
kfraser@12600 406 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|iiii", kwd_list,
kaf24@8970 407 &dom, &store_evtchn, &memsize,
kfraser@12600 408 &image, &vcpus, &pae, &acpi, &apic) )
iap10@3390 409 return NULL;
iap10@3390 410
kfraser@12600 411 if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )
kfraser@12834 412 return pyxc_error_to_exception();
iap10@3390 413
awilliam@12780 414 #if !defined(__ia64__)
kfraser@12600 415 /* Set up the HVM info table. */
kfraser@12705 416 va_map = xc_map_foreign_range(self->xc_handle, dom, XC_PAGE_SIZE,
kfraser@12600 417 PROT_READ | PROT_WRITE,
kfraser@12600 418 HVM_INFO_PFN);
kfraser@12600 419 if ( va_map == NULL )
kfraser@12834 420 return PyErr_SetFromErrno(xc_error_obj);
kfraser@12600 421 va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
kfraser@12600 422 memset(va_hvm, 0, sizeof(*va_hvm));
kfraser@12600 423 strncpy(va_hvm->signature, "HVM INFO", 8);
kfraser@12600 424 va_hvm->length = sizeof(struct hvm_info_table);
kfraser@12600 425 va_hvm->acpi_enabled = acpi;
kfraser@12600 426 va_hvm->apic_mode = apic;
kfraser@12600 427 va_hvm->nr_vcpus = vcpus;
kfraser@12600 428 for ( i = 0, sum = 0; i < va_hvm->length; i++ )
kfraser@12600 429 sum += ((uint8_t *)va_hvm)[i];
kfraser@12600 430 va_hvm->checksum = -sum;
kfraser@12705 431 munmap(va_map, XC_PAGE_SIZE);
awilliam@12780 432 #endif
kfraser@12600 433
kfraser@12600 434 xc_get_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_PFN, &store_mfn);
awilliam@12780 435 #if !defined(__ia64__)
kfraser@12600 436 xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
awilliam@12780 437 #endif
kfraser@12600 438 xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_EVTCHN,
kfraser@12600 439 store_evtchn);
kfraser@12600 440
cl349@6083 441 return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
iap10@3390 442 }
iap10@3390 443
emellor@7971 444 static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,
kaf24@2713 445 PyObject *args,
kaf24@2713 446 PyObject *kwds)
kaf24@2713 447 {
kaf24@7349 448 uint32_t dom, remote_dom;
kaf24@7246 449 int port;
kaf24@2713 450
acnt2@12073 451 static char *kwd_list[] = { "domid", "remote_dom", NULL };
kaf24@2713 452
kaf24@7250 453 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
kaf24@7250 454 &dom, &remote_dom) )
kaf24@2713 455 return NULL;
kaf24@2713 456
emellor@7971 457 if ( (port = xc_evtchn_alloc_unbound(self->xc_handle, dom, remote_dom)) < 0 )
kfraser@12834 458 return pyxc_error_to_exception();
kaf24@2713 459
kaf24@2713 460 return PyInt_FromLong(port);
kaf24@2713 461 }
kaf24@2713 462
emellor@7971 463 static PyObject *pyxc_physdev_pci_access_modify(XcObject *self,
mjw@1629 464 PyObject *args,
mjw@1629 465 PyObject *kwds)
mjw@1629 466 {
kaf24@7349 467 uint32_t dom;
mjw@1629 468 int bus, dev, func, enable, ret;
mjw@1629 469
acnt2@12073 470 static char *kwd_list[] = { "domid", "bus", "dev", "func", "enable", NULL };
mjw@1629 471
mjw@1629 472 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiii", kwd_list,
mjw@1629 473 &dom, &bus, &dev, &func, &enable) )
mjw@1629 474 return NULL;
mjw@1629 475
mjw@1629 476 ret = xc_physdev_pci_access_modify(
emellor@7971 477 self->xc_handle, dom, bus, dev, func, enable);
mjw@1629 478 if ( ret != 0 )
kfraser@12834 479 return pyxc_error_to_exception();
mjw@1629 480
mjw@1629 481 Py_INCREF(zero);
mjw@1629 482 return zero;
mjw@1629 483 }
mjw@1629 484
emellor@7971 485 static PyObject *pyxc_readconsolering(XcObject *self,
mjw@1629 486 PyObject *args,
mjw@1629 487 PyObject *kwds)
mjw@1629 488 {
mjw@1629 489 unsigned int clear = 0;
kaf24@5327 490 char _str[32768], *str = _str;
kaf24@5327 491 unsigned int count = 32768;
mjw@1629 492 int ret;
mjw@1629 493
mjw@1629 494 static char *kwd_list[] = { "clear", NULL };
mjw@1629 495
mjw@1629 496 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &clear) )
mjw@1629 497 return NULL;
mjw@1629 498
emellor@7971 499 ret = xc_readconsolering(self->xc_handle, &str, &count, clear);
mjw@1629 500 if ( ret < 0 )
kfraser@12834 501 return pyxc_error_to_exception();
mjw@1629 502
kaf24@5327 503 return PyString_FromStringAndSize(str, count);
mjw@1629 504 }
mjw@1629 505
emellor@8140 506
kaf24@10541 507 static unsigned long pages_to_kib(unsigned long pages)
kaf24@10541 508 {
kaf24@10541 509 return pages * (XC_PAGE_SIZE / 1024);
kaf24@10541 510 }
kaf24@10541 511
kaf24@10541 512
emellor@8158 513 static PyObject *pyxc_pages_to_kib(XcObject *self, PyObject *args)
emellor@8158 514 {
emellor@8158 515 unsigned long pages;
emellor@8158 516
emellor@8158 517 if (!PyArg_ParseTuple(args, "l", &pages))
emellor@8158 518 return NULL;
emellor@8158 519
kaf24@10541 520 return PyLong_FromUnsignedLong(pages_to_kib(pages));
emellor@8140 521 }
emellor@8140 522
emellor@8140 523
emellor@7971 524 static PyObject *pyxc_physinfo(XcObject *self)
mjw@1629 525 {
mjw@1629 526 xc_physinfo_t info;
iap10@6721 527 char cpu_cap[128], *p=cpu_cap, *q=cpu_cap;
iap10@6721 528 int i;
mjw@1629 529
emellor@7971 530 if ( xc_physinfo(self->xc_handle, &info) != 0 )
kfraser@12834 531 return pyxc_error_to_exception();
mjw@1629 532
iap10@6721 533 *q=0;
iap10@6721 534 for(i=0;i<sizeof(info.hw_cap)/4;i++)
iap10@6721 535 {
iap10@6721 536 p+=sprintf(p,"%08x:",info.hw_cap[i]);
iap10@6721 537 if(info.hw_cap[i])
kfraser@11076 538 q=p;
iap10@6721 539 }
iap10@6721 540 if(q>cpu_cap)
iap10@6721 541 *(q-1)=0;
iap10@6721 542
kaf24@10541 543 return Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s}",
kaf24@5666 544 "threads_per_core", info.threads_per_core,
kaf24@5666 545 "cores_per_socket", info.cores_per_socket,
kaf24@5666 546 "sockets_per_node", info.sockets_per_node,
kaf24@5666 547 "nr_nodes", info.nr_nodes,
kaf24@10541 548 "total_memory", pages_to_kib(info.total_pages),
kaf24@10541 549 "free_memory", pages_to_kib(info.free_pages),
kaf24@10541 550 "scrub_memory", pages_to_kib(info.scrub_pages),
iap10@6721 551 "cpu_khz", info.cpu_khz,
iap10@6721 552 "hw_caps", cpu_cap);
mjw@1629 553 }
mjw@1629 554
emellor@7971 555 static PyObject *pyxc_xeninfo(XcObject *self)
vh249@6567 556 {
vh249@6567 557 xen_extraversion_t xen_extra;
vh249@6567 558 xen_compile_info_t xen_cc;
vh249@6567 559 xen_changeset_info_t xen_chgset;
iap10@6721 560 xen_capabilities_info_t xen_caps;
kaf24@7857 561 xen_platform_parameters_t p_parms;
vh249@6567 562 long xen_version;
kaf24@10529 563 long xen_pagesize;
iap10@6721 564 char str[128];
vh249@6567 565
emellor@7971 566 xen_version = xc_version(self->xc_handle, XENVER_version, NULL);
vh249@6567 567
emellor@7971 568 if ( xc_version(self->xc_handle, XENVER_extraversion, &xen_extra) != 0 )
kfraser@12834 569 return pyxc_error_to_exception();
vh249@6567 570
emellor@7971 571 if ( xc_version(self->xc_handle, XENVER_compile_info, &xen_cc) != 0 )
kfraser@12834 572 return pyxc_error_to_exception();
vh249@6567 573
emellor@7971 574 if ( xc_version(self->xc_handle, XENVER_changeset, &xen_chgset) != 0 )
kfraser@12834 575 return pyxc_error_to_exception();
vh249@6567 576
emellor@7971 577 if ( xc_version(self->xc_handle, XENVER_capabilities, &xen_caps) != 0 )
kfraser@12834 578 return pyxc_error_to_exception();
iap10@6721 579
emellor@7971 580 if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 )
kfraser@12834 581 return pyxc_error_to_exception();
iap10@6721 582
kaf24@7857 583 sprintf(str, "virt_start=0x%lx", p_parms.virt_start);
iap10@6721 584
kaf24@10529 585 xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL);
kaf24@10529 586 if (xen_pagesize < 0 )
kfraser@12834 587 return pyxc_error_to_exception();
kaf24@10529 588
kaf24@10529 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}",
vh249@6567 590 "xen_major", xen_version >> 16,
vh249@6567 591 "xen_minor", (xen_version & 0xffff),
vh249@6567 592 "xen_extra", xen_extra,
kaf24@6725 593 "xen_caps", xen_caps,
kaf24@10529 594 "xen_pagesize", xen_pagesize,
kaf24@7857 595 "platform_params", str,
vh249@6567 596 "xen_changeset", xen_chgset,
vh249@6567 597 "cc_compiler", xen_cc.compiler,
vh249@6567 598 "cc_compile_by", xen_cc.compile_by,
vh249@6567 599 "cc_compile_domain", xen_cc.compile_domain,
vh249@6567 600 "cc_compile_date", xen_cc.compile_date);
vh249@6567 601 }
vh249@6567 602
vh249@6567 603
emellor@7971 604 static PyObject *pyxc_sedf_domain_set(XcObject *self,
emellor@7436 605 PyObject *args,
emellor@7436 606 PyObject *kwds)
sd386@3449 607 {
kaf24@7349 608 uint32_t domid;
kaf24@7349 609 uint64_t period, slice, latency;
kaf24@7349 610 uint16_t extratime, weight;
acnt2@12073 611 static char *kwd_list[] = { "domid", "period", "slice",
kaf24@5666 612 "latency", "extratime", "weight",NULL };
sd386@3449 613
kaf24@5666 614 if( !PyArg_ParseTupleAndKeywords(args, kwds, "iLLLhh", kwd_list,
kaf24@5666 615 &domid, &period, &slice,
kaf24@5666 616 &latency, &extratime, &weight) )
sd386@3449 617 return NULL;
emellor@7971 618 if ( xc_sedf_domain_set(self->xc_handle, domid, period,
kaf24@5666 619 slice, latency, extratime,weight) != 0 )
kfraser@12834 620 return pyxc_error_to_exception();
sd386@3449 621
sd386@3449 622 Py_INCREF(zero);
sd386@3449 623 return zero;
sd386@3449 624 }
sd386@3449 625
emellor@7971 626 static PyObject *pyxc_sedf_domain_get(XcObject *self, PyObject *args)
sd386@3449 627 {
kaf24@7349 628 uint32_t domid;
kaf24@7349 629 uint64_t period, slice,latency;
kaf24@7349 630 uint16_t weight, extratime;
sd386@3573 631
emellor@7971 632 if(!PyArg_ParseTuple(args, "i", &domid))
sd386@3449 633 return NULL;
sd386@3449 634
emellor@7971 635 if (xc_sedf_domain_get(self->xc_handle, domid, &period,
emellor@7971 636 &slice,&latency,&extratime,&weight))
kfraser@12834 637 return pyxc_error_to_exception();
sd386@3449 638
emellor@7436 639 return Py_BuildValue("{s:i,s:L,s:L,s:L,s:i,s:i}",
acnt2@12073 640 "domid", domid,
sd386@3573 641 "period", period,
sd386@3573 642 "slice", slice,
kfraser@11076 643 "latency", latency,
kfraser@11076 644 "extratime", extratime,
emellor@7436 645 "weight", weight);
sd386@3449 646 }
sd386@3449 647
tdeegan@11172 648 static PyObject *pyxc_shadow_control(PyObject *self,
tdeegan@11172 649 PyObject *args,
tdeegan@11172 650 PyObject *kwds)
tdeegan@11172 651 {
tdeegan@11172 652 XcObject *xc = (XcObject *)self;
tdeegan@11172 653
tdeegan@11172 654 uint32_t dom;
tdeegan@11172 655 int op=0;
tdeegan@11172 656
tdeegan@11172 657 static char *kwd_list[] = { "dom", "op", NULL };
tdeegan@11172 658
tdeegan@11172 659 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
tdeegan@11172 660 &dom, &op) )
tdeegan@11172 661 return NULL;
tdeegan@11172 662
tdeegan@11172 663 if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, NULL, 0, NULL)
tdeegan@11172 664 < 0 )
kfraser@12834 665 return pyxc_error_to_exception();
tdeegan@11172 666
tdeegan@11172 667 Py_INCREF(zero);
tdeegan@11172 668 return zero;
tdeegan@11172 669 }
tdeegan@11172 670
tdeegan@11172 671 static PyObject *pyxc_shadow_mem_control(PyObject *self,
tdeegan@11172 672 PyObject *args,
tdeegan@11172 673 PyObject *kwds)
tdeegan@11172 674 {
tdeegan@11172 675 XcObject *xc = (XcObject *)self;
tdeegan@11172 676 int op;
tdeegan@11172 677 uint32_t dom;
tdeegan@11172 678 int mbarg = -1;
tdeegan@11172 679 unsigned long mb;
tdeegan@11172 680
tdeegan@11172 681 static char *kwd_list[] = { "dom", "mb", NULL };
tdeegan@11172 682
tdeegan@11172 683 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
tdeegan@11172 684 &dom, &mbarg) )
tdeegan@11172 685 return NULL;
tdeegan@11172 686
tdeegan@11172 687 if ( mbarg < 0 )
kfraser@11296 688 op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
tdeegan@11172 689 else
tdeegan@11172 690 {
tdeegan@11172 691 mb = mbarg;
kfraser@11296 692 op = XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION;
tdeegan@11172 693 }
tdeegan@11172 694 if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, &mb, 0, NULL) < 0 )
kfraser@12834 695 return pyxc_error_to_exception();
tdeegan@11172 696
tdeegan@11172 697 mbarg = mb;
tdeegan@11172 698 return Py_BuildValue("i", mbarg);
tdeegan@11172 699 }
tdeegan@11172 700
atse@12145 701 static PyObject *pyxc_sched_id_get(XcObject *self) {
atse@12145 702
atse@12145 703 int sched_id;
atse@12145 704 if (xc_sched_id(self->xc_handle, &sched_id) != 0)
kfraser@12834 705 return PyErr_SetFromErrno(xc_error_obj);
atse@12145 706
atse@12145 707 return Py_BuildValue("i", sched_id);
atse@12145 708 }
atse@12145 709
kaf24@10206 710 static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
kaf24@10206 711 PyObject *args,
kaf24@10206 712 PyObject *kwds)
ack@10188 713 {
ack@10188 714 uint32_t domid;
ack@10188 715 uint16_t weight;
ack@10188 716 uint16_t cap;
acnt2@12073 717 static char *kwd_list[] = { "domid", "weight", "cap", NULL };
ack@10188 718 static char kwd_type[] = "I|HH";
kfraser@11296 719 struct xen_domctl_sched_credit sdom;
ack@10188 720
ack@10188 721 weight = 0;
ack@10188 722 cap = (uint16_t)~0U;
ack@10188 723 if( !PyArg_ParseTupleAndKeywords(args, kwds, kwd_type, kwd_list,
ack@10188 724 &domid, &weight, &cap) )
ack@10188 725 return NULL;
ack@10188 726
ack@10188 727 sdom.weight = weight;
ack@10188 728 sdom.cap = cap;
ack@10188 729
kaf24@10206 730 if ( xc_sched_credit_domain_set(self->xc_handle, domid, &sdom) != 0 )
kfraser@12834 731 return pyxc_error_to_exception();
ack@10188 732
ack@10188 733 Py_INCREF(zero);
ack@10188 734 return zero;
ack@10188 735 }
ack@10188 736
kaf24@10206 737 static PyObject *pyxc_sched_credit_domain_get(XcObject *self, PyObject *args)
ack@10188 738 {
ack@10188 739 uint32_t domid;
kfraser@11296 740 struct xen_domctl_sched_credit sdom;
ack@10188 741
ack@10188 742 if( !PyArg_ParseTuple(args, "I", &domid) )
ack@10188 743 return NULL;
ack@10188 744
kaf24@10206 745 if ( xc_sched_credit_domain_get(self->xc_handle, domid, &sdom) != 0 )
kfraser@12834 746 return pyxc_error_to_exception();
ack@10188 747
ack@10188 748 return Py_BuildValue("{s:H,s:H}",
ack@10188 749 "weight", sdom.weight,
ack@10188 750 "cap", sdom.cap);
ack@10188 751 }
ack@10188 752
emellor@7971 753 static PyObject *pyxc_domain_setmaxmem(XcObject *self, PyObject *args)
mjw@1629 754 {
kaf24@7349 755 uint32_t dom;
emellor@6997 756 unsigned int maxmem_kb;
mjw@1629 757
emellor@7971 758 if (!PyArg_ParseTuple(args, "ii", &dom, &maxmem_kb))
mjw@1629 759 return NULL;
mjw@1629 760
emellor@7971 761 if (xc_domain_setmaxmem(self->xc_handle, dom, maxmem_kb) != 0)
kfraser@12834 762 return pyxc_error_to_exception();
mjw@1629 763
mjw@1629 764 Py_INCREF(zero);
mjw@1629 765 return zero;
mjw@1629 766 }
mjw@1629 767
kfraser@12872 768 static PyObject *pyxc_domain_set_memmap_limit(XcObject *self, PyObject *args)
kfraser@12872 769 {
kfraser@12872 770 uint32_t dom;
kfraser@12872 771 unsigned int maplimit_kb;
kfraser@12872 772
kfraser@12872 773 if ( !PyArg_ParseTuple(args, "ii", &dom, &maplimit_kb) )
kfraser@12872 774 return NULL;
kfraser@12872 775
kfraser@12872 776 if ( xc_domain_set_memmap_limit(self->xc_handle, dom, maplimit_kb) != 0 )
kfraser@12872 777 return pyxc_error_to_exception();
kfraser@12872 778
kfraser@12872 779 Py_INCREF(zero);
kfraser@12872 780 return zero;
kfraser@12872 781 }
kfraser@12872 782
emellor@7971 783 static PyObject *pyxc_domain_memory_increase_reservation(XcObject *self,
kfraser@11076 784 PyObject *args,
kfraser@11076 785 PyObject *kwds)
cl349@5045 786 {
kaf24@7349 787 uint32_t dom;
cl349@5045 788 unsigned long mem_kb;
iap10@6700 789 unsigned int extent_order = 0 , address_bits = 0;
iap10@6706 790 unsigned long nr_extents;
cl349@5045 791
acnt2@12073 792 static char *kwd_list[] = { "domid", "mem_kb", "extent_order", "address_bits", NULL };
cl349@5045 793
iap10@6711 794 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "il|ii", kwd_list,
iap10@6700 795 &dom, &mem_kb, &extent_order, &address_bits) )
cl349@5045 796 return NULL;
cl349@5045 797
iap10@6706 798 /* round down to nearest power of 2. Assume callers using extent_order>0
iap10@6706 799 know what they are doing */
iap10@6706 800 nr_extents = (mem_kb / (XC_PAGE_SIZE/1024)) >> extent_order;
emellor@7971 801 if ( xc_domain_memory_increase_reservation(self->xc_handle, dom,
kfraser@11076 802 nr_extents, extent_order,
kfraser@11076 803 address_bits, NULL) )
kfraser@12834 804 return pyxc_error_to_exception();
cl349@5045 805
cl349@5045 806 Py_INCREF(zero);
cl349@5045 807 return zero;
cl349@5045 808 }
cl349@5045 809
emellor@7971 810 static PyObject *pyxc_domain_ioport_permission(XcObject *self,
kaf24@7638 811 PyObject *args,
kaf24@7638 812 PyObject *kwds)
kaf24@7638 813 {
kaf24@7638 814 uint32_t dom;
kaf24@7638 815 int first_port, nr_ports, allow_access, ret;
kaf24@7638 816
acnt2@12073 817 static char *kwd_list[] = { "domid", "first_port", "nr_ports", "allow_access", NULL };
kaf24@7638 818
kaf24@7638 819 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiii", kwd_list,
kaf24@7638 820 &dom, &first_port, &nr_ports, &allow_access) )
kaf24@7638 821 return NULL;
kaf24@7638 822
kaf24@7638 823 ret = xc_domain_ioport_permission(
emellor@7971 824 self->xc_handle, dom, first_port, nr_ports, allow_access);
kaf24@7638 825 if ( ret != 0 )
kfraser@12834 826 return pyxc_error_to_exception();
kaf24@7638 827
kaf24@7638 828 Py_INCREF(zero);
kaf24@7638 829 return zero;
kaf24@7638 830 }
kaf24@7638 831
kaf24@8468 832 static PyObject *pyxc_domain_irq_permission(PyObject *self,
kaf24@8468 833 PyObject *args,
kaf24@8468 834 PyObject *kwds)
kaf24@8468 835 {
kaf24@8468 836 XcObject *xc = (XcObject *)self;
kaf24@8468 837 uint32_t dom;
kaf24@8468 838 int pirq, allow_access, ret;
kaf24@8468 839
acnt2@12073 840 static char *kwd_list[] = { "domid", "pirq", "allow_access", NULL };
kaf24@8468 841
kaf24@8468 842 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list,
kaf24@8468 843 &dom, &pirq, &allow_access) )
kaf24@8468 844 return NULL;
kaf24@8468 845
kaf24@8468 846 ret = xc_domain_irq_permission(
kaf24@8468 847 xc->xc_handle, dom, pirq, allow_access);
kaf24@8468 848 if ( ret != 0 )
kfraser@12834 849 return pyxc_error_to_exception();
kaf24@8468 850
kaf24@8468 851 Py_INCREF(zero);
kaf24@8468 852 return zero;
kaf24@8468 853 }
kaf24@8468 854
kaf24@8468 855 static PyObject *pyxc_domain_iomem_permission(PyObject *self,
kaf24@8468 856 PyObject *args,
kaf24@8468 857 PyObject *kwds)
kaf24@8468 858 {
kaf24@8468 859 XcObject *xc = (XcObject *)self;
kaf24@8468 860 uint32_t dom;
kaf24@8468 861 unsigned long first_pfn, nr_pfns, allow_access, ret;
kaf24@8468 862
acnt2@12073 863 static char *kwd_list[] = { "domid", "first_pfn", "nr_pfns", "allow_access", NULL };
kaf24@8468 864
kaf24@8468 865 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "illi", kwd_list,
kaf24@8468 866 &dom, &first_pfn, &nr_pfns, &allow_access) )
kaf24@8468 867 return NULL;
kaf24@8468 868
kaf24@8468 869 ret = xc_domain_iomem_permission(
kaf24@8468 870 xc->xc_handle, dom, first_pfn, nr_pfns, allow_access);
kaf24@8468 871 if ( ret != 0 )
kfraser@12834 872 return pyxc_error_to_exception();
kaf24@8468 873
kaf24@8468 874 Py_INCREF(zero);
kaf24@8468 875 return zero;
kaf24@8468 876 }
kaf24@8468 877
kaf24@10506 878 static PyObject *pyxc_domain_set_time_offset(XcObject *self, PyObject *args)
kaf24@10506 879 {
kaf24@10506 880 uint32_t dom;
kaf24@10506 881 int32_t time_offset_seconds;
kaf24@10506 882 time_t calendar_time;
kaf24@10506 883 struct tm local_time;
kaf24@10506 884 struct tm utc_time;
kaf24@10506 885
kaf24@10506 886 if (!PyArg_ParseTuple(args, "i", &dom))
kaf24@10506 887 return NULL;
kaf24@10506 888
kaf24@10506 889 calendar_time = time(NULL);
kaf24@10506 890 localtime_r(&calendar_time, &local_time);
kaf24@10506 891 gmtime_r(&calendar_time, &utc_time);
kaf24@10506 892 /* set up to get calendar time based on utc_time, with local dst setting */
kaf24@10506 893 utc_time.tm_isdst = local_time.tm_isdst;
kaf24@10506 894 time_offset_seconds = (int32_t)difftime(calendar_time, mktime(&utc_time));
kaf24@10506 895
kaf24@10506 896 if (xc_domain_set_time_offset(self->xc_handle, dom, time_offset_seconds) != 0)
kaf24@10506 897 return NULL;
kaf24@10506 898
kaf24@10506 899 Py_INCREF(zero);
kaf24@10506 900 return zero;
kaf24@10506 901 }
emellor@7971 902
emellor@7971 903 static PyObject *dom_op(XcObject *self, PyObject *args,
emellor@7971 904 int (*fn)(int, uint32_t))
emellor@7971 905 {
emellor@7971 906 uint32_t dom;
emellor@7971 907
emellor@7971 908 if (!PyArg_ParseTuple(args, "i", &dom))
emellor@7971 909 return NULL;
emellor@7971 910
emellor@7971 911 if (fn(self->xc_handle, dom) != 0)
kfraser@12834 912 return pyxc_error_to_exception();
emellor@7971 913
emellor@7971 914 Py_INCREF(zero);
emellor@7971 915 return zero;
emellor@7971 916 }
emellor@7971 917
kfraser@12991 918 #ifdef __powerpc__
kfraser@12991 919 static PyObject *pyxc_alloc_real_mode_area(XcObject *self,
kfraser@12991 920 PyObject *args,
kfraser@12991 921 PyObject *kwds)
kfraser@12991 922 {
kfraser@12991 923 uint32_t dom;
kfraser@12991 924 unsigned int log;
kfraser@12991 925
kfraser@12991 926 static char *kwd_list[] = { "dom", "log", NULL };
kfraser@12991 927
kfraser@12991 928 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
kfraser@12991 929 &dom, &log) )
kfraser@12991 930 return NULL;
kfraser@12991 931
kfraser@12991 932 if ( xc_alloc_real_mode_area(self->xc_handle, dom, log) )
hollisb@13924 933 return pyxc_error_to_exception();
kfraser@12991 934
kfraser@12991 935 Py_INCREF(zero);
kfraser@12991 936 return zero;
kfraser@12991 937 }
kfraser@12991 938
kfraser@12991 939 static PyObject *pyxc_prose_build(XcObject *self,
kfraser@12991 940 PyObject *args,
kfraser@12991 941 PyObject *kwds)
kfraser@12991 942 {
kfraser@12991 943 uint32_t dom;
kfraser@12991 944 char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
kfraser@12991 945 int flags = 0;
kfraser@12991 946 int store_evtchn, console_evtchn;
hollisb@13924 947 unsigned int mem_mb;
kfraser@12991 948 unsigned long store_mfn = 0;
kfraser@12991 949 unsigned long console_mfn = 0;
kfraser@12991 950 int unused;
kfraser@12991 951
kfraser@12991 952 static char *kwd_list[] = { "dom", "store_evtchn",
jimix@13931 953 "console_evtchn", "image", "memsize",
kfraser@12991 954 /* optional */
kfraser@12991 955 "ramdisk", "cmdline", "flags",
jimix@13939 956 "features", NULL };
kfraser@12991 957
jimix@13939 958 if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis#", kwd_list,
hollisb@13924 959 &dom, &store_evtchn, &mem_mb,
kfraser@12991 960 &console_evtchn, &image,
kfraser@12991 961 /* optional */
kfraser@12991 962 &ramdisk, &cmdline, &flags,
jimix@13939 963 &features, &unused) )
kfraser@12991 964 return NULL;
kfraser@12991 965
hollisb@13924 966 if ( xc_prose_build(self->xc_handle, dom, mem_mb, image,
kfraser@12991 967 ramdisk, cmdline, features, flags,
kfraser@12991 968 store_evtchn, &store_mfn,
jimix@13939 969 console_evtchn, &console_mfn) != 0 ) {
kfraser@12991 970 if (!errno)
kfraser@12991 971 errno = EINVAL;
hollisb@13924 972 return pyxc_error_to_exception();
kfraser@12991 973 }
kfraser@12991 974 return Py_BuildValue("{s:i,s:i}",
kfraser@12991 975 "store_mfn", store_mfn,
kfraser@12991 976 "console_mfn", console_mfn);
kfraser@12991 977 }
kfraser@12991 978 #endif /* powerpc */
emellor@7971 979
mjw@1629 980 static PyMethodDef pyxc_methods[] = {
cl349@5099 981 { "handle",
cl349@5099 982 (PyCFunction)pyxc_handle,
emellor@7971 983 METH_NOARGS, "\n"
cl349@5099 984 "Query the xc control interface file descriptor.\n\n"
cl349@5099 985 "Returns: [int] file descriptor\n" },
cl349@5306 986
mjw@1629 987 { "domain_create",
mjw@1629 988 (PyCFunction)pyxc_domain_create,
mjw@1629 989 METH_VARARGS | METH_KEYWORDS, "\n"
mjw@1629 990 "Create a new domain.\n"
mjw@1891 991 " dom [int, 0]: Domain identifier to use (allocated if zero).\n"
mjw@1629 992 "Returns: [int] new domain identifier; -1 on error.\n" },
mjw@1629 993
kaf24@7364 994 { "domain_max_vcpus",
kaf24@7364 995 (PyCFunction)pyxc_domain_max_vcpus,
emellor@7971 996 METH_VARARGS, "\n"
kaf24@7364 997 "Set the maximum number of VCPUs a domain may create.\n"
kaf24@7364 998 " dom [int, 0]: Domain identifier to use.\n"
kaf24@7364 999 " max [int, 0]: New maximum number of VCPUs in domain.\n"
kaf24@7364 1000 "Returns: [int] 0 on success; -1 on error.\n" },
kaf24@7364 1001
kaf24@4719 1002 { "domain_dumpcore",
kaf24@4719 1003 (PyCFunction)pyxc_domain_dumpcore,
emellor@7971 1004 METH_VARARGS, "\n"
cl349@5304 1005 "Dump core of a domain.\n"
cl349@5306 1006 " dom [int]: Identifier of domain to dump core of.\n"
kaf24@4719 1007 " corefile [string]: Name of corefile to be created.\n\n"
kaf24@4719 1008 "Returns: [int] 0 on success; -1 on error.\n" },
kaf24@4719 1009
mjw@1629 1010 { "domain_pause",
mjw@1629 1011 (PyCFunction)pyxc_domain_pause,
emellor@7971 1012 METH_VARARGS, "\n"
mjw@1629 1013 "Temporarily pause execution of a domain.\n"
mjw@1629 1014 " dom [int]: Identifier of domain to be paused.\n\n"
mjw@1629 1015 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1016
mjw@1629 1017 { "domain_unpause",
mjw@1629 1018 (PyCFunction)pyxc_domain_unpause,
emellor@7971 1019 METH_VARARGS, "\n"
mjw@1629 1020 "(Re)start execution of a domain.\n"
mjw@1629 1021 " dom [int]: Identifier of domain to be unpaused.\n\n"
mjw@1629 1022 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1023
mjw@1629 1024 { "domain_destroy",
mjw@1629 1025 (PyCFunction)pyxc_domain_destroy,
emellor@7971 1026 METH_VARARGS, "\n"
mjw@1629 1027 "Destroy a domain.\n"
mjw@1629 1028 " dom [int]: Identifier of domain to be destroyed.\n\n"
mjw@1629 1029 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1030
kaf24@8508 1031 { "vcpu_setaffinity",
kaf24@8508 1032 (PyCFunction)pyxc_vcpu_setaffinity,
mjw@1629 1033 METH_VARARGS | METH_KEYWORDS, "\n"
cl349@4845 1034 "Pin a VCPU to a specified set CPUs.\n"
cl349@4845 1035 " dom [int]: Identifier of domain to which VCPU belongs.\n"
cl349@4845 1036 " vcpu [int, 0]: VCPU being pinned.\n"
kaf24@7483 1037 " cpumap [list, []]: list of usable CPUs.\n\n"
mjw@1629 1038 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1039
cl349@5045 1040 { "domain_setcpuweight",
cl349@5045 1041 (PyCFunction)pyxc_domain_setcpuweight,
cl349@5045 1042 METH_VARARGS | METH_KEYWORDS, "\n"
cl349@5045 1043 "Set cpuweight scheduler parameter for domain.\n"
cl349@5045 1044 " dom [int]: Identifier of domain to be changed.\n"
cl349@5045 1045 " cpuweight [float, 1]: VCPU being pinned.\n"
cl349@5045 1046 "Returns: [int] 0 on success; -1 on error.\n" },
cl349@5045 1047
kaf24@7389 1048 { "domain_sethandle",
kaf24@7389 1049 (PyCFunction)pyxc_domain_sethandle,
emellor@7971 1050 METH_VARARGS, "\n"
kaf24@7389 1051 "Set domain's opaque handle.\n"
kaf24@7389 1052 " dom [int]: Identifier of domain.\n"
kaf24@7389 1053 " handle [list of 16 ints]: New opaque handle.\n"
kaf24@7389 1054 "Returns: [int] 0 on success; -1 on error.\n" },
kaf24@7389 1055
mjw@1629 1056 { "domain_getinfo",
mjw@1629 1057 (PyCFunction)pyxc_domain_getinfo,
mjw@1629 1058 METH_VARARGS | METH_KEYWORDS, "\n"
mjw@1629 1059 "Get information regarding a set of domains, in increasing id order.\n"
mjw@1629 1060 " first_dom [int, 0]: First domain to retrieve info about.\n"
mjw@1629 1061 " max_doms [int, 1024]: Maximum number of domains to retrieve info"
mjw@1629 1062 " about.\n\n"
mjw@1629 1063 "Returns: [list of dicts] if list length is less than 'max_doms'\n"
mjw@1629 1064 " parameter then there was an error, or the end of the\n"
mjw@1629 1065 " domain-id space was reached.\n"
mjw@1629 1066 " dom [int]: Identifier of domain to which this info pertains\n"
mjw@1629 1067 " cpu [int]: CPU to which this domain is bound\n"
cl349@4845 1068 " vcpus [int]: Number of Virtual CPUS in this domain\n"
mjw@1629 1069 " dying [int]: Bool - is the domain dying?\n"
mjw@1629 1070 " crashed [int]: Bool - has the domain crashed?\n"
mjw@1629 1071 " shutdown [int]: Bool - has the domain shut itself down?\n"
mjw@1629 1072 " paused [int]: Bool - is the domain paused by control software?\n"
mjw@1629 1073 " blocked [int]: Bool - is the domain blocked waiting for an event?\n"
mjw@1629 1074 " running [int]: Bool - is the domain currently running?\n"
mjw@1629 1075 " mem_kb [int]: Memory reservation, in kilobytes\n"
mjw@1928 1076 " maxmem_kb [int]: Maximum memory limit, in kilobytes\n"
mjw@1629 1077 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
mjw@1629 1078 " shutdown_reason [int]: Numeric code from guest OS, explaining "
emellor@7410 1079 "reason why it shut itself down.\n" },
mjw@1629 1080
kaf24@7407 1081 { "vcpu_getinfo",
kaf24@7407 1082 (PyCFunction)pyxc_vcpu_getinfo,
kaf24@7407 1083 METH_VARARGS | METH_KEYWORDS, "\n"
kaf24@7407 1084 "Get information regarding a VCPU.\n"
kaf24@7407 1085 " dom [int]: Domain to retrieve info about.\n"
kaf24@7407 1086 " vcpu [int, 0]: VCPU to retrieve info about.\n\n"
kaf24@7407 1087 "Returns: [dict]\n"
kaf24@7407 1088 " online [int]: Bool - Is this VCPU currently online?\n"
kaf24@7407 1089 " blocked [int]: Bool - Is this VCPU blocked waiting for an event?\n"
kaf24@7407 1090 " running [int]: Bool - Is this VCPU currently running on a CPU?\n"
kaf24@7407 1091 " cpu_time [long]: CPU time consumed, in nanoseconds\n"
kaf24@7407 1092 " cpumap [int]: Bitmap of CPUs this VCPU can run on\n"
kaf24@7407 1093 " cpu [int]: CPU that this VCPU is currently bound to\n" },
kaf24@7407 1094
mjw@1629 1095 { "linux_build",
mjw@1629 1096 (PyCFunction)pyxc_linux_build,
mjw@1629 1097 METH_VARARGS | METH_KEYWORDS, "\n"
mjw@1629 1098 "Build a new Linux guest OS.\n"
mjw@1629 1099 " dom [int]: Identifier of domain to build into.\n"
mjw@1629 1100 " image [str]: Name of kernel image file. May be gzipped.\n"
mjw@1629 1101 " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
mjw@1629 1102 " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
cl349@3451 1103 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
mjw@1629 1104 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1105
kaf24@8708 1106 { "hvm_build",
kaf24@8708 1107 (PyCFunction)pyxc_hvm_build,
iap10@3390 1108 METH_VARARGS | METH_KEYWORDS, "\n"
kaf24@8708 1109 "Build a new HVM guest OS.\n"
iap10@3390 1110 " dom [int]: Identifier of domain to build into.\n"
kaf24@8708 1111 " image [str]: Name of HVM loader image file.\n"
emellor@7448 1112 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
mjw@1629 1113 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1114
atse@12145 1115 { "sched_id_get",
atse@12145 1116 (PyCFunction)pyxc_sched_id_get,
atse@12145 1117 METH_NOARGS, "\n"
atse@12145 1118 "Get the current scheduler type in use.\n"
atse@12145 1119 "Returns: [int] sched_id.\n" },
atse@12145 1120
sd386@3449 1121 { "sedf_domain_set",
sd386@3449 1122 (PyCFunction)pyxc_sedf_domain_set,
sd386@3449 1123 METH_KEYWORDS, "\n"
sd386@3449 1124 "Set the scheduling parameters for a domain when running with Atropos.\n"
sd386@3573 1125 " dom [int]: domain to set\n"
sd386@3573 1126 " period [long]: domain's scheduling period\n"
sd386@3573 1127 " slice [long]: domain's slice per period\n"
sd386@3573 1128 " latency [long]: domain's wakeup latency hint\n"
sd386@3573 1129 " extratime [int]: domain aware of extratime?\n"
sd386@3449 1130 "Returns: [int] 0 on success; -1 on error.\n" },
sd386@3449 1131
sd386@3449 1132 { "sedf_domain_get",
sd386@3449 1133 (PyCFunction)pyxc_sedf_domain_get,
emellor@7971 1134 METH_VARARGS, "\n"
sd386@3449 1135 "Get the current scheduling parameters for a domain when running with\n"
sd386@3449 1136 "the Atropos scheduler."
sd386@3573 1137 " dom [int]: domain to query\n"
sd386@3573 1138 "Returns: [dict]\n"
sd386@3573 1139 " domain [int]: domain ID\n"
sd386@3573 1140 " period [long]: scheduler period\n"
sd386@3573 1141 " slice [long]: CPU reservation per period\n"
sd386@3573 1142 " latency [long]: domain's wakeup latency hint\n"
sd386@3573 1143 " extratime [int]: domain aware of extratime?\n"},
ack@10188 1144
kaf24@10206 1145 { "sched_credit_domain_set",
kaf24@10206 1146 (PyCFunction)pyxc_sched_credit_domain_set,
ack@10188 1147 METH_KEYWORDS, "\n"
ack@10188 1148 "Set the scheduling parameters for a domain when running with the\n"
ack@10188 1149 "SMP credit scheduler.\n"
ack@10188 1150 " domid [int]: domain id to set\n"
ack@10188 1151 " weight [short]: domain's scheduling weight\n"
ack@10188 1152 "Returns: [int] 0 on success; -1 on error.\n" },
ack@10188 1153
kaf24@10206 1154 { "sched_credit_domain_get",
kaf24@10206 1155 (PyCFunction)pyxc_sched_credit_domain_get,
ack@10188 1156 METH_VARARGS, "\n"
ack@10188 1157 "Get the scheduling parameters for a domain when running with the\n"
ack@10188 1158 "SMP credit scheduler.\n"
ack@10188 1159 " domid [int]: domain id to get\n"
ack@10188 1160 "Returns: [dict]\n"
ack@10188 1161 " weight [short]: domain's scheduling weight\n"},
mjw@1629 1162
kaf24@2713 1163 { "evtchn_alloc_unbound",
kaf24@2713 1164 (PyCFunction)pyxc_evtchn_alloc_unbound,
kaf24@2713 1165 METH_VARARGS | METH_KEYWORDS, "\n"
kaf24@7250 1166 "Allocate an unbound port that will await a remote connection.\n"
kaf24@7250 1167 " dom [int]: Domain whose port space to allocate from.\n"
kaf24@7250 1168 " remote_dom [int]: Remote domain to accept connections from.\n\n"
kaf24@2713 1169 "Returns: [int] Unbound event-channel port.\n" },
kaf24@2713 1170
mjw@1629 1171 { "physdev_pci_access_modify",
mjw@1629 1172 (PyCFunction)pyxc_physdev_pci_access_modify,
mjw@1629 1173 METH_VARARGS | METH_KEYWORDS, "\n"
mjw@1629 1174 "Allow a domain access to a PCI device\n"
mjw@1629 1175 " dom [int]: Identifier of domain to be allowed access.\n"
mjw@1629 1176 " bus [int]: PCI bus\n"
mjw@1629 1177 " dev [int]: PCI slot\n"
mjw@1629 1178 " func [int]: PCI function\n"
mjw@1629 1179 " enable [int]: Non-zero means enable access; else disable access\n\n"
mjw@1629 1180 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1181
mjw@1629 1182 { "readconsolering",
mjw@1629 1183 (PyCFunction)pyxc_readconsolering,
mjw@1629 1184 METH_VARARGS | METH_KEYWORDS, "\n"
mjw@1629 1185 "Read Xen's console ring.\n"
mjw@1629 1186 " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
mjw@1629 1187 "Returns: [str] string is empty on failure.\n" },
mjw@1629 1188
mjw@1629 1189 { "physinfo",
mjw@1629 1190 (PyCFunction)pyxc_physinfo,
emellor@7971 1191 METH_NOARGS, "\n"
mjw@1629 1192 "Get information about the physical host machine\n"
mjw@1629 1193 "Returns [dict]: information about the hardware"
mjw@1629 1194 " [None]: on failure.\n" },
mjw@1629 1195
vh249@6567 1196 { "xeninfo",
vh249@6567 1197 (PyCFunction)pyxc_xeninfo,
emellor@7971 1198 METH_NOARGS, "\n"
vh249@6567 1199 "Get information about the Xen host\n"
vh249@6567 1200 "Returns [dict]: information about Xen"
vh249@6567 1201 " [None]: on failure.\n" },
vh249@6567 1202
tdeegan@11172 1203 { "shadow_control",
tdeegan@11172 1204 (PyCFunction)pyxc_shadow_control,
tdeegan@11172 1205 METH_VARARGS | METH_KEYWORDS, "\n"
tdeegan@11172 1206 "Set parameter for shadow pagetable interface\n"
tdeegan@11172 1207 " dom [int]: Identifier of domain.\n"
tdeegan@11172 1208 " op [int, 0]: operation\n\n"
tdeegan@11172 1209 "Returns: [int] 0 on success; -1 on error.\n" },
tdeegan@11172 1210
tdeegan@11172 1211 { "shadow_mem_control",
tdeegan@11172 1212 (PyCFunction)pyxc_shadow_mem_control,
tdeegan@11172 1213 METH_VARARGS | METH_KEYWORDS, "\n"
tdeegan@11172 1214 "Set or read shadow pagetable memory use\n"
tdeegan@11172 1215 " dom [int]: Identifier of domain.\n"
tdeegan@11172 1216 " mb [int, -1]: MB of shadow memory this domain should have.\n\n"
tdeegan@11172 1217 "Returns: [int] MB of shadow memory in use by this domain.\n" },
tdeegan@11172 1218
mjw@1629 1219 { "domain_setmaxmem",
mjw@1629 1220 (PyCFunction)pyxc_domain_setmaxmem,
emellor@7971 1221 METH_VARARGS, "\n"
mjw@1629 1222 "Set a domain's memory limit\n"
mjw@1629 1223 " dom [int]: Identifier of domain.\n"
emellor@6997 1224 " maxmem_kb [int]: .\n"
mjw@1629 1225 "Returns: [int] 0 on success; -1 on error.\n" },
mjw@1629 1226
kfraser@12872 1227 { "domain_set_memmap_limit",
kfraser@12872 1228 (PyCFunction)pyxc_domain_set_memmap_limit,
kfraser@12872 1229 METH_VARARGS, "\n"
kfraser@12872 1230 "Set a domain's physical memory mappping limit\n"
kfraser@12872 1231 " dom [int]: Identifier of domain.\n"
kfraser@12872 1232 " map_limitkb [int]: .\n"
kfraser@12872 1233 "Returns: [int] 0 on success; -1 on error.\n" },
kfraser@12872 1234
cl349@5045 1235 { "domain_memory_increase_reservation",
cl349@5045 1236 (PyCFunction)pyxc_domain_memory_increase_reservation,
cl349@5045 1237 METH_VARARGS | METH_KEYWORDS, "\n"
cl349@5045 1238 "Increase a domain's memory reservation\n"
cl349@5045 1239 " dom [int]: Identifier of domain.\n"
cl349@5045 1240 " mem_kb [long]: .\n"
cl349@5045 1241 "Returns: [int] 0 on success; -1 on error.\n" },
cl349@5045 1242
kaf24@7638 1243 { "domain_ioport_permission",
kaf24@7638 1244 (PyCFunction)pyxc_domain_ioport_permission,
kaf24@7638 1245 METH_VARARGS | METH_KEYWORDS, "\n"
kaf24@7638 1246 "Allow a domain access to a range of IO ports\n"
kaf24@7638 1247 " dom [int]: Identifier of domain to be allowed access.\n"
kaf24@7638 1248 " first_port [int]: First IO port\n"
kaf24@7638 1249 " nr_ports [int]: Number of IO ports\n"
kaf24@7638 1250 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
kaf24@7638 1251 "Returns: [int] 0 on success; -1 on error.\n" },
kaf24@7638 1252
kaf24@8468 1253 { "domain_irq_permission",
kaf24@8468 1254 (PyCFunction)pyxc_domain_irq_permission,
kaf24@8468 1255 METH_VARARGS | METH_KEYWORDS, "\n"
kaf24@8468 1256 "Allow a domain access to a physical IRQ\n"
kaf24@8468 1257 " dom [int]: Identifier of domain to be allowed access.\n"
kaf24@8468 1258 " pirq [int]: The Physical IRQ\n"
kaf24@8468 1259 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
kaf24@8468 1260 "Returns: [int] 0 on success; -1 on error.\n" },
kaf24@8468 1261
kaf24@8468 1262 { "domain_iomem_permission",
kaf24@8468 1263 (PyCFunction)pyxc_domain_iomem_permission,
kaf24@8468 1264 METH_VARARGS | METH_KEYWORDS, "\n"
kaf24@8468 1265 "Allow a domain access to a range of IO memory pages\n"
kaf24@8468 1266 " dom [int]: Identifier of domain to be allowed access.\n"
kaf24@8468 1267 " first_pfn [long]: First page of I/O Memory\n"
kaf24@8468 1268 " nr_pfns [long]: Number of pages of I/O Memory (>0)\n"
kaf24@8468 1269 " allow_access [int]: Non-zero means enable access; else disable access\n\n"
kaf24@8468 1270 "Returns: [int] 0 on success; -1 on error.\n" },
kaf24@8468 1271
emellor@8158 1272 { "pages_to_kib",
emellor@8158 1273 (PyCFunction)pyxc_pages_to_kib,
emellor@8158 1274 METH_VARARGS, "\n"
emellor@8158 1275 "Returns: [int]: The size in KiB of memory spanning the given number "
emellor@8158 1276 "of pages.\n" },
emellor@8158 1277
kaf24@10506 1278 { "domain_set_time_offset",
kaf24@10506 1279 (PyCFunction)pyxc_domain_set_time_offset,
kaf24@10506 1280 METH_VARARGS, "\n"
kaf24@10506 1281 "Set a domain's time offset to Dom0's localtime\n"
kaf24@10506 1282 " dom [int]: Domain whose time offset is being set.\n"
kaf24@10506 1283 "Returns: [int] 0 on success; -1 on error.\n" },
kaf24@10506 1284
kfraser@12991 1285 #ifdef __powerpc__
kfraser@12991 1286 { "arch_alloc_real_mode_area",
kfraser@12991 1287 (PyCFunction)pyxc_alloc_real_mode_area,
kfraser@12991 1288 METH_VARARGS | METH_KEYWORDS, "\n"
kfraser@12991 1289 "Allocate a domain's real mode area.\n"
kfraser@12991 1290 " dom [int]: Identifier of domain.\n"
kfraser@12991 1291 " log [int]: Specifies the area's size.\n"
kfraser@12991 1292 "Returns: [int] 0 on success; -1 on error.\n" },
kfraser@12991 1293
kfraser@12991 1294 { "arch_prose_build",
kfraser@12991 1295 (PyCFunction)pyxc_prose_build,
kfraser@12991 1296 METH_VARARGS | METH_KEYWORDS, "\n"
kfraser@12991 1297 "Build a new Linux guest OS.\n"
kfraser@12991 1298 " dom [int]: Identifier of domain to build into.\n"
kfraser@12991 1299 " image [str]: Name of kernel image file. May be gzipped.\n"
kfraser@12991 1300 " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
kfraser@12991 1301 " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
kfraser@12991 1302 " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
kfraser@12991 1303 "Returns: [int] 0 on success; -1 on error.\n" },
kfraser@12991 1304 #endif /* __powerpc */
kfraser@12991 1305
mjw@1629 1306 { NULL, NULL, 0, NULL }
mjw@1629 1307 };
mjw@1629 1308
mjw@1629 1309
mjw@1629 1310 static PyObject *PyXc_getattr(PyObject *obj, char *name)
mjw@1629 1311 {
mjw@1629 1312 return Py_FindMethod(pyxc_methods, obj, name);
mjw@1629 1313 }
mjw@1629 1314
emellor@7977 1315 static PyObject *PyXc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
mjw@1629 1316 {
emellor@7973 1317 XcObject *self = (XcObject *)type->tp_alloc(type, 0);
emellor@7973 1318
emellor@7973 1319 if (self == NULL)
emellor@7973 1320 return NULL;
emellor@7973 1321
emellor@7977 1322 self->xc_handle = -1;
emellor@7973 1323
emellor@7973 1324 return (PyObject *)self;
emellor@7973 1325 }
emellor@7973 1326
emellor@7973 1327 static int
emellor@7973 1328 PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
emellor@7973 1329 {
emellor@7973 1330 if ((self->xc_handle = xc_interface_open()) == -1) {
kfraser@12834 1331 pyxc_error_to_exception();
emellor@7973 1332 return -1;
emellor@7973 1333 }
emellor@7973 1334
emellor@7973 1335 return 0;
emellor@7973 1336 }
emellor@7973 1337
emellor@7973 1338 static void PyXc_dealloc(XcObject *self)
emellor@7973 1339 {
emellor@7977 1340 if (self->xc_handle != -1) {
emellor@7973 1341 xc_interface_close(self->xc_handle);
emellor@7977 1342 self->xc_handle = -1;
emellor@7973 1343 }
emellor@7973 1344
emellor@7973 1345 self->ob_type->tp_free((PyObject *)self);
mjw@1629 1346 }
mjw@1629 1347
mjw@1629 1348 static PyTypeObject PyXcType = {
emellor@7973 1349 PyObject_HEAD_INIT(NULL)
mjw@1629 1350 0,
emellor@7973 1351 PKG "." CLS,
mjw@1629 1352 sizeof(XcObject),
mjw@1629 1353 0,
emellor@7973 1354 (destructor)PyXc_dealloc, /* tp_dealloc */
emellor@7973 1355 NULL, /* tp_print */
emellor@7973 1356 PyXc_getattr, /* tp_getattr */
emellor@7973 1357 NULL, /* tp_setattr */
emellor@7973 1358 NULL, /* tp_compare */
emellor@7973 1359 NULL, /* tp_repr */
emellor@7973 1360 NULL, /* tp_as_number */
emellor@7973 1361 NULL, /* tp_as_sequence */
emellor@7973 1362 NULL, /* tp_as_mapping */
emellor@7973 1363 NULL, /* tp_hash */
emellor@7973 1364 NULL, /* tp_call */
emellor@7973 1365 NULL, /* tp_str */
emellor@7973 1366 NULL, /* tp_getattro */
emellor@7973 1367 NULL, /* tp_setattro */
emellor@7973 1368 NULL, /* tp_as_buffer */
emellor@7973 1369 Py_TPFLAGS_DEFAULT, /* tp_flags */
emellor@7973 1370 "Xen client connections", /* tp_doc */
emellor@7973 1371 NULL, /* tp_traverse */
emellor@7973 1372 NULL, /* tp_clear */
emellor@7973 1373 NULL, /* tp_richcompare */
emellor@7973 1374 0, /* tp_weaklistoffset */
emellor@7973 1375 NULL, /* tp_iter */
emellor@7973 1376 NULL, /* tp_iternext */
emellor@7973 1377 pyxc_methods, /* tp_methods */
emellor@7973 1378 NULL, /* tp_members */
emellor@7973 1379 NULL, /* tp_getset */
emellor@7973 1380 NULL, /* tp_base */
emellor@7973 1381 NULL, /* tp_dict */
emellor@7973 1382 NULL, /* tp_descr_get */
emellor@7973 1383 NULL, /* tp_descr_set */
emellor@7973 1384 0, /* tp_dictoffset */
emellor@7973 1385 (initproc)PyXc_init, /* tp_init */
emellor@7973 1386 NULL, /* tp_alloc */
emellor@7973 1387 PyXc_new, /* tp_new */
mjw@1629 1388 };
mjw@1629 1389
emellor@7973 1390 static PyMethodDef xc_methods[] = { { NULL } };
mjw@1629 1391
mjw@1629 1392 PyMODINIT_FUNC initxc(void)
mjw@1629 1393 {
emellor@7973 1394 PyObject *m;
mjw@1629 1395
emellor@7973 1396 if (PyType_Ready(&PyXcType) < 0)
emellor@7973 1397 return;
mjw@1629 1398
emellor@7977 1399 m = Py_InitModule(PKG, xc_methods);
emellor@7973 1400
emellor@7973 1401 if (m == NULL)
emellor@7973 1402 return;
emellor@7973 1403
kfraser@12834 1404 xc_error_obj = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
mjw@1629 1405 zero = PyInt_FromLong(0);
kaf24@2500 1406
kaf24@2500 1407 /* KAF: This ensures that we get debug output in a timely manner. */
kaf24@2500 1408 setbuf(stdout, NULL);
kaf24@2500 1409 setbuf(stderr, NULL);
emellor@7973 1410
emellor@7973 1411 Py_INCREF(&PyXcType);
emellor@7973 1412 PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
anthony@10116 1413
kfraser@12834 1414 Py_INCREF(xc_error_obj);
kfraser@12834 1415 PyModule_AddObject(m, "Error", xc_error_obj);
atse@12145 1416
atse@12145 1417 /* Expose some libxc constants to Python */
atse@12145 1418 PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF);
atse@12145 1419 PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT);
atse@12145 1420
mjw@1629 1421 }
emellor@7971 1422
emellor@7971 1423
emellor@7971 1424 /*
emellor@7971 1425 * Local variables:
emellor@7971 1426 * c-indent-level: 4
emellor@7971 1427 * c-basic-offset: 4
emellor@7971 1428 * End:
emellor@7971 1429 */