direct-io.hg
changeset 6669:4e4aac33809f
g/c unused xu extension.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Wed Sep 07 18:37:55 2005 +0000 (2005-09-07) |
parents | 0e2b1e04d4cb |
children | 38c5199155fc |
files | tools/python/setup.py tools/python/xen/xend/server/channel.py |
line diff
1.1 --- a/tools/python/setup.py Wed Sep 07 18:28:04 2005 +0000 1.2 +++ b/tools/python/setup.py Wed Sep 07 18:37:55 2005 +0000 1.3 @@ -7,10 +7,8 @@ XEN_ROOT = "../.." 1.4 extra_compile_args = [ "-fno-strict-aliasing", "-Wall", "-Werror" ] 1.5 1.6 1.7 -include_dirs = [ XEN_ROOT + "/tools/python/xen/lowlevel/xu", 1.8 - XEN_ROOT + "/tools/libxc", 1.9 +include_dirs = [ XEN_ROOT + "/tools/libxc", 1.10 XEN_ROOT + "/tools/xenstore", 1.11 - XEN_ROOT + "/tools/xcs", 1.12 ] 1.13 1.14 library_dirs = [ XEN_ROOT + "/tools/libxc", 1.15 @@ -26,13 +24,6 @@ xc = Extension("xc", 1.16 libraries = libraries, 1.17 sources = [ "xen/lowlevel/xc/xc.c" ]) 1.18 1.19 -xu = Extension("xu", 1.20 - extra_compile_args = extra_compile_args, 1.21 - include_dirs = include_dirs + [ "xen/lowlevel/xu" ], 1.22 - library_dirs = library_dirs, 1.23 - libraries = libraries, 1.24 - sources = [ "xen/lowlevel/xu/xu.c" ]) 1.25 - 1.26 xs = Extension("xs", 1.27 extra_compile_args = extra_compile_args, 1.28 include_dirs = include_dirs + [ "xen/lowlevel/xs" ], 1.29 @@ -51,10 +42,10 @@ setup(name = 'xen', 1.30 'xen.xend.xenstore', 1.31 'xen.xm', 1.32 'xen.web', 1.33 - 'xen.sv' 1.34 + 'xen.sv' 1.35 ], 1.36 ext_package = "xen.lowlevel", 1.37 - ext_modules = [ xc, xu, xs ] 1.38 + ext_modules = [ xc, xs ] 1.39 ) 1.40 1.41 os.chdir('logging')
3.1 --- a/tools/python/xen/lowlevel/xu/xu.c Wed Sep 07 18:28:04 2005 +0000 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,1781 +0,0 @@ 3.4 -/****************************************************************************** 3.5 - * utils.c 3.6 - * 3.7 - * Copyright (c) 2004, K A Fraser 3.8 - */ 3.9 - 3.10 -#include <Python.h> 3.11 -#include <stdio.h> 3.12 -#include <stdlib.h> 3.13 -#include <string.h> 3.14 -#include <sys/ioctl.h> 3.15 -#include <sys/types.h> 3.16 -#include <sys/wait.h> 3.17 -#include <sys/stat.h> 3.18 -#include <sys/socket.h> 3.19 -#include <sys/un.h> 3.20 -#include <sys/mman.h> 3.21 -#include <sys/poll.h> 3.22 -#include <sys/sysmacros.h> 3.23 -#include <fcntl.h> 3.24 -#include <unistd.h> 3.25 -#include <errno.h> 3.26 -#include <signal.h> 3.27 -#include <xenctrl.h> 3.28 - 3.29 -#include <xen/xen.h> 3.30 -#include <xen/io/domain_controller.h> 3.31 -#include <xen/linux/privcmd.h> 3.32 - 3.33 -#define XENPKG "xen.lowlevel.xu" 3.34 - 3.35 -/* Needed for Python versions earlier than 2.3. */ 3.36 -#ifndef PyMODINIT_FUNC 3.37 -#define PyMODINIT_FUNC DL_EXPORT(void) 3.38 -#endif 3.39 - 3.40 -/* NB. The following should be kept in sync with the kernel's evtchn driver. */ 3.41 -#define EVTCHN_DEV_NAME "/dev/xen/evtchn" 3.42 -#define EVTCHN_DEV_MAJOR 10 3.43 -#define EVTCHN_DEV_MINOR 201 3.44 -/* /dev/xen/evtchn ioctls: */ 3.45 -/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */ 3.46 -#define EVTCHN_RESET _IO('E', 1) 3.47 -/* EVTCHN_BIND: Bind to teh specified event-channel port. */ 3.48 -#define EVTCHN_BIND _IO('E', 2) 3.49 -/* EVTCHN_UNBIND: Unbind from the specified event-channel port. */ 3.50 -#define EVTCHN_UNBIND _IO('E', 3) 3.51 - 3.52 -/* Set the close-on-exec flag on a file descriptor. Doesn't currently bother 3.53 - * to check for errors. */ 3.54 -/* 3.55 -static void set_cloexec(int fd) 3.56 -{ 3.57 - int flags = fcntl(fd, F_GETFD, 0); 3.58 - 3.59 - if ( flags < 0 ) 3.60 - return; 3.61 - 3.62 - flags |= FD_CLOEXEC; 3.63 - fcntl(fd, F_SETFD, flags); 3.64 -} 3.65 -*/ 3.66 -/* 3.67 - * *********************** XCS INTERFACE *********************** 3.68 - */ 3.69 - 3.70 -#include <arpa/inet.h> 3.71 -#include <xcs_proto.h> 3.72 - 3.73 -static int xcs_ctrl_fd = -1; /* control connection to the xcs server. */ 3.74 -static int xcs_data_fd = -1; /* data connection to the xcs server. */ 3.75 -static unsigned long xcs_session_id = 0; 3.76 - 3.77 -static int xcs_ctrl_send(xcs_msg_t *msg); 3.78 -static int xcs_ctrl_read(xcs_msg_t *msg); 3.79 -static int xcs_data_send(xcs_msg_t *msg); 3.80 -static int xcs_data_read(xcs_msg_t *msg); 3.81 - 3.82 -static int xcs_connect(char *path) 3.83 -{ 3.84 - struct sockaddr_un addr; 3.85 - int ret, len, flags; 3.86 - xcs_msg_t msg; 3.87 - 3.88 - if (xcs_data_fd != -1) /* already connected */ 3.89 - return 0; 3.90 - 3.91 - xcs_ctrl_fd = socket(AF_UNIX, SOCK_STREAM, 0); 3.92 - if (xcs_ctrl_fd < 0) 3.93 - { 3.94 - printf("error creating xcs socket!\n"); 3.95 - goto fail; 3.96 - } 3.97 - 3.98 - addr.sun_family = AF_UNIX; 3.99 - strcpy(addr.sun_path, path); 3.100 - len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1; 3.101 - 3.102 - ret = connect(xcs_ctrl_fd, (struct sockaddr *)&addr, len); 3.103 - if (ret < 0) 3.104 - { 3.105 - printf("error connecting to xcs(ctrl)! (%d)\n", errno); 3.106 - goto ctrl_fd_fail; 3.107 - } 3.108 - 3.109 - /*set_cloexec(xcs_ctrl_fd);*/ 3.110 - 3.111 - msg.type = XCS_CONNECT_CTRL; 3.112 - msg.u.connect.session_id = xcs_session_id; 3.113 - xcs_ctrl_send(&msg); 3.114 - xcs_ctrl_read(&msg); /* TODO: timeout + error! */ 3.115 - 3.116 - if (msg.result != XCS_RSLT_OK) 3.117 - { 3.118 - printf("error connecting xcs control channel!\n"); 3.119 - goto ctrl_fd_fail; 3.120 - } 3.121 - xcs_session_id = msg.u.connect.session_id; 3.122 - 3.123 - /* now the data connection. */ 3.124 - xcs_data_fd = socket(AF_UNIX, SOCK_STREAM, 0); 3.125 - if (xcs_data_fd < 0) 3.126 - { 3.127 - printf("error creating xcs data socket!\n"); 3.128 - goto ctrl_fd_fail; 3.129 - } 3.130 - 3.131 - addr.sun_family = AF_UNIX; 3.132 - strcpy(addr.sun_path, path); 3.133 - len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1; 3.134 - 3.135 - ret = connect(xcs_data_fd, (struct sockaddr *)&addr, len); 3.136 - if (ret < 0) 3.137 - { 3.138 - printf("error connecting to xcs(data)! (%d)\n", errno); 3.139 - goto data_fd_fail; 3.140 - } 3.141 - 3.142 - //set_cloexec(xcs_data_fd); 3.143 - msg.type = XCS_CONNECT_DATA; 3.144 - msg.u.connect.session_id = xcs_session_id; 3.145 - xcs_data_send(&msg); 3.146 - xcs_data_read(&msg); /* TODO: timeout + error! */ 3.147 - 3.148 - if (msg.result != XCS_RSLT_OK) 3.149 - { 3.150 - printf("error connecting xcs control channel!\n"); 3.151 - goto ctrl_fd_fail; 3.152 - } 3.153 - 3.154 - if ( ((flags = fcntl(xcs_data_fd, F_GETFL, 0)) < 0) || 3.155 - (fcntl(xcs_data_fd, F_SETFL, flags | O_NONBLOCK) < 0) ) 3.156 - { 3.157 - printf("Unable to set non-blocking status on data socket."); 3.158 - goto data_fd_fail; 3.159 - } 3.160 - 3.161 - return 0; 3.162 - 3.163 -data_fd_fail: 3.164 - close(xcs_data_fd); 3.165 - xcs_data_fd = -1; 3.166 - 3.167 -ctrl_fd_fail: 3.168 - close(xcs_ctrl_fd); 3.169 - xcs_ctrl_fd = -1; 3.170 - 3.171 -fail: 3.172 - return -1; 3.173 - 3.174 -} 3.175 - 3.176 -static void xcs_disconnect(void) 3.177 -{ 3.178 - close(xcs_data_fd); 3.179 - xcs_data_fd = -1; 3.180 - close(xcs_ctrl_fd); 3.181 - xcs_ctrl_fd = -1; 3.182 -} 3.183 - 3.184 -static int xcs_ctrl_read(xcs_msg_t *msg) 3.185 -{ 3.186 - int ret; 3.187 - 3.188 - ret = read(xcs_ctrl_fd, msg, sizeof(xcs_msg_t)); 3.189 - return ret; 3.190 -} 3.191 - 3.192 -static int xcs_ctrl_send(xcs_msg_t *msg) 3.193 -{ 3.194 - int ret; 3.195 - 3.196 - ret = send(xcs_ctrl_fd, msg, sizeof(xcs_msg_t), 0); 3.197 - return ret; 3.198 -} 3.199 - 3.200 -static int xcs_data_read(xcs_msg_t *msg) 3.201 -{ 3.202 - int ret; 3.203 - 3.204 - ret = read(xcs_data_fd, msg, sizeof(xcs_msg_t)); 3.205 - return ret; 3.206 -} 3.207 - 3.208 -static int xcs_data_send(xcs_msg_t *msg) 3.209 -{ 3.210 - int ret; 3.211 - 3.212 - ret = send(xcs_data_fd, msg, sizeof(xcs_msg_t), 0); 3.213 - return ret; 3.214 -} 3.215 - 3.216 - 3.217 -typedef struct kme_st { 3.218 - xcs_msg_t msg; 3.219 - struct kme_st *next; 3.220 -} xcs_msg_ent_t; 3.221 - 3.222 - 3.223 -#define XCS_RING_SIZE 64 3.224 -static xcs_msg_ent_t *req_ring[64]; 3.225 -static unsigned req_prod = 0; 3.226 -static unsigned req_cons = 0; 3.227 - 3.228 -static xcs_msg_ent_t *rsp_ring[64]; 3.229 -static unsigned rsp_prod = 0; 3.230 -static unsigned rsp_cons = 0; 3.231 - 3.232 -#define REQ_RING_ENT(_idx) (req_ring[(_idx) % XCS_RING_SIZE]) 3.233 -#define RSP_RING_ENT(_idx) (rsp_ring[(_idx) % XCS_RING_SIZE]) 3.234 -#define REQ_RING_FULL ( req_prod - req_cons == XCS_RING_SIZE ) 3.235 -#define RSP_RING_FULL ( rsp_prod - rsp_cons == XCS_RING_SIZE ) 3.236 -#define REQ_RING_EMPTY ( req_prod == req_cons ) 3.237 -#define RSP_RING_EMPTY ( rsp_prod == rsp_cons ) 3.238 -/* 3.239 - * *********************** NOTIFIER *********************** 3.240 - */ 3.241 - 3.242 -typedef struct { 3.243 - PyObject_HEAD; 3.244 - int evtchn_fd; 3.245 -} xu_notifier_object; 3.246 - 3.247 -static PyObject *xu_notifier_read(PyObject *self, PyObject *args) 3.248 -{ 3.249 - xcs_msg_ent_t *ent; 3.250 - int ret; 3.251 - 3.252 - if ( !PyArg_ParseTuple(args, "") ) 3.253 - return NULL; 3.254 - 3.255 - while ((!REQ_RING_FULL) && (!RSP_RING_FULL)) 3.256 - { 3.257 - ent = (xcs_msg_ent_t *)malloc(sizeof(xcs_msg_ent_t)); 3.258 - ret = xcs_data_read(&ent->msg); 3.259 - 3.260 - if (ret == -1) 3.261 - { 3.262 - free(ent); 3.263 - if ( errno == EINTR ) 3.264 - continue; 3.265 - if ( errno == EAGAIN ) 3.266 - break; 3.267 - return PyErr_SetFromErrno(PyExc_IOError); 3.268 - } 3.269 - 3.270 - switch (ent->msg.type) 3.271 - { 3.272 - case XCS_REQUEST: 3.273 - REQ_RING_ENT(req_prod) = ent; 3.274 - req_prod++; 3.275 - continue; 3.276 - 3.277 - case XCS_RESPONSE: 3.278 - RSP_RING_ENT(rsp_prod) = ent; 3.279 - rsp_prod++; 3.280 - continue; 3.281 - 3.282 - case XCS_VIRQ: 3.283 - ret = ent->msg.u.control.local_port; 3.284 - free(ent); 3.285 - return PyInt_FromLong(ret); 3.286 - 3.287 - default: 3.288 - /*printf("Throwing away xcs msg type: %u\n", ent->msg.type);*/ 3.289 - free(ent); 3.290 - } 3.291 - } 3.292 - 3.293 - if (!REQ_RING_EMPTY) 3.294 - { 3.295 - return PyInt_FromLong(REQ_RING_ENT(req_cons)->msg.u.control.local_port); 3.296 - } 3.297 - 3.298 - if (!RSP_RING_EMPTY) 3.299 - { 3.300 - return PyInt_FromLong(RSP_RING_ENT(rsp_cons)->msg.u.control.local_port); 3.301 - } 3.302 - 3.303 - Py_INCREF(Py_None); 3.304 - return Py_None; 3.305 -} 3.306 - 3.307 -static PyObject *xu_notifier_bind_virq(PyObject *self, 3.308 - PyObject *args, PyObject *kwds) 3.309 -{ 3.310 - int virq; 3.311 - xcs_msg_t kmsg; 3.312 - 3.313 - static char *kwd_list[] = { "virq", NULL }; 3.314 - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &virq) ) 3.315 - return NULL; 3.316 - 3.317 - kmsg.type = XCS_VIRQ_BIND; 3.318 - kmsg.u.virq.virq = virq; 3.319 - xcs_ctrl_send(&kmsg); 3.320 - xcs_ctrl_read(&kmsg); 3.321 - 3.322 - if ( kmsg.result != XCS_RSLT_OK ) 3.323 - { 3.324 - Py_INCREF(Py_None); 3.325 - return Py_None; 3.326 - } 3.327 - 3.328 - return PyInt_FromLong(kmsg.u.virq.port); 3.329 -} 3.330 - 3.331 -static PyObject *xu_notifier_virq_send(PyObject *self, 3.332 - PyObject *args, PyObject *kwds) 3.333 -{ 3.334 - int port; 3.335 - xcs_msg_t kmsg; 3.336 - 3.337 - static char *kwd_list[] = { "port", NULL }; 3.338 - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &port) ) 3.339 - return NULL; 3.340 - 3.341 - kmsg.type = XCS_VIRQ; 3.342 - kmsg.u.control.local_port = port; 3.343 - xcs_ctrl_send(&kmsg); 3.344 - xcs_ctrl_read(&kmsg); 3.345 - 3.346 - if ( kmsg.result != XCS_RSLT_OK ) 3.347 - { 3.348 - Py_INCREF(Py_None); 3.349 - return Py_None; 3.350 - } 3.351 - 3.352 - return PyInt_FromLong(kmsg.u.virq.port); 3.353 -} 3.354 - 3.355 -static PyObject *xu_notifier_fileno(PyObject *self, PyObject *args) 3.356 -{ 3.357 - return PyInt_FromLong(xcs_data_fd); 3.358 -} 3.359 - 3.360 -static PyMethodDef xu_notifier_methods[] = { 3.361 - { "read", 3.362 - (PyCFunction)xu_notifier_read, 3.363 - METH_VARARGS, 3.364 - "Read a @port with pending notifications.\n" }, 3.365 - 3.366 - { "bind_virq", 3.367 - (PyCFunction)xu_notifier_bind_virq, 3.368 - METH_VARARGS | METH_KEYWORDS, 3.369 - "Get notifications for a virq.\n" 3.370 - " virq [int]: VIRQ to bind.\n\n" }, 3.371 - 3.372 - { "virq_send", 3.373 - (PyCFunction)xu_notifier_virq_send, 3.374 - METH_VARARGS | METH_KEYWORDS, 3.375 - "Fire a virq notification.\n" 3.376 - " port [int]: port that VIRQ is bound to.\n\n" }, 3.377 - 3.378 - { "fileno", 3.379 - (PyCFunction)xu_notifier_fileno, 3.380 - METH_VARARGS, 3.381 - "Return the file descriptor for the notification channel.\n" }, 3.382 - 3.383 - { NULL, NULL, 0, NULL } 3.384 -}; 3.385 - 3.386 -staticforward PyTypeObject xu_notifier_type; 3.387 - 3.388 -/* connect to xcs if we aren't already, and return a dummy object. */ 3.389 -static PyObject *xu_notifier_new(PyObject *self, PyObject *args) 3.390 -{ 3.391 - xu_notifier_object *xun; 3.392 - int i; 3.393 - 3.394 - if ( !PyArg_ParseTuple(args, "") ) 3.395 - return NULL; 3.396 - 3.397 - xun = PyObject_New(xu_notifier_object, &xu_notifier_type); 3.398 - 3.399 - for (i = 0; i < XCS_RING_SIZE; i++) 3.400 - REQ_RING_ENT(i) = RSP_RING_ENT(i) = NULL; 3.401 - 3.402 - (void)xcs_connect(XCS_SUN_PATH); 3.403 - 3.404 - 3.405 - return (PyObject *)xun; 3.406 -} 3.407 - 3.408 -static PyObject *xu_notifier_getattr(PyObject *obj, char *name) 3.409 -{ 3.410 - return Py_FindMethod(xu_notifier_methods, obj, name); 3.411 -} 3.412 - 3.413 -static void xu_notifier_dealloc(PyObject *self) 3.414 -{ 3.415 - xcs_disconnect(); 3.416 - PyObject_Del(self); 3.417 -} 3.418 - 3.419 -static PyTypeObject xu_notifier_type = { 3.420 - PyObject_HEAD_INIT(&PyType_Type) 3.421 - 0, 3.422 - "notifier", 3.423 - sizeof(xu_notifier_object), 3.424 - 0, 3.425 - xu_notifier_dealloc, /* tp_dealloc */ 3.426 - NULL, /* tp_print */ 3.427 - xu_notifier_getattr, /* tp_getattr */ 3.428 - NULL, /* tp_setattr */ 3.429 - NULL, /* tp_compare */ 3.430 - NULL, /* tp_repr */ 3.431 - NULL, /* tp_as_number */ 3.432 - NULL, /* tp_as_sequence */ 3.433 - NULL, /* tp_as_mapping */ 3.434 - NULL /* tp_hash */ 3.435 -}; 3.436 - 3.437 - 3.438 - 3.439 -/* 3.440 - * *********************** MESSAGE *********************** 3.441 - */ 3.442 - 3.443 -#define TYPE(_x,_y) (((_x)<<8)|(_y)) 3.444 - 3.445 -#define P2C(_struct, _field, _ctype) \ 3.446 - do { \ 3.447 - PyObject *obj; \ 3.448 - if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL ) \ 3.449 - { \ 3.450 - if ( PyInt_Check(obj) ) \ 3.451 - { \ 3.452 - ((_struct *)&xum->msg.msg[0])->_field = \ 3.453 - (_ctype)PyInt_AsLong(obj); \ 3.454 - dict_items_parsed++; \ 3.455 - } \ 3.456 - else if ( PyLong_Check(obj) ) \ 3.457 - { \ 3.458 - ((_struct *)&xum->msg.msg[0])->_field = \ 3.459 - (_ctype)PyLong_AsUnsignedLongLong(obj); \ 3.460 - dict_items_parsed++; \ 3.461 - } \ 3.462 - } \ 3.463 - xum->msg.length = sizeof(_struct); \ 3.464 - } while ( 0 ) 3.465 - 3.466 -/** Set a char[] field in a struct from a Python string. 3.467 - * Can't do this in P2C because of the typing. 3.468 - */ 3.469 -#define P2CSTRING(_struct, _field) \ 3.470 - do { \ 3.471 - PyObject *obj; \ 3.472 - if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL ) \ 3.473 - { \ 3.474 - if ( PyString_Check(obj) ) \ 3.475 - { \ 3.476 - _struct * _cobj = (_struct *)&xum->msg.msg[0]; \ 3.477 - int _field_n = sizeof(_cobj->_field); \ 3.478 - memset(_cobj->_field, 0, _field_n); \ 3.479 - strncpy(_cobj->_field, \ 3.480 - PyString_AsString(obj), \ 3.481 - _field_n - 1); \ 3.482 - dict_items_parsed++; \ 3.483 - } \ 3.484 - } \ 3.485 - xum->msg.length = sizeof(_struct); \ 3.486 - } while ( 0 ) 3.487 - 3.488 -#define C2P(_struct, _field, _pytype, _ctype) \ 3.489 - do { \ 3.490 - PyObject *obj = Py ## _pytype ## _From ## _ctype \ 3.491 - (((_struct *)&xum->msg.msg[0])->_field); \ 3.492 - if ( dict == NULL ) dict = PyDict_New(); \ 3.493 - PyDict_SetItemString(dict, #_field, obj); \ 3.494 - } while ( 0 ) 3.495 - 3.496 -#define PSTR2CHAR(_struct, _field) \ 3.497 - do { \ 3.498 - PyObject *obj; \ 3.499 - if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL ) \ 3.500 - { \ 3.501 - if ( PyString_Check(obj) ) \ 3.502 - { \ 3.503 - char *buffer = PyString_AsString(obj); \ 3.504 - \ 3.505 - strcpy(((_struct *)&xum->msg.msg[0])->_field, \ 3.506 - buffer); \ 3.507 - /* Should complain about length - think later */ \ 3.508 - dict_items_parsed++; \ 3.509 - } \ 3.510 - } \ 3.511 - xum->msg.length = sizeof(_struct); \ 3.512 - } while ( 0 ) 3.513 - 3.514 -typedef struct { 3.515 - PyObject_HEAD; 3.516 - control_msg_t msg; 3.517 -} xu_message_object; 3.518 - 3.519 -static PyObject *xu_message_append_payload(PyObject *self, PyObject *args) 3.520 -{ 3.521 - xu_message_object *xum = (xu_message_object *)self; 3.522 - char *str; 3.523 - int len; 3.524 - 3.525 - if ( !PyArg_ParseTuple(args, "s#", &str, &len) ) 3.526 - return NULL; 3.527 - 3.528 - if ( (len + xum->msg.length) > sizeof(xum->msg.msg) ) 3.529 - { 3.530 - PyErr_SetString(PyExc_RuntimeError, "out of space in control message"); 3.531 - return NULL; 3.532 - } 3.533 - 3.534 - memcpy(&xum->msg.msg[xum->msg.length], str, len); 3.535 - xum->msg.length += len; 3.536 - 3.537 - Py_INCREF(Py_None); 3.538 - return Py_None; 3.539 -} 3.540 - 3.541 -static PyObject *xu_message_set_response_fields(PyObject *self, PyObject *args) 3.542 -{ 3.543 - xu_message_object *xum = (xu_message_object *)self; 3.544 - PyObject *payload; 3.545 - int dict_items_parsed = 0; 3.546 - 3.547 - if ( !PyArg_ParseTuple(args, "O", &payload) ) 3.548 - return NULL; 3.549 - 3.550 - if ( !PyDict_Check(payload) ) 3.551 - { 3.552 - PyErr_SetString(PyExc_TypeError, "payload is not a dictionary"); 3.553 - return NULL; 3.554 - } 3.555 - 3.556 - switch ( TYPE(xum->msg.type, xum->msg.subtype) ) 3.557 - { 3.558 - case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_DRIVER_STATUS): 3.559 - P2C(blkif_fe_driver_status_t, max_handle, u32); 3.560 - break; 3.561 - case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS): 3.562 - P2C(netif_fe_driver_status_t, max_handle, u32); 3.563 - break; 3.564 - } 3.565 - 3.566 - if ( dict_items_parsed != PyDict_Size(payload) ) 3.567 - { 3.568 - PyErr_SetString(PyExc_TypeError, "payload contains bad items"); 3.569 - return NULL; 3.570 - } 3.571 - 3.572 - Py_INCREF(Py_None); 3.573 - return Py_None; 3.574 -} 3.575 - 3.576 -static PyObject *xu_message_get_payload(PyObject *self, PyObject *args) 3.577 -{ 3.578 - xu_message_object *xum = (xu_message_object *)self; 3.579 - PyObject *dict = NULL; 3.580 - 3.581 - if ( !PyArg_ParseTuple(args, "") ) 3.582 - return NULL; 3.583 - 3.584 - switch ( TYPE(xum->msg.type, xum->msg.subtype) ) 3.585 - { 3.586 - case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_STATUS): 3.587 - C2P(blkif_fe_interface_status_t, handle, Int, Long); 3.588 - C2P(blkif_fe_interface_status_t, status, Int, Long); 3.589 - C2P(blkif_fe_interface_status_t, evtchn, Int, Long); 3.590 - return dict; 3.591 - case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_DRIVER_STATUS): 3.592 - C2P(blkif_fe_driver_status_t, status, Int, Long); 3.593 - return dict; 3.594 - case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_CONNECT): 3.595 - C2P(blkif_fe_interface_connect_t, handle, Int, Long); 3.596 - C2P(blkif_fe_interface_connect_t, shmem_frame, Int, Long); 3.597 - C2P(blkif_fe_interface_connect_t, shmem_ref , Int, Long); 3.598 - return dict; 3.599 - case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_DISCONNECT): 3.600 - C2P(blkif_fe_interface_disconnect_t, handle, Int, Long); 3.601 - return dict; 3.602 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE): 3.603 - C2P(blkif_be_create_t, domid, Int, Long); 3.604 - C2P(blkif_be_create_t, blkif_handle, Int, Long); 3.605 - C2P(blkif_be_create_t, status, Int, Long); 3.606 - return dict; 3.607 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY): 3.608 - C2P(blkif_be_destroy_t, domid, Int, Long); 3.609 - C2P(blkif_be_destroy_t, blkif_handle, Int, Long); 3.610 - C2P(blkif_be_destroy_t, status, Int, Long); 3.611 - return dict; 3.612 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT): 3.613 - C2P(blkif_be_connect_t, domid, Int, Long); 3.614 - C2P(blkif_be_connect_t, blkif_handle, Int, Long); 3.615 - C2P(blkif_be_connect_t, shmem_frame, Int, Long); 3.616 - C2P(blkif_be_connect_t, shmem_ref, Int, Long); 3.617 - C2P(blkif_be_connect_t, evtchn, Int, Long); 3.618 - C2P(blkif_be_connect_t, status, Int, Long); 3.619 - return dict; 3.620 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT): 3.621 - C2P(blkif_be_disconnect_t, domid, Int, Long); 3.622 - C2P(blkif_be_disconnect_t, blkif_handle, Int, Long); 3.623 - C2P(blkif_be_disconnect_t, status, Int, Long); 3.624 - return dict; 3.625 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE): 3.626 - C2P(blkif_be_vbd_create_t, domid, Int, Long); 3.627 - C2P(blkif_be_vbd_create_t, blkif_handle, Int, Long); 3.628 - C2P(blkif_be_vbd_create_t, pdevice, Int, Long); 3.629 - C2P(blkif_be_vbd_create_t, dev_handle, Int, Long); 3.630 - C2P(blkif_be_vbd_create_t, vdevice, Int, Long); 3.631 - C2P(blkif_be_vbd_create_t, readonly, Int, Long); 3.632 - C2P(blkif_be_vbd_create_t, status, Int, Long); 3.633 - return dict; 3.634 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_DESTROY): 3.635 - C2P(blkif_be_vbd_destroy_t, domid, Int, Long); 3.636 - C2P(blkif_be_vbd_destroy_t, blkif_handle, Int, Long); 3.637 - C2P(blkif_be_vbd_destroy_t, vdevice, Int, Long); 3.638 - C2P(blkif_be_vbd_destroy_t, status, Int, Long); 3.639 - return dict; 3.640 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DRIVER_STATUS): 3.641 - C2P(blkif_be_driver_status_t, status, Int, Long); 3.642 - return dict; 3.643 - case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_STATUS): 3.644 - C2P(netif_fe_interface_status_t, handle, Int, Long); 3.645 - C2P(netif_fe_interface_status_t, status, Int, Long); 3.646 - C2P(netif_fe_interface_status_t, evtchn, Int, Long); 3.647 - C2P(netif_fe_interface_status_t, mac[0], Int, Long); 3.648 - C2P(netif_fe_interface_status_t, mac[1], Int, Long); 3.649 - C2P(netif_fe_interface_status_t, mac[2], Int, Long); 3.650 - C2P(netif_fe_interface_status_t, mac[3], Int, Long); 3.651 - C2P(netif_fe_interface_status_t, mac[4], Int, Long); 3.652 - C2P(netif_fe_interface_status_t, mac[5], Int, Long); 3.653 - return dict; 3.654 - case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS): 3.655 - C2P(netif_fe_driver_status_t, status, Int, Long); 3.656 - C2P(netif_fe_driver_status_t, max_handle, Int, Long); 3.657 - return dict; 3.658 - case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_CONNECT): 3.659 - C2P(netif_fe_interface_connect_t, handle, Int, Long); 3.660 - C2P(netif_fe_interface_connect_t, tx_shmem_frame, Int, Long); 3.661 - C2P(netif_fe_interface_connect_t, tx_shmem_ref, Int, Long); 3.662 - C2P(netif_fe_interface_connect_t, rx_shmem_frame, Int, Long); 3.663 - C2P(netif_fe_interface_connect_t, rx_shmem_ref, Int, Long); 3.664 - return dict; 3.665 - case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_DISCONNECT): 3.666 - C2P(netif_fe_interface_disconnect_t, handle, Int, Long); 3.667 - return dict; 3.668 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE): 3.669 - C2P(netif_be_create_t, domid, Int, Long); 3.670 - C2P(netif_be_create_t, netif_handle, Int, Long); 3.671 - C2P(netif_be_create_t, status, Int, Long); 3.672 - return dict; 3.673 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY): 3.674 - C2P(netif_be_destroy_t, domid, Int, Long); 3.675 - C2P(netif_be_destroy_t, netif_handle, Int, Long); 3.676 - C2P(netif_be_destroy_t, status, Int, Long); 3.677 - return dict; 3.678 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT): 3.679 - C2P(netif_be_creditlimit_t, domid, Int, Long); 3.680 - C2P(netif_be_creditlimit_t, netif_handle, Int, Long); 3.681 - C2P(netif_be_creditlimit_t, credit_bytes, Int, Long); 3.682 - C2P(netif_be_creditlimit_t, period_usec, Int, Long); 3.683 - C2P(netif_be_creditlimit_t, status, Int, Long); 3.684 - return dict; 3.685 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT): 3.686 - C2P(netif_be_connect_t, domid, Int, Long); 3.687 - C2P(netif_be_connect_t, netif_handle, Int, Long); 3.688 - C2P(netif_be_connect_t, tx_shmem_frame, Int, Long); 3.689 - C2P(netif_be_connect_t, tx_shmem_ref, Int, Long); 3.690 - C2P(netif_be_connect_t, rx_shmem_frame, Int, Long); 3.691 - C2P(netif_be_connect_t, rx_shmem_ref, Int, Long); 3.692 - C2P(netif_be_connect_t, evtchn, Int, Long); 3.693 - C2P(netif_be_connect_t, status, Int, Long); 3.694 - return dict; 3.695 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DISCONNECT): 3.696 - C2P(netif_be_disconnect_t, domid, Int, Long); 3.697 - C2P(netif_be_disconnect_t, netif_handle, Int, Long); 3.698 - C2P(netif_be_disconnect_t, status, Int, Long); 3.699 - return dict; 3.700 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DRIVER_STATUS): 3.701 - C2P(netif_be_driver_status_t, status, Int, Long); 3.702 - return dict; 3.703 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED): 3.704 - C2P(usbif_fe_interface_status_changed_t, status, Int, Long); 3.705 - C2P(usbif_fe_interface_status_changed_t, evtchn, Int, Long); 3.706 - C2P(usbif_fe_interface_status_changed_t, domid, Int, Long); 3.707 - C2P(usbif_fe_interface_status_changed_t, bandwidth, Int, Long); 3.708 - C2P(usbif_fe_interface_status_changed_t, num_ports, Int, Long); 3.709 - return dict; 3.710 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_DRIVER_STATUS_CHANGED): 3.711 - C2P(usbif_fe_driver_status_changed_t, status, Int, Long); 3.712 - return dict; 3.713 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_CONNECT): 3.714 - C2P(usbif_fe_interface_connect_t, shmem_frame, Int, Long); 3.715 - return dict; 3.716 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_DISCONNECT): 3.717 - return dict; 3.718 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CREATE): 3.719 - C2P(usbif_be_create_t, domid, Int, Long); 3.720 - C2P(usbif_be_create_t, status, Int, Long); 3.721 - return dict; 3.722 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DESTROY): 3.723 - C2P(usbif_be_destroy_t, domid, Int, Long); 3.724 - C2P(usbif_be_destroy_t, status, Int, Long); 3.725 - return dict; 3.726 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CONNECT): 3.727 - C2P(usbif_be_connect_t, domid, Int, Long); 3.728 - C2P(usbif_be_connect_t, shmem_frame, Int, Long); 3.729 - C2P(usbif_be_connect_t, evtchn, Int, Long); 3.730 - C2P(usbif_be_connect_t, bandwidth, Int, Long); 3.731 - C2P(usbif_be_connect_t, status, Int, Long); 3.732 - return dict; 3.733 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DISCONNECT): 3.734 - C2P(usbif_be_disconnect_t, domid, Int, Long); 3.735 - C2P(usbif_be_disconnect_t, status, Int, Long); 3.736 - return dict; 3.737 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DRIVER_STATUS_CHANGED): 3.738 - C2P(usbif_be_driver_status_changed_t, status, Int, Long); 3.739 - return dict; 3.740 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CLAIM_PORT): 3.741 - C2P(usbif_be_claim_port_t, domid, Int, Long); 3.742 - C2P(usbif_be_claim_port_t, usbif_port, Int, Long); 3.743 - C2P(usbif_be_claim_port_t, status, Int, Long); 3.744 - C2P(usbif_be_claim_port_t, path, String, String); 3.745 - return dict; 3.746 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_RELEASE_PORT): 3.747 - C2P(usbif_be_release_port_t, path, String, String); 3.748 - return dict; 3.749 - case TYPE(CMSG_MEM_REQUEST, CMSG_MEM_REQUEST_SET): 3.750 - C2P(mem_request_t, target, Int, Long); 3.751 - C2P(mem_request_t, status, Int, Long); 3.752 - return dict; 3.753 - case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF): 3.754 - C2P(vcpu_hotplug_t, vcpu, Int, Long); 3.755 - C2P(vcpu_hotplug_t, status, Int, Long); 3.756 - return dict; 3.757 - case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON): 3.758 - C2P(vcpu_hotplug_t, vcpu, Int, Long); 3.759 - C2P(vcpu_hotplug_t, status, Int, Long); 3.760 - return dict; 3.761 - } 3.762 - 3.763 - return PyString_FromStringAndSize((char *)xum->msg.msg, xum->msg.length); 3.764 -} 3.765 - 3.766 -static PyObject *xu_message_get_header(PyObject *self, PyObject *args) 3.767 -{ 3.768 - xu_message_object *xum = (xu_message_object *)self; 3.769 - 3.770 - if ( !PyArg_ParseTuple(args, "") ) 3.771 - return NULL; 3.772 - 3.773 - return Py_BuildValue("{s:i,s:i,s:i}", 3.774 - "type", xum->msg.type, 3.775 - "subtype", xum->msg.subtype, 3.776 - "id", xum->msg.id); 3.777 -} 3.778 - 3.779 -static PyMethodDef xu_message_methods[] = { 3.780 - { "append_payload", 3.781 - (PyCFunction)xu_message_append_payload, 3.782 - METH_VARARGS, 3.783 - "Append @str to the message payload.\n" }, 3.784 - 3.785 - { "set_response_fields", 3.786 - (PyCFunction)xu_message_set_response_fields, 3.787 - METH_VARARGS, 3.788 - "Fill in the response fields in a message that was passed to us.\n" }, 3.789 - 3.790 - { "get_payload", 3.791 - (PyCFunction)xu_message_get_payload, 3.792 - METH_VARARGS, 3.793 - "Return the message payload in string form.\n" }, 3.794 - 3.795 - { "get_header", 3.796 - (PyCFunction)xu_message_get_header, 3.797 - METH_VARARGS, 3.798 - "Returns a dictionary of values for @type, @subtype, and @id.\n" }, 3.799 - 3.800 - { NULL, NULL, 0, NULL } 3.801 -}; 3.802 - 3.803 -staticforward PyTypeObject xu_message_type; 3.804 - 3.805 -static PyObject *xu_message_new(PyObject *self, PyObject *args) 3.806 -{ 3.807 - xu_message_object *xum; 3.808 - int type, subtype, id, dict_items_parsed = 0; 3.809 - PyObject *payload = NULL; 3.810 - 3.811 - if ( !PyArg_ParseTuple(args, "iii|O", &type, &subtype, &id, &payload) ) 3.812 - return NULL; 3.813 - 3.814 - xum = PyObject_New(xu_message_object, &xu_message_type); 3.815 - 3.816 - xum->msg.type = type; 3.817 - xum->msg.subtype = subtype; 3.818 - xum->msg.id = id; 3.819 - xum->msg.length = 0; 3.820 - 3.821 - if ( payload == NULL ) 3.822 - return (PyObject *)xum; 3.823 - 3.824 - if ( !PyDict_Check(payload) ) 3.825 - { 3.826 - PyErr_SetString(PyExc_TypeError, "payload is not a dictionary"); 3.827 - PyObject_Del((PyObject *)xum); 3.828 - return NULL; 3.829 - } 3.830 - 3.831 - switch ( TYPE(type, subtype) ) 3.832 - { 3.833 - case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_STATUS): 3.834 - P2C(blkif_fe_interface_status_t, handle, u32); 3.835 - P2C(blkif_fe_interface_status_t, status, u32); 3.836 - P2C(blkif_fe_interface_status_t, evtchn, u16); 3.837 - P2C(blkif_fe_interface_status_t, domid, u16); 3.838 - break; 3.839 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE): 3.840 - P2C(blkif_be_create_t, domid, u32); 3.841 - P2C(blkif_be_create_t, blkif_handle, u32); 3.842 - break; 3.843 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY): 3.844 - P2C(blkif_be_destroy_t, domid, u32); 3.845 - P2C(blkif_be_destroy_t, blkif_handle, u32); 3.846 - break; 3.847 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT): 3.848 - P2C(blkif_be_connect_t, domid, u32); 3.849 - P2C(blkif_be_connect_t, blkif_handle, u32); 3.850 - P2C(blkif_be_connect_t, shmem_frame, unsigned long); 3.851 - P2C(blkif_be_connect_t, shmem_ref, u32); 3.852 - P2C(blkif_be_connect_t, evtchn, u16); 3.853 - break; 3.854 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT): 3.855 - P2C(blkif_be_disconnect_t, domid, u32); 3.856 - P2C(blkif_be_disconnect_t, blkif_handle, u32); 3.857 - break; 3.858 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE): 3.859 - P2C(blkif_be_vbd_create_t, domid, u32); 3.860 - P2C(blkif_be_vbd_create_t, blkif_handle, u32); 3.861 - P2C(blkif_be_vbd_create_t, pdevice, blkif_pdev_t); 3.862 - P2C(blkif_be_vbd_create_t, dev_handle, u32); 3.863 - P2C(blkif_be_vbd_create_t, vdevice, blkif_vdev_t); 3.864 - P2C(blkif_be_vbd_create_t, readonly, u16); 3.865 - break; 3.866 - case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_DESTROY): 3.867 - P2C(blkif_be_vbd_destroy_t, domid, u32); 3.868 - P2C(blkif_be_vbd_destroy_t, blkif_handle, u32); 3.869 - P2C(blkif_be_vbd_destroy_t, vdevice, blkif_vdev_t); 3.870 - break; 3.871 - case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_STATUS): 3.872 - P2C(netif_fe_interface_status_t, handle, u32); 3.873 - P2C(netif_fe_interface_status_t, status, u32); 3.874 - P2C(netif_fe_interface_status_t, evtchn, u16); 3.875 - P2C(netif_fe_interface_status_t, domid, u16); 3.876 - P2C(netif_fe_interface_status_t, mac[0], u8); 3.877 - P2C(netif_fe_interface_status_t, mac[1], u8); 3.878 - P2C(netif_fe_interface_status_t, mac[2], u8); 3.879 - P2C(netif_fe_interface_status_t, mac[3], u8); 3.880 - P2C(netif_fe_interface_status_t, mac[4], u8); 3.881 - P2C(netif_fe_interface_status_t, mac[5], u8); 3.882 - break; 3.883 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE): 3.884 - P2C(netif_be_create_t, domid, u32); 3.885 - P2C(netif_be_create_t, netif_handle, u32); 3.886 - P2C(netif_be_create_t, mac[0], u8); 3.887 - P2C(netif_be_create_t, mac[1], u8); 3.888 - P2C(netif_be_create_t, mac[2], u8); 3.889 - P2C(netif_be_create_t, mac[3], u8); 3.890 - P2C(netif_be_create_t, mac[4], u8); 3.891 - P2C(netif_be_create_t, mac[5], u8); 3.892 - P2C(netif_be_create_t, be_mac[0], u8); 3.893 - P2C(netif_be_create_t, be_mac[1], u8); 3.894 - P2C(netif_be_create_t, be_mac[2], u8); 3.895 - P2C(netif_be_create_t, be_mac[3], u8); 3.896 - P2C(netif_be_create_t, be_mac[4], u8); 3.897 - P2C(netif_be_create_t, be_mac[5], u8); 3.898 - break; 3.899 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY): 3.900 - P2C(netif_be_destroy_t, domid, u32); 3.901 - P2C(netif_be_destroy_t, netif_handle, u32); 3.902 - break; 3.903 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT): 3.904 - P2C(netif_be_creditlimit_t, domid, u32); 3.905 - P2C(netif_be_creditlimit_t, netif_handle, u32); 3.906 - P2C(netif_be_creditlimit_t, credit_bytes, u32); 3.907 - P2C(netif_be_creditlimit_t, period_usec, u32); 3.908 - break; 3.909 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT): 3.910 - P2C(netif_be_connect_t, domid, u32); 3.911 - P2C(netif_be_connect_t, netif_handle, u32); 3.912 - P2C(netif_be_connect_t, tx_shmem_frame, unsigned long); 3.913 - P2C(netif_be_connect_t, tx_shmem_ref, u32); 3.914 - P2C(netif_be_connect_t, rx_shmem_frame, unsigned long); 3.915 - P2C(netif_be_connect_t, rx_shmem_ref, u32); 3.916 - P2C(netif_be_connect_t, evtchn, u16); 3.917 - break; 3.918 - case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DISCONNECT): 3.919 - P2C(netif_be_disconnect_t, domid, u32); 3.920 - P2C(netif_be_disconnect_t, netif_handle, u32); 3.921 - break; 3.922 - case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS): 3.923 - P2C(netif_fe_driver_status_t, status, u32); 3.924 - P2C(netif_fe_driver_status_t, max_handle, u32); 3.925 - break; 3.926 - case TYPE(CMSG_MEM_REQUEST, CMSG_MEM_REQUEST_SET): 3.927 - P2C(mem_request_t, target, u32); 3.928 - break; 3.929 - case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF): 3.930 - P2C(vcpu_hotplug_t, vcpu, u32); 3.931 - P2C(vcpu_hotplug_t, status, u32); 3.932 - break; 3.933 - case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON): 3.934 - P2C(vcpu_hotplug_t, vcpu, u32); 3.935 - P2C(vcpu_hotplug_t, status, u32); 3.936 - break; 3.937 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED): 3.938 - P2C(usbif_fe_interface_status_changed_t, status, u32); 3.939 - P2C(usbif_fe_interface_status_changed_t, evtchn, u16); 3.940 - P2C(usbif_fe_interface_status_changed_t, domid, domid_t); 3.941 - P2C(usbif_fe_interface_status_changed_t, bandwidth, u32); 3.942 - P2C(usbif_fe_interface_status_changed_t, num_ports, u32); 3.943 - break; 3.944 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_DRIVER_STATUS_CHANGED): 3.945 - P2C(usbif_fe_driver_status_changed_t, status, u32); 3.946 - break; 3.947 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_CONNECT): 3.948 - P2C(usbif_fe_interface_connect_t, shmem_frame, unsigned long); 3.949 - break; 3.950 - case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_DISCONNECT): 3.951 - break; 3.952 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CREATE): 3.953 - P2C(usbif_be_create_t, domid, domid_t); 3.954 - P2C(usbif_be_create_t, status, u32); 3.955 - break; 3.956 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DESTROY): 3.957 - P2C(usbif_be_destroy_t, domid, domid_t); 3.958 - P2C(usbif_be_destroy_t, status, u32); 3.959 - break; 3.960 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CONNECT): 3.961 - P2C(usbif_be_connect_t, domid, domid_t); 3.962 - P2C(usbif_be_connect_t, shmem_frame, unsigned long); 3.963 - P2C(usbif_be_connect_t, evtchn, u32); 3.964 - P2C(usbif_be_connect_t, bandwidth, u32); 3.965 - P2C(usbif_be_connect_t, status, u32); 3.966 - break; 3.967 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DISCONNECT): 3.968 - P2C(usbif_be_disconnect_t, domid, domid_t); 3.969 - P2C(usbif_be_disconnect_t, status, u32); 3.970 - break; 3.971 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DRIVER_STATUS_CHANGED): 3.972 - P2C(usbif_be_driver_status_changed_t, status, u32); 3.973 - break; 3.974 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CLAIM_PORT): 3.975 - P2C(usbif_be_claim_port_t, domid, domid_t); 3.976 - P2C(usbif_be_claim_port_t, usbif_port, u32); 3.977 - P2C(usbif_be_claim_port_t, status, u32); 3.978 - PSTR2CHAR(usbif_be_claim_port_t, path); 3.979 - printf("dict items parsed = %d", dict_items_parsed); 3.980 - break; 3.981 - case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_RELEASE_PORT): 3.982 - PSTR2CHAR(usbif_be_release_port_t, path); 3.983 - break; 3.984 - case TYPE(CMSG_SHUTDOWN, CMSG_SHUTDOWN_SYSRQ): 3.985 - P2C(shutdown_sysrq_t, key, char); 3.986 - break; 3.987 - } 3.988 - 3.989 - if ( dict_items_parsed != PyDict_Size(payload) ) 3.990 - { 3.991 - PyErr_SetString(PyExc_TypeError, "payload contains bad items"); 3.992 - PyObject_Del((PyObject *)xum); 3.993 - return NULL; 3.994 - } 3.995 - 3.996 - return (PyObject *)xum; 3.997 -} 3.998 - 3.999 -static PyObject *xu_message_getattr(PyObject *obj, char *name) 3.1000 -{ 3.1001 - xu_message_object *xum; 3.1002 - if ( strcmp(name, "MAX_PAYLOAD") == 0 ) 3.1003 - return PyInt_FromLong(sizeof(xum->msg.msg)); 3.1004 - return Py_FindMethod(xu_message_methods, obj, name); 3.1005 -} 3.1006 - 3.1007 -static void xu_message_dealloc(PyObject *self) 3.1008 -{ 3.1009 - PyObject_Del(self); 3.1010 -} 3.1011 - 3.1012 -static PyTypeObject xu_message_type = { 3.1013 - PyObject_HEAD_INIT(&PyType_Type) 3.1014 - 0, 3.1015 - "message", 3.1016 - sizeof(xu_message_object), 3.1017 - 0, 3.1018 - xu_message_dealloc, /* tp_dealloc */ 3.1019 - NULL, /* tp_print */ 3.1020 - xu_message_getattr, /* tp_getattr */ 3.1021 - NULL, /* tp_setattr */ 3.1022 - NULL, /* tp_compare */ 3.1023 - NULL, /* tp_repr */ 3.1024 - NULL, /* tp_as_number */ 3.1025 - NULL, /* tp_as_sequence */ 3.1026 - NULL, /* tp_as_mapping */ 3.1027 - NULL /* tp_hash */ 3.1028 -}; 3.1029 - 3.1030 - 3.1031 - 3.1032 -/* 3.1033 - * *********************** PORT *********************** 3.1034 - */ 3.1035 - 3.1036 -typedef struct xu_port_object { 3.1037 - PyObject_HEAD; 3.1038 - int xc_handle; 3.1039 - int connected; 3.1040 - u32 remote_dom; 3.1041 - int local_port, remote_port; 3.1042 - struct xu_port_object *fix_next; 3.1043 -} xu_port_object; 3.1044 - 3.1045 -static PyObject *port_error; 3.1046 - 3.1047 -static PyObject *xu_port_read_request(PyObject *self, PyObject *args) 3.1048 -{ 3.1049 - xu_port_object *xup = (xu_port_object *)self; 3.1050 - xu_message_object *xum; 3.1051 - control_msg_t *cmsg; 3.1052 - unsigned i; 3.1053 - xcs_msg_ent_t *ent = NULL; 3.1054 - 3.1055 - for ( i = req_cons; (i != req_prod); i++ ) { 3.1056 - ent = REQ_RING_ENT(i); 3.1057 - if (ent == NULL) 3.1058 - continue; 3.1059 - if (ent->msg.u.control.remote_dom == xup->remote_dom) 3.1060 - break; 3.1061 - } 3.1062 - 3.1063 - if ((ent == NULL) || 3.1064 - (ent->msg.u.control.remote_dom != xup->remote_dom)) 3.1065 - goto none; 3.1066 - 3.1067 - cmsg = &ent->msg.u.control.msg; 3.1068 - xum = PyObject_New(xu_message_object, &xu_message_type); 3.1069 - memcpy(&xum->msg, cmsg, sizeof(*cmsg)); 3.1070 - if ( xum->msg.length > sizeof(xum->msg.msg) ) 3.1071 - xum->msg.length = sizeof(xum->msg.msg); 3.1072 - free(ent); 3.1073 - 3.1074 - /* remove the entry from the ring and advance the consumer if possible */ 3.1075 - REQ_RING_ENT(i) = NULL; 3.1076 - while ( (REQ_RING_ENT(req_cons) == NULL) && (!REQ_RING_EMPTY) ) 3.1077 - req_cons++; 3.1078 - 3.1079 - return (PyObject *)xum; 3.1080 - 3.1081 -none: 3.1082 - Py_INCREF(Py_None); 3.1083 - return Py_None; 3.1084 - 3.1085 -} 3.1086 - 3.1087 -static PyObject *xu_port_write_request(PyObject *self, PyObject *args) 3.1088 -{ 3.1089 - xu_port_object *xup = (xu_port_object *)self; 3.1090 - xu_message_object *xum; 3.1091 - xcs_msg_t kmsg; 3.1092 - 3.1093 - if ( !PyArg_ParseTuple(args, "O", (PyObject **)&xum) ) 3.1094 - return NULL; 3.1095 - 3.1096 - if ( !PyObject_TypeCheck((PyObject *)xum, &xu_message_type) ) 3.1097 - { 3.1098 - PyErr_SetString(PyExc_TypeError, "expected a " XENPKG ".message"); 3.1099 - return NULL; 3.1100 - } 3.1101 - 3.1102 - kmsg.type = XCS_REQUEST; 3.1103 - kmsg.u.control.remote_dom = xup->remote_dom; 3.1104 - memcpy(&kmsg.u.control.msg, &xum->msg, sizeof(control_msg_t)); 3.1105 - xcs_data_send(&kmsg); 3.1106 - 3.1107 - Py_INCREF(Py_None); 3.1108 - return Py_None; 3.1109 -} 3.1110 - 3.1111 -static PyObject *xu_port_read_response(PyObject *self, PyObject *args) 3.1112 -{ 3.1113 - xu_port_object *xup = (xu_port_object *)self; 3.1114 - xu_message_object *xum; 3.1115 - control_msg_t *cmsg; 3.1116 - unsigned i; 3.1117 - xcs_msg_ent_t *ent = NULL; 3.1118 - 3.1119 - for ( i = rsp_cons; (i != rsp_prod); i++ ) { 3.1120 - ent = RSP_RING_ENT(i); 3.1121 - if (ent == NULL) 3.1122 - continue; 3.1123 - if (ent->msg.u.control.remote_dom == xup->remote_dom) 3.1124 - break; 3.1125 - } 3.1126 - 3.1127 - if ((ent == NULL) || 3.1128 - (ent->msg.u.control.remote_dom != xup->remote_dom)) 3.1129 - goto none; 3.1130 - 3.1131 - cmsg = &ent->msg.u.control.msg; 3.1132 - xum = PyObject_New(xu_message_object, &xu_message_type); 3.1133 - memcpy(&xum->msg, cmsg, sizeof(*cmsg)); 3.1134 - if ( xum->msg.length > sizeof(xum->msg.msg) ) 3.1135 - xum->msg.length = sizeof(xum->msg.msg); 3.1136 - free(ent); 3.1137 - 3.1138 - /* remove the entry from the ring and advance the consumer if possible */ 3.1139 - RSP_RING_ENT(i) = NULL; 3.1140 - while ( (RSP_RING_ENT(rsp_cons) == NULL) && (!RSP_RING_EMPTY) ) 3.1141 - rsp_cons++; 3.1142 - 3.1143 - return (PyObject *)xum; 3.1144 - 3.1145 -none: 3.1146 - Py_INCREF(Py_None); 3.1147 - return Py_None; 3.1148 - 3.1149 -} 3.1150 - 3.1151 -static PyObject *xu_port_write_response(PyObject *self, PyObject *args) 3.1152 -{ 3.1153 - xu_port_object *xup = (xu_port_object *)self; 3.1154 - xu_message_object *xum; 3.1155 - xcs_msg_t kmsg; 3.1156 - 3.1157 - if ( !PyArg_ParseTuple(args, "O", (PyObject **)&xum) ) 3.1158 - return NULL; 3.1159 - 3.1160 - if ( !PyObject_TypeCheck((PyObject *)xum, &xu_message_type) ) 3.1161 - { 3.1162 - PyErr_SetString(PyExc_TypeError, "expected a " XENPKG ".message"); 3.1163 - return NULL; 3.1164 - } 3.1165 - 3.1166 - kmsg.type = XCS_RESPONSE; 3.1167 - kmsg.u.control.remote_dom = xup->remote_dom; 3.1168 - memcpy(&kmsg.u.control.msg, &xum->msg, sizeof(control_msg_t)); 3.1169 - xcs_data_send(&kmsg); 3.1170 - 3.1171 - Py_INCREF(Py_None); 3.1172 - return Py_None; 3.1173 -} 3.1174 - 3.1175 -static PyObject *xu_port_request_to_read(PyObject *self, PyObject *args) 3.1176 -{ 3.1177 - xu_port_object *xup = (xu_port_object *)self; 3.1178 - xcs_msg_ent_t *ent; 3.1179 - int found = 0; 3.1180 - unsigned i; 3.1181 - 3.1182 - if ( !PyArg_ParseTuple(args, "") ) 3.1183 - return NULL; 3.1184 - 3.1185 - for ( i = req_cons; (i != req_prod); i++ ) { 3.1186 - ent = REQ_RING_ENT(i); 3.1187 - if (ent == NULL) 3.1188 - continue; 3.1189 - if (ent->msg.u.control.remote_dom == xup->remote_dom) { 3.1190 - found = 1; 3.1191 - break; 3.1192 - } 3.1193 - } 3.1194 - 3.1195 - return PyInt_FromLong(found); 3.1196 -} 3.1197 - 3.1198 -static PyObject *xu_port_response_to_read(PyObject *self, PyObject *args) 3.1199 -{ 3.1200 - xu_port_object *xup = (xu_port_object *)self; 3.1201 - xcs_msg_ent_t *ent; 3.1202 - int found = 0; 3.1203 - unsigned i; 3.1204 - 3.1205 - if ( !PyArg_ParseTuple(args, "") ) 3.1206 - return NULL; 3.1207 - 3.1208 - for ( i = rsp_cons; (i != rsp_prod); i++ ) { 3.1209 - ent = RSP_RING_ENT(i); 3.1210 - if (ent == NULL) 3.1211 - continue; 3.1212 - if (ent->msg.u.control.remote_dom == xup->remote_dom) { 3.1213 - found = 1; 3.1214 - break; 3.1215 - } 3.1216 - } 3.1217 - 3.1218 - return PyInt_FromLong(found); 3.1219 -} 3.1220 - 3.1221 -static void _xu_port_close(xu_port_object *xup ) 3.1222 -{ 3.1223 - if ( xup->connected && xup->remote_dom != 0 ) 3.1224 - { 3.1225 - xcs_msg_t kmsg; 3.1226 - kmsg.type = XCS_CIF_FREE_CC; 3.1227 - kmsg.u.interface.dom = xup->remote_dom; 3.1228 - kmsg.u.interface.local_port = xup->local_port; 3.1229 - kmsg.u.interface.remote_port = xup->remote_port; 3.1230 - xcs_ctrl_send(&kmsg); 3.1231 - xcs_ctrl_read(&kmsg); 3.1232 - xup->connected = 0; 3.1233 - } 3.1234 -} 3.1235 - 3.1236 -static PyObject *xu_port_close(PyObject *self, PyObject *args) 3.1237 -{ 3.1238 - xu_port_object *xup = (xu_port_object *)self; 3.1239 - 3.1240 - _xu_port_close(xup); 3.1241 - 3.1242 - Py_INCREF(Py_None); 3.1243 - return Py_None; 3.1244 -} 3.1245 - 3.1246 -static PyObject *xu_port_register(PyObject *self, PyObject *args, 3.1247 - PyObject *kwds) 3.1248 -{ 3.1249 - int type; 3.1250 - xcs_msg_t msg; 3.1251 - xu_port_object *xup = (xu_port_object *)self; 3.1252 - static char *kwd_list[] = { "type", NULL }; 3.1253 - 3.1254 - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, 3.1255 - &type) ) 3.1256 - return NULL; 3.1257 - 3.1258 - if (!xup->connected) 3.1259 - { 3.1260 - return PyInt_FromLong(0); 3.1261 - } 3.1262 - 3.1263 - msg.type = XCS_MSG_BIND; 3.1264 - msg.u.bind.port = xup->local_port; 3.1265 - msg.u.bind.type = type; 3.1266 - xcs_ctrl_send(&msg); 3.1267 - xcs_ctrl_read(&msg); 3.1268 - 3.1269 - if (msg.result != XCS_RSLT_OK) 3.1270 - { 3.1271 - return PyInt_FromLong(0); 3.1272 - } 3.1273 - 3.1274 - return PyInt_FromLong(1); 3.1275 -} 3.1276 - 3.1277 -static PyObject *xu_port_deregister(PyObject *self, PyObject *args, 3.1278 - PyObject *kwds) 3.1279 -{ 3.1280 - int type; 3.1281 - xcs_msg_t msg; 3.1282 - xu_port_object *xup = (xu_port_object *)self; 3.1283 - static char *kwd_list[] = { "type", NULL }; 3.1284 - 3.1285 - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, 3.1286 - &type) ) 3.1287 - return NULL; 3.1288 - 3.1289 - if (!xup->connected) 3.1290 - { 3.1291 - return PyInt_FromLong(0); 3.1292 - } 3.1293 - 3.1294 - msg.type = XCS_MSG_UNBIND; 3.1295 - msg.u.bind.port = xup->local_port; 3.1296 - msg.u.bind.type = type; 3.1297 - xcs_ctrl_send(&msg); 3.1298 - xcs_ctrl_read(&msg); 3.1299 - 3.1300 - if (msg.result != XCS_RSLT_OK) 3.1301 - { 3.1302 - return PyInt_FromLong(0); 3.1303 - } 3.1304 - 3.1305 - return PyInt_FromLong(1); 3.1306 -} 3.1307 - 3.1308 -static PyMethodDef xu_port_methods[] = { 3.1309 - 3.1310 - { "read_request", 3.1311 - (PyCFunction)xu_port_read_request, 3.1312 - METH_VARARGS, 3.1313 - "Read a request message from the control interface.\n" }, 3.1314 - 3.1315 - { "write_request", 3.1316 - (PyCFunction)xu_port_write_request, 3.1317 - METH_VARARGS, 3.1318 - "Write a request message to the control interface.\n" }, 3.1319 - 3.1320 - { "read_response", 3.1321 - (PyCFunction)xu_port_read_response, 3.1322 - METH_VARARGS, 3.1323 - "Read a response message from the control interface.\n" }, 3.1324 - 3.1325 - { "write_response", 3.1326 - (PyCFunction)xu_port_write_response, 3.1327 - METH_VARARGS, 3.1328 - "Write a response message to the control interface.\n" }, 3.1329 - 3.1330 - { "request_to_read", 3.1331 - (PyCFunction)xu_port_request_to_read, 3.1332 - METH_VARARGS, 3.1333 - "Returns TRUE if there is a request message to read.\n" }, 3.1334 - 3.1335 - 3.1336 - { "response_to_read", 3.1337 - (PyCFunction)xu_port_response_to_read, 3.1338 - METH_VARARGS, 3.1339 - "Returns TRUE if there is a response message to read.\n" }, 3.1340 - 3.1341 - { "register", 3.1342 - (PyCFunction)xu_port_register, 3.1343 - METH_VARARGS | METH_KEYWORDS, 3.1344 - "Register to receive a type of message on this channel.\n" }, 3.1345 - 3.1346 - { "deregister", 3.1347 - (PyCFunction)xu_port_deregister, 3.1348 - METH_VARARGS | METH_KEYWORDS, 3.1349 - "Stop receiving a type of message on this port.\n" }, 3.1350 - 3.1351 - { "close", 3.1352 - (PyCFunction)xu_port_close, 3.1353 - METH_VARARGS, 3.1354 - "Close the port.\n" }, 3.1355 - 3.1356 - { NULL, NULL, 0, NULL } 3.1357 -}; 3.1358 - 3.1359 -staticforward PyTypeObject xu_port_type; 3.1360 - 3.1361 -static PyObject *xu_port_new(PyObject *self, PyObject *args, PyObject *kwds) 3.1362 -{ 3.1363 - xu_port_object *xup; 3.1364 - u32 dom; 3.1365 - int port1 = 0, port2 = 0; 3.1366 - xcs_msg_t kmsg; 3.1367 - 3.1368 - static char *kwd_list[] = { "dom", "local_port", "remote_port", NULL }; 3.1369 - 3.1370 - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwd_list, 3.1371 - &dom, &port1, &port2) ) 3.1372 - return NULL; 3.1373 - 3.1374 - xup = PyObject_New(xu_port_object, &xu_port_type); 3.1375 - 3.1376 - xup->connected = 0; 3.1377 - xup->remote_dom = dom; 3.1378 - 3.1379 - kmsg.type = XCS_CIF_NEW_CC; 3.1380 - kmsg.u.interface.dom = xup->remote_dom; 3.1381 - kmsg.u.interface.local_port = port1; 3.1382 - kmsg.u.interface.remote_port = port2; 3.1383 - xcs_ctrl_send(&kmsg); 3.1384 - xcs_ctrl_read(&kmsg); 3.1385 - 3.1386 - if ( kmsg.result != XCS_RSLT_OK ) 3.1387 - goto fail1; 3.1388 - 3.1389 - xup->local_port = kmsg.u.interface.local_port; 3.1390 - xup->remote_port = kmsg.u.interface.remote_port; 3.1391 - xup->connected = 1; 3.1392 - 3.1393 - return (PyObject *)xup; 3.1394 - 3.1395 - fail1: 3.1396 - PyObject_Del((PyObject *)xup); 3.1397 - PyErr_SetString(PyExc_ValueError, "cannot create port"); 3.1398 - return NULL; 3.1399 -} 3.1400 - 3.1401 -static PyObject *xu_port_getattr(PyObject *obj, char *name) 3.1402 -{ 3.1403 - xu_port_object *xup = (xu_port_object *)obj; 3.1404 - 3.1405 - if ( strcmp(name, "local_port") == 0 ) 3.1406 - { 3.1407 - return PyInt_FromLong(xup->connected ? xup->local_port : -1); 3.1408 - } 3.1409 - if ( strcmp(name, "remote_port") == 0 ) 3.1410 - { 3.1411 - return PyInt_FromLong(xup->connected ? xup->remote_port : -1); 3.1412 - } 3.1413 - if ( strcmp(name, "remote_dom") == 0 ) 3.1414 - { 3.1415 - return PyInt_FromLong(xup->remote_dom); 3.1416 - } 3.1417 - if ( strcmp(name, "connected") == 0 ) 3.1418 - { 3.1419 - return PyInt_FromLong(xup->connected); 3.1420 - } 3.1421 - return Py_FindMethod(xu_port_methods, obj, name); 3.1422 -} 3.1423 - 3.1424 -static void xu_port_dealloc(PyObject *self) 3.1425 -{ 3.1426 - xu_port_object *xup = (xu_port_object *)self; 3.1427 - 3.1428 - _xu_port_close(xup); 3.1429 - 3.1430 - PyObject_Del(self); 3.1431 -} 3.1432 - 3.1433 -static PyTypeObject xu_port_type = { 3.1434 - PyObject_HEAD_INIT(&PyType_Type) 3.1435 - 0, 3.1436 - "port", 3.1437 - sizeof(xu_port_object), 3.1438 - 0, 3.1439 - xu_port_dealloc, /* tp_dealloc */ 3.1440 - NULL, /* tp_print */ 3.1441 - xu_port_getattr, /* tp_getattr */ 3.1442 - NULL, /* tp_setattr */ 3.1443 - NULL, /* tp_compare */ 3.1444 - NULL, /* tp_repr */ 3.1445 - NULL, /* tp_as_number */ 3.1446 - NULL, /* tp_as_sequence */ 3.1447 - NULL, /* tp_as_mapping */ 3.1448 - NULL /* tp_hash */ 3.1449 -}; 3.1450 - 3.1451 - 3.1452 - 3.1453 -/* 3.1454 - * *********************** BUFFER *********************** 3.1455 - */ 3.1456 - 3.1457 -#define BUFSZ 65536 3.1458 -#define MASK_BUF_IDX(_i) ((_i)&(BUFSZ-1)) 3.1459 -typedef unsigned int BUF_IDX; 3.1460 - 3.1461 -typedef struct { 3.1462 - PyObject_HEAD; 3.1463 - char *buf; 3.1464 - unsigned int prod, cons; 3.1465 -} xu_buffer_object; 3.1466 - 3.1467 -static PyObject *__xu_buffer_peek(xu_buffer_object *xub, int max) 3.1468 -{ 3.1469 - PyObject *str1, *str2; 3.1470 - int len1, len2, c = MASK_BUF_IDX(xub->cons); 3.1471 - 3.1472 - len1 = xub->prod - xub->cons; 3.1473 - if ( len1 > (BUFSZ - c) ) /* clip to ring wrap */ 3.1474 - len1 = BUFSZ - c; 3.1475 - if ( len1 > max ) /* clip to specified maximum */ 3.1476 - len1 = max; 3.1477 - if ( len1 < 0 ) /* sanity */ 3.1478 - len1 = 0; 3.1479 - 3.1480 - if ( (str1 = PyString_FromStringAndSize(&xub->buf[c], len1)) == NULL ) 3.1481 - return NULL; 3.1482 - 3.1483 - if ( (len1 < (xub->prod - xub->cons)) && (len1 < max) ) 3.1484 - { 3.1485 - len2 = max - len1; 3.1486 - if ( len2 > MASK_BUF_IDX(xub->prod) ) 3.1487 - len2 = MASK_BUF_IDX(xub->prod); 3.1488 - if ( len2 > 0 ) 3.1489 - { 3.1490 - str2 = PyString_FromStringAndSize(&xub->buf[0], len2); 3.1491 - if ( str2 == NULL ) 3.1492 - return NULL; 3.1493 - PyString_ConcatAndDel(&str1, str2); 3.1494 - if ( str1 == NULL ) 3.1495 - return NULL; 3.1496 - } 3.1497 - } 3.1498 - 3.1499 - return str1; 3.1500 -} 3.1501 - 3.1502 -static PyObject *xu_buffer_peek(PyObject *self, PyObject *args) 3.1503 -{ 3.1504 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1505 - int max = 1024; 3.1506 - 3.1507 - if ( !PyArg_ParseTuple(args, "|i", &max) ) 3.1508 - return NULL; 3.1509 - 3.1510 - return __xu_buffer_peek(xub, max); 3.1511 -} 3.1512 - 3.1513 -static PyObject *xu_buffer_read(PyObject *self, PyObject *args) 3.1514 -{ 3.1515 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1516 - PyObject *str; 3.1517 - int max = 1024; 3.1518 - 3.1519 - if ( !PyArg_ParseTuple(args, "|i", &max) ) 3.1520 - return NULL; 3.1521 - 3.1522 - if ( (str = __xu_buffer_peek(xub, max)) != NULL ) 3.1523 - xub->cons += PyString_Size(str); 3.1524 - 3.1525 - return str; 3.1526 -} 3.1527 - 3.1528 -static PyObject *xu_buffer_discard(PyObject *self, PyObject *args) 3.1529 -{ 3.1530 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1531 - int max, len; 3.1532 - 3.1533 - if ( !PyArg_ParseTuple(args, "i", &max) ) 3.1534 - return NULL; 3.1535 - 3.1536 - len = xub->prod - xub->cons; 3.1537 - if ( len > max ) 3.1538 - len = max; 3.1539 - if ( len < 0 ) 3.1540 - len = 0; 3.1541 - 3.1542 - xub->cons += len; 3.1543 - 3.1544 - return PyInt_FromLong(len); 3.1545 -} 3.1546 - 3.1547 -static PyObject *xu_buffer_write(PyObject *self, PyObject *args) 3.1548 -{ 3.1549 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1550 - char *str; 3.1551 - int len, len1, len2; 3.1552 - 3.1553 - if ( !PyArg_ParseTuple(args, "s#", &str, &len) ) 3.1554 - return NULL; 3.1555 - 3.1556 - len1 = len; 3.1557 - if ( len1 > (BUFSZ - MASK_BUF_IDX(xub->prod)) ) 3.1558 - len1 = BUFSZ - MASK_BUF_IDX(xub->prod); 3.1559 - if ( len1 > (BUFSZ - (xub->prod - xub->cons)) ) 3.1560 - len1 = BUFSZ - (xub->prod - xub->cons); 3.1561 - 3.1562 - if ( len1 == 0 ) 3.1563 - return PyInt_FromLong(0); 3.1564 - 3.1565 - memcpy(&xub->buf[MASK_BUF_IDX(xub->prod)], &str[0], len1); 3.1566 - xub->prod += len1; 3.1567 - 3.1568 - if ( len1 < len ) 3.1569 - { 3.1570 - len2 = len - len1; 3.1571 - if ( len2 > (BUFSZ - MASK_BUF_IDX(xub->prod)) ) 3.1572 - len2 = BUFSZ - MASK_BUF_IDX(xub->prod); 3.1573 - if ( len2 > (BUFSZ - (xub->prod - xub->cons)) ) 3.1574 - len2 = BUFSZ - (xub->prod - xub->cons); 3.1575 - if ( len2 != 0 ) 3.1576 - { 3.1577 - memcpy(&xub->buf[MASK_BUF_IDX(xub->prod)], &str[len1], len2); 3.1578 - xub->prod += len2; 3.1579 - return PyInt_FromLong(len1 + len2); 3.1580 - } 3.1581 - } 3.1582 - 3.1583 - return PyInt_FromLong(len1); 3.1584 -} 3.1585 - 3.1586 -static PyObject *xu_buffer_empty(PyObject *self, PyObject *args) 3.1587 -{ 3.1588 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1589 - 3.1590 - if ( !PyArg_ParseTuple(args, "") ) 3.1591 - return NULL; 3.1592 - 3.1593 - if ( xub->cons == xub->prod ) 3.1594 - return PyInt_FromLong(1); 3.1595 - 3.1596 - return PyInt_FromLong(0); 3.1597 -} 3.1598 - 3.1599 -static PyObject *xu_buffer_full(PyObject *self, PyObject *args) 3.1600 -{ 3.1601 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1602 - 3.1603 - if ( !PyArg_ParseTuple(args, "") ) 3.1604 - return NULL; 3.1605 - 3.1606 - if ( (xub->prod - xub->cons) == BUFSZ ) 3.1607 - return PyInt_FromLong(1); 3.1608 - 3.1609 - return PyInt_FromLong(0); 3.1610 -} 3.1611 - 3.1612 -static PyObject *xu_buffer_size(PyObject *self, PyObject *args) 3.1613 -{ 3.1614 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1615 - 3.1616 - if ( !PyArg_ParseTuple(args, "") ) 3.1617 - return NULL; 3.1618 - 3.1619 - return PyInt_FromLong(xub->prod - xub->cons); 3.1620 -} 3.1621 - 3.1622 -static PyObject *xu_buffer_space(PyObject *self, PyObject *args) 3.1623 -{ 3.1624 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1625 - 3.1626 - if ( !PyArg_ParseTuple(args, "") ) 3.1627 - return NULL; 3.1628 - 3.1629 - return PyInt_FromLong(BUFSZ - (xub->prod - xub->cons)); 3.1630 -} 3.1631 - 3.1632 -static PyMethodDef xu_buffer_methods[] = { 3.1633 - { "peek", 3.1634 - (PyCFunction)xu_buffer_peek, 3.1635 - METH_VARARGS, 3.1636 - "Peek up to @max bytes from the buffer. Returns a string.\n" }, 3.1637 - 3.1638 - { "read", 3.1639 - (PyCFunction)xu_buffer_read, 3.1640 - METH_VARARGS, 3.1641 - "Read up to @max bytes from the buffer. Returns a string.\n" }, 3.1642 - 3.1643 - { "discard", 3.1644 - (PyCFunction)xu_buffer_discard, 3.1645 - METH_VARARGS, 3.1646 - "Discard up to @max bytes from the buffer. Returns number of bytes.\n" }, 3.1647 - 3.1648 - { "write", 3.1649 - (PyCFunction)xu_buffer_write, 3.1650 - METH_VARARGS, 3.1651 - "Write @string into buffer. Return number of bytes written.\n" }, 3.1652 - 3.1653 - { "empty", 3.1654 - (PyCFunction)xu_buffer_empty, 3.1655 - METH_VARARGS, 3.1656 - "Return TRUE if the buffer is empty.\n" }, 3.1657 - 3.1658 - { "full", 3.1659 - (PyCFunction)xu_buffer_full, 3.1660 - METH_VARARGS, 3.1661 - "Return TRUE if the buffer is full.\n" }, 3.1662 - 3.1663 - { "size", 3.1664 - (PyCFunction)xu_buffer_size, 3.1665 - METH_VARARGS, 3.1666 - "Return number of bytes in the buffer.\n" }, 3.1667 - 3.1668 - { "space", 3.1669 - (PyCFunction)xu_buffer_space, 3.1670 - METH_VARARGS, 3.1671 - "Return space left in the buffer.\n" }, 3.1672 - 3.1673 - { NULL, NULL, 0, NULL } 3.1674 -}; 3.1675 - 3.1676 -staticforward PyTypeObject xu_buffer_type; 3.1677 - 3.1678 -static PyObject *xu_buffer_new(PyObject *self, PyObject *args) 3.1679 -{ 3.1680 - xu_buffer_object *xub; 3.1681 - 3.1682 - if ( !PyArg_ParseTuple(args, "") ) 3.1683 - return NULL; 3.1684 - 3.1685 - xub = PyObject_New(xu_buffer_object, &xu_buffer_type); 3.1686 - 3.1687 - if ( (xub->buf = malloc(BUFSZ)) == NULL ) 3.1688 - { 3.1689 - PyObject_Del((PyObject *)xub); 3.1690 - return NULL; 3.1691 - } 3.1692 - 3.1693 - xub->prod = xub->cons = 0; 3.1694 - 3.1695 - return (PyObject *)xub; 3.1696 -} 3.1697 - 3.1698 -static PyObject *xu_buffer_getattr(PyObject *obj, char *name) 3.1699 -{ 3.1700 - return Py_FindMethod(xu_buffer_methods, obj, name); 3.1701 -} 3.1702 - 3.1703 -static void xu_buffer_dealloc(PyObject *self) 3.1704 -{ 3.1705 - xu_buffer_object *xub = (xu_buffer_object *)self; 3.1706 - free(xub->buf); 3.1707 - PyObject_Del(self); 3.1708 -} 3.1709 - 3.1710 -static PyTypeObject xu_buffer_type = { 3.1711 - PyObject_HEAD_INIT(&PyType_Type) 3.1712 - 0, 3.1713 - "buffer", 3.1714 - sizeof(xu_buffer_object), 3.1715 - 0, 3.1716 - xu_buffer_dealloc, /* tp_dealloc */ 3.1717 - NULL, /* tp_print */ 3.1718 - xu_buffer_getattr, /* tp_getattr */ 3.1719 - NULL, /* tp_setattr */ 3.1720 - NULL, /* tp_compare */ 3.1721 - NULL, /* tp_repr */ 3.1722 - NULL, /* tp_as_number */ 3.1723 - NULL, /* tp_as_sequence */ 3.1724 - NULL, /* tp_as_mapping */ 3.1725 - NULL /* tp_hash */ 3.1726 -}; 3.1727 - 3.1728 - 3.1729 - 3.1730 -/* 3.1731 - * *********************** MODULE WRAPPER *********************** 3.1732 - */ 3.1733 - 3.1734 -static void handle_child_death(int dummy) 3.1735 -{ 3.1736 - while ( waitpid(-1, NULL, WNOHANG) > 0 ) 3.1737 - continue; 3.1738 -} 3.1739 - 3.1740 -static PyObject *xu_autoreap(PyObject *self, PyObject *args) 3.1741 -{ 3.1742 - struct sigaction sa; 3.1743 - 3.1744 - if ( !PyArg_ParseTuple(args, "") ) 3.1745 - return NULL; 3.1746 - 3.1747 - memset(&sa, 0, sizeof(sa)); 3.1748 - sa.sa_handler = handle_child_death; 3.1749 - sigemptyset(&sa.sa_mask); 3.1750 - sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; 3.1751 - (void)sigaction(SIGCHLD, &sa, NULL); 3.1752 - 3.1753 - Py_INCREF(Py_None); 3.1754 - return Py_None; 3.1755 -} 3.1756 - 3.1757 -static PyMethodDef xu_methods[] = { 3.1758 - { "notifier", xu_notifier_new, METH_VARARGS, 3.1759 - "Create a new notifier." }, 3.1760 - { "message", xu_message_new, METH_VARARGS, 3.1761 - "Create a new communications message." }, 3.1762 - { "port", (PyCFunction)xu_port_new, METH_VARARGS | METH_KEYWORDS, 3.1763 - "Create a new communications port." }, 3.1764 - { "buffer", xu_buffer_new, METH_VARARGS, 3.1765 - "Create a new ring buffer." }, 3.1766 - { "autoreap", xu_autoreap, METH_VARARGS, 3.1767 - "Ensure that zombie children are automatically reaped by the OS." }, 3.1768 - { NULL, NULL, 0, NULL } 3.1769 -}; 3.1770 - 3.1771 -PyMODINIT_FUNC initxu(void) 3.1772 -{ 3.1773 - PyObject *m, *d; 3.1774 - 3.1775 - m = Py_InitModule(XENPKG, xu_methods); 3.1776 - 3.1777 - d = PyModule_GetDict(m); 3.1778 - port_error = PyErr_NewException(XENPKG ".PortError", NULL, NULL); 3.1779 - PyDict_SetItemString(d, "PortError", port_error); 3.1780 - 3.1781 - /* KAF: This ensures that we get debug output in a timely manner. */ 3.1782 - setbuf(stdout, NULL); 3.1783 - setbuf(stderr, NULL); 3.1784 -}
4.1 --- a/tools/python/xen/xend/server/channel.py Wed Sep 07 18:28:04 2005 +0000 4.2 +++ b/tools/python/xen/xend/server/channel.py Wed Sep 07 18:37:55 2005 +0000 4.3 @@ -19,7 +19,6 @@ import threading 4.4 import select 4.5 4.6 import xen.lowlevel.xc; xc = xen.lowlevel.xc.new() 4.7 -from xen.lowlevel import xu 4.8 4.9 from xen.xend.XendLogging import log 4.10