ia64/xen-unstable

changeset 6687:4e4aac33809f

g/c unused xu extension.
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')
     2.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Wed Sep 07 18:28:04 2005 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,1781 +0,0 @@
     2.4 -/******************************************************************************
     2.5 - * utils.c
     2.6 - * 
     2.7 - * Copyright (c) 2004, K A Fraser
     2.8 - */
     2.9 -
    2.10 -#include <Python.h>
    2.11 -#include <stdio.h>
    2.12 -#include <stdlib.h>
    2.13 -#include <string.h>
    2.14 -#include <sys/ioctl.h>
    2.15 -#include <sys/types.h>
    2.16 -#include <sys/wait.h>
    2.17 -#include <sys/stat.h>
    2.18 -#include <sys/socket.h>
    2.19 -#include <sys/un.h>
    2.20 -#include <sys/mman.h>
    2.21 -#include <sys/poll.h>
    2.22 -#include <sys/sysmacros.h>
    2.23 -#include <fcntl.h>
    2.24 -#include <unistd.h>
    2.25 -#include <errno.h>
    2.26 -#include <signal.h>
    2.27 -#include <xenctrl.h>
    2.28 -
    2.29 -#include <xen/xen.h>
    2.30 -#include <xen/io/domain_controller.h>
    2.31 -#include <xen/linux/privcmd.h>
    2.32 -
    2.33 -#define XENPKG "xen.lowlevel.xu"
    2.34 -
    2.35 -/* Needed for Python versions earlier than 2.3. */
    2.36 -#ifndef PyMODINIT_FUNC
    2.37 -#define PyMODINIT_FUNC DL_EXPORT(void)
    2.38 -#endif
    2.39 -
    2.40 -/* NB. The following should be kept in sync with the kernel's evtchn driver. */
    2.41 -#define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
    2.42 -#define EVTCHN_DEV_MAJOR 10
    2.43 -#define EVTCHN_DEV_MINOR 201
    2.44 -/* /dev/xen/evtchn ioctls: */
    2.45 -/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
    2.46 -#define EVTCHN_RESET  _IO('E', 1)
    2.47 -/* EVTCHN_BIND: Bind to teh specified event-channel port. */
    2.48 -#define EVTCHN_BIND   _IO('E', 2)
    2.49 -/* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
    2.50 -#define EVTCHN_UNBIND _IO('E', 3)
    2.51 -
    2.52 -/* Set the close-on-exec flag on a file descriptor.  Doesn't currently bother
    2.53 - * to check for errors. */
    2.54 -/*
    2.55 -static void set_cloexec(int fd)
    2.56 -{
    2.57 -    int flags = fcntl(fd, F_GETFD, 0);
    2.58 -
    2.59 -    if ( flags < 0 )
    2.60 -	return;
    2.61 -
    2.62 -    flags |= FD_CLOEXEC;
    2.63 -    fcntl(fd, F_SETFD, flags);
    2.64 -}
    2.65 -*/
    2.66 -/*
    2.67 - * *********************** XCS INTERFACE ***********************
    2.68 - */
    2.69 -
    2.70 -#include <arpa/inet.h>
    2.71 -#include <xcs_proto.h>
    2.72 -
    2.73 -static int xcs_ctrl_fd = -1; /* control connection to the xcs server. */
    2.74 -static int xcs_data_fd = -1; /*    data connection to the xcs server. */
    2.75 -static unsigned long  xcs_session_id = 0;
    2.76 -
    2.77 -static int xcs_ctrl_send(xcs_msg_t *msg);
    2.78 -static int xcs_ctrl_read(xcs_msg_t *msg);
    2.79 -static int xcs_data_send(xcs_msg_t *msg);
    2.80 -static int xcs_data_read(xcs_msg_t *msg);
    2.81 -
    2.82 -static int xcs_connect(char *path)
    2.83 -{
    2.84 -    struct sockaddr_un addr;
    2.85 -    int ret, len, flags;
    2.86 -    xcs_msg_t msg;
    2.87 -
    2.88 -    if (xcs_data_fd != -1) /* already connected */
    2.89 -        return 0;
    2.90 -    
    2.91 -    xcs_ctrl_fd = socket(AF_UNIX, SOCK_STREAM, 0);
    2.92 -    if (xcs_ctrl_fd < 0)
    2.93 -    {
    2.94 -        printf("error creating xcs socket!\n");
    2.95 -        goto fail;
    2.96 -    }
    2.97 -    
    2.98 -    addr.sun_family = AF_UNIX;
    2.99 -    strcpy(addr.sun_path, path);
   2.100 -    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
   2.101 -
   2.102 -    ret = connect(xcs_ctrl_fd, (struct sockaddr *)&addr, len);
   2.103 -    if (ret < 0) 
   2.104 -    {
   2.105 -        printf("error connecting to xcs(ctrl)! (%d)\n", errno);
   2.106 -        goto ctrl_fd_fail;
   2.107 -    }
   2.108 -
   2.109 -    /*set_cloexec(xcs_ctrl_fd);*/
   2.110 -            
   2.111 -    msg.type = XCS_CONNECT_CTRL;
   2.112 -    msg.u.connect.session_id = xcs_session_id;
   2.113 -    xcs_ctrl_send(&msg);
   2.114 -    xcs_ctrl_read(&msg); /* TODO: timeout + error! */
   2.115 -    
   2.116 -    if (msg.result != XCS_RSLT_OK)
   2.117 -    {
   2.118 -        printf("error connecting xcs control channel!\n");
   2.119 -        goto ctrl_fd_fail;
   2.120 -    }
   2.121 -    xcs_session_id = msg.u.connect.session_id;
   2.122 -    
   2.123 -    /* now the data connection. */
   2.124 -    xcs_data_fd = socket(AF_UNIX, SOCK_STREAM, 0);
   2.125 -    if (xcs_data_fd < 0)
   2.126 -    {
   2.127 -        printf("error creating xcs data socket!\n");
   2.128 -        goto ctrl_fd_fail;
   2.129 -    }
   2.130 -    
   2.131 -    addr.sun_family = AF_UNIX;
   2.132 -    strcpy(addr.sun_path, path);
   2.133 -    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
   2.134 -    
   2.135 -    ret = connect(xcs_data_fd, (struct sockaddr *)&addr, len);
   2.136 -    if (ret < 0) 
   2.137 -    {
   2.138 -        printf("error connecting to xcs(data)! (%d)\n", errno);
   2.139 -        goto data_fd_fail;
   2.140 -    }
   2.141 -
   2.142 -    //set_cloexec(xcs_data_fd);
   2.143 -    msg.type = XCS_CONNECT_DATA;
   2.144 -    msg.u.connect.session_id = xcs_session_id;
   2.145 -    xcs_data_send(&msg);
   2.146 -    xcs_data_read(&msg); /* TODO: timeout + error! */
   2.147 -    
   2.148 -    if (msg.result != XCS_RSLT_OK)
   2.149 -    {
   2.150 -        printf("error connecting xcs control channel!\n");
   2.151 -        goto ctrl_fd_fail;
   2.152 -    }
   2.153 -    
   2.154 -    if ( ((flags = fcntl(xcs_data_fd, F_GETFL, 0)) < 0) ||
   2.155 -        (fcntl(xcs_data_fd, F_SETFL, flags | O_NONBLOCK) < 0) )
   2.156 -    {
   2.157 -        printf("Unable to set non-blocking status on data socket.");
   2.158 -        goto data_fd_fail;
   2.159 -    }
   2.160 -    
   2.161 -    return 0;
   2.162 -
   2.163 -data_fd_fail: 
   2.164 -    close(xcs_data_fd);  
   2.165 -    xcs_data_fd = -1;  
   2.166 -    
   2.167 -ctrl_fd_fail:
   2.168 -    close(xcs_ctrl_fd);
   2.169 -    xcs_ctrl_fd = -1; 
   2.170 -     
   2.171 -fail:
   2.172 -    return -1;
   2.173 -    
   2.174 -}
   2.175 -
   2.176 -static void xcs_disconnect(void)
   2.177 -{
   2.178 -    close(xcs_data_fd);
   2.179 -    xcs_data_fd = -1;
   2.180 -    close(xcs_ctrl_fd);
   2.181 -    xcs_ctrl_fd = -1;
   2.182 -}
   2.183 -
   2.184 -static int xcs_ctrl_read(xcs_msg_t *msg)
   2.185 -{
   2.186 -    int ret;
   2.187 -    
   2.188 -    ret = read(xcs_ctrl_fd, msg, sizeof(xcs_msg_t));
   2.189 -    return ret;
   2.190 -}
   2.191 -
   2.192 -static int xcs_ctrl_send(xcs_msg_t *msg)
   2.193 -{
   2.194 -    int ret;
   2.195 -    
   2.196 -    ret = send(xcs_ctrl_fd, msg, sizeof(xcs_msg_t), 0);
   2.197 -    return ret;
   2.198 -}
   2.199 -
   2.200 -static int xcs_data_read(xcs_msg_t *msg)
   2.201 -{
   2.202 -    int ret;
   2.203 -    
   2.204 -    ret = read(xcs_data_fd, msg, sizeof(xcs_msg_t));
   2.205 -    return ret;
   2.206 -}
   2.207 -
   2.208 -static int xcs_data_send(xcs_msg_t *msg)
   2.209 -{
   2.210 -    int ret;
   2.211 -    
   2.212 -    ret = send(xcs_data_fd, msg, sizeof(xcs_msg_t), 0);
   2.213 -    return ret;
   2.214 -}
   2.215 -
   2.216 -
   2.217 -typedef struct kme_st {
   2.218 -    xcs_msg_t         msg;
   2.219 -    struct kme_st    *next;
   2.220 -} xcs_msg_ent_t;
   2.221 -    
   2.222 -
   2.223 -#define XCS_RING_SIZE 64
   2.224 -static xcs_msg_ent_t *req_ring[64];
   2.225 -static unsigned req_prod = 0;
   2.226 -static unsigned req_cons = 0;
   2.227 -
   2.228 -static xcs_msg_ent_t *rsp_ring[64];
   2.229 -static unsigned rsp_prod = 0;
   2.230 -static unsigned rsp_cons = 0;
   2.231 -
   2.232 -#define REQ_RING_ENT(_idx) (req_ring[(_idx) % XCS_RING_SIZE])
   2.233 -#define RSP_RING_ENT(_idx) (rsp_ring[(_idx) % XCS_RING_SIZE]) 
   2.234 -#define REQ_RING_FULL ( req_prod - req_cons == XCS_RING_SIZE )
   2.235 -#define RSP_RING_FULL ( rsp_prod - rsp_cons == XCS_RING_SIZE )
   2.236 -#define REQ_RING_EMPTY ( req_prod == req_cons )
   2.237 -#define RSP_RING_EMPTY ( rsp_prod == rsp_cons )
   2.238 -/*
   2.239 - * *********************** NOTIFIER ***********************
   2.240 - */
   2.241 -
   2.242 -typedef struct {
   2.243 -    PyObject_HEAD;
   2.244 -    int evtchn_fd;
   2.245 -} xu_notifier_object;
   2.246 -
   2.247 -static PyObject *xu_notifier_read(PyObject *self, PyObject *args)
   2.248 -{
   2.249 -    xcs_msg_ent_t *ent;
   2.250 -    int ret;
   2.251 -
   2.252 -    if ( !PyArg_ParseTuple(args, "") )
   2.253 -        return NULL;
   2.254 -         
   2.255 -    while ((!REQ_RING_FULL) && (!RSP_RING_FULL))
   2.256 -    {
   2.257 -        ent = (xcs_msg_ent_t *)malloc(sizeof(xcs_msg_ent_t));
   2.258 -        ret = xcs_data_read(&ent->msg);
   2.259 -
   2.260 -        if (ret == -1)
   2.261 -        {
   2.262 -            free(ent);
   2.263 -            if ( errno == EINTR )
   2.264 -                continue;
   2.265 -            if ( errno == EAGAIN )
   2.266 -                break;
   2.267 -            return PyErr_SetFromErrno(PyExc_IOError);
   2.268 -        }
   2.269 -        
   2.270 -        switch (ent->msg.type)
   2.271 -        {
   2.272 -        case XCS_REQUEST:
   2.273 -            REQ_RING_ENT(req_prod) = ent;
   2.274 -            req_prod++;
   2.275 -            continue;
   2.276 -
   2.277 -        case XCS_RESPONSE:
   2.278 -            RSP_RING_ENT(rsp_prod) = ent;
   2.279 -            rsp_prod++;
   2.280 -            continue;
   2.281 -            
   2.282 -        case XCS_VIRQ:
   2.283 -            ret = ent->msg.u.control.local_port;
   2.284 -            free(ent);
   2.285 -            return PyInt_FromLong(ret);
   2.286 -
   2.287 -        default:
   2.288 -            /*printf("Throwing away xcs msg type: %u\n", ent->msg.type);*/
   2.289 -            free(ent);
   2.290 -        }
   2.291 -    }
   2.292 -    
   2.293 -    if (!REQ_RING_EMPTY) 
   2.294 -    {
   2.295 -        return PyInt_FromLong(REQ_RING_ENT(req_cons)->msg.u.control.local_port); 
   2.296 -    }
   2.297 -    
   2.298 -    if (!RSP_RING_EMPTY) 
   2.299 -    {
   2.300 -        return PyInt_FromLong(RSP_RING_ENT(rsp_cons)->msg.u.control.local_port); 
   2.301 -    }
   2.302 -    
   2.303 -    Py_INCREF(Py_None);
   2.304 -    return Py_None;
   2.305 -}
   2.306 -
   2.307 -static PyObject *xu_notifier_bind_virq(PyObject *self, 
   2.308 -            PyObject *args, PyObject *kwds)
   2.309 -{
   2.310 -    int virq;
   2.311 -    xcs_msg_t kmsg;
   2.312 -
   2.313 -    static char *kwd_list[] = { "virq", NULL };
   2.314 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &virq) )
   2.315 -        return NULL;
   2.316 -    
   2.317 -    kmsg.type = XCS_VIRQ_BIND;
   2.318 -    kmsg.u.virq.virq  = virq;
   2.319 -    xcs_ctrl_send(&kmsg);
   2.320 -    xcs_ctrl_read(&kmsg);
   2.321 -    
   2.322 -    if ( kmsg.result != XCS_RSLT_OK )
   2.323 -    {  
   2.324 -        Py_INCREF(Py_None);
   2.325 -        return Py_None;
   2.326 -    }
   2.327 -    
   2.328 -    return PyInt_FromLong(kmsg.u.virq.port);
   2.329 -}
   2.330 -
   2.331 -static PyObject *xu_notifier_virq_send(PyObject *self, 
   2.332 -            PyObject *args, PyObject *kwds)
   2.333 -{
   2.334 -    int port;
   2.335 -    xcs_msg_t kmsg;
   2.336 -
   2.337 -    static char *kwd_list[] = { "port", NULL };
   2.338 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &port) )
   2.339 -        return NULL;
   2.340 -    
   2.341 -    kmsg.type = XCS_VIRQ;
   2.342 -    kmsg.u.control.local_port  = port;
   2.343 -    xcs_ctrl_send(&kmsg);
   2.344 -    xcs_ctrl_read(&kmsg);
   2.345 -    
   2.346 -    if ( kmsg.result != XCS_RSLT_OK )
   2.347 -    {  
   2.348 -        Py_INCREF(Py_None);
   2.349 -        return Py_None;
   2.350 -    }
   2.351 -    
   2.352 -    return PyInt_FromLong(kmsg.u.virq.port);
   2.353 -}
   2.354 -
   2.355 -static PyObject *xu_notifier_fileno(PyObject *self, PyObject *args)
   2.356 -{
   2.357 -    return PyInt_FromLong(xcs_data_fd);
   2.358 -}
   2.359 -
   2.360 -static PyMethodDef xu_notifier_methods[] = {
   2.361 -    { "read",
   2.362 -      (PyCFunction)xu_notifier_read,
   2.363 -      METH_VARARGS,
   2.364 -      "Read a @port with pending notifications.\n" },
   2.365 -
   2.366 -    { "bind_virq",
   2.367 -      (PyCFunction)xu_notifier_bind_virq,
   2.368 -      METH_VARARGS | METH_KEYWORDS,
   2.369 -      "Get notifications for a virq.\n" 
   2.370 -      " virq [int]: VIRQ to bind.\n\n" },
   2.371 -      
   2.372 -    { "virq_send",
   2.373 -      (PyCFunction)xu_notifier_virq_send,
   2.374 -      METH_VARARGS | METH_KEYWORDS,
   2.375 -      "Fire a virq notification.\n" 
   2.376 -      " port [int]: port that VIRQ is bound to.\n\n" },
   2.377 -
   2.378 -    { "fileno", 
   2.379 -      (PyCFunction)xu_notifier_fileno,
   2.380 -      METH_VARARGS,
   2.381 -      "Return the file descriptor for the notification channel.\n" },
   2.382 -
   2.383 -    { NULL, NULL, 0, NULL }
   2.384 -};
   2.385 -
   2.386 -staticforward PyTypeObject xu_notifier_type;
   2.387 -
   2.388 -/* connect to xcs if we aren't already, and return a dummy object. */
   2.389 -static PyObject *xu_notifier_new(PyObject *self, PyObject *args)
   2.390 -{
   2.391 -    xu_notifier_object *xun;
   2.392 -    int i;
   2.393 -
   2.394 -    if ( !PyArg_ParseTuple(args, "") )
   2.395 -        return NULL;
   2.396 -
   2.397 -    xun = PyObject_New(xu_notifier_object, &xu_notifier_type);
   2.398 -
   2.399 -    for (i = 0; i < XCS_RING_SIZE; i++) 
   2.400 -        REQ_RING_ENT(i) = RSP_RING_ENT(i) = NULL;
   2.401 -    
   2.402 -    (void)xcs_connect(XCS_SUN_PATH);
   2.403 -    
   2.404 -
   2.405 -    return (PyObject *)xun;
   2.406 -}
   2.407 -
   2.408 -static PyObject *xu_notifier_getattr(PyObject *obj, char *name)
   2.409 -{
   2.410 -    return Py_FindMethod(xu_notifier_methods, obj, name);
   2.411 -}
   2.412 -
   2.413 -static void xu_notifier_dealloc(PyObject *self)
   2.414 -{
   2.415 -    xcs_disconnect();
   2.416 -    PyObject_Del(self);
   2.417 -}
   2.418 -
   2.419 -static PyTypeObject xu_notifier_type = {
   2.420 -    PyObject_HEAD_INIT(&PyType_Type)
   2.421 -    0,
   2.422 -    "notifier",
   2.423 -    sizeof(xu_notifier_object),
   2.424 -    0,
   2.425 -    xu_notifier_dealloc, /* tp_dealloc     */
   2.426 -    NULL,                /* tp_print       */
   2.427 -    xu_notifier_getattr, /* tp_getattr     */
   2.428 -    NULL,                /* tp_setattr     */
   2.429 -    NULL,                /* tp_compare     */
   2.430 -    NULL,                /* tp_repr        */
   2.431 -    NULL,                /* tp_as_number   */
   2.432 -    NULL,                /* tp_as_sequence */
   2.433 -    NULL,                /* tp_as_mapping  */
   2.434 -    NULL                 /* tp_hash        */
   2.435 -};
   2.436 -
   2.437 -
   2.438 -
   2.439 -/*
   2.440 - * *********************** MESSAGE ***********************
   2.441 - */
   2.442 -
   2.443 -#define TYPE(_x,_y) (((_x)<<8)|(_y))
   2.444 -
   2.445 -#define P2C(_struct, _field, _ctype)                                      \
   2.446 -    do {                                                                  \
   2.447 -        PyObject *obj;                                                    \
   2.448 -        if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL )     \
   2.449 -        {                                                                 \
   2.450 -            if ( PyInt_Check(obj) )                                       \
   2.451 -            {                                                             \
   2.452 -                ((_struct *)&xum->msg.msg[0])->_field =                   \
   2.453 -                  (_ctype)PyInt_AsLong(obj);                              \
   2.454 -                dict_items_parsed++;                                      \
   2.455 -            }                                                             \
   2.456 -            else if ( PyLong_Check(obj) )                                 \
   2.457 -            {                                                             \
   2.458 -                ((_struct *)&xum->msg.msg[0])->_field =                   \
   2.459 -                  (_ctype)PyLong_AsUnsignedLongLong(obj);                 \
   2.460 -                dict_items_parsed++;                                      \
   2.461 -            }                                                             \
   2.462 -        }                                                                 \
   2.463 -        xum->msg.length = sizeof(_struct);                                \
   2.464 -    } while ( 0 )
   2.465 -
   2.466 -/** Set a char[] field in a struct from a Python string.
   2.467 - * Can't do this in P2C because of the typing.
   2.468 - */
   2.469 -#define P2CSTRING(_struct, _field)                                        \
   2.470 -    do {                                                                  \
   2.471 -        PyObject *obj;                                                    \
   2.472 -        if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL )     \
   2.473 -        {                                                                 \
   2.474 -            if ( PyString_Check(obj) )                                    \
   2.475 -            {                                                             \
   2.476 -                _struct * _cobj = (_struct *)&xum->msg.msg[0];            \
   2.477 -                int _field_n = sizeof(_cobj->_field);                     \
   2.478 -                memset(_cobj->_field, 0, _field_n);                       \
   2.479 -                strncpy(_cobj->_field,                                    \
   2.480 -                        PyString_AsString(obj),                           \
   2.481 -                        _field_n - 1);                                    \
   2.482 -                dict_items_parsed++;                                      \
   2.483 -            }                                                             \
   2.484 -        }                                                                 \
   2.485 -        xum->msg.length = sizeof(_struct);                                \
   2.486 -    } while ( 0 )
   2.487 -
   2.488 -#define C2P(_struct, _field, _pytype, _ctype)                             \
   2.489 -    do {                                                                  \
   2.490 -        PyObject *obj = Py ## _pytype ## _From ## _ctype                  \
   2.491 -                        (((_struct *)&xum->msg.msg[0])->_field);          \
   2.492 -        if ( dict == NULL ) dict = PyDict_New();                          \
   2.493 -        PyDict_SetItemString(dict, #_field, obj);                         \
   2.494 -    } while ( 0 )
   2.495 -
   2.496 -#define PSTR2CHAR(_struct, _field)                                        \
   2.497 - do {                                                                     \
   2.498 -     PyObject *obj;                                                       \
   2.499 -        if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL )     \
   2.500 -        {                                                                 \
   2.501 -            if ( PyString_Check(obj) )                                    \
   2.502 -            {                                                             \
   2.503 -                char *buffer = PyString_AsString(obj);                    \
   2.504 -                                                                          \
   2.505 -                strcpy(((_struct *)&xum->msg.msg[0])->_field,             \
   2.506 -                        buffer);                                          \
   2.507 -                /* Should complain about length - think later */          \
   2.508 -                dict_items_parsed++;                                      \
   2.509 -            }                                                             \
   2.510 -        }                                                                 \
   2.511 -        xum->msg.length = sizeof(_struct);                                \
   2.512 - } while ( 0 )
   2.513 -
   2.514 -typedef struct {
   2.515 -    PyObject_HEAD;
   2.516 -    control_msg_t msg;
   2.517 -} xu_message_object;
   2.518 -
   2.519 -static PyObject *xu_message_append_payload(PyObject *self, PyObject *args)
   2.520 -{
   2.521 -    xu_message_object *xum = (xu_message_object *)self;
   2.522 -    char *str;
   2.523 -    int len;
   2.524 -
   2.525 -    if ( !PyArg_ParseTuple(args, "s#", &str, &len) )
   2.526 -        return NULL;
   2.527 -
   2.528 -    if ( (len + xum->msg.length) > sizeof(xum->msg.msg) )
   2.529 -    {
   2.530 -        PyErr_SetString(PyExc_RuntimeError, "out of space in control message");
   2.531 -        return NULL;
   2.532 -    }
   2.533 -
   2.534 -    memcpy(&xum->msg.msg[xum->msg.length], str, len);
   2.535 -    xum->msg.length += len;
   2.536 -
   2.537 -    Py_INCREF(Py_None);
   2.538 -    return Py_None;
   2.539 -}
   2.540 -
   2.541 -static PyObject *xu_message_set_response_fields(PyObject *self, PyObject *args)
   2.542 -{
   2.543 -    xu_message_object *xum = (xu_message_object *)self;
   2.544 -    PyObject *payload;
   2.545 -    int dict_items_parsed = 0;
   2.546 -
   2.547 -    if ( !PyArg_ParseTuple(args, "O", &payload) )
   2.548 -        return NULL;
   2.549 -
   2.550 -    if ( !PyDict_Check(payload) )
   2.551 -    {
   2.552 -        PyErr_SetString(PyExc_TypeError, "payload is not a dictionary");
   2.553 -        return NULL;
   2.554 -    }
   2.555 -
   2.556 -    switch ( TYPE(xum->msg.type, xum->msg.subtype) )
   2.557 -    {
   2.558 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_DRIVER_STATUS):
   2.559 -        P2C(blkif_fe_driver_status_t, max_handle, u32);
   2.560 -        break;
   2.561 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS):
   2.562 -        P2C(netif_fe_driver_status_t, max_handle, u32);
   2.563 -        break;
   2.564 -    }
   2.565 -
   2.566 -    if ( dict_items_parsed != PyDict_Size(payload) )
   2.567 -    {
   2.568 -        PyErr_SetString(PyExc_TypeError, "payload contains bad items");
   2.569 -        return NULL;
   2.570 -    }
   2.571 -
   2.572 -    Py_INCREF(Py_None);
   2.573 -    return Py_None;
   2.574 -}
   2.575 -
   2.576 -static PyObject *xu_message_get_payload(PyObject *self, PyObject *args)
   2.577 -{
   2.578 -    xu_message_object *xum = (xu_message_object *)self;
   2.579 -    PyObject *dict = NULL;
   2.580 -
   2.581 -    if ( !PyArg_ParseTuple(args, "") )
   2.582 -        return NULL;
   2.583 -
   2.584 -    switch ( TYPE(xum->msg.type, xum->msg.subtype) )
   2.585 -    {
   2.586 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_STATUS):
   2.587 -        C2P(blkif_fe_interface_status_t, handle, Int, Long);
   2.588 -        C2P(blkif_fe_interface_status_t, status, Int, Long);
   2.589 -        C2P(blkif_fe_interface_status_t, evtchn, Int, Long);
   2.590 -        return dict;
   2.591 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_DRIVER_STATUS):
   2.592 -        C2P(blkif_fe_driver_status_t, status, Int, Long);
   2.593 -        return dict;
   2.594 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_CONNECT):
   2.595 -        C2P(blkif_fe_interface_connect_t, handle,      Int, Long);
   2.596 -        C2P(blkif_fe_interface_connect_t, shmem_frame, Int, Long);
   2.597 -        C2P(blkif_fe_interface_connect_t, shmem_ref  , Int, Long);
   2.598 -        return dict;
   2.599 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_DISCONNECT):
   2.600 -        C2P(blkif_fe_interface_disconnect_t, handle, Int, Long);
   2.601 -        return dict;
   2.602 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE):
   2.603 -        C2P(blkif_be_create_t, domid,        Int, Long);
   2.604 -        C2P(blkif_be_create_t, blkif_handle, Int, Long);
   2.605 -        C2P(blkif_be_create_t, status,       Int, Long);
   2.606 -        return dict;
   2.607 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY):
   2.608 -        C2P(blkif_be_destroy_t, domid,        Int, Long);
   2.609 -        C2P(blkif_be_destroy_t, blkif_handle, Int, Long);
   2.610 -        C2P(blkif_be_destroy_t, status,       Int, Long);
   2.611 -        return dict;
   2.612 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT):
   2.613 -        C2P(blkif_be_connect_t, domid,        Int, Long);
   2.614 -        C2P(blkif_be_connect_t, blkif_handle, Int, Long);
   2.615 -        C2P(blkif_be_connect_t, shmem_frame,  Int, Long);
   2.616 -        C2P(blkif_be_connect_t, shmem_ref,    Int, Long);
   2.617 -        C2P(blkif_be_connect_t, evtchn,       Int, Long);
   2.618 -        C2P(blkif_be_connect_t, status,       Int, Long);
   2.619 -        return dict;
   2.620 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT):
   2.621 -        C2P(blkif_be_disconnect_t, domid,        Int, Long);
   2.622 -        C2P(blkif_be_disconnect_t, blkif_handle, Int, Long);
   2.623 -        C2P(blkif_be_disconnect_t, status,       Int, Long);
   2.624 -        return dict;
   2.625 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE):
   2.626 -        C2P(blkif_be_vbd_create_t, domid,        Int, Long);
   2.627 -        C2P(blkif_be_vbd_create_t, blkif_handle, Int, Long);
   2.628 -        C2P(blkif_be_vbd_create_t, pdevice,      Int, Long);
   2.629 -        C2P(blkif_be_vbd_create_t, dev_handle,   Int, Long);
   2.630 -        C2P(blkif_be_vbd_create_t, vdevice,      Int, Long);
   2.631 -        C2P(blkif_be_vbd_create_t, readonly,     Int, Long);
   2.632 -        C2P(blkif_be_vbd_create_t, status,       Int, Long);
   2.633 -        return dict;
   2.634 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_DESTROY):
   2.635 -        C2P(blkif_be_vbd_destroy_t, domid,        Int, Long);
   2.636 -        C2P(blkif_be_vbd_destroy_t, blkif_handle, Int, Long);
   2.637 -        C2P(blkif_be_vbd_destroy_t, vdevice,      Int, Long);
   2.638 -        C2P(blkif_be_vbd_destroy_t, status,       Int, Long);
   2.639 -        return dict;
   2.640 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DRIVER_STATUS):
   2.641 -        C2P(blkif_be_driver_status_t, status, Int, Long);
   2.642 -        return dict;
   2.643 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_STATUS):
   2.644 -        C2P(netif_fe_interface_status_t, handle, Int, Long);
   2.645 -        C2P(netif_fe_interface_status_t, status, Int, Long);
   2.646 -        C2P(netif_fe_interface_status_t, evtchn, Int, Long);
   2.647 -        C2P(netif_fe_interface_status_t, mac[0], Int, Long);
   2.648 -        C2P(netif_fe_interface_status_t, mac[1], Int, Long);
   2.649 -        C2P(netif_fe_interface_status_t, mac[2], Int, Long);
   2.650 -        C2P(netif_fe_interface_status_t, mac[3], Int, Long);
   2.651 -        C2P(netif_fe_interface_status_t, mac[4], Int, Long);
   2.652 -        C2P(netif_fe_interface_status_t, mac[5], Int, Long);
   2.653 -        return dict;
   2.654 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS):
   2.655 -        C2P(netif_fe_driver_status_t, status,        Int, Long);
   2.656 -        C2P(netif_fe_driver_status_t, max_handle,    Int, Long);
   2.657 -        return dict;
   2.658 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_CONNECT):
   2.659 -        C2P(netif_fe_interface_connect_t, handle,         Int, Long);
   2.660 -        C2P(netif_fe_interface_connect_t, tx_shmem_frame, Int, Long);
   2.661 -        C2P(netif_fe_interface_connect_t, tx_shmem_ref,   Int, Long);
   2.662 -        C2P(netif_fe_interface_connect_t, rx_shmem_frame, Int, Long);
   2.663 -        C2P(netif_fe_interface_connect_t, rx_shmem_ref,   Int, Long);
   2.664 -        return dict;
   2.665 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_DISCONNECT):
   2.666 -        C2P(netif_fe_interface_disconnect_t, handle, Int, Long);
   2.667 -        return dict;
   2.668 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE):
   2.669 -        C2P(netif_be_create_t, domid,        Int, Long);
   2.670 -        C2P(netif_be_create_t, netif_handle, Int, Long);
   2.671 -        C2P(netif_be_create_t, status,       Int, Long);
   2.672 -        return dict;
   2.673 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
   2.674 -        C2P(netif_be_destroy_t, domid,        Int, Long);
   2.675 -        C2P(netif_be_destroy_t, netif_handle, Int, Long);
   2.676 -        C2P(netif_be_destroy_t, status,       Int, Long);
   2.677 -        return dict;
   2.678 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT):
   2.679 -        C2P(netif_be_creditlimit_t, domid,        Int, Long);
   2.680 -        C2P(netif_be_creditlimit_t, netif_handle, Int, Long);
   2.681 -        C2P(netif_be_creditlimit_t, credit_bytes, Int, Long);
   2.682 -        C2P(netif_be_creditlimit_t, period_usec,  Int, Long);
   2.683 -        C2P(netif_be_creditlimit_t, status,       Int, Long);
   2.684 -        return dict;
   2.685 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT):
   2.686 -        C2P(netif_be_connect_t, domid,          Int, Long);
   2.687 -        C2P(netif_be_connect_t, netif_handle,   Int, Long);
   2.688 -        C2P(netif_be_connect_t, tx_shmem_frame, Int, Long);
   2.689 -        C2P(netif_be_connect_t, tx_shmem_ref,   Int, Long);
   2.690 -        C2P(netif_be_connect_t, rx_shmem_frame, Int, Long);
   2.691 -        C2P(netif_be_connect_t, rx_shmem_ref,   Int, Long);
   2.692 -        C2P(netif_be_connect_t, evtchn,         Int, Long);
   2.693 -        C2P(netif_be_connect_t, status,         Int, Long);
   2.694 -        return dict;
   2.695 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DISCONNECT):
   2.696 -        C2P(netif_be_disconnect_t, domid,        Int, Long);
   2.697 -        C2P(netif_be_disconnect_t, netif_handle, Int, Long);
   2.698 -        C2P(netif_be_disconnect_t, status,       Int, Long);
   2.699 -        return dict;
   2.700 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DRIVER_STATUS):
   2.701 -        C2P(netif_be_driver_status_t, status, Int, Long);
   2.702 -        return dict;
   2.703 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED):
   2.704 -        C2P(usbif_fe_interface_status_changed_t, status, Int, Long);
   2.705 -        C2P(usbif_fe_interface_status_changed_t, evtchn, Int, Long);
   2.706 -        C2P(usbif_fe_interface_status_changed_t, domid, Int, Long);
   2.707 -        C2P(usbif_fe_interface_status_changed_t, bandwidth, Int, Long);
   2.708 -	C2P(usbif_fe_interface_status_changed_t, num_ports, Int, Long);
   2.709 -        return dict;
   2.710 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_DRIVER_STATUS_CHANGED):
   2.711 -        C2P(usbif_fe_driver_status_changed_t, status, Int, Long);
   2.712 -        return dict;
   2.713 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_CONNECT):
   2.714 -        C2P(usbif_fe_interface_connect_t, shmem_frame, Int, Long);
   2.715 -        return dict;
   2.716 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_DISCONNECT):
   2.717 -        return dict;
   2.718 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CREATE):
   2.719 -        C2P(usbif_be_create_t, domid, Int, Long);
   2.720 -        C2P(usbif_be_create_t, status, Int, Long);
   2.721 -        return dict;
   2.722 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DESTROY):
   2.723 -        C2P(usbif_be_destroy_t, domid, Int, Long);
   2.724 -        C2P(usbif_be_destroy_t, status, Int, Long);
   2.725 -        return dict;
   2.726 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CONNECT):
   2.727 -        C2P(usbif_be_connect_t, domid, Int, Long);
   2.728 -        C2P(usbif_be_connect_t, shmem_frame, Int, Long);
   2.729 -        C2P(usbif_be_connect_t, evtchn, Int, Long);
   2.730 -        C2P(usbif_be_connect_t, bandwidth, Int, Long);
   2.731 -        C2P(usbif_be_connect_t, status, Int, Long);
   2.732 -        return dict;
   2.733 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DISCONNECT):
   2.734 -        C2P(usbif_be_disconnect_t, domid, Int, Long);
   2.735 -        C2P(usbif_be_disconnect_t, status, Int, Long);
   2.736 -        return dict;
   2.737 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DRIVER_STATUS_CHANGED):
   2.738 -        C2P(usbif_be_driver_status_changed_t, status, Int, Long);
   2.739 -        return dict;
   2.740 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CLAIM_PORT):
   2.741 -        C2P(usbif_be_claim_port_t, domid, Int, Long);
   2.742 -        C2P(usbif_be_claim_port_t, usbif_port, Int, Long);
   2.743 -        C2P(usbif_be_claim_port_t, status, Int, Long);
   2.744 -        C2P(usbif_be_claim_port_t, path, String, String);
   2.745 -        return dict;
   2.746 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_RELEASE_PORT):
   2.747 -        C2P(usbif_be_release_port_t, path, String, String);
   2.748 -        return dict;
   2.749 -    case TYPE(CMSG_MEM_REQUEST, CMSG_MEM_REQUEST_SET):
   2.750 -        C2P(mem_request_t, target, Int, Long);
   2.751 -        C2P(mem_request_t, status, Int, Long);
   2.752 -        return dict;
   2.753 -    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF):
   2.754 -        C2P(vcpu_hotplug_t, vcpu, Int, Long);
   2.755 -        C2P(vcpu_hotplug_t, status, Int, Long);
   2.756 -        return dict;
   2.757 -    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON):
   2.758 -        C2P(vcpu_hotplug_t, vcpu, Int, Long);
   2.759 -        C2P(vcpu_hotplug_t, status, Int, Long);
   2.760 -        return dict;
   2.761 -    }
   2.762 -
   2.763 -    return PyString_FromStringAndSize((char *)xum->msg.msg, xum->msg.length);
   2.764 -}
   2.765 -
   2.766 -static PyObject *xu_message_get_header(PyObject *self, PyObject *args)
   2.767 -{
   2.768 -    xu_message_object *xum = (xu_message_object *)self;
   2.769 -
   2.770 -    if ( !PyArg_ParseTuple(args, "") )
   2.771 -        return NULL;
   2.772 -
   2.773 -    return Py_BuildValue("{s:i,s:i,s:i}",
   2.774 -                         "type",    xum->msg.type,
   2.775 -                         "subtype", xum->msg.subtype,
   2.776 -                         "id",      xum->msg.id);
   2.777 -}
   2.778 -
   2.779 -static PyMethodDef xu_message_methods[] = {
   2.780 -    { "append_payload", 
   2.781 -      (PyCFunction)xu_message_append_payload,
   2.782 -      METH_VARARGS,
   2.783 -      "Append @str to the message payload.\n" },
   2.784 -
   2.785 -    { "set_response_fields",
   2.786 -      (PyCFunction)xu_message_set_response_fields,
   2.787 -      METH_VARARGS,
   2.788 -      "Fill in the response fields in a message that was passed to us.\n" },
   2.789 -
   2.790 -    { "get_payload",
   2.791 -      (PyCFunction)xu_message_get_payload,
   2.792 -      METH_VARARGS,
   2.793 -      "Return the message payload in string form.\n" },
   2.794 -
   2.795 -    { "get_header",
   2.796 -      (PyCFunction)xu_message_get_header,
   2.797 -      METH_VARARGS,
   2.798 -      "Returns a dictionary of values for @type, @subtype, and @id.\n" },
   2.799 -
   2.800 -    { NULL, NULL, 0, NULL }
   2.801 -};
   2.802 -
   2.803 -staticforward PyTypeObject xu_message_type;
   2.804 -
   2.805 -static PyObject *xu_message_new(PyObject *self, PyObject *args)
   2.806 -{
   2.807 -    xu_message_object *xum;
   2.808 -    int type, subtype, id, dict_items_parsed = 0;
   2.809 -    PyObject *payload = NULL;
   2.810 -
   2.811 -    if ( !PyArg_ParseTuple(args, "iii|O", &type, &subtype, &id, &payload) )
   2.812 -        return NULL;
   2.813 -
   2.814 -    xum = PyObject_New(xu_message_object, &xu_message_type);
   2.815 -
   2.816 -    xum->msg.type    = type;
   2.817 -    xum->msg.subtype = subtype;
   2.818 -    xum->msg.id      = id;
   2.819 -    xum->msg.length  = 0;
   2.820 -
   2.821 -    if ( payload == NULL )
   2.822 -        return (PyObject *)xum;
   2.823 -
   2.824 -    if ( !PyDict_Check(payload) )
   2.825 -    {
   2.826 -        PyErr_SetString(PyExc_TypeError, "payload is not a dictionary");
   2.827 -        PyObject_Del((PyObject *)xum);
   2.828 -        return NULL;
   2.829 -    }
   2.830 -
   2.831 -    switch ( TYPE(type, subtype) )
   2.832 -    {
   2.833 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_STATUS):
   2.834 -        P2C(blkif_fe_interface_status_t, handle, u32);
   2.835 -        P2C(blkif_fe_interface_status_t, status, u32);
   2.836 -        P2C(blkif_fe_interface_status_t, evtchn, u16);
   2.837 -        P2C(blkif_fe_interface_status_t, domid,  u16);
   2.838 -        break;
   2.839 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE):
   2.840 -        P2C(blkif_be_create_t, domid,        u32);
   2.841 -        P2C(blkif_be_create_t, blkif_handle, u32);
   2.842 -        break;
   2.843 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY):
   2.844 -        P2C(blkif_be_destroy_t, domid,        u32);
   2.845 -        P2C(blkif_be_destroy_t, blkif_handle, u32);
   2.846 -        break;
   2.847 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT):
   2.848 -        P2C(blkif_be_connect_t, domid,        u32);
   2.849 -        P2C(blkif_be_connect_t, blkif_handle, u32);
   2.850 -        P2C(blkif_be_connect_t, shmem_frame,  unsigned long);
   2.851 -        P2C(blkif_be_connect_t, shmem_ref,    u32);
   2.852 -        P2C(blkif_be_connect_t, evtchn,       u16);
   2.853 -        break;
   2.854 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT):
   2.855 -        P2C(blkif_be_disconnect_t, domid,        u32);
   2.856 -        P2C(blkif_be_disconnect_t, blkif_handle, u32);
   2.857 -        break;
   2.858 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE):
   2.859 -        P2C(blkif_be_vbd_create_t, domid,        u32);
   2.860 -        P2C(blkif_be_vbd_create_t, blkif_handle, u32);
   2.861 -        P2C(blkif_be_vbd_create_t, pdevice,      blkif_pdev_t);
   2.862 -        P2C(blkif_be_vbd_create_t, dev_handle,   u32);
   2.863 -        P2C(blkif_be_vbd_create_t, vdevice,      blkif_vdev_t);
   2.864 -        P2C(blkif_be_vbd_create_t, readonly,     u16);
   2.865 -        break;
   2.866 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_DESTROY):
   2.867 -        P2C(blkif_be_vbd_destroy_t, domid,        u32);
   2.868 -        P2C(blkif_be_vbd_destroy_t, blkif_handle, u32);
   2.869 -        P2C(blkif_be_vbd_destroy_t, vdevice,      blkif_vdev_t);
   2.870 -        break;
   2.871 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_STATUS):
   2.872 -        P2C(netif_fe_interface_status_t, handle, u32);
   2.873 -        P2C(netif_fe_interface_status_t, status, u32);
   2.874 -        P2C(netif_fe_interface_status_t, evtchn, u16);
   2.875 -        P2C(netif_fe_interface_status_t, domid,  u16);
   2.876 -        P2C(netif_fe_interface_status_t, mac[0], u8);
   2.877 -        P2C(netif_fe_interface_status_t, mac[1], u8);
   2.878 -        P2C(netif_fe_interface_status_t, mac[2], u8);
   2.879 -        P2C(netif_fe_interface_status_t, mac[3], u8);
   2.880 -        P2C(netif_fe_interface_status_t, mac[4], u8);
   2.881 -        P2C(netif_fe_interface_status_t, mac[5], u8);
   2.882 -        break;
   2.883 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE):
   2.884 -        P2C(netif_be_create_t, domid,        u32);
   2.885 -        P2C(netif_be_create_t, netif_handle, u32);
   2.886 -        P2C(netif_be_create_t, mac[0],       u8);
   2.887 -        P2C(netif_be_create_t, mac[1],       u8);
   2.888 -        P2C(netif_be_create_t, mac[2],       u8);
   2.889 -        P2C(netif_be_create_t, mac[3],       u8);
   2.890 -        P2C(netif_be_create_t, mac[4],       u8);
   2.891 -        P2C(netif_be_create_t, mac[5],       u8);
   2.892 -        P2C(netif_be_create_t, be_mac[0],    u8);
   2.893 -        P2C(netif_be_create_t, be_mac[1],    u8);
   2.894 -        P2C(netif_be_create_t, be_mac[2],    u8);
   2.895 -        P2C(netif_be_create_t, be_mac[3],    u8);
   2.896 -        P2C(netif_be_create_t, be_mac[4],    u8);
   2.897 -        P2C(netif_be_create_t, be_mac[5],    u8);
   2.898 -        break;
   2.899 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
   2.900 -        P2C(netif_be_destroy_t, domid,        u32);
   2.901 -        P2C(netif_be_destroy_t, netif_handle, u32);
   2.902 -        break;
   2.903 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT):
   2.904 -        P2C(netif_be_creditlimit_t, domid,        u32);
   2.905 -        P2C(netif_be_creditlimit_t, netif_handle, u32);
   2.906 -        P2C(netif_be_creditlimit_t, credit_bytes, u32);
   2.907 -        P2C(netif_be_creditlimit_t, period_usec,  u32);
   2.908 -        break;
   2.909 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT):
   2.910 -        P2C(netif_be_connect_t, domid,          u32);
   2.911 -        P2C(netif_be_connect_t, netif_handle,   u32);
   2.912 -        P2C(netif_be_connect_t, tx_shmem_frame, unsigned long);
   2.913 -        P2C(netif_be_connect_t, tx_shmem_ref,   u32); 
   2.914 -        P2C(netif_be_connect_t, rx_shmem_frame, unsigned long);
   2.915 -        P2C(netif_be_connect_t, rx_shmem_ref,   u32); 
   2.916 -        P2C(netif_be_connect_t, evtchn,         u16); 
   2.917 -        break;
   2.918 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DISCONNECT):
   2.919 -        P2C(netif_be_disconnect_t, domid,        u32);
   2.920 -        P2C(netif_be_disconnect_t, netif_handle, u32);
   2.921 -        break;
   2.922 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS):
   2.923 -        P2C(netif_fe_driver_status_t, status,        u32);
   2.924 -        P2C(netif_fe_driver_status_t, max_handle,    u32);
   2.925 -        break;
   2.926 -    case TYPE(CMSG_MEM_REQUEST, CMSG_MEM_REQUEST_SET):
   2.927 -        P2C(mem_request_t, target, u32);
   2.928 -        break;
   2.929 -    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF):
   2.930 -        P2C(vcpu_hotplug_t, vcpu, u32);
   2.931 -        P2C(vcpu_hotplug_t, status, u32);
   2.932 -        break;
   2.933 -    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON):
   2.934 -        P2C(vcpu_hotplug_t, vcpu, u32);
   2.935 -        P2C(vcpu_hotplug_t, status, u32);
   2.936 -        break;
   2.937 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED):
   2.938 -        P2C(usbif_fe_interface_status_changed_t, status, u32);
   2.939 -        P2C(usbif_fe_interface_status_changed_t, evtchn, u16);
   2.940 -        P2C(usbif_fe_interface_status_changed_t, domid, domid_t);
   2.941 -        P2C(usbif_fe_interface_status_changed_t, bandwidth, u32);
   2.942 -	P2C(usbif_fe_interface_status_changed_t, num_ports, u32);
   2.943 -        break;
   2.944 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_DRIVER_STATUS_CHANGED):
   2.945 -        P2C(usbif_fe_driver_status_changed_t, status, u32);
   2.946 -        break;
   2.947 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_CONNECT):
   2.948 -        P2C(usbif_fe_interface_connect_t, shmem_frame, unsigned long);
   2.949 -        break;
   2.950 -    case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_DISCONNECT):
   2.951 -        break;
   2.952 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CREATE):
   2.953 -        P2C(usbif_be_create_t, domid, domid_t);
   2.954 -        P2C(usbif_be_create_t, status, u32);
   2.955 -        break;
   2.956 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DESTROY):
   2.957 -        P2C(usbif_be_destroy_t, domid, domid_t);
   2.958 -        P2C(usbif_be_destroy_t, status, u32);
   2.959 -        break;
   2.960 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CONNECT):
   2.961 -        P2C(usbif_be_connect_t, domid, domid_t);
   2.962 -        P2C(usbif_be_connect_t, shmem_frame, unsigned long);
   2.963 -        P2C(usbif_be_connect_t, evtchn, u32);
   2.964 -        P2C(usbif_be_connect_t, bandwidth, u32);
   2.965 -        P2C(usbif_be_connect_t, status, u32);
   2.966 -        break;
   2.967 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DISCONNECT):
   2.968 -        P2C(usbif_be_disconnect_t, domid, domid_t);
   2.969 -        P2C(usbif_be_disconnect_t, status, u32);
   2.970 -        break;
   2.971 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_DRIVER_STATUS_CHANGED):
   2.972 -        P2C(usbif_be_driver_status_changed_t, status, u32);
   2.973 -        break;
   2.974 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CLAIM_PORT):
   2.975 -        P2C(usbif_be_claim_port_t, domid, domid_t);
   2.976 -        P2C(usbif_be_claim_port_t, usbif_port, u32);
   2.977 -        P2C(usbif_be_claim_port_t, status, u32);
   2.978 -        PSTR2CHAR(usbif_be_claim_port_t, path);
   2.979 -        printf("dict items parsed = %d", dict_items_parsed);
   2.980 -        break;
   2.981 -    case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_RELEASE_PORT):
   2.982 -        PSTR2CHAR(usbif_be_release_port_t, path);
   2.983 -        break;
   2.984 -    case TYPE(CMSG_SHUTDOWN, CMSG_SHUTDOWN_SYSRQ):
   2.985 -        P2C(shutdown_sysrq_t, key, char);
   2.986 -        break;
   2.987 -    }
   2.988 -
   2.989 -    if ( dict_items_parsed != PyDict_Size(payload) )
   2.990 -    {
   2.991 -        PyErr_SetString(PyExc_TypeError, "payload contains bad items");
   2.992 -        PyObject_Del((PyObject *)xum);
   2.993 -        return NULL;
   2.994 -    }
   2.995 -
   2.996 -    return (PyObject *)xum;
   2.997 -}
   2.998 -
   2.999 -static PyObject *xu_message_getattr(PyObject *obj, char *name)
  2.1000 -{
  2.1001 -    xu_message_object *xum;
  2.1002 -    if ( strcmp(name, "MAX_PAYLOAD") == 0 )
  2.1003 -        return PyInt_FromLong(sizeof(xum->msg.msg));
  2.1004 -    return Py_FindMethod(xu_message_methods, obj, name);
  2.1005 -}
  2.1006 -
  2.1007 -static void xu_message_dealloc(PyObject *self)
  2.1008 -{
  2.1009 -    PyObject_Del(self);
  2.1010 -}
  2.1011 -
  2.1012 -static PyTypeObject xu_message_type = {
  2.1013 -    PyObject_HEAD_INIT(&PyType_Type)
  2.1014 -    0,
  2.1015 -    "message",
  2.1016 -    sizeof(xu_message_object),
  2.1017 -    0,
  2.1018 -    xu_message_dealloc,   /* tp_dealloc     */
  2.1019 -    NULL,                /* tp_print       */
  2.1020 -    xu_message_getattr,   /* tp_getattr     */
  2.1021 -    NULL,                /* tp_setattr     */
  2.1022 -    NULL,                /* tp_compare     */
  2.1023 -    NULL,                /* tp_repr        */
  2.1024 -    NULL,                /* tp_as_number   */
  2.1025 -    NULL,                /* tp_as_sequence */
  2.1026 -    NULL,                /* tp_as_mapping  */
  2.1027 -    NULL                 /* tp_hash        */
  2.1028 -};
  2.1029 -
  2.1030 -
  2.1031 -
  2.1032 -/*
  2.1033 - * *********************** PORT ***********************
  2.1034 - */
  2.1035 -
  2.1036 -typedef struct xu_port_object {
  2.1037 -    PyObject_HEAD;
  2.1038 -    int xc_handle;
  2.1039 -    int connected;
  2.1040 -    u32 remote_dom;
  2.1041 -    int local_port, remote_port;
  2.1042 -    struct xu_port_object *fix_next;
  2.1043 -} xu_port_object;
  2.1044 -
  2.1045 -static PyObject *port_error;
  2.1046 -
  2.1047 -static PyObject *xu_port_read_request(PyObject *self, PyObject *args)
  2.1048 -{
  2.1049 -    xu_port_object    *xup = (xu_port_object *)self;
  2.1050 -    xu_message_object *xum;
  2.1051 -    control_msg_t     *cmsg;
  2.1052 -    unsigned          i;
  2.1053 -    xcs_msg_ent_t    *ent = NULL;
  2.1054 -    
  2.1055 -    for ( i = req_cons; (i != req_prod); i++ ) {
  2.1056 -        ent = REQ_RING_ENT(i);
  2.1057 -        if (ent == NULL) 
  2.1058 -            continue;
  2.1059 -        if (ent->msg.u.control.remote_dom == xup->remote_dom)
  2.1060 -            break;
  2.1061 -    }
  2.1062 -    
  2.1063 -    if ((ent == NULL) ||
  2.1064 -        (ent->msg.u.control.remote_dom != xup->remote_dom)) 
  2.1065 -        goto none;
  2.1066 -
  2.1067 -    cmsg = &ent->msg.u.control.msg;
  2.1068 -    xum = PyObject_New(xu_message_object, &xu_message_type);
  2.1069 -    memcpy(&xum->msg, cmsg, sizeof(*cmsg));
  2.1070 -    if ( xum->msg.length > sizeof(xum->msg.msg) )
  2.1071 -        xum->msg.length = sizeof(xum->msg.msg);
  2.1072 -    free(ent);
  2.1073 -    
  2.1074 -    /* remove the entry from the ring and advance the consumer if possible */
  2.1075 -    REQ_RING_ENT(i) = NULL;
  2.1076 -    while ( (REQ_RING_ENT(req_cons) == NULL) && (!REQ_RING_EMPTY) )
  2.1077 -        req_cons++;
  2.1078 -    
  2.1079 -    return (PyObject *)xum;
  2.1080 -    
  2.1081 -none:
  2.1082 -    Py_INCREF(Py_None);
  2.1083 -    return Py_None;
  2.1084 -    
  2.1085 -}
  2.1086 -
  2.1087 -static PyObject *xu_port_write_request(PyObject *self, PyObject *args)
  2.1088 -{
  2.1089 -    xu_port_object    *xup = (xu_port_object *)self;
  2.1090 -    xu_message_object *xum;
  2.1091 -    xcs_msg_t          kmsg;
  2.1092 -
  2.1093 -    if ( !PyArg_ParseTuple(args, "O", (PyObject **)&xum) )
  2.1094 -        return NULL;
  2.1095 -
  2.1096 -    if ( !PyObject_TypeCheck((PyObject *)xum, &xu_message_type) )
  2.1097 -    {
  2.1098 -        PyErr_SetString(PyExc_TypeError, "expected a " XENPKG ".message");
  2.1099 -        return NULL;        
  2.1100 -    }
  2.1101 -
  2.1102 -    kmsg.type = XCS_REQUEST;
  2.1103 -    kmsg.u.control.remote_dom = xup->remote_dom;
  2.1104 -    memcpy(&kmsg.u.control.msg, &xum->msg, sizeof(control_msg_t));
  2.1105 -    xcs_data_send(&kmsg);
  2.1106 -    
  2.1107 -    Py_INCREF(Py_None);
  2.1108 -    return Py_None;
  2.1109 -}
  2.1110 -
  2.1111 -static PyObject *xu_port_read_response(PyObject *self, PyObject *args)
  2.1112 -{
  2.1113 -    xu_port_object    *xup = (xu_port_object *)self;
  2.1114 -    xu_message_object *xum;
  2.1115 -    control_msg_t     *cmsg;
  2.1116 -    unsigned          i;
  2.1117 -    xcs_msg_ent_t    *ent = NULL;
  2.1118 -    
  2.1119 -    for ( i = rsp_cons; (i != rsp_prod); i++ ) {
  2.1120 -        ent = RSP_RING_ENT(i);
  2.1121 -        if (ent == NULL) 
  2.1122 -            continue;
  2.1123 -        if (ent->msg.u.control.remote_dom == xup->remote_dom)
  2.1124 -            break;
  2.1125 -    }
  2.1126 -    
  2.1127 -    if ((ent == NULL) ||
  2.1128 -        (ent->msg.u.control.remote_dom != xup->remote_dom))
  2.1129 -         goto none;
  2.1130 -
  2.1131 -    cmsg = &ent->msg.u.control.msg;
  2.1132 -    xum = PyObject_New(xu_message_object, &xu_message_type);
  2.1133 -    memcpy(&xum->msg, cmsg, sizeof(*cmsg));
  2.1134 -    if ( xum->msg.length > sizeof(xum->msg.msg) )
  2.1135 -        xum->msg.length = sizeof(xum->msg.msg);
  2.1136 -    free(ent);
  2.1137 -    
  2.1138 -    /* remove the entry from the ring and advance the consumer if possible */
  2.1139 -    RSP_RING_ENT(i) = NULL;
  2.1140 -    while ( (RSP_RING_ENT(rsp_cons) == NULL) && (!RSP_RING_EMPTY) )
  2.1141 -        rsp_cons++;
  2.1142 -    
  2.1143 -    return (PyObject *)xum;
  2.1144 -    
  2.1145 -none:
  2.1146 -    Py_INCREF(Py_None);
  2.1147 -    return Py_None;
  2.1148 -    
  2.1149 -}
  2.1150 -
  2.1151 -static PyObject *xu_port_write_response(PyObject *self, PyObject *args)
  2.1152 -{
  2.1153 -    xu_port_object    *xup = (xu_port_object *)self;
  2.1154 -    xu_message_object *xum;
  2.1155 -    xcs_msg_t          kmsg;
  2.1156 -
  2.1157 -    if ( !PyArg_ParseTuple(args, "O", (PyObject **)&xum) )
  2.1158 -        return NULL;
  2.1159 -
  2.1160 -    if ( !PyObject_TypeCheck((PyObject *)xum, &xu_message_type) )
  2.1161 -    {
  2.1162 -        PyErr_SetString(PyExc_TypeError, "expected a " XENPKG ".message");
  2.1163 -        return NULL;        
  2.1164 -    }
  2.1165 -
  2.1166 -    kmsg.type = XCS_RESPONSE;
  2.1167 -    kmsg.u.control.remote_dom = xup->remote_dom;
  2.1168 -    memcpy(&kmsg.u.control.msg, &xum->msg, sizeof(control_msg_t));
  2.1169 -    xcs_data_send(&kmsg);
  2.1170 -
  2.1171 -    Py_INCREF(Py_None);
  2.1172 -    return Py_None;
  2.1173 -}
  2.1174 -
  2.1175 -static PyObject *xu_port_request_to_read(PyObject *self, PyObject *args)
  2.1176 -{
  2.1177 -    xu_port_object   *xup = (xu_port_object *)self;
  2.1178 -    xcs_msg_ent_t    *ent;
  2.1179 -    int               found = 0;
  2.1180 -    unsigned          i;
  2.1181 -  
  2.1182 -    if ( !PyArg_ParseTuple(args, "") )
  2.1183 -        return NULL;
  2.1184 -
  2.1185 -    for ( i = req_cons; (i != req_prod); i++ ) {
  2.1186 -        ent = REQ_RING_ENT(i);
  2.1187 -        if (ent == NULL) 
  2.1188 -            continue;
  2.1189 -        if (ent->msg.u.control.remote_dom == xup->remote_dom) {
  2.1190 -            found = 1;
  2.1191 -            break;
  2.1192 -        }
  2.1193 -    }
  2.1194 -    
  2.1195 -    return PyInt_FromLong(found);
  2.1196 -}
  2.1197 -
  2.1198 -static PyObject *xu_port_response_to_read(PyObject *self, PyObject *args)
  2.1199 -{
  2.1200 -    xu_port_object   *xup = (xu_port_object *)self;
  2.1201 -    xcs_msg_ent_t    *ent;
  2.1202 -    int               found = 0;
  2.1203 -    unsigned          i;
  2.1204 -  
  2.1205 -    if ( !PyArg_ParseTuple(args, "") )
  2.1206 -        return NULL;
  2.1207 -
  2.1208 -    for ( i = rsp_cons; (i != rsp_prod); i++ ) {
  2.1209 -        ent = RSP_RING_ENT(i);
  2.1210 -        if (ent == NULL) 
  2.1211 -            continue;
  2.1212 -        if (ent->msg.u.control.remote_dom == xup->remote_dom) {
  2.1213 -            found = 1;
  2.1214 -            break;
  2.1215 -        }
  2.1216 -    }
  2.1217 -    
  2.1218 -    return PyInt_FromLong(found);
  2.1219 -}
  2.1220 -
  2.1221 -static void _xu_port_close(xu_port_object *xup )
  2.1222 -{
  2.1223 -    if ( xup->connected && xup->remote_dom != 0 )
  2.1224 -    {  
  2.1225 -        xcs_msg_t kmsg;
  2.1226 -        kmsg.type = XCS_CIF_FREE_CC;
  2.1227 -        kmsg.u.interface.dom         = xup->remote_dom;
  2.1228 -        kmsg.u.interface.local_port  = xup->local_port; 
  2.1229 -        kmsg.u.interface.remote_port = xup->remote_port;
  2.1230 -        xcs_ctrl_send(&kmsg);
  2.1231 -        xcs_ctrl_read(&kmsg);
  2.1232 -        xup->connected = 0;
  2.1233 -    }
  2.1234 -}
  2.1235 -
  2.1236 -static PyObject *xu_port_close(PyObject *self, PyObject *args)
  2.1237 -{
  2.1238 -    xu_port_object *xup = (xu_port_object *)self;
  2.1239 -
  2.1240 -    _xu_port_close(xup);
  2.1241 -
  2.1242 -    Py_INCREF(Py_None);
  2.1243 -    return Py_None;
  2.1244 -}
  2.1245 -
  2.1246 -static PyObject *xu_port_register(PyObject *self, PyObject *args, 
  2.1247 -        PyObject *kwds)
  2.1248 -{
  2.1249 -    int type;
  2.1250 -    xcs_msg_t msg;
  2.1251 -    xu_port_object   *xup = (xu_port_object *)self;
  2.1252 -    static char *kwd_list[] = { "type", NULL };
  2.1253 -
  2.1254 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list,
  2.1255 -                                      &type) )
  2.1256 -        return NULL;
  2.1257 -    
  2.1258 -    if (!xup->connected)
  2.1259 -    {
  2.1260 -        return PyInt_FromLong(0);
  2.1261 -    }
  2.1262 -    
  2.1263 -    msg.type = XCS_MSG_BIND;
  2.1264 -    msg.u.bind.port = xup->local_port;
  2.1265 -    msg.u.bind.type = type;
  2.1266 -    xcs_ctrl_send(&msg);
  2.1267 -    xcs_ctrl_read(&msg);
  2.1268 -    
  2.1269 -    if (msg.result != XCS_RSLT_OK)
  2.1270 -    {
  2.1271 -        return PyInt_FromLong(0);
  2.1272 -    }
  2.1273 -    
  2.1274 -    return PyInt_FromLong(1);        
  2.1275 -}
  2.1276 -
  2.1277 -static PyObject *xu_port_deregister(PyObject *self, PyObject *args,
  2.1278 -        PyObject *kwds)
  2.1279 -{
  2.1280 -    int type;
  2.1281 -    xcs_msg_t msg;
  2.1282 -    xu_port_object   *xup = (xu_port_object *)self;
  2.1283 -    static char *kwd_list[] = { "type", NULL };
  2.1284 -
  2.1285 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list,
  2.1286 -                                      &type) )
  2.1287 -        return NULL;
  2.1288 -
  2.1289 -    if (!xup->connected)
  2.1290 -    {
  2.1291 -        return PyInt_FromLong(0);
  2.1292 -    }
  2.1293 -    
  2.1294 -    msg.type = XCS_MSG_UNBIND;
  2.1295 -    msg.u.bind.port = xup->local_port;
  2.1296 -    msg.u.bind.type = type;
  2.1297 -    xcs_ctrl_send(&msg);
  2.1298 -    xcs_ctrl_read(&msg);
  2.1299 -    
  2.1300 -    if (msg.result != XCS_RSLT_OK)
  2.1301 -    {
  2.1302 -        return PyInt_FromLong(0);
  2.1303 -    }
  2.1304 -    
  2.1305 -    return PyInt_FromLong(1);        
  2.1306 -}
  2.1307 -
  2.1308 -static PyMethodDef xu_port_methods[] = {
  2.1309 -
  2.1310 -    { "read_request",
  2.1311 -      (PyCFunction)xu_port_read_request,
  2.1312 -      METH_VARARGS,
  2.1313 -      "Read a request message from the control interface.\n" },
  2.1314 -
  2.1315 -    { "write_request",
  2.1316 -      (PyCFunction)xu_port_write_request,
  2.1317 -      METH_VARARGS,
  2.1318 -      "Write a request message to the control interface.\n" },
  2.1319 -
  2.1320 -    { "read_response",
  2.1321 -      (PyCFunction)xu_port_read_response,
  2.1322 -      METH_VARARGS,
  2.1323 -      "Read a response message from the control interface.\n" },
  2.1324 -
  2.1325 -    { "write_response",
  2.1326 -      (PyCFunction)xu_port_write_response,
  2.1327 -      METH_VARARGS,
  2.1328 -      "Write a response message to the control interface.\n" },
  2.1329 -
  2.1330 -    { "request_to_read",
  2.1331 -      (PyCFunction)xu_port_request_to_read,
  2.1332 -      METH_VARARGS,
  2.1333 -      "Returns TRUE if there is a request message to read.\n" },
  2.1334 -
  2.1335 -
  2.1336 -    { "response_to_read",
  2.1337 -      (PyCFunction)xu_port_response_to_read,
  2.1338 -      METH_VARARGS,
  2.1339 -      "Returns TRUE if there is a response message to read.\n" },
  2.1340 -
  2.1341 -    { "register",
  2.1342 -      (PyCFunction)xu_port_register,
  2.1343 -      METH_VARARGS | METH_KEYWORDS,
  2.1344 -      "Register to receive a type of message on this channel.\n" },
  2.1345 -      
  2.1346 -    { "deregister",
  2.1347 -      (PyCFunction)xu_port_deregister,
  2.1348 -      METH_VARARGS | METH_KEYWORDS,
  2.1349 -      "Stop receiving a type of message on this port.\n" },
  2.1350 -
  2.1351 -    { "close",
  2.1352 -      (PyCFunction)xu_port_close,
  2.1353 -      METH_VARARGS,
  2.1354 -      "Close the port.\n" },
  2.1355 -
  2.1356 -    { NULL, NULL, 0, NULL }
  2.1357 -};
  2.1358 -
  2.1359 -staticforward PyTypeObject xu_port_type;
  2.1360 -
  2.1361 -static PyObject *xu_port_new(PyObject *self, PyObject *args, PyObject *kwds)
  2.1362 -{
  2.1363 -    xu_port_object *xup;
  2.1364 -    u32 dom;
  2.1365 -    int port1 = 0, port2 = 0;
  2.1366 -    xcs_msg_t kmsg;
  2.1367 -
  2.1368 -    static char *kwd_list[] = { "dom", "local_port", "remote_port", NULL };
  2.1369 -
  2.1370 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwd_list,
  2.1371 -                                      &dom, &port1, &port2) )
  2.1372 -        return NULL;
  2.1373 -
  2.1374 -    xup = PyObject_New(xu_port_object, &xu_port_type);
  2.1375 -
  2.1376 -    xup->connected  = 0;
  2.1377 -    xup->remote_dom = dom;
  2.1378 -    
  2.1379 -    kmsg.type = XCS_CIF_NEW_CC;
  2.1380 -    kmsg.u.interface.dom         = xup->remote_dom;
  2.1381 -    kmsg.u.interface.local_port  = port1; 
  2.1382 -    kmsg.u.interface.remote_port = port2;
  2.1383 -    xcs_ctrl_send(&kmsg);
  2.1384 -    xcs_ctrl_read(&kmsg);
  2.1385 -    
  2.1386 -    if ( kmsg.result != XCS_RSLT_OK ) 
  2.1387 -        goto fail1;
  2.1388 -        
  2.1389 -    xup->local_port  = kmsg.u.interface.local_port;
  2.1390 -    xup->remote_port = kmsg.u.interface.remote_port;
  2.1391 -    xup->connected = 1;
  2.1392 -                
  2.1393 -    return (PyObject *)xup;
  2.1394 -
  2.1395 - fail1:
  2.1396 -    PyObject_Del((PyObject *)xup);
  2.1397 -    PyErr_SetString(PyExc_ValueError, "cannot create port");
  2.1398 -    return NULL;
  2.1399 -}
  2.1400 -
  2.1401 -static PyObject *xu_port_getattr(PyObject *obj, char *name)
  2.1402 -{
  2.1403 -    xu_port_object *xup = (xu_port_object *)obj;
  2.1404 -
  2.1405 -    if ( strcmp(name, "local_port") == 0 )
  2.1406 -    {
  2.1407 -        return PyInt_FromLong(xup->connected ? xup->local_port : -1);
  2.1408 -    }
  2.1409 -    if ( strcmp(name, "remote_port") == 0 )
  2.1410 -    {
  2.1411 -        return PyInt_FromLong(xup->connected ? xup->remote_port : -1);
  2.1412 -    }
  2.1413 -    if ( strcmp(name, "remote_dom") == 0 )
  2.1414 -    {
  2.1415 -        return PyInt_FromLong(xup->remote_dom);
  2.1416 -    }
  2.1417 -    if ( strcmp(name, "connected") == 0 )
  2.1418 -    {
  2.1419 -        return PyInt_FromLong(xup->connected);
  2.1420 -    }
  2.1421 -    return Py_FindMethod(xu_port_methods, obj, name);
  2.1422 -}
  2.1423 -
  2.1424 -static void xu_port_dealloc(PyObject *self)
  2.1425 -{
  2.1426 -    xu_port_object *xup = (xu_port_object *)self;
  2.1427 -
  2.1428 -    _xu_port_close(xup);
  2.1429 -
  2.1430 -    PyObject_Del(self);
  2.1431 -}
  2.1432 -
  2.1433 -static PyTypeObject xu_port_type = {
  2.1434 -    PyObject_HEAD_INIT(&PyType_Type)
  2.1435 -    0,
  2.1436 -    "port",
  2.1437 -    sizeof(xu_port_object),
  2.1438 -    0,
  2.1439 -    xu_port_dealloc,     /* tp_dealloc     */
  2.1440 -    NULL,                /* tp_print       */
  2.1441 -    xu_port_getattr,     /* tp_getattr     */
  2.1442 -    NULL,                /* tp_setattr     */
  2.1443 -    NULL,                /* tp_compare     */
  2.1444 -    NULL,                /* tp_repr        */
  2.1445 -    NULL,                /* tp_as_number   */
  2.1446 -    NULL,                /* tp_as_sequence */
  2.1447 -    NULL,                /* tp_as_mapping  */
  2.1448 -    NULL                 /* tp_hash        */
  2.1449 -};
  2.1450 -
  2.1451 -
  2.1452 -
  2.1453 -/*
  2.1454 - * *********************** BUFFER ***********************
  2.1455 - */
  2.1456 -
  2.1457 -#define BUFSZ 65536
  2.1458 -#define MASK_BUF_IDX(_i) ((_i)&(BUFSZ-1))
  2.1459 -typedef unsigned int BUF_IDX;
  2.1460 -
  2.1461 -typedef struct {
  2.1462 -    PyObject_HEAD;
  2.1463 -    char        *buf;
  2.1464 -    unsigned int prod, cons;
  2.1465 -} xu_buffer_object;
  2.1466 -
  2.1467 -static PyObject *__xu_buffer_peek(xu_buffer_object *xub, int max)
  2.1468 -{
  2.1469 -    PyObject *str1, *str2;
  2.1470 -    int len1, len2, c = MASK_BUF_IDX(xub->cons);
  2.1471 -
  2.1472 -    len1 = xub->prod - xub->cons;
  2.1473 -    if ( len1 > (BUFSZ - c) ) /* clip to ring wrap */
  2.1474 -        len1 = BUFSZ - c;
  2.1475 -    if ( len1 > max )         /* clip to specified maximum */
  2.1476 -        len1 = max;
  2.1477 -    if ( len1 < 0 )           /* sanity */
  2.1478 -        len1 = 0;
  2.1479 -
  2.1480 -    if ( (str1 = PyString_FromStringAndSize(&xub->buf[c], len1)) == NULL )
  2.1481 -        return NULL;
  2.1482 -
  2.1483 -    if ( (len1 < (xub->prod - xub->cons)) && (len1 < max) )
  2.1484 -    {
  2.1485 -        len2 = max - len1;
  2.1486 -        if ( len2 > MASK_BUF_IDX(xub->prod) )
  2.1487 -            len2 = MASK_BUF_IDX(xub->prod);
  2.1488 -        if ( len2 > 0 )
  2.1489 -        {
  2.1490 -            str2 = PyString_FromStringAndSize(&xub->buf[0], len2);
  2.1491 -            if ( str2 == NULL )
  2.1492 -                return NULL;
  2.1493 -            PyString_ConcatAndDel(&str1, str2);
  2.1494 -            if ( str1 == NULL )
  2.1495 -                return NULL;
  2.1496 -        }
  2.1497 -    }
  2.1498 -
  2.1499 -    return str1;
  2.1500 -}
  2.1501 -
  2.1502 -static PyObject *xu_buffer_peek(PyObject *self, PyObject *args)
  2.1503 -{
  2.1504 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1505 -    int max = 1024;
  2.1506 -
  2.1507 -    if ( !PyArg_ParseTuple(args, "|i", &max) )
  2.1508 -        return NULL;
  2.1509 -    
  2.1510 -    return __xu_buffer_peek(xub, max);
  2.1511 -}
  2.1512 -
  2.1513 -static PyObject *xu_buffer_read(PyObject *self, PyObject *args)
  2.1514 -{
  2.1515 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1516 -    PyObject *str;
  2.1517 -    int max = 1024;
  2.1518 -
  2.1519 -    if ( !PyArg_ParseTuple(args, "|i", &max) )
  2.1520 -        return NULL;
  2.1521 -
  2.1522 -    if ( (str = __xu_buffer_peek(xub, max)) != NULL )
  2.1523 -        xub->cons += PyString_Size(str);
  2.1524 -
  2.1525 -    return str;
  2.1526 -}
  2.1527 -
  2.1528 -static PyObject *xu_buffer_discard(PyObject *self, PyObject *args)
  2.1529 -{
  2.1530 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1531 -    int max, len;
  2.1532 -
  2.1533 -    if ( !PyArg_ParseTuple(args, "i", &max) )
  2.1534 -        return NULL;
  2.1535 -
  2.1536 -    len = xub->prod - xub->cons;
  2.1537 -    if ( len > max )
  2.1538 -        len = max;
  2.1539 -    if ( len < 0 )
  2.1540 -        len = 0;
  2.1541 -
  2.1542 -    xub->cons += len;
  2.1543 -
  2.1544 -    return PyInt_FromLong(len);
  2.1545 -}
  2.1546 -
  2.1547 -static PyObject *xu_buffer_write(PyObject *self, PyObject *args)
  2.1548 -{
  2.1549 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1550 -    char *str;
  2.1551 -    int len, len1, len2;
  2.1552 -
  2.1553 -    if ( !PyArg_ParseTuple(args, "s#", &str, &len) )
  2.1554 -        return NULL;
  2.1555 -
  2.1556 -    len1 = len;
  2.1557 -    if ( len1 > (BUFSZ - MASK_BUF_IDX(xub->prod)) )
  2.1558 -        len1 = BUFSZ - MASK_BUF_IDX(xub->prod);
  2.1559 -    if ( len1 > (BUFSZ - (xub->prod - xub->cons)) )
  2.1560 -        len1 = BUFSZ - (xub->prod - xub->cons);
  2.1561 -
  2.1562 -    if ( len1 == 0 )
  2.1563 -        return PyInt_FromLong(0);
  2.1564 -
  2.1565 -    memcpy(&xub->buf[MASK_BUF_IDX(xub->prod)], &str[0], len1);
  2.1566 -    xub->prod += len1;
  2.1567 -
  2.1568 -    if ( len1 < len )
  2.1569 -    {
  2.1570 -        len2 = len - len1;
  2.1571 -        if ( len2 > (BUFSZ - MASK_BUF_IDX(xub->prod)) )
  2.1572 -            len2 = BUFSZ - MASK_BUF_IDX(xub->prod);
  2.1573 -        if ( len2 > (BUFSZ - (xub->prod - xub->cons)) )
  2.1574 -            len2 = BUFSZ - (xub->prod - xub->cons);
  2.1575 -        if ( len2 != 0 )
  2.1576 -        {
  2.1577 -            memcpy(&xub->buf[MASK_BUF_IDX(xub->prod)], &str[len1], len2);
  2.1578 -            xub->prod += len2;
  2.1579 -            return PyInt_FromLong(len1 + len2);
  2.1580 -        }
  2.1581 -    }
  2.1582 -
  2.1583 -    return PyInt_FromLong(len1);
  2.1584 -}
  2.1585 -
  2.1586 -static PyObject *xu_buffer_empty(PyObject *self, PyObject *args)
  2.1587 -{
  2.1588 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1589 -
  2.1590 -    if ( !PyArg_ParseTuple(args, "") )
  2.1591 -        return NULL;
  2.1592 -
  2.1593 -    if ( xub->cons == xub->prod )
  2.1594 -        return PyInt_FromLong(1);
  2.1595 -
  2.1596 -    return PyInt_FromLong(0);
  2.1597 -}
  2.1598 -
  2.1599 -static PyObject *xu_buffer_full(PyObject *self, PyObject *args)
  2.1600 -{
  2.1601 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1602 -
  2.1603 -    if ( !PyArg_ParseTuple(args, "") )
  2.1604 -        return NULL;
  2.1605 -
  2.1606 -    if ( (xub->prod - xub->cons) == BUFSZ )
  2.1607 -        return PyInt_FromLong(1);
  2.1608 -
  2.1609 -    return PyInt_FromLong(0);
  2.1610 -}
  2.1611 -
  2.1612 -static PyObject *xu_buffer_size(PyObject *self, PyObject *args)
  2.1613 -{
  2.1614 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1615 -
  2.1616 -    if ( !PyArg_ParseTuple(args, "") )
  2.1617 -        return NULL;
  2.1618 -
  2.1619 -    return PyInt_FromLong(xub->prod - xub->cons);
  2.1620 -}
  2.1621 -
  2.1622 -static PyObject *xu_buffer_space(PyObject *self, PyObject *args)
  2.1623 -{
  2.1624 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1625 -
  2.1626 -    if ( !PyArg_ParseTuple(args, "") )
  2.1627 -        return NULL;
  2.1628 -
  2.1629 -    return PyInt_FromLong(BUFSZ - (xub->prod - xub->cons));
  2.1630 -}
  2.1631 -
  2.1632 -static PyMethodDef xu_buffer_methods[] = {
  2.1633 -    { "peek", 
  2.1634 -      (PyCFunction)xu_buffer_peek,
  2.1635 -      METH_VARARGS,
  2.1636 -      "Peek up to @max bytes from the buffer. Returns a string.\n" },
  2.1637 -
  2.1638 -    { "read", 
  2.1639 -      (PyCFunction)xu_buffer_read,
  2.1640 -      METH_VARARGS,
  2.1641 -      "Read up to @max bytes from the buffer. Returns a string.\n" },
  2.1642 -
  2.1643 -    { "discard", 
  2.1644 -      (PyCFunction)xu_buffer_discard,
  2.1645 -      METH_VARARGS,
  2.1646 -      "Discard up to @max bytes from the buffer. Returns number of bytes.\n" },
  2.1647 -
  2.1648 -    { "write", 
  2.1649 -      (PyCFunction)xu_buffer_write,
  2.1650 -      METH_VARARGS,
  2.1651 -      "Write @string into buffer. Return number of bytes written.\n" },
  2.1652 -
  2.1653 -    { "empty", 
  2.1654 -      (PyCFunction)xu_buffer_empty,
  2.1655 -      METH_VARARGS,
  2.1656 -      "Return TRUE if the buffer is empty.\n" },
  2.1657 -
  2.1658 -    { "full", 
  2.1659 -      (PyCFunction)xu_buffer_full,
  2.1660 -      METH_VARARGS,
  2.1661 -      "Return TRUE if the buffer is full.\n" },
  2.1662 -
  2.1663 -    { "size", 
  2.1664 -      (PyCFunction)xu_buffer_size,
  2.1665 -      METH_VARARGS,
  2.1666 -      "Return number of bytes in the buffer.\n" },
  2.1667 -
  2.1668 -    { "space", 
  2.1669 -      (PyCFunction)xu_buffer_space,
  2.1670 -      METH_VARARGS,
  2.1671 -      "Return space left in the buffer.\n" },
  2.1672 -
  2.1673 -    { NULL, NULL, 0, NULL }
  2.1674 -};
  2.1675 -
  2.1676 -staticforward PyTypeObject xu_buffer_type;
  2.1677 -
  2.1678 -static PyObject *xu_buffer_new(PyObject *self, PyObject *args)
  2.1679 -{
  2.1680 -    xu_buffer_object *xub;
  2.1681 -
  2.1682 -    if ( !PyArg_ParseTuple(args, "") )
  2.1683 -        return NULL;
  2.1684 -
  2.1685 -    xub = PyObject_New(xu_buffer_object, &xu_buffer_type);
  2.1686 -
  2.1687 -    if ( (xub->buf = malloc(BUFSZ)) == NULL )
  2.1688 -    {
  2.1689 -        PyObject_Del((PyObject *)xub);
  2.1690 -        return NULL;
  2.1691 -    }
  2.1692 -
  2.1693 -    xub->prod = xub->cons = 0;
  2.1694 -
  2.1695 -    return (PyObject *)xub;
  2.1696 -}
  2.1697 -
  2.1698 -static PyObject *xu_buffer_getattr(PyObject *obj, char *name)
  2.1699 -{
  2.1700 -    return Py_FindMethod(xu_buffer_methods, obj, name);
  2.1701 -}
  2.1702 -
  2.1703 -static void xu_buffer_dealloc(PyObject *self)
  2.1704 -{
  2.1705 -    xu_buffer_object *xub = (xu_buffer_object *)self;
  2.1706 -    free(xub->buf);
  2.1707 -    PyObject_Del(self);
  2.1708 -}
  2.1709 -
  2.1710 -static PyTypeObject xu_buffer_type = {
  2.1711 -    PyObject_HEAD_INIT(&PyType_Type)
  2.1712 -    0,
  2.1713 -    "buffer",
  2.1714 -    sizeof(xu_buffer_object),
  2.1715 -    0,
  2.1716 -    xu_buffer_dealloc,   /* tp_dealloc     */
  2.1717 -    NULL,                /* tp_print       */
  2.1718 -    xu_buffer_getattr,   /* tp_getattr     */
  2.1719 -    NULL,                /* tp_setattr     */
  2.1720 -    NULL,                /* tp_compare     */
  2.1721 -    NULL,                /* tp_repr        */
  2.1722 -    NULL,                /* tp_as_number   */
  2.1723 -    NULL,                /* tp_as_sequence */
  2.1724 -    NULL,                /* tp_as_mapping  */
  2.1725 -    NULL                 /* tp_hash        */
  2.1726 -};
  2.1727 -
  2.1728 -
  2.1729 -
  2.1730 -/*
  2.1731 - * *********************** MODULE WRAPPER ***********************
  2.1732 - */
  2.1733 -
  2.1734 -static void handle_child_death(int dummy)
  2.1735 -{
  2.1736 -    while ( waitpid(-1, NULL, WNOHANG) > 0 )
  2.1737 -        continue;
  2.1738 -}
  2.1739 -
  2.1740 -static PyObject *xu_autoreap(PyObject *self, PyObject *args)
  2.1741 -{
  2.1742 -    struct sigaction sa;
  2.1743 -
  2.1744 -    if ( !PyArg_ParseTuple(args, "") )
  2.1745 -        return NULL;
  2.1746 -
  2.1747 -    memset(&sa, 0, sizeof(sa));
  2.1748 -    sa.sa_handler = handle_child_death;
  2.1749 -    sigemptyset(&sa.sa_mask);
  2.1750 -    sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
  2.1751 -    (void)sigaction(SIGCHLD, &sa, NULL);
  2.1752 -
  2.1753 -    Py_INCREF(Py_None);
  2.1754 -    return Py_None;
  2.1755 -}
  2.1756 -
  2.1757 -static PyMethodDef xu_methods[] = {
  2.1758 -    { "notifier", xu_notifier_new, METH_VARARGS, 
  2.1759 -      "Create a new notifier." },
  2.1760 -    { "message", xu_message_new, METH_VARARGS, 
  2.1761 -      "Create a new communications message." },
  2.1762 -    { "port", (PyCFunction)xu_port_new, METH_VARARGS | METH_KEYWORDS, 
  2.1763 -      "Create a new communications port." },
  2.1764 -    { "buffer", xu_buffer_new, METH_VARARGS, 
  2.1765 -      "Create a new ring buffer." },
  2.1766 -    { "autoreap", xu_autoreap, METH_VARARGS,
  2.1767 -      "Ensure that zombie children are automatically reaped by the OS." },
  2.1768 -    { NULL, NULL, 0, NULL }
  2.1769 -};
  2.1770 -
  2.1771 -PyMODINIT_FUNC initxu(void)
  2.1772 -{
  2.1773 -    PyObject *m, *d;
  2.1774 -
  2.1775 -    m = Py_InitModule(XENPKG, xu_methods);
  2.1776 -
  2.1777 -    d = PyModule_GetDict(m);
  2.1778 -    port_error = PyErr_NewException(XENPKG ".PortError", NULL, NULL);
  2.1779 -    PyDict_SetItemString(d, "PortError", port_error);
  2.1780 -
  2.1781 -    /* KAF: This ensures that we get debug output in a timely manner. */
  2.1782 -    setbuf(stdout, NULL);
  2.1783 -    setbuf(stderr, NULL);
  2.1784 -}
     3.1 --- a/tools/python/xen/xend/server/channel.py	Wed Sep 07 18:28:04 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/channel.py	Wed Sep 07 18:37:55 2005 +0000
     3.3 @@ -19,7 +19,6 @@ import threading
     3.4  import select
     3.5  
     3.6  import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
     3.7 -from xen.lowlevel import xu
     3.8  
     3.9  from xen.xend.XendLogging import log
    3.10