ia64/xen-unstable

changeset 1596:48a1cf52dfaf

bitkeeper revision 1.1024 (40dfec54gY1vhwP_t4BlnteFO7Jq2g)

remove obsolete files.
author kaf24@scramble.cl.cam.ac.uk
date Mon Jun 28 10:00:52 2004 +0000 (2004-06-28)
parents 3d3f21585b96
children 94eddae02f4a
files .rootkeys tools/misc/Makefile tools/misc/netfix tools/xen/Makefile tools/xen/netfix tools/xend-old/Makefile tools/xend-old/lib/__init__.py tools/xend-old/lib/blkif.py tools/xend-old/lib/console.py tools/xend-old/lib/domain_controller.h tools/xend-old/lib/main.py tools/xend-old/lib/manager.py tools/xend-old/lib/netif.py tools/xend-old/lib/utils.c tools/xend-old/setup.py tools/xend-old/xend
line diff
     1.1 --- a/.rootkeys	Mon Jun 28 08:20:16 2004 +0000
     1.2 +++ b/.rootkeys	Mon Jun 28 10:00:52 2004 +0000
     1.3 @@ -169,6 +169,7 @@ 40ab2cfawIw8tsYo0dQKtp83h4qfTQ tools/mis
     1.4  3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile
     1.5  3f6dc140C8tAeBfroAF24VrmCS4v_w tools/misc/miniterm/README
     1.6  3f6dc142IHaf6XIcAYGmhV9nNSIHFQ tools/misc/miniterm/miniterm.c
     1.7 +40c9c469kT0H9COWzA4XzPBjWK0WsA tools/misc/netfix
     1.8  3f870808_8aFBAcZbWiWGdgrGQyIEw tools/misc/p4perf.h
     1.9  3f5ef5a2ir1kVAthS14Dc5QIRCEFWg tools/misc/xen-clone
    1.10  3f5ef5a2dTZP0nnsFoeq2jRf3mWDDg tools/misc/xen-clone.README
    1.11 @@ -249,21 +250,9 @@ 40cf2937gKQcATgXKGtNeWb1PDH5nA tools/xen
    1.12  40cf2937isyS250zyd0Q2GuEDoNXfQ tools/xen/lib/xm/main.py
    1.13  40cf2937PSslwBliN1g7ofDy2H_RhA tools/xen/lib/xm/opts.py
    1.14  40cf2937Z8WCNOnO2FcWdubvEAF9QQ tools/xen/lib/xm/shutdown.py
    1.15 -40c9c469kT0H9COWzA4XzPBjWK0WsA tools/xen/netfix
    1.16  40c9c469n2RRwCmjWdjdyyVRWKmgWg tools/xen/setup.py
    1.17  40c9c4697z76HDfkCLdMhmaEwzFoNQ tools/xen/xend
    1.18  40cf2937dqM1jWW87O5OoOYND8leuA tools/xen/xm
    1.19 -40431ac64Hj4ixUnKmlugZKhXPFE_Q tools/xend-old/Makefile
    1.20 -4055ad95Se-FqttgxollqOAAHB94zA tools/xend-old/lib/__init__.py
    1.21 -4092738fMRGC9fFBcPRCWaJaj9U3ag tools/xend-old/lib/blkif.py
    1.22 -4055ad97wMLUj0BZT0e_T0EwQN0Bvw tools/xend-old/lib/console.py
    1.23 -4048c0ddsF0WrU7HUzTvg1MJoCIfWg tools/xend-old/lib/domain_controller.h
    1.24 -4054a301VEag2GwrBrFBna5U1BGlLA tools/xend-old/lib/main.py
    1.25 -4055ad9ah9IuC3sJT2c_gYIFY5Tw_g tools/xend-old/lib/manager.py
    1.26 -409ba2e729HhE7fEra4B5EqX-F8Xzw tools/xend-old/lib/netif.py
    1.27 -40431ac8wrUEj-XM7B8smFtx_HA7lQ tools/xend-old/lib/utils.c
    1.28 -4054a2fdkdATEnRw-U7AUlgu-6JiUA tools/xend-old/setup.py
    1.29 -4056cd26Qyp09iNoOjrvzg8KYzSqOw tools/xend-old/xend
    1.30  403a3edbrr8RE34gkbR40zep98SXbg tools/xentrace/Makefile
    1.31  40a107afN60pFdURgBv9KwEzgRl5mQ tools/xentrace/formats
    1.32  4050c413PhhLNAYk3TEwP37i_iLw9Q tools/xentrace/xentrace.8
     2.1 --- a/tools/misc/Makefile	Mon Jun 28 08:20:16 2004 +0000
     2.2 +++ b/tools/misc/Makefile	Mon Jun 28 10:00:52 2004 +0000
     2.3 @@ -19,6 +19,7 @@ all: $(TARGETS)
     2.4  install: all
     2.5  	mkdir -p $(prefix)/usr/bin
     2.6  	install -m0755 $(INSTALL) $(prefix)/usr/bin
     2.7 +	install -m0755 netfix $(prefix)/usr/sbin
     2.8  	$(MAKE) -C miniterm install
     2.9  
    2.10  clean:
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/misc/netfix	Mon Jun 28 10:00:52 2004 +0000
     3.3 @@ -0,0 +1,61 @@
     3.4 +#!/usr/bin/python
     3.5 +#  -*- mode: python; -*-
     3.6 +# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
     3.7 +#============================================================================
     3.8 +# Move the IP address from eth0 onto the Xen bridge (nbe-br).
     3.9 +# Only works if the bridge control utils (brctl) have been installed.
    3.10 +#============================================================================
    3.11 +
    3.12 +from getopt import getopt
    3.13 +from xen.xend.XendBridge import *
    3.14 +
    3.15 +short_options = 'hvqni:b:c'
    3.16 +long_options  = ['help', 'verbose', 'quiet',
    3.17 +                 'interface=', 'bridge=', 'create']
    3.18 +
    3.19 +def usage():
    3.20 +    print """Usage:
    3.21 +    %s [options]
    3.22 +
    3.23 +    Reconfigure routing so that <bridge> has the IP address from
    3.24 +    <interface>. This lets IP carry on working when <interface>
    3.25 +    is attached to <bridge> for virtual networking.
    3.26 +    Uses brctl to add <interface> to <bridge>,
    3.27 +    so this can be run before any domains have been created.
    3.28 +    """ % sys.argv[0]
    3.29 +    print """
    3.30 +    -i, --interface <interface>    interface, default %(interface)s.
    3.31 +    -b, --bridge <bridge>          bridge, default %(bridge)s.
    3.32 +    -c, --create                   create the bridge.
    3.33 +    -v, --verbose                  Print commands.
    3.34 +    -q, --quiet                    Don't print commands.
    3.35 +    -n, --dry-run                  Don't execute commands.
    3.36 +    -h, --help                     Print this help.
    3.37 +    """ % defaults
    3.38 +    sys.exit(1)
    3.39 +
    3.40 +
    3.41 +def main():
    3.42 +    lopts = set_opts(Opts(defaults))
    3.43 +    lopts.dryrun = 0
    3.44 +    (options, args) = getopt(sys.argv[1:], short_options, long_options)
    3.45 +    if args: usage()
    3.46 +    for k, v in options:
    3.47 +        if k in ['-h', '--help']:
    3.48 +            usage()
    3.49 +        elif k in ['-c', '--create']:
    3.50 +            lopts.create = 1
    3.51 +        elif k in ['-i', '--interface']:
    3.52 +            lopts.interface = v
    3.53 +        elif k in ['-b', '--bridge']:
    3.54 +            lopts.bridge = v
    3.55 +        elif k in ['-q', '--quiet']:
    3.56 +            lopts.verbose = 0
    3.57 +        elif k in ['-v', '--verbose']:
    3.58 +            lopts.verbose = 1
    3.59 +        elif k in ['-n', '--dry-run']:
    3.60 +            lopts.dryrun = 1
    3.61 +    reconfigure(lopts.interface, lopts.bridge)
    3.62 +
    3.63 +if __name__ == '__main__':
    3.64 +    main()
     4.1 --- a/tools/xen/Makefile	Mon Jun 28 08:20:16 2004 +0000
     4.2 +++ b/tools/xen/Makefile	Mon Jun 28 10:00:52 2004 +0000
     4.3 @@ -12,7 +12,6 @@ install: all
     4.4  	fi
     4.5  	mkdir -p $(prefix)/usr/sbin
     4.6  	install -m0755 xend $(prefix)/usr/sbin
     4.7 -	install -m0755 netfix $(prefix)/usr/sbin
     4.8  	install -m0755 xm $(prefix)/usr/sbin
     4.9  
    4.10  clean:
     5.1 --- a/tools/xen/netfix	Mon Jun 28 08:20:16 2004 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,61 +0,0 @@
     5.4 -#!/usr/bin/python
     5.5 -#  -*- mode: python; -*-
     5.6 -# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
     5.7 -#============================================================================
     5.8 -# Move the IP address from eth0 onto the Xen bridge (nbe-br).
     5.9 -# Only works if the bridge control utils (brctl) have been installed.
    5.10 -#============================================================================
    5.11 -
    5.12 -from getopt import getopt
    5.13 -from xen.xend.XendBridge import *
    5.14 -
    5.15 -short_options = 'hvqni:b:c'
    5.16 -long_options  = ['help', 'verbose', 'quiet',
    5.17 -                 'interface=', 'bridge=', 'create']
    5.18 -
    5.19 -def usage():
    5.20 -    print """Usage:
    5.21 -    %s [options]
    5.22 -
    5.23 -    Reconfigure routing so that <bridge> has the IP address from
    5.24 -    <interface>. This lets IP carry on working when <interface>
    5.25 -    is attached to <bridge> for virtual networking.
    5.26 -    Uses brctl to add <interface> to <bridge>,
    5.27 -    so this can be run before any domains have been created.
    5.28 -    """ % sys.argv[0]
    5.29 -    print """
    5.30 -    -i, --interface <interface>    interface, default %(interface)s.
    5.31 -    -b, --bridge <bridge>          bridge, default %(bridge)s.
    5.32 -    -c, --create                   create the bridge.
    5.33 -    -v, --verbose                  Print commands.
    5.34 -    -q, --quiet                    Don't print commands.
    5.35 -    -n, --dry-run                  Don't execute commands.
    5.36 -    -h, --help                     Print this help.
    5.37 -    """ % defaults
    5.38 -    sys.exit(1)
    5.39 -
    5.40 -
    5.41 -def main():
    5.42 -    lopts = set_opts(Opts(defaults))
    5.43 -    lopts.dryrun = 0
    5.44 -    (options, args) = getopt(sys.argv[1:], short_options, long_options)
    5.45 -    if args: usage()
    5.46 -    for k, v in options:
    5.47 -        if k in ['-h', '--help']:
    5.48 -            usage()
    5.49 -        elif k in ['-c', '--create']:
    5.50 -            lopts.create = 1
    5.51 -        elif k in ['-i', '--interface']:
    5.52 -            lopts.interface = v
    5.53 -        elif k in ['-b', '--bridge']:
    5.54 -            lopts.bridge = v
    5.55 -        elif k in ['-q', '--quiet']:
    5.56 -            lopts.verbose = 0
    5.57 -        elif k in ['-v', '--verbose']:
    5.58 -            lopts.verbose = 1
    5.59 -        elif k in ['-n', '--dry-run']:
    5.60 -            lopts.dryrun = 1
    5.61 -    reconfigure(lopts.interface, lopts.bridge)
    5.62 -
    5.63 -if __name__ == '__main__':
    5.64 -    main()
     6.1 --- a/tools/xend-old/Makefile	Mon Jun 28 08:20:16 2004 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,17 +0,0 @@
     6.4 -
     6.5 -all:
     6.6 -	python setup.py build
     6.7 -
     6.8 -install: all
     6.9 -	if [ "$(prefix)" = "" ]; then                   \
    6.10 -	    python setup.py install;                    \
    6.11 -	elif [ "$(dist)" = "yes" ]; then                \
    6.12 -	    python setup.py install --home="$(prefix)"; \
    6.13 -	else                                            \
    6.14 -	    python setup.py install --root="$(prefix)"; \
    6.15 -	fi
    6.16 -	mkdir -p $(prefix)/usr/sbin
    6.17 -	install -m0755 xend $(prefix)/usr/sbin
    6.18 -
    6.19 -clean:
    6.20 -	rm -rf build *.pyc *.pyo *.a *.so *.o *~ *.rpm 
     8.1 --- a/tools/xend-old/lib/blkif.py	Mon Jun 28 08:20:16 2004 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,214 +0,0 @@
     8.4 -
     8.5 -#################################################################
     8.6 -## xend/blkif.py -- Block-interface management functions for Xend
     8.7 -## Copyright (c) 2004, K A Fraser (University of Cambridge)
     8.8 -#################################################################
     8.9 -
    8.10 -import errno, re, os, select, signal, socket, sys
    8.11 -import xend.main, xend.console, xend.manager, xend.utils, Xc
    8.12 -
    8.13 -CMSG_BLKIF_BE = 1
    8.14 -CMSG_BLKIF_FE = 2
    8.15 -CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED =  0
    8.16 -CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED    = 32
    8.17 -CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED    = 32
    8.18 -CMSG_BLKIF_FE_INTERFACE_CONNECT        = 33
    8.19 -CMSG_BLKIF_FE_INTERFACE_DISCONNECT     = 34
    8.20 -CMSG_BLKIF_BE_CREATE      = 0
    8.21 -CMSG_BLKIF_BE_DESTROY     = 1
    8.22 -CMSG_BLKIF_BE_CONNECT     = 2
    8.23 -CMSG_BLKIF_BE_DISCONNECT  = 3
    8.24 -CMSG_BLKIF_BE_VBD_CREATE  = 4
    8.25 -CMSG_BLKIF_BE_VBD_DESTROY = 5
    8.26 -CMSG_BLKIF_BE_VBD_GROW    = 6
    8.27 -CMSG_BLKIF_BE_VBD_SHRINK  = 7
    8.28 -
    8.29 -BLKIF_DRIVER_STATUS_DOWN  = 0
    8.30 -BLKIF_DRIVER_STATUS_UP    = 1
    8.31 -
    8.32 -pendmsg = None
    8.33 -pendaddr = None
    8.34 -
    8.35 -recovery = False # Is a recovery in progress? (if so we'll need to notify guests)
    8.36 -be_port  = None  # Port object for backend domain
    8.37 -
    8.38 -def backend_tx_req(msg):
    8.39 -    port = xend.blkif.be_port
    8.40 -    if not port:
    8.41 -        print "BUG: attempt to transmit request to non-existant blkif driver"
    8.42 -    if port.space_to_write_request():
    8.43 -        port.write_request(msg)
    8.44 -        port.notify()
    8.45 -    else:
    8.46 -        xend.blkif.pendmsg = msg
    8.47 -
    8.48 -def backend_rx_req(port, msg):
    8.49 -    port.write_response(msg)
    8.50 -    subtype = (msg.get_header())['subtype']
    8.51 -    print "Received blkif-be request, subtype %d" % subtype
    8.52 -    if subtype == CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED:
    8.53 -        status = (msg.get_payload())['status']
    8.54 -        if status == BLKIF_DRIVER_STATUS_UP:
    8.55 -            if xend.blkif.recovery:
    8.56 -                # Nasty hack: we count the number of VBDs we reattach so that
    8.57 -                # we'll know when to notify the guests.  Must make this better!
    8.58 -                interface.rebuilt_so_far = 0
    8.59 -                interface.nr_to_rebuild  = 0
    8.60 -                print "New blkif backend now UP, rebuilding VBDs:"
    8.61 -                for blkif_key in interface.list.keys():
    8.62 -                    blkif = interface.list[blkif_key]
    8.63 -                    blkif.create()
    8.64 -                    for vdev in blkif.devices.keys():
    8.65 -                        blkif.reattach_device(vdev)
    8.66 -                        interface.nr_to_rebuild += 1
    8.67 -        else:
    8.68 -            print "Unexpected block backend driver status: %d" % status
    8.69 -
    8.70 -
    8.71 -def backend_rx_rsp(port, msg):
    8.72 -    subtype = (msg.get_header())['subtype']
    8.73 -    print "Received blkif-be response, subtype %d" % subtype
    8.74 -    if subtype == CMSG_BLKIF_BE_CREATE:
    8.75 -        rsp = { 'success': True }
    8.76 -        xend.main.send_management_response(rsp, xend.blkif.pendaddr)
    8.77 -    elif subtype == CMSG_BLKIF_BE_CONNECT:
    8.78 -        pl = msg.get_payload()
    8.79 -        (dom, hnd, frame, evtchn, st) = (pl['domid'], pl['blkif_handle'],
    8.80 -                                         pl['shmem_frame'], pl['evtchn'],
    8.81 -                                         pl['status'])
    8.82 -        blkif = interface.list[xend.main.port_from_dom(dom).local_port]
    8.83 -        msg = xend.utils.message(CMSG_BLKIF_FE,
    8.84 -                                 CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED, 0,
    8.85 -                                 { 'handle' : 0, 'status' : 2,
    8.86 -                                   'evtchn' : blkif.evtchn['port2'] })
    8.87 -        blkif.ctrlif_tx_req(xend.main.port_list[blkif.key], msg)
    8.88 -    elif subtype == CMSG_BLKIF_BE_VBD_CREATE:
    8.89 -        pl = msg.get_payload()
    8.90 -        (dom, hnd, vdev, ro, st) = (pl['domid'], pl['blkif_handle'],
    8.91 -                                    pl['vdevice'], pl['readonly'],
    8.92 -                                    pl['status'])
    8.93 -        blkif = interface.list[xend.main.port_from_dom(dom).local_port]
    8.94 -        (pdev, start_sect, nr_sect, readonly) = blkif.devices[vdev]
    8.95 -        msg = xend.utils.message(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_GROW, 0,
    8.96 -                                 { 'domid' : dom, 'blkif_handle' : 0,
    8.97 -                                   'vdevice' : vdev,
    8.98 -                                   'extent.sector_start' : start_sect,
    8.99 -                                   'extent.sector_length' : nr_sect,
   8.100 -                                   'extent.device' : pdev })
   8.101 -        backend_tx_req(msg)
   8.102 -    elif subtype == CMSG_BLKIF_BE_VBD_GROW:
   8.103 -       if not xend.blkif.recovery:
   8.104 -           rsp = { 'success': True }
   8.105 -           xend.main.send_management_response(rsp, xend.blkif.pendaddr)
   8.106 -       else:
   8.107 -           interface.rebuilt_so_far += 1
   8.108 -           if interface.rebuilt_so_far == interface.nr_to_rebuild:
   8.109 -               print "Rebuilt VBDs, notifying guests:"
   8.110 -               for blkif_key in interface.list.keys():
   8.111 -                   blkif = interface.list[blkif_key]
   8.112 -                   print "  Notifying %d" % blkif.dom
   8.113 -                   msg = xend.utils.message(CMSG_BLKIF_FE,
   8.114 -                                            CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED,
   8.115 -                                            0, { 'handle' : 0, 'status' : 1 })
   8.116 -                   blkif.ctrlif_tx_req(xend.main.port_from_dom(blkif.dom),msg)
   8.117 -               xend.blkif.recovery = False
   8.118 -               print "Done notifying guests"
   8.119 -
   8.120 -
   8.121 -def backend_do_work(port):
   8.122 -    global pendmsg
   8.123 -    if pendmsg and port.space_to_write_request():
   8.124 -        port.write_request(pendmsg)
   8.125 -        pendmsg = None
   8.126 -        return True
   8.127 -    return False
   8.128 -
   8.129 -
   8.130 -class interface:
   8.131 -
   8.132 -    # Dictionary of all block-device interfaces.
   8.133 -    list = {}
   8.134 -
   8.135 -    # NB. 'key' is an opaque value that has no meaning in this class.
   8.136 -    def __init__(self, dom, key):
   8.137 -        self.dom     = dom
   8.138 -        self.key     = key
   8.139 -        self.devices = {}
   8.140 -        self.pendmsg = None
   8.141 -        interface.list[key] = self
   8.142 -        self.create()
   8.143 -
   8.144 -    def create(self):
   8.145 -        msg = xend.utils.message(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE, 0,
   8.146 -                                 { 'domid' : self.dom, 'blkif_handle' : 0 })
   8.147 -        xend.blkif.pendaddr = xend.main.mgmt_req_addr
   8.148 -        backend_tx_req(msg)
   8.149 -
   8.150 -    # Attach a device to the specified interface
   8.151 -    def attach_device(self, vdev, pdev, start_sect, nr_sect, readonly):
   8.152 -        if self.devices.has_key(vdev):
   8.153 -            return False
   8.154 -        self.devices[vdev] = (pdev, start_sect, nr_sect, readonly)
   8.155 -        msg = xend.utils.message(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE, 0,
   8.156 -                                 { 'domid' : self.dom, 'blkif_handle' : 0,
   8.157 -                                   'vdevice' : vdev, 'readonly' : readonly })
   8.158 -        xend.blkif.pendaddr = xend.main.mgmt_req_addr
   8.159 -        backend_tx_req(msg)
   8.160 -        return True
   8.161 -
   8.162 -    def reattach_device(self, vdev):
   8.163 -        (pdev, start_sect, nr_sect, readonly) = self.devices[vdev]
   8.164 -        msg = xend.utils.message(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE,
   8.165 -                                 0, { 'domid' : self.dom,
   8.166 -                                      'blkif_handle' : 0,
   8.167 -                                      'vdevice' : vdev,
   8.168 -                                      'readonly' : readonly })
   8.169 -        xend.blkif.pendaddr = xend.main.mgmt_req_addr
   8.170 -        backend_tx_req(msg)
   8.171 -
   8.172 -    # Completely destroy this interface.
   8.173 -    def destroy(self):
   8.174 -        del interface.list[self.key]
   8.175 -        msg = xend.utils.message(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY, 0,
   8.176 -                                 { 'domid' : self.dom, 'blkif_handle' : 0 })
   8.177 -        backend_tx_req(msg)        
   8.178 -
   8.179 -
   8.180 -    # The parameter @port is the control-interface event channel. This method
   8.181 -    # returns True if messages were written to the control interface.
   8.182 -    def ctrlif_transmit_work(self, port):
   8.183 -        if self.pendmsg and port.space_to_write_request():
   8.184 -            port.write_request(self.pendmsg)
   8.185 -            self.pendmsg = None
   8.186 -            return True
   8.187 -        return False
   8.188 -
   8.189 -    def ctrlif_tx_req(self, port, msg):
   8.190 -        if port.space_to_write_request():
   8.191 -            port.write_request(msg)
   8.192 -            port.notify()
   8.193 -        else:
   8.194 -            self.pendmsg = msg
   8.195 -
   8.196 -    def ctrlif_rx_req(self, port, msg):
   8.197 -        port.write_response(msg)
   8.198 -        subtype = (msg.get_header())['subtype']
   8.199 -        if subtype == CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED:
   8.200 -            msg = xend.utils.message(CMSG_BLKIF_FE,
   8.201 -                                     CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED,
   8.202 -                                     0,
   8.203 -                                     { 'handle' : 0, 'status' : 1 })
   8.204 -            self.ctrlif_tx_req(port, msg)
   8.205 -        elif subtype == CMSG_BLKIF_FE_INTERFACE_CONNECT:
   8.206 -            pl = msg.get_payload()
   8.207 -            (hnd, frame) = (pl['handle'], pl['shmem_frame'])
   8.208 -            xc = Xc.new()
   8.209 -            self.evtchn = xc.evtchn_bind_interdomain(
   8.210 -                                            dom1=xend.blkif.be_port.remote_dom,
   8.211 -                                            dom2=self.dom)
   8.212 -            msg = xend.utils.message(CMSG_BLKIF_BE,
   8.213 -                                     CMSG_BLKIF_BE_CONNECT, 0,
   8.214 -                                     { 'domid' : self.dom, 'blkif_handle' : 0,
   8.215 -                                       'shmem_frame' : frame,
   8.216 -                                       'evtchn' : self.evtchn['port1'] })
   8.217 -            backend_tx_req(msg)
     9.1 --- a/tools/xend-old/lib/console.py	Mon Jun 28 08:20:16 2004 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,180 +0,0 @@
     9.4 -
     9.5 -#############################################################
     9.6 -## xend/console.py -- Console-management functions for Xend
     9.7 -## Copyright (c) 2004, K A Fraser (University of Cambridge)
     9.8 -#############################################################
     9.9 -
    9.10 -import errno, re, os, select, signal, socket, struct, sys
    9.11 -import xend.blkif, xend.main, xend.manager, xend.utils, Xc
    9.12 -
    9.13 -##
    9.14 -## interface:
    9.15 -##  Each control interface owns an instance of this class, which manages
    9.16 -##  the current state of the console interface. Normally a console interface
    9.17 -##  will be one of two state:
    9.18 -##   LISTENING: listening for a connection on TCP port 'self.port'
    9.19 -##   CONNECTED: sending/receiving console data on TCP port 'self.port'
    9.20 -##
    9.21 -##  A dictionary of all active interfaces, indexed by TCP socket descriptor,
    9.22 -##  is accessible as 'interface.list_by_fd'.
    9.23 -##
    9.24 -##  NB. When a class instance is to be destroyed you *must* call the 'close'
    9.25 -##  method. Otherwise a stale reference will eb left in the interface list.
    9.26 -##
    9.27 -class interface:
    9.28 -
    9.29 -    # The various states that a console interface may be in.
    9.30 -    CLOSED    = 0 # No console activity
    9.31 -    LISTENING = 1 # Listening on port 'self.port'. Socket object 'self.sock'.
    9.32 -    CONNECTED = 2 # Active connection on 'self.port'. Socket obj 'self.sock'.
    9.33 -
    9.34 -
    9.35 -    # Dictionary of all active (non-closed) console interfaces.
    9.36 -    list_by_fd = {}
    9.37 -
    9.38 -
    9.39 -    # Dictionary of all console interfaces, closed and open.
    9.40 -    list = {}
    9.41 -
    9.42 -
    9.43 -    # NB. 'key' is an opaque value that has no meaning in this class.
    9.44 -    def __init__(self, port, key):
    9.45 -        self.status = interface.CLOSED
    9.46 -        self.port   = port
    9.47 -        self.key    = key
    9.48 -        self.rbuf   = xend.utils.buffer()
    9.49 -        self.wbuf   = xend.utils.buffer()
    9.50 -        interface.list[key] = self
    9.51 -
    9.52 -
    9.53 -    # Is this interface closed (inactive)?
    9.54 -    def closed(self):
    9.55 -        return self.status == interface.CLOSED
    9.56 -
    9.57 -
    9.58 -    # Is this interface listening?
    9.59 -    def listening(self):
    9.60 -        return self.status == interface.LISTENING
    9.61 -
    9.62 -
    9.63 -    # Is this interface active and connected?
    9.64 -    def connected(self):
    9.65 -        return self.status == interface.CONNECTED
    9.66 -
    9.67 -
    9.68 -    # Close the interface, if it is not closed already.
    9.69 -    def close(self):
    9.70 -        if not self.closed():
    9.71 -            del interface.list_by_fd[self.sock.fileno()]
    9.72 -            self.sock.close()
    9.73 -            del self.sock
    9.74 -            self.status = interface.CLOSED
    9.75 -
    9.76 -
    9.77 -    # Move the interface into the 'listening' state. Opens a new listening
    9.78 -    # socket and updates 'list_by_fd'.
    9.79 -    def listen(self):
    9.80 -        # Close old socket (if any), and create a fresh one.
    9.81 -        self.close()
    9.82 -        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
    9.83 -
    9.84 -        try:
    9.85 -            # Turn the new socket into a non-blocking listener.
    9.86 -            self.sock.setblocking(False)
    9.87 -            self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    9.88 -            self.sock.bind(('', self.port))
    9.89 -            self.sock.listen(1)
    9.90 -
    9.91 -            # Announce the new status of thsi interface.
    9.92 -            self.status = interface.LISTENING
    9.93 -            interface.list_by_fd[self.sock.fileno()] = self
    9.94 -
    9.95 -        except:
    9.96 -            # In case of trouble ensure we get rid of dangling socket reference
    9.97 -            self.sock.close()
    9.98 -            del self.sock
    9.99 -            raise
   9.100 -
   9.101 -
   9.102 -    # Move a listening interface into the 'connected' state.
   9.103 -    def connect(self):
   9.104 -        # Pick up a new connection, if one is available.
   9.105 -        try:
   9.106 -            (sock, addr) = self.sock.accept()
   9.107 -        except:
   9.108 -            return 0
   9.109 -        sock.setblocking(False)
   9.110 -        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
   9.111 -
   9.112 -        # Close the listening socket.
   9.113 -        self.sock.close()
   9.114 -
   9.115 -        # Publish the new socket and the new interface state.
   9.116 -        self.sock = sock
   9.117 -        self.status = interface.CONNECTED
   9.118 -        interface.list_by_fd[self.sock.fileno()] = self
   9.119 -        return 1
   9.120 -
   9.121 -
   9.122 -    # Completely sestroy a console interface.
   9.123 -    def destroy(self):
   9.124 -        self.close()
   9.125 -        del interface.list[self.key]
   9.126 -
   9.127 -
   9.128 -    # Do work triggered by resource availability on a console-interface socket.
   9.129 -    def socket_work(self):
   9.130 -        # If the interface is listening, check for pending connections.
   9.131 -        if self.listening():
   9.132 -            self.connect()
   9.133 -
   9.134 -        # All done if the interface is not connected.
   9.135 -        if not self.connected():
   9.136 -            return
   9.137 -
   9.138 -        # Send as much pending data as possible via the socket.
   9.139 -        while not self.rbuf.empty():
   9.140 -            try:
   9.141 -                bytes = self.sock.send(self.rbuf.peek())
   9.142 -                if bytes > 0:
   9.143 -                    self.rbuf.discard(bytes)
   9.144 -            except socket.error, error:
   9.145 -                pass
   9.146 -
   9.147 -        # Read as much data as is available. Don't worry about
   9.148 -        # overflowing our buffer: it's more important to read the
   9.149 -        # incoming data stream and detect errors or closure of the
   9.150 -        # remote end in a timely manner.
   9.151 -        try:
   9.152 -            while 1:
   9.153 -                data = self.sock.recv(2048)
   9.154 -                # Return of zero means the remote end has disconnected.
   9.155 -                # We therefore return the console interface to listening.
   9.156 -                if not data:
   9.157 -                    self.listen()
   9.158 -                    break
   9.159 -                self.wbuf.write(data)
   9.160 -        except socket.error, error:
   9.161 -            # Assume that most errors mean that the connection is dead.
   9.162 -            # In such cases we return the interface to 'listening' state.
   9.163 -            if error[0] != errno.EAGAIN:
   9.164 -                print "Better return to listening"
   9.165 -                self.listen()
   9.166 -                print "New status: " + str(self.status)
   9.167 -
   9.168 -
   9.169 -    # The parameter @port is the control-interface event channel. This method
   9.170 -    # returns True if messages were written to the control interface.
   9.171 -    def ctrlif_transmit_work(self, port):
   9.172 -        work_done = False
   9.173 -        while not self.wbuf.empty() and port.space_to_write_request():
   9.174 -            msg = xend.utils.message(0, 0, 0)
   9.175 -            msg.append_payload(self.wbuf.read(msg.MAX_PAYLOAD))
   9.176 -            port.write_request(msg)
   9.177 -            work_done = True
   9.178 -        return work_done
   9.179 -
   9.180 -
   9.181 -    def ctrlif_rx_req(self, port, msg):
   9.182 -        self.rbuf.write(msg.get_payload())
   9.183 -        port.write_response(msg)
    10.1 --- a/tools/xend-old/lib/domain_controller.h	Mon Jun 28 08:20:16 2004 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,532 +0,0 @@
    10.4 -/******************************************************************************
    10.5 - * domain_controller.h
    10.6 - * 
    10.7 - * Interface to server controller (e.g., 'xend'). This header file defines the 
    10.8 - * interface that is shared with guest OSes.
    10.9 - * 
   10.10 - * Copyright (c) 2004, K A Fraser
   10.11 - */
   10.12 -
   10.13 -#ifndef __DOMAIN_CONTROLLER_H__
   10.14 -#define __DOMAIN_CONTROLLER_H__
   10.15 -
   10.16 -
   10.17 -#ifndef BASIC_START_INFO
   10.18 -#error "Xen header file hypervisor-if.h must already be included here."
   10.19 -#endif
   10.20 -
   10.21 -
   10.22 -/*
   10.23 - * EXTENDED BOOTSTRAP STRUCTURE FOR NEW DOMAINS.
   10.24 - */
   10.25 -
   10.26 -typedef struct {
   10.27 -    BASIC_START_INFO;
   10.28 -    u16 domain_controller_evtchn; /* 320 */
   10.29 -} PACKED extended_start_info_t; /* 322 bytes */
   10.30 -#define SIF_BLK_BE_DOMAIN (1<<4)  /* Is this a block backend domain? */
   10.31 -#define SIF_NET_BE_DOMAIN (1<<5)  /* Is this a net backend domain? */
   10.32 -
   10.33 -
   10.34 -/*
   10.35 - * Reason codes for SCHEDOP_shutdown. These are opaque to Xen but may be
   10.36 - * interpreted by control software to determine the appropriate action. These 
   10.37 - * are only really advisories: the controller can actually do as it likes.
   10.38 - */
   10.39 -#define SHUTDOWN_poweroff   0  /* Domain exited normally. Clean up and kill. */
   10.40 -#define SHUTDOWN_reboot     1  /* Clean up, kill, and then restart.          */
   10.41 -#define SHUTDOWN_suspend    2  /* Clean up, save suspend info, kill.         */
   10.42 -
   10.43 -
   10.44 -/*
   10.45 - * CONTROLLER MESSAGING INTERFACE.
   10.46 - */
   10.47 -
   10.48 -typedef struct {
   10.49 -    u8 type;     /*  0: echoed in response */
   10.50 -    u8 subtype;  /*  1: echoed in response */
   10.51 -    u8 id;       /*  2: echoed in response */
   10.52 -    u8 length;   /*  3: number of bytes in 'msg' */
   10.53 -    u8 msg[60];  /*  4: type-specific message data */
   10.54 -} PACKED control_msg_t; /* 64 bytes */
   10.55 -
   10.56 -#define CONTROL_RING_SIZE 8
   10.57 -typedef u32 CONTROL_RING_IDX;
   10.58 -#define MASK_CONTROL_IDX(_i) ((_i)&(CONTROL_RING_SIZE-1))
   10.59 -
   10.60 -typedef struct {
   10.61 -    control_msg_t tx_ring[CONTROL_RING_SIZE];   /*    0: guest -> controller */
   10.62 -    control_msg_t rx_ring[CONTROL_RING_SIZE];   /*  512: controller -> guest */
   10.63 -    CONTROL_RING_IDX tx_req_prod, tx_resp_prod; /* 1024, 1028 */
   10.64 -    CONTROL_RING_IDX rx_req_prod, rx_resp_prod; /* 1032, 1036 */
   10.65 -} PACKED control_if_t; /* 1040 bytes */
   10.66 -
   10.67 -/*
   10.68 - * Top-level command types.
   10.69 - */
   10.70 -#define CMSG_CONSOLE        0  /* Console                 */
   10.71 -#define CMSG_BLKIF_BE       1  /* Block-device backend    */
   10.72 -#define CMSG_BLKIF_FE       2  /* Block-device frontend   */
   10.73 -#define CMSG_NETIF_BE       3  /* Network-device backend  */
   10.74 -#define CMSG_NETIF_FE       4  /* Network-device frontend */
   10.75 -#define CMSG_SHUTDOWN       6  /* Shutdown messages       */
   10.76 -
   10.77 -
   10.78 -/******************************************************************************
   10.79 - * CONSOLE DEFINITIONS
   10.80 - */
   10.81 -
   10.82 -/*
   10.83 - * Subtypes for console messages.
   10.84 - */
   10.85 -#define CMSG_CONSOLE_DATA       0
   10.86 -
   10.87 -
   10.88 -/******************************************************************************
   10.89 - * BLOCK-INTERFACE FRONTEND DEFINITIONS
   10.90 - */
   10.91 -
   10.92 -/* Messages from domain controller to guest. */
   10.93 -#define CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED   0
   10.94 -
   10.95 -/* Messages from guest to domain controller. */
   10.96 -#define CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED     32
   10.97 -#define CMSG_BLKIF_FE_INTERFACE_CONNECT         33
   10.98 -#define CMSG_BLKIF_FE_INTERFACE_DISCONNECT      34
   10.99 -
  10.100 -/* These are used by both front-end and back-end drivers. */
  10.101 -#define blkif_vdev_t   u16
  10.102 -#define blkif_pdev_t   u16
  10.103 -#define blkif_sector_t u64
  10.104 -
  10.105 -/*
  10.106 - * CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED:
  10.107 - *  Notify a guest about a status change on one of its block interfaces.
  10.108 - *  If the interface is DESTROYED or DOWN then the interface is disconnected:
  10.109 - *   1. The shared-memory frame is available for reuse.
  10.110 - *   2. Any unacknowledged messgaes pending on the interface were dropped.
  10.111 - */
  10.112 -#define BLKIF_INTERFACE_STATUS_DESTROYED    0 /* Interface doesn't exist.    */
  10.113 -#define BLKIF_INTERFACE_STATUS_DISCONNECTED 1 /* Exists but is disconnected. */
  10.114 -#define BLKIF_INTERFACE_STATUS_CONNECTED    2 /* Exists and is connected.    */
  10.115 -typedef struct {
  10.116 -    u32 handle; /*  0 */
  10.117 -    u32 status; /*  4 */
  10.118 -    u16 evtchn; /*  8: (only if status == BLKIF_INTERFACE_STATUS_CONNECTED). */
  10.119 -} PACKED blkif_fe_interface_status_changed_t; /* 10 bytes */
  10.120 -
  10.121 -/*
  10.122 - * CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED:
  10.123 - *  Notify the domain controller that the front-end driver is DOWN or UP.
  10.124 - *  When the driver goes DOWN then the controller will send no more
  10.125 - *  status-change notifications. When the driver comes UP then the controller
  10.126 - *  will send a notification for each interface that currently exists.
  10.127 - *  If the driver goes DOWN while interfaces are still UP, the domain
  10.128 - *  will automatically take the interfaces DOWN.
  10.129 - */
  10.130 -#define BLKIF_DRIVER_STATUS_DOWN   0
  10.131 -#define BLKIF_DRIVER_STATUS_UP     1
  10.132 -typedef struct {
  10.133 -    /* IN */
  10.134 -    u32 status;        /*  0: BLKIF_DRIVER_STATUS_??? */
  10.135 -    /* OUT */
  10.136 -    /*
  10.137 -     * Tells driver how many interfaces it should expect to immediately
  10.138 -     * receive notifications about.
  10.139 -     */
  10.140 -    u32 nr_interfaces; /*  4 */
  10.141 -} PACKED blkif_fe_driver_status_changed_t; /* 8 bytes */
  10.142 -
  10.143 -/*
  10.144 - * CMSG_BLKIF_FE_INTERFACE_CONNECT:
  10.145 - *  If successful, the domain controller will acknowledge with a
  10.146 - *  STATUS_CONNECTED message.
  10.147 - */
  10.148 -typedef struct {
  10.149 -    u32      handle;      /*  0 */
  10.150 -    u32      __pad;
  10.151 -    memory_t shmem_frame; /*  8 */
  10.152 -    MEMORY_PADDING;
  10.153 -} PACKED blkif_fe_interface_connect_t; /* 16 bytes */
  10.154 -
  10.155 -/*
  10.156 - * CMSG_BLKIF_FE_INTERFACE_DISCONNECT:
  10.157 - *  If successful, the domain controller will acknowledge with a
  10.158 - *  STATUS_DISCONNECTED message.
  10.159 - */
  10.160 -typedef struct {
  10.161 -    u32 handle; /*  0 */
  10.162 -} PACKED blkif_fe_interface_disconnect_t; /* 4 bytes */
  10.163 -
  10.164 -
  10.165 -/******************************************************************************
  10.166 - * BLOCK-INTERFACE BACKEND DEFINITIONS
  10.167 - */
  10.168 -
  10.169 -/* Messages from domain controller. */
  10.170 -#define CMSG_BLKIF_BE_CREATE      0  /* Create a new block-device interface. */
  10.171 -#define CMSG_BLKIF_BE_DESTROY     1  /* Destroy a block-device interface.    */
  10.172 -#define CMSG_BLKIF_BE_CONNECT     2  /* Connect i/f to remote driver.        */
  10.173 -#define CMSG_BLKIF_BE_DISCONNECT  3  /* Disconnect i/f from remote driver.   */
  10.174 -#define CMSG_BLKIF_BE_VBD_CREATE  4  /* Create a new VBD for an interface.   */
  10.175 -#define CMSG_BLKIF_BE_VBD_DESTROY 5  /* Delete a VBD from an interface.      */
  10.176 -#define CMSG_BLKIF_BE_VBD_GROW    6  /* Append an extent to a given VBD.     */
  10.177 -#define CMSG_BLKIF_BE_VBD_SHRINK  7  /* Remove last extent from a given VBD. */
  10.178 -
  10.179 -/* Messages to domain controller. */
  10.180 -#define CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED 32
  10.181 -
  10.182 -/*
  10.183 - * Message request/response definitions for block-device messages.
  10.184 - */
  10.185 -
  10.186 -typedef struct {
  10.187 -    blkif_sector_t sector_start;   /*  0 */
  10.188 -    blkif_sector_t sector_length;  /*  8 */
  10.189 -    blkif_pdev_t   device;         /* 16 */
  10.190 -    u16            __pad;          /* 18 */
  10.191 -} PACKED blkif_extent_t; /* 20 bytes */
  10.192 -
  10.193 -/* Non-specific 'okay' return. */
  10.194 -#define BLKIF_BE_STATUS_OKAY                0
  10.195 -/* Non-specific 'error' return. */
  10.196 -#define BLKIF_BE_STATUS_ERROR               1
  10.197 -/* The following are specific error returns. */
  10.198 -#define BLKIF_BE_STATUS_INTERFACE_EXISTS    2
  10.199 -#define BLKIF_BE_STATUS_INTERFACE_NOT_FOUND 3
  10.200 -#define BLKIF_BE_STATUS_INTERFACE_CONNECTED 4
  10.201 -#define BLKIF_BE_STATUS_VBD_EXISTS          5
  10.202 -#define BLKIF_BE_STATUS_VBD_NOT_FOUND       6
  10.203 -#define BLKIF_BE_STATUS_OUT_OF_MEMORY       7
  10.204 -#define BLKIF_BE_STATUS_EXTENT_NOT_FOUND    8
  10.205 -#define BLKIF_BE_STATUS_MAPPING_ERROR       9
  10.206 -
  10.207 -/* This macro can be used to create an array of descriptive error strings. */
  10.208 -#define BLKIF_BE_STATUS_ERRORS {    \
  10.209 -    "Okay",                         \
  10.210 -    "Non-specific error",           \
  10.211 -    "Interface already exists",     \
  10.212 -    "Interface not found",          \
  10.213 -    "Interface is still connected", \
  10.214 -    "VBD already exists",           \
  10.215 -    "VBD not found",                \
  10.216 -    "Out of memory",                \
  10.217 -    "Extent not found for VBD",     \
  10.218 -    "Could not map domain memory" }
  10.219 -
  10.220 -/*
  10.221 - * CMSG_BLKIF_BE_CREATE:
  10.222 - *  When the driver sends a successful response then the interface is fully
  10.223 - *  created. The controller will send a DOWN notification to the front-end
  10.224 - *  driver.
  10.225 - */
  10.226 -typedef struct { 
  10.227 -    /* IN */
  10.228 -    domid_t    domid;         /*  0: Domain attached to new interface.   */
  10.229 -    u32        blkif_handle;  /*  4: Domain-specific interface handle.   */
  10.230 -    /* OUT */
  10.231 -    u32        status;        /*  8 */
  10.232 -} PACKED blkif_be_create_t; /* 12 bytes */
  10.233 -
  10.234 -/*
  10.235 - * CMSG_BLKIF_BE_DESTROY:
  10.236 - *  When the driver sends a successful response then the interface is fully
  10.237 - *  torn down. The controller will send a DESTROYED notification to the
  10.238 - *  front-end driver.
  10.239 - */
  10.240 -typedef struct { 
  10.241 -    /* IN */
  10.242 -    domid_t    domid;         /*  0: Identify interface to be destroyed. */
  10.243 -    u32        blkif_handle;  /*  4: ...ditto...                         */
  10.244 -    /* OUT */
  10.245 -    u32        status;        /*  8 */
  10.246 -} PACKED blkif_be_destroy_t; /* 12 bytes */
  10.247 -
  10.248 -/*
  10.249 - * CMSG_BLKIF_BE_CONNECT:
  10.250 - *  When the driver sends a successful response then the interface is fully
  10.251 - *  connected. The controller will send a CONNECTED notification to the
  10.252 - *  front-end driver.
  10.253 - */
  10.254 -typedef struct { 
  10.255 -    /* IN */
  10.256 -    domid_t    domid;         /*  0: Domain attached to new interface.   */
  10.257 -    u32        blkif_handle;  /*  4: Domain-specific interface handle.   */
  10.258 -    memory_t   shmem_frame;   /*  8: Page cont. shared comms window.     */
  10.259 -    MEMORY_PADDING;
  10.260 -    u32        evtchn;        /* 16: Event channel for notifications.    */
  10.261 -    /* OUT */
  10.262 -    u32        status;        /* 20 */
  10.263 -} PACKED blkif_be_connect_t;  /* 24 bytes */
  10.264 -
  10.265 -/*
  10.266 - * CMSG_BLKIF_BE_DISCONNECT:
  10.267 - *  When the driver sends a successful response then the interface is fully
  10.268 - *  disconnected. The controller will send a DOWN notification to the front-end
  10.269 - *  driver.
  10.270 - */
  10.271 -typedef struct { 
  10.272 -    /* IN */
  10.273 -    domid_t    domid;         /*  0: Domain attached to new interface.   */
  10.274 -    u32        blkif_handle;  /*  4: Domain-specific interface handle.   */
  10.275 -    /* OUT */
  10.276 -    u32        status;        /*  8 */
  10.277 -} PACKED blkif_be_disconnect_t; /* 12 bytes */
  10.278 -
  10.279 -/* CMSG_BLKIF_BE_VBD_CREATE */
  10.280 -typedef struct { 
  10.281 -    /* IN */
  10.282 -    domid_t    domid;         /*  0: Identify blkdev interface.          */
  10.283 -    u32        blkif_handle;  /*  4: ...ditto...                         */
  10.284 -    blkif_vdev_t vdevice;     /*  8: Interface-specific id for this VBD. */
  10.285 -    u16        readonly;      /* 10: Non-zero -> VBD isn't writeable.    */
  10.286 -    /* OUT */
  10.287 -    u32        status;        /* 12 */
  10.288 -} PACKED blkif_be_vbd_create_t; /* 16 bytes */
  10.289 -
  10.290 -/* CMSG_BLKIF_BE_VBD_DESTROY */
  10.291 -typedef struct {
  10.292 -    /* IN */
  10.293 -    domid_t    domid;         /*  0: Identify blkdev interface.          */
  10.294 -    u32        blkif_handle;  /*  4: ...ditto...                         */
  10.295 -    blkif_vdev_t vdevice;     /*  8: Interface-specific id of the VBD.   */
  10.296 -    u16        __pad;         /* 10 */
  10.297 -    /* OUT */
  10.298 -    u32        status;        /* 12 */
  10.299 -} PACKED blkif_be_vbd_destroy_t; /* 16 bytes */
  10.300 -
  10.301 -/* CMSG_BLKIF_BE_VBD_GROW */
  10.302 -typedef struct { 
  10.303 -    /* IN */
  10.304 -    domid_t    domid;         /*  0: Identify blkdev interface.          */
  10.305 -    u32        blkif_handle;  /*  4: ...ditto...                         */
  10.306 -    blkif_extent_t extent;    /*  8: Physical extent to append to VBD.   */
  10.307 -    blkif_vdev_t vdevice;     /* 28: Interface-specific id of the VBD.   */
  10.308 -    u16        __pad;         /* 30 */
  10.309 -    /* OUT */
  10.310 -    u32        status;        /* 32 */
  10.311 -} PACKED blkif_be_vbd_grow_t; /* 36 bytes */
  10.312 -
  10.313 -/* CMSG_BLKIF_BE_VBD_SHRINK */
  10.314 -typedef struct { 
  10.315 -    /* IN */
  10.316 -    domid_t    domid;         /*  0: Identify blkdev interface.          */
  10.317 -    u32        blkif_handle;  /*  4: ...ditto...                         */
  10.318 -    blkif_vdev_t vdevice;     /*  8: Interface-specific id of the VBD.   */
  10.319 -    u16        __pad;         /* 10 */
  10.320 -    /* OUT */
  10.321 -    u32        status;        /* 12 */
  10.322 -} PACKED blkif_be_vbd_shrink_t; /* 16 bytes */
  10.323 -
  10.324 -/*
  10.325 - * CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED:
  10.326 - *  Notify the domain controller that the back-end driver is DOWN or UP.
  10.327 - *  If the driver goes DOWN while interfaces are still UP, the controller
  10.328 - *  will automatically send DOWN notifications.
  10.329 - */
  10.330 -typedef struct {
  10.331 -    u32        status;        /*  0: BLKIF_DRIVER_STATUS_??? */
  10.332 -} PACKED blkif_be_driver_status_changed_t; /* 4 bytes */
  10.333 -
  10.334 -
  10.335 -/******************************************************************************
  10.336 - * NETWORK-INTERFACE FRONTEND DEFINITIONS
  10.337 - */
  10.338 -
  10.339 -/* Messages from domain controller to guest. */
  10.340 -#define CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED   0
  10.341 -
  10.342 -/* Messages from guest to domain controller. */
  10.343 -#define CMSG_NETIF_FE_DRIVER_STATUS_CHANGED     32
  10.344 -#define CMSG_NETIF_FE_INTERFACE_CONNECT         33
  10.345 -#define CMSG_NETIF_FE_INTERFACE_DISCONNECT      34
  10.346 -
  10.347 -/*
  10.348 - * CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED:
  10.349 - *  Notify a guest about a status change on one of its network interfaces.
  10.350 - *  If the interface is DESTROYED or DOWN then the interface is disconnected:
  10.351 - *   1. The shared-memory frame is available for reuse.
  10.352 - *   2. Any unacknowledged messgaes pending on the interface were dropped.
  10.353 - */
  10.354 -#define NETIF_INTERFACE_STATUS_DESTROYED    0 /* Interface doesn't exist.    */
  10.355 -#define NETIF_INTERFACE_STATUS_DISCONNECTED 1 /* Exists but is disconnected. */
  10.356 -#define NETIF_INTERFACE_STATUS_CONNECTED    2 /* Exists and is connected.    */
  10.357 -typedef struct {
  10.358 -    u32        handle; /*  0 */
  10.359 -    u32        status; /*  4 */
  10.360 -    u16        evtchn; /*  8: status == NETIF_INTERFACE_STATUS_CONNECTED */
  10.361 -    u8         mac[6]; /* 10: status == NETIF_INTERFACE_STATUS_CONNECTED */
  10.362 -} PACKED netif_fe_interface_status_changed_t; /* 16 bytes */
  10.363 -
  10.364 -/*
  10.365 - * CMSG_NETIF_FE_DRIVER_STATUS_CHANGED:
  10.366 - *  Notify the domain controller that the front-end driver is DOWN or UP.
  10.367 - *  When the driver goes DOWN then the controller will send no more
  10.368 - *  status-change notifications. When the driver comes UP then the controller
  10.369 - *  will send a notification for each interface that currently exists.
  10.370 - *  If the driver goes DOWN while interfaces are still UP, the domain
  10.371 - *  will automatically take the interfaces DOWN.
  10.372 - */
  10.373 -#define NETIF_DRIVER_STATUS_DOWN   0
  10.374 -#define NETIF_DRIVER_STATUS_UP     1
  10.375 -typedef struct {
  10.376 -    /* IN */
  10.377 -    u32        status;        /*  0: NETIF_DRIVER_STATUS_??? */
  10.378 -    /* OUT */
  10.379 -    /*
  10.380 -     * Tells driver how many interfaces it should expect to immediately
  10.381 -     * receive notifications about.
  10.382 -     */
  10.383 -    u32        nr_interfaces; /*  4 */
  10.384 -} PACKED netif_fe_driver_status_changed_t; /* 8 bytes */
  10.385 -
  10.386 -/*
  10.387 - * CMSG_NETIF_FE_INTERFACE_CONNECT:
  10.388 - *  If successful, the domain controller will acknowledge with a
  10.389 - *  STATUS_CONNECTED message.
  10.390 - */
  10.391 -typedef struct {
  10.392 -    u32        handle;         /*  0 */
  10.393 -    u32        __pad;          /*  4 */
  10.394 -    memory_t   tx_shmem_frame; /*  8 */
  10.395 -    MEMORY_PADDING;
  10.396 -    memory_t   rx_shmem_frame; /* 16 */
  10.397 -    MEMORY_PADDING;
  10.398 -} PACKED netif_fe_interface_connect_t; /* 24 bytes */
  10.399 -
  10.400 -/*
  10.401 - * CMSG_NETIF_FE_INTERFACE_DISCONNECT:
  10.402 - *  If successful, the domain controller will acknowledge with a
  10.403 - *  STATUS_DISCONNECTED message.
  10.404 - */
  10.405 -typedef struct {
  10.406 -    u32        handle;        /*  0 */
  10.407 -} PACKED netif_fe_interface_disconnect_t; /* 4 bytes */
  10.408 -
  10.409 -
  10.410 -/******************************************************************************
  10.411 - * NETWORK-INTERFACE BACKEND DEFINITIONS
  10.412 - */
  10.413 -
  10.414 -/* Messages from domain controller. */
  10.415 -#define CMSG_NETIF_BE_CREATE      0  /* Create a new net-device interface. */
  10.416 -#define CMSG_NETIF_BE_DESTROY     1  /* Destroy a net-device interface.    */
  10.417 -#define CMSG_NETIF_BE_CONNECT     2  /* Connect i/f to remote driver.        */
  10.418 -#define CMSG_NETIF_BE_DISCONNECT  3  /* Disconnect i/f from remote driver.   */
  10.419 -
  10.420 -/* Messages to domain controller. */
  10.421 -#define CMSG_NETIF_BE_DRIVER_STATUS_CHANGED 32
  10.422 -
  10.423 -/*
  10.424 - * Message request/response definitions for net-device messages.
  10.425 - */
  10.426 -
  10.427 -/* Non-specific 'okay' return. */
  10.428 -#define NETIF_BE_STATUS_OKAY                0
  10.429 -/* Non-specific 'error' return. */
  10.430 -#define NETIF_BE_STATUS_ERROR               1
  10.431 -/* The following are specific error returns. */
  10.432 -#define NETIF_BE_STATUS_INTERFACE_EXISTS    2
  10.433 -#define NETIF_BE_STATUS_INTERFACE_NOT_FOUND 3
  10.434 -#define NETIF_BE_STATUS_INTERFACE_CONNECTED 4
  10.435 -#define NETIF_BE_STATUS_OUT_OF_MEMORY       5
  10.436 -#define NETIF_BE_STATUS_MAPPING_ERROR       6
  10.437 -
  10.438 -/* This macro can be used to create an array of descriptive error strings. */
  10.439 -#define NETIF_BE_STATUS_ERRORS {    \
  10.440 -    "Okay",                         \
  10.441 -    "Non-specific error",           \
  10.442 -    "Interface already exists",     \
  10.443 -    "Interface not found",          \
  10.444 -    "Interface is still connected", \
  10.445 -    "Out of memory",                \
  10.446 -    "Could not map domain memory" }
  10.447 -
  10.448 -/*
  10.449 - * CMSG_NETIF_BE_CREATE:
  10.450 - *  When the driver sends a successful response then the interface is fully
  10.451 - *  created. The controller will send a DOWN notification to the front-end
  10.452 - *  driver.
  10.453 - */
  10.454 -typedef struct { 
  10.455 -    /* IN */
  10.456 -    domid_t    domid;         /*  0: Domain attached to new interface.   */
  10.457 -    u32        netif_handle;  /*  4: Domain-specific interface handle.   */
  10.458 -    u8         mac[6];        /*  8 */
  10.459 -    u16        __pad;         /* 14 */
  10.460 -    /* OUT */
  10.461 -    u32        status;        /* 16 */
  10.462 -} PACKED netif_be_create_t; /* 20 bytes */
  10.463 -
  10.464 -/*
  10.465 - * CMSG_NETIF_BE_DESTROY:
  10.466 - *  When the driver sends a successful response then the interface is fully
  10.467 - *  torn down. The controller will send a DESTROYED notification to the
  10.468 - *  front-end driver.
  10.469 - */
  10.470 -typedef struct { 
  10.471 -    /* IN */
  10.472 -    domid_t    domid;         /*  0: Identify interface to be destroyed. */
  10.473 -    u32        netif_handle;  /*  4: ...ditto...                         */
  10.474 -    /* OUT */
  10.475 -    u32   status;             /*  8 */
  10.476 -} PACKED netif_be_destroy_t; /* 12 bytes */
  10.477 -
  10.478 -/*
  10.479 - * CMSG_NETIF_BE_CONNECT:
  10.480 - *  When the driver sends a successful response then the interface is fully
  10.481 - *  connected. The controller will send a CONNECTED notification to the
  10.482 - *  front-end driver.
  10.483 - */
  10.484 -typedef struct { 
  10.485 -    /* IN */
  10.486 -    domid_t    domid;          /*  0: Domain attached to new interface.   */
  10.487 -    u32        netif_handle;   /*  4: Domain-specific interface handle.   */
  10.488 -    memory_t   tx_shmem_frame; /*  8: Page cont. tx shared comms window.  */
  10.489 -    MEMORY_PADDING;
  10.490 -    memory_t   rx_shmem_frame; /* 16: Page cont. rx shared comms window.  */
  10.491 -    MEMORY_PADDING;
  10.492 -    u16        evtchn;         /* 24: Event channel for notifications.    */
  10.493 -    u16        __pad;          /* 26 */
  10.494 -    /* OUT */
  10.495 -    u32        status;         /* 28 */
  10.496 -} PACKED netif_be_connect_t; /* 32 bytes */
  10.497 -
  10.498 -/*
  10.499 - * CMSG_NETIF_BE_DISCONNECT:
  10.500 - *  When the driver sends a successful response then the interface is fully
  10.501 - *  disconnected. The controller will send a DOWN notification to the front-end
  10.502 - *  driver.
  10.503 - */
  10.504 -typedef struct { 
  10.505 -    /* IN */
  10.506 -    domid_t    domid;         /*  0: Domain attached to new interface.   */
  10.507 -    u32        netif_handle;  /*  4: Domain-specific interface handle.   */
  10.508 -    /* OUT */
  10.509 -    u32        status;        /*  8 */
  10.510 -} PACKED netif_be_disconnect_t; /* 12 bytes */
  10.511 -
  10.512 -/*
  10.513 - * CMSG_NETIF_BE_DRIVER_STATUS_CHANGED:
  10.514 - *  Notify the domain controller that the back-end driver is DOWN or UP.
  10.515 - *  If the driver goes DOWN while interfaces are still UP, the domain
  10.516 - *  will automatically send DOWN notifications.
  10.517 - */
  10.518 -typedef struct {
  10.519 -    u32        status;        /*  0: NETIF_DRIVER_STATUS_??? */
  10.520 -} PACKED netif_be_driver_status_changed_t; /* 4 bytes */
  10.521 -
  10.522 -
  10.523 -/******************************************************************************
  10.524 - * SHUTDOWN DEFINITIONS
  10.525 - */
  10.526 -
  10.527 -/*
  10.528 - * Subtypes for shutdown messages.
  10.529 - */
  10.530 -#define CMSG_SHUTDOWN_POWEROFF  0   /* Clean shutdown (SHUTDOWN_poweroff).   */
  10.531 -#define CMSG_SHUTDOWN_REBOOT    1   /* Clean shutdown (SHUTDOWN_reboot).     */
  10.532 -#define CMSG_SHUTDOWN_SUSPEND   2   /* Create suspend info, then             */
  10.533 -                                    /* SHUTDOWN_suspend.                     */
  10.534 -
  10.535 -#endif /* __DOMAIN_CONTROLLER_H__ */
    11.1 --- a/tools/xend-old/lib/main.py	Mon Jun 28 08:20:16 2004 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,317 +0,0 @@
    11.4 -
    11.5 -###########################################################
    11.6 -## xend.py -- Xen controller daemon
    11.7 -## Copyright (c) 2004, K A Fraser (University of Cambridge)
    11.8 -###########################################################
    11.9 -
   11.10 -import errno, re, os, pwd, select, signal, socket, struct, sys, time
   11.11 -import xend.blkif, xend.netif, xend.console, xend.manager, xend.utils, Xc
   11.12 -
   11.13 -
   11.14 -# The following parameters could be placed in a configuration file.
   11.15 -PID  = '/var/run/xend.pid'
   11.16 -LOG  = '/var/log/xend.log'
   11.17 -USER = 'root'
   11.18 -CONTROL_DIR  = '/var/run/xend'
   11.19 -UNIX_SOCK    = 'management_sock' # relative to CONTROL_DIR
   11.20 -
   11.21 -
   11.22 -CMSG_CONSOLE  = 0
   11.23 -CMSG_BLKIF_BE = 1
   11.24 -CMSG_BLKIF_FE = 2
   11.25 -CMSG_NETIF_BE = 3
   11.26 -CMSG_NETIF_FE = 4
   11.27 -
   11.28 -
   11.29 -def port_from_dom(dom):
   11.30 -    global port_list
   11.31 -    for idx, port in port_list.items():
   11.32 -        if port.remote_dom == dom:
   11.33 -            return port
   11.34 -    return None
   11.35 -
   11.36 -
   11.37 -def send_management_response(response, addr):
   11.38 -    try:
   11.39 -        response = str(response)
   11.40 -        print "Mgmt_rsp[%s]: %s" % (addr, response)
   11.41 -        management_interface.sendto(response, addr)
   11.42 -    except socket.error, error:
   11.43 -        pass
   11.44 -
   11.45 -
   11.46 -def daemon_loop():
   11.47 -    # Could we do this more nicely? The xend.manager functions need access
   11.48 -    # to this global state to do their work.
   11.49 -    global port_list, notifier, management_interface, mgmt_req_addr, dom0_port
   11.50 -
   11.51 -    # Lists of all interfaces, indexed by local event-channel port.
   11.52 -    port_list = {}
   11.53 -    
   11.54 -    xc = Xc.new()
   11.55 -
   11.56 -    # Ignore writes to disconnected sockets. We clean up differently.
   11.57 -    signal.signal(signal.SIGPIPE, signal.SIG_IGN)
   11.58 -
   11.59 -    # Construct the management interface. This is a UNIX domain socket via
   11.60 -    # which we receive 'request' datagrams. Each request is a string that
   11.61 -    # can be eval'ed as a Python statement. Responses can be remotely eval'ed
   11.62 -    # by the requester to create a Python dictionary of result values.
   11.63 -    management_interface = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
   11.64 -    if os.path.exists(CONTROL_DIR+'/'+UNIX_SOCK):
   11.65 -        os.unlink(CONTROL_DIR+'/'+UNIX_SOCK)
   11.66 -    management_interface.setblocking(False)
   11.67 -    management_interface.bind(CONTROL_DIR+'/'+UNIX_SOCK)
   11.68 -
   11.69 -    # Interface via which we receive event notifications from other guest
   11.70 -    # OSes. This interface also allows us to clear/acknowledge outstanding
   11.71 -    # notifications.
   11.72 -    notifier = xend.utils.notifier()
   11.73 -
   11.74 -    # The DOM0 control interface is not set up via the management interface.
   11.75 -    # Note that console messages don't come our way (actually, only driver
   11.76 -    # back-ends should use the DOM0 control interface).
   11.77 -    dom0_port = xend.utils.port(0)
   11.78 -    xend.netif.be_port = dom0_port
   11.79 -    xend.blkif.be_port = dom0_port
   11.80 -    notifier.bind(dom0_port.local_port)
   11.81 -    port_list[dom0_port.local_port] = dom0_port
   11.82 -
   11.83 -    ##
   11.84 -    ## MAIN LOOP
   11.85 -    ## 
   11.86 -    while 1:
   11.87 -
   11.88 -        # Construct a poll set. We wait on:
   11.89 -        #  1. Requests on the management interface.
   11.90 -        #  2. Incoming event-channel notifications.
   11.91 -        # Furthermore, for each active control interface:
   11.92 -        #  3. Incoming console data.
   11.93 -        #  4. Space for outgoing console data (if there is data to send).
   11.94 -        waitset = select.poll()
   11.95 -        waitset.register(management_interface, select.POLLIN)
   11.96 -        waitset.register(notifier, select.POLLIN)
   11.97 -        for idx, con_if in xend.console.interface.list_by_fd.items():
   11.98 -            if not con_if.closed():
   11.99 -                pflags = select.POLLIN
  11.100 -                if not con_if.rbuf.empty() and con_if.connected():
  11.101 -                    pflags = select.POLLIN | select.POLLOUT
  11.102 -                waitset.register(con_if.sock.fileno(), pflags)
  11.103 -
  11.104 -        # Wait for something to do...
  11.105 -        fdset = waitset.poll()
  11.106 -        
  11.107 -        # Look for messages on the management interface.
  11.108 -        # These should consist of executable Python statements that call
  11.109 -        # well-known management functions (e.g., new_control_interface(dom=9)).
  11.110 -        try:
  11.111 -            data, mgmt_req_addr = management_interface.recvfrom(2048)
  11.112 -        except socket.error, error:
  11.113 -            if error[0] != errno.EAGAIN:
  11.114 -                raise
  11.115 -        else:
  11.116 -            if mgmt_req_addr:
  11.117 -                # Evaluate the request in an exception-trapping sandbox.
  11.118 -                try:
  11.119 -                    print "Mgmt_req[%s]: %s" % (mgmt_req_addr, data)
  11.120 -                    response = eval('xend.manager.'+data)
  11.121 -
  11.122 -                except:
  11.123 -                    # Catch all exceptions and turn into an error response:
  11.124 -                    #  status:          False
  11.125 -                    #  error_type:      'exception'
  11.126 -                    #  exception_type:  name of exception type.
  11.127 -                    #  exception value: textual exception value.
  11.128 -                    exc_type, exc_val = sys.exc_info()[:2]
  11.129 -                    response = { 'success': False }
  11.130 -                    response['error_type'] = 'exception'
  11.131 -                    response['exception_type'] = str(exc_type)
  11.132 -                    response['exception_value'] = str(exc_val)
  11.133 -                    response = str(response)
  11.134 -
  11.135 -                # Try to send a response to the requester.
  11.136 -                if response:
  11.137 -                    send_management_response(response, mgmt_req_addr)
  11.138 -                
  11.139 -        # Do work for every console interface that hit in the poll set.
  11.140 -        for (fd, events) in fdset:
  11.141 -            if xend.console.interface.list_by_fd.has_key(fd):
  11.142 -                con_if = xend.console.interface.list_by_fd[fd]
  11.143 -                con_if.socket_work()
  11.144 -                # We may now have pending data to send via the control
  11.145 -                # interface. If so then send all we can and notify the remote.
  11.146 -                port = port_list[con_if.key]
  11.147 -                if con_if.ctrlif_transmit_work(port):
  11.148 -                    port.notify()
  11.149 -                    
  11.150 -        # Process control-interface notifications from other guest OSes.
  11.151 -        while 1:            
  11.152 -            # Grab a notification, if there is one.
  11.153 -            notification = notifier.read()
  11.154 -            if not notification:
  11.155 -                break
  11.156 -            (idx, type) = notification
  11.157 -
  11.158 -            if not port_list.has_key(idx):
  11.159 -                continue
  11.160 -
  11.161 -            port = port_list[idx]
  11.162 -            work_done = False
  11.163 -
  11.164 -            con_if = False
  11.165 -            if xend.console.interface.list.has_key(idx):
  11.166 -                con_if = xend.console.interface.list[idx]
  11.167 -
  11.168 -            blk_if = False
  11.169 -            if xend.blkif.interface.list.has_key(idx):
  11.170 -                blk_if = xend.blkif.interface.list[idx]
  11.171 -
  11.172 -            net_if = False
  11.173 -            if xend.netif.interface.list.has_key(idx):
  11.174 -                net_if = xend.netif.interface.list[idx]
  11.175 -
  11.176 -            # If we pick up a disconnect notification then we do any necessary
  11.177 -            # cleanup.
  11.178 -            if type == notifier.EXCEPTION:
  11.179 -                ret = xc.evtchn_status(idx)
  11.180 -                if ret['status'] == 'unbound':
  11.181 -                    notifier.unbind(idx)
  11.182 -                    del port_list[idx], port
  11.183 -                    if con_if:
  11.184 -                        con_if.destroy()
  11.185 -                        del con_if
  11.186 -                    if blk_if:
  11.187 -                        blk_if.destroy()
  11.188 -                        del blk_if
  11.189 -                    if net_if:
  11.190 -                        net_if.destroy()
  11.191 -                        del net_if
  11.192 -                    continue
  11.193 -
  11.194 -            # Process incoming requests.
  11.195 -            while port.request_to_read():
  11.196 -                msg = port.read_request()
  11.197 -                work_done = True
  11.198 -                type = (msg.get_header())['type']
  11.199 -                if type == CMSG_CONSOLE and con_if:
  11.200 -                    con_if.ctrlif_rx_req(port, msg)
  11.201 -                elif type == CMSG_BLKIF_FE and blk_if:
  11.202 -                    blk_if.ctrlif_rx_req(port, msg)
  11.203 -                elif type == CMSG_BLKIF_BE and port == xend.blkif.be_port:
  11.204 -                    xend.blkif.backend_rx_req(port, msg)
  11.205 -                elif type == CMSG_NETIF_FE and net_if:
  11.206 -                    net_if.ctrlif_rx_req(port, msg)
  11.207 -                elif type == CMSG_NETIF_BE and port == xend.netif.be_port:
  11.208 -                    xend.netif.backend_rx_req(port, msg)
  11.209 -                else:
  11.210 -                    port.write_response(msg)
  11.211 -
  11.212 -            # Process incoming responses.
  11.213 -            while port.response_to_read():
  11.214 -                msg = port.read_response()
  11.215 -                work_done = True
  11.216 -                type = (msg.get_header())['type']
  11.217 -                if type == CMSG_BLKIF_BE and port == xend.blkif.be_port:
  11.218 -                    xend.blkif.backend_rx_rsp(port, msg)
  11.219 -                elif type == CMSG_NETIF_BE and port == xend.netif.be_port:
  11.220 -                    xend.netif.backend_rx_rsp(port, msg)
  11.221 -
  11.222 -            # Send console data.
  11.223 -            if con_if and con_if.ctrlif_transmit_work(port):
  11.224 -                work_done = True
  11.225 -
  11.226 -            # Send blkif messages.
  11.227 -            if blk_if and blk_if.ctrlif_transmit_work(port):
  11.228 -                work_done = True
  11.229 -
  11.230 -            # Send netif messages.
  11.231 -            if net_if and net_if.ctrlif_transmit_work(port):
  11.232 -                work_done = True
  11.233 -
  11.234 -            # Back-end block-device work.
  11.235 -            if port == dom0_port and xend.blkif.backend_do_work(port):
  11.236 -                work_done = True
  11.237 -                
  11.238 -            # Back-end network-device work.
  11.239 -            if port == xend.netif.be_port and xend.netif.backend_do_work(port):
  11.240 -                work_done = True
  11.241 -                
  11.242 -            # Finally, notify the remote end of any work that we did.
  11.243 -            if work_done:
  11.244 -                port.notify()
  11.245 -
  11.246 -            # Unmask notifications for this port.
  11.247 -            notifier.unmask(idx)
  11.248 -
  11.249 -
  11.250 -
  11.251 -def cleanup_daemon(kill=False):
  11.252 -    # No cleanup to do if the PID file is empty.
  11.253 -    if not os.path.isfile(PID) or not os.path.getsize(PID):
  11.254 -        return 0
  11.255 -    # Read the PID of the previous invocation and search active process list.
  11.256 -    pid = open(PID, 'r').read()
  11.257 -    lines = os.popen('ps ' + pid + ' 2>/dev/null').readlines()
  11.258 -    for line in lines:
  11.259 -        if re.search('^ *' + pid + '.+xend', line):
  11.260 -            if not kill:
  11.261 -                print "Daemon is already running (PID %d)" % int(pid)
  11.262 -                return 1
  11.263 -            # Old daemon is still active: terminate it.
  11.264 -            os.kill(int(pid), 1)
  11.265 -    # Delete the, now stale, PID file.
  11.266 -    os.remove(PID)
  11.267 -    return 0
  11.268 -
  11.269 -
  11.270 -
  11.271 -def start_daemon():
  11.272 -    if cleanup_daemon(kill=False):
  11.273 -        return 1
  11.274 -
  11.275 -    if not os.path.exists(CONTROL_DIR):
  11.276 -        os.mkdir(CONTROL_DIR)
  11.277 -
  11.278 -    # Open log file. Truncate it if non-empty, and request line buffering.
  11.279 -    if os.path.isfile(LOG):
  11.280 -        os.rename(LOG, LOG+'.old')
  11.281 -    logfile = open(LOG, 'w+', 1)
  11.282 -
  11.283 -    # Detach from TTY.
  11.284 -    os.setsid()
  11.285 -
  11.286 -    # Set the UID.
  11.287 -    try:
  11.288 -        os.setuid(pwd.getpwnam(USER)[2])
  11.289 -    except KeyError, error:
  11.290 -        print "Error: no such user '%s'" % USER
  11.291 -        return 1
  11.292 -
  11.293 -    # Ensure that zombie children are automatically reaped.
  11.294 -    xend.utils.autoreap()
  11.295 -
  11.296 -    # Fork -- parent writes the PID file and exits.
  11.297 -    pid = os.fork()
  11.298 -    if pid:
  11.299 -        pidfile = open(PID, 'w')
  11.300 -        pidfile.write(str(pid))
  11.301 -        pidfile.close()
  11.302 -        return 0
  11.303 -
  11.304 -    # Close down standard file handles
  11.305 -    try:
  11.306 -        os.close(0) # stdin
  11.307 -        os.close(1) # stdout
  11.308 -        os.close(2) # stderr
  11.309 -    except:
  11.310 -        pass
  11.311 -
  11.312 -    # Redirect output to log file, then enter the main loop.
  11.313 -    sys.stdout = sys.stderr = logfile
  11.314 -    daemon_loop()
  11.315 -    return 0
  11.316 -
  11.317 -
  11.318 -
  11.319 -def stop_daemon():
  11.320 -    return cleanup_daemon(kill=True)
    12.1 --- a/tools/xend-old/lib/manager.py	Mon Jun 28 08:20:16 2004 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,174 +0,0 @@
    12.4 -
    12.5 -#############################################################
    12.6 -## xend/manager.py -- Management-interface functions for Xend
    12.7 -## Copyright (c) 2004, K A Fraser (University of Cambridge)
    12.8 -#############################################################
    12.9 -
   12.10 -import xend.blkif, xend.netif, xend.console, xend.main, xend.utils
   12.11 -
   12.12 -
   12.13 -##
   12.14 -## new_control_interface:
   12.15 -##  Create a new control interface with the specified domain @dom.
   12.16 -##  The console port may also be specified; otherwise a suitable port is
   12.17 -##  automatically allocated.
   12.18 -##
   12.19 -def new_control_interface(dom, console_port=-1):
   12.20 -    # Allocate an event channel and binbd to it.
   12.21 -    port = xend.utils.port(dom)
   12.22 -    xend.main.notifier.bind(port.local_port)
   12.23 -    
   12.24 -    # If necessary, compute a suitable TCP port for console I/O.
   12.25 -    if console_port < 0:
   12.26 -        console_port = 9600 + port.local_port
   12.27 -
   12.28 -    # Create a listening console interface.
   12.29 -    con_if = xend.console.interface(console_port, port.local_port)
   12.30 -    con_if.listen()
   12.31 -
   12.32 -    # Update the master port list.
   12.33 -    xend.main.port_list[port.local_port] = port
   12.34 -
   12.35 -    # Construct the successful response to be returned to the requester.
   12.36 -    response = { 'success': True }
   12.37 -    response['local_port']   = port.local_port
   12.38 -    response['remote_port']  = port.remote_port
   12.39 -    response['console_port'] = console_port
   12.40 -    return response
   12.41 -
   12.42 -
   12.43 -##
   12.44 -## new_block_interface:
   12.45 -##  Create a new block interface for the specified domain @dom.
   12.46 -##
   12.47 -def new_block_interface(dom, handle=-1):
   12.48 -    # By default we create an interface with handle zero.
   12.49 -    if handle < 0:
   12.50 -        handle = 0
   12.51 -
   12.52 -    # We only support one interface per domain, which must have handle zero.
   12.53 -    if handle != 0:
   12.54 -        response = { 'success': False }
   12.55 -        response['error_type'] = 'Bad handle %d (only handle 0 ' + \
   12.56 -                                 'is supported)' % handle
   12.57 -        return response
   12.58 -
   12.59 -    # Find local event-channel port associated with the specified domain.
   12.60 -    port = xend.main.port_from_dom(dom)
   12.61 -    if not port:
   12.62 -        response = { 'success': False }
   12.63 -        response['error_type'] = 'Unknown domain %d' % dom
   12.64 -        return response
   12.65 -
   12.66 -    # The interface must not already exist.
   12.67 -    if xend.blkif.interface.list.has_key(port.local_port):
   12.68 -        response = { 'success': False }
   12.69 -        response['error_type'] = 'Interface (dom=%d,handle=%d) already ' + \
   12.70 -                                 'exists' % (dom, handle)
   12.71 -        return response
   12.72 -
   12.73 -    # Create the new interface. Initially no virtual devices are attached.
   12.74 -    xend.blkif.interface(dom, port.local_port)
   12.75 -
   12.76 -    # Response is deferred until back-end driver sends acknowledgement.
   12.77 -    return None
   12.78 -
   12.79 -
   12.80 -##
   12.81 -## new_block_device:
   12.82 -##  Attach a new virtual block device to the specified block interface
   12.83 -##  (@dom, @handle). The new device is identified by @vdev, and maps to
   12.84 -##  the real block extent (@pdev, @start_sect, @nr_sect). If @readonly then
   12.85 -##  write requests to @vdev will be rejected.
   12.86 -##
   12.87 -def new_block_device(dom, handle, vdev, pdev, start_sect, nr_sect, readonly):
   12.88 -    # We only support one interface per domain, which must have handle zero.
   12.89 -    if handle != 0:
   12.90 -        response = { 'success': False }
   12.91 -        response['error_type'] = 'Bad handle %d (only handle 0 ' + \
   12.92 -                                 'is supported)' % handle
   12.93 -        return response
   12.94 -
   12.95 -    # Find local event-channel port associated with the specified domain.
   12.96 -    port = xend.main.port_from_dom(dom)
   12.97 -    if not port:
   12.98 -        response = { 'success': False }
   12.99 -        response['error_type'] = 'Unknown domain %d' % dom
  12.100 -        return response
  12.101 -        
  12.102 -    # The interface must exist.
  12.103 -    if not xend.blkif.interface.list.has_key(port.local_port):
  12.104 -        response = { 'success': False }
  12.105 -        response['error_type'] = 'Interface (dom=%d,handle=%d) does not ' + \
  12.106 -                                 'exists' % (dom, handle)
  12.107 -        return response
  12.108 -
  12.109 -    # The virtual device must not yet exist.
  12.110 -    blkif = xend.blkif.interface.list[port.local_port]
  12.111 -    if not blkif.attach_device(vdev, pdev, start_sect, nr_sect, readonly):
  12.112 -        response = { 'success': False }
  12.113 -        response['error_type'] = 'Vdevice (dom=%d,handle=%d,vdevice=%d) ' + \
  12.114 -                                 'already exists' % (dom, handle, vdev)
  12.115 -        return response
  12.116 -
  12.117 -    # Response is deferred until back-end driver sends acknowledgement.
  12.118 -    return None
  12.119 -
  12.120 -
  12.121 -##
  12.122 -## new_network_interface:
  12.123 -##  Create a new network interface for the specified domain @dom.
  12.124 -##
  12.125 -def new_network_interface(dom, handle=-1):
  12.126 -    # By default we create an interface with handle zero.
  12.127 -    if handle < 0:
  12.128 -        handle = 0
  12.129 -
  12.130 -    # We only support one interface per domain, which must have handle zero.
  12.131 -    if handle != 0:
  12.132 -        response = { 'success': False }
  12.133 -        response['error_type'] = 'Bad handle %d (only handle 0 ' + \
  12.134 -                                 'is supported)' % handle
  12.135 -        return response
  12.136 -
  12.137 -    # Find local event-channel port associated with the specified domain.
  12.138 -    port = xend.main.port_from_dom(dom)
  12.139 -    if not port:
  12.140 -        response = { 'success': False }
  12.141 -        response['error_type'] = 'Unknown domain %d' % dom
  12.142 -        return response
  12.143 -
  12.144 -    # The interface must not already exist.
  12.145 -    if xend.netif.interface.list.has_key(port.local_port):
  12.146 -        response = { 'success': False }
  12.147 -        response['error_type'] = 'Interface (dom=%d,handle=%d) already ' + \
  12.148 -                                 'exists' % (dom, handle)
  12.149 -        return response
  12.150 -
  12.151 -    # Create the new interface. Initially no virtual devices are attached.
  12.152 -    xend.netif.interface(dom, port.local_port)
  12.153 -
  12.154 -    # Response is deferred until back-end driver sends acknowledgement.
  12.155 -    return None
  12.156 -
  12.157 -##
  12.158 -## set_network_backend
  12.159 -##   Authorise a domain to act as the net backend (assumes we only have one
  12.160 -##   backend driver for now).  After this call, back end "up" notifications
  12.161 -##   for the network will only be accepted from this domain.
  12.162 -##
  12.163 -def set_network_backend(dom):
  12.164 -    if xend.netif.be_port.remote_dom != 0:
  12.165 -        xend.netif.recovery = True
  12.166 -    xend.netif.be_port = xend.main.port_from_dom(dom)
  12.167 -    return { 'success' : True }
  12.168 -
  12.169 -##
  12.170 -## set_block_backend
  12.171 -##  Authorise a domain to act as the block backend (assumes we only have one
  12.172 -##  backend driver for now).  After this call, back end "up" notifications
  12.173 -##  for the network will only be accepted from this domain.
  12.174 -def set_block_backend(dom):
  12.175 -    if xend.blkif.be_port: xend.blkif.recovery = True
  12.176 -    xend.blkif.be_port = xend.main.port_from_dom(dom)
  12.177 -    return { 'success' : True }
    13.1 --- a/tools/xend-old/lib/netif.py	Mon Jun 28 08:20:16 2004 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,187 +0,0 @@
    13.4 -
    13.5 -###################################################################
    13.6 -## xend/netif.py -- Network-interface management functions for Xend
    13.7 -## Copyright (c) 2004, K A Fraser (University of Cambridge)
    13.8 -###################################################################
    13.9 -
   13.10 -import errno, random, re, os, select, signal, socket, struct, sys
   13.11 -import xend.main, xend.console, xend.manager, xend.utils, Xc
   13.12 -
   13.13 -CMSG_NETIF_BE = 3
   13.14 -CMSG_NETIF_FE = 4
   13.15 -CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED =  0
   13.16 -CMSG_NETIF_FE_DRIVER_STATUS_CHANGED    = 32
   13.17 -CMSG_NETIF_BE_DRIVER_STATUS_CHANGED    = 32
   13.18 -CMSG_NETIF_FE_INTERFACE_CONNECT        = 33
   13.19 -CMSG_NETIF_FE_INTERFACE_DISCONNECT     = 34
   13.20 -CMSG_NETIF_BE_CREATE      = 0
   13.21 -CMSG_NETIF_BE_DESTROY     = 1
   13.22 -CMSG_NETIF_BE_CONNECT     = 2
   13.23 -CMSG_NETIF_BE_DISCONNECT  = 3
   13.24 -
   13.25 -NETIF_DRIVER_STATUS_DOWN  = 0
   13.26 -NETIF_DRIVER_STATUS_UP    = 1
   13.27 -
   13.28 -pendmsg = None
   13.29 -pendaddr = None
   13.30 -
   13.31 -recovery = False # Is a recovery in progress?
   13.32 -be_port  = None  # Port object for backend domain
   13.33 -
   13.34 -def backend_tx_req(msg):
   13.35 -    if xend.netif.be_port.space_to_write_request():
   13.36 -        xend.netif.be_port.write_request(msg)
   13.37 -        xend.netif.be_port.notify()
   13.38 -    else:
   13.39 -        xend.netif.pendmsg = msg
   13.40 -
   13.41 -def backend_rx_req(port, msg):
   13.42 -    port.write_response(msg)
   13.43 -    subtype = (msg.get_header())['subtype']
   13.44 -    print "Received netif-be request, subtype %d" % subtype
   13.45 -    if subtype == CMSG_NETIF_BE_DRIVER_STATUS_CHANGED:
   13.46 -        pl = msg.get_payload()
   13.47 -        status = pl['status']
   13.48 -        if status == NETIF_DRIVER_STATUS_UP:
   13.49 -            if xend.netif.recovery:
   13.50 -                print "New netif backend now UP, notifying guests:"
   13.51 -                for netif_key in interface.list.keys():
   13.52 -                    netif = interface.list[netif_key]
   13.53 -                    netif.create()
   13.54 -                    print "  Notifying %d" % netif.dom
   13.55 -                    msg = xend.utils.message(
   13.56 -                        CMSG_NETIF_FE,
   13.57 -                        CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED, 0,
   13.58 -                        { 'handle' : 0, 'status' : 1 })
   13.59 -                    netif.ctrlif_tx_req(xend.main.port_from_dom(netif.dom),msg)
   13.60 -                print "Done notifying guests"
   13.61 -                recovery = False
   13.62 -        else:
   13.63 -            print "Unexpected net backend driver status: %d" % status
   13.64 -
   13.65 -def backend_rx_rsp(port, msg):
   13.66 -    subtype = (msg.get_header())['subtype']
   13.67 -    print "Received netif-be response, subtype %d" % subtype
   13.68 -    if subtype == CMSG_NETIF_BE_CREATE:
   13.69 -        rsp = { 'success': True }
   13.70 -        xend.main.send_management_response(rsp, xend.netif.pendaddr)
   13.71 -    elif subtype == CMSG_NETIF_BE_CONNECT:
   13.72 -        pl = msg.get_payload()
   13.73 -        (dom, hnd, evtchn, tx_frame, rx_frame, st) = (
   13.74 -            pl['domid'], pl['netif_handle'], pl['evtchn'],
   13.75 -            pl['tx_shmem_frame'], pl['rx_shmem_frame'], pl['status'])
   13.76 -        netif = interface.list[xend.main.port_from_dom(dom).local_port]
   13.77 -        msg = xend.utils.message(CMSG_NETIF_FE,
   13.78 -                                 CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED, 0,
   13.79 -                                 { 'handle' : 0, 'status' : 2,
   13.80 -                                   'evtchn' : netif.evtchn['port2'],
   13.81 -                                   'mac[0]' : netif.mac[0],
   13.82 -                                   'mac[1]' : netif.mac[1],
   13.83 -                                   'mac[2]' : netif.mac[2],
   13.84 -                                   'mac[3]' : netif.mac[3],
   13.85 -                                   'mac[4]' : netif.mac[4],
   13.86 -                                   'mac[5]' : netif.mac[5] })
   13.87 -        netif.ctrlif_tx_req(xend.main.port_list[netif.key], msg)
   13.88 -
   13.89 -def backend_do_work(port):
   13.90 -    global pendmsg
   13.91 -    if pendmsg and port.space_to_write_request():
   13.92 -        port.write_request(pendmsg)
   13.93 -        pendmsg = None
   13.94 -        return True
   13.95 -    return False
   13.96 -
   13.97 -
   13.98 -class interface:
   13.99 -
  13.100 -    # Dictionary of all network-device interfaces.
  13.101 -    list = {}
  13.102 -
  13.103 -    drvdom = None
  13.104 -
  13.105 -    # NB. 'key' is an opaque value that has no meaning in this class.
  13.106 -    def __init__(self, dom, key):
  13.107 -        self.dom     = dom
  13.108 -        self.key     = key
  13.109 -        self.pendmsg = None
  13.110 -
  13.111 -        # VIFs get a random MAC address with a "special" vendor id.
  13.112 -        # 
  13.113 -        # NB. The vendor is currently an "obsolete" one that used to belong
  13.114 -        # to DEC (AA-00-00). Using it is probably a bit rude :-)
  13.115 -        # 
  13.116 -        # NB2. The first bit of the first random octet is set to zero for
  13.117 -        # all dynamic MAC addresses. This may allow us to manually specify
  13.118 -        # MAC addresses for some VIFs with no fear of clashes.
  13.119 -        self.mac = [ 0xaa, 0x00, 0x00 ]
  13.120 -        self.mac.append(int(random.random()*128))
  13.121 -        self.mac.append(int(random.random()*256))
  13.122 -        self.mac.append(int(random.random()*256))
  13.123 -                
  13.124 -        interface.list[key] = self
  13.125 -        self.create()
  13.126 -
  13.127 -    def create(self):
  13.128 -        """Notify the current network back end to create the virtual interface
  13.129 -        represented by this object."""
  13.130 -        msg = xend.utils.message(CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE, 0,
  13.131 -                                 { 'domid' : self.dom, 'netif_handle' : 0,
  13.132 -                                   'mac[0]' : self.mac[0],
  13.133 -                                   'mac[1]' : self.mac[1],
  13.134 -                                   'mac[2]' : self.mac[2],
  13.135 -                                   'mac[3]' : self.mac[3],
  13.136 -                                   'mac[4]' : self.mac[4],
  13.137 -                                   'mac[5]' : self.mac[5] })
  13.138 -        xend.netif.pendaddr = xend.main.mgmt_req_addr
  13.139 -        backend_tx_req(msg)
  13.140 -
  13.141 -
  13.142 -    # Completely destroy this interface.
  13.143 -    def destroy(self):
  13.144 -        del interface.list[self.key]
  13.145 -        msg = xend.utils.message(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY, 0,
  13.146 -                                 { 'domid' : self.dom, 'netif_handle' : 0 })
  13.147 -        backend_tx_req(msg)        
  13.148 -
  13.149 -
  13.150 -    # The parameter @port is the control-interface event channel. This method
  13.151 -    # returns True if messages were written to the control interface.
  13.152 -    def ctrlif_transmit_work(self, port):
  13.153 -        if self.pendmsg and port.space_to_write_request():
  13.154 -            port.write_request(self.pendmsg)
  13.155 -            self.pendmsg = None
  13.156 -            return True
  13.157 -        return False
  13.158 -
  13.159 -    def ctrlif_tx_req(self, port, msg):
  13.160 -        if port.space_to_write_request():
  13.161 -            port.write_request(msg)
  13.162 -            port.notify()
  13.163 -        else:
  13.164 -            self.pendmsg = msg
  13.165 -
  13.166 -    def ctrlif_rx_req(self, port, msg):
  13.167 -        port.write_response(msg)
  13.168 -        subtype = (msg.get_header())['subtype']
  13.169 -        if subtype == CMSG_NETIF_FE_DRIVER_STATUS_CHANGED:
  13.170 -            print "netif driver up message from %d" % port.remote_dom
  13.171 -            msg = xend.utils.message(CMSG_NETIF_FE,
  13.172 -                                     CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED, 0,
  13.173 -                                     { 'handle' : 0, 'status' : 1 })
  13.174 -            self.ctrlif_tx_req(port, msg)
  13.175 -        elif subtype == CMSG_NETIF_FE_INTERFACE_CONNECT:
  13.176 -            print "netif connect request from %d" % port.remote_dom
  13.177 -            pl = msg.get_payload()
  13.178 -            (hnd, tx_frame, rx_frame) = (pl['handle'], pl['tx_shmem_frame'],
  13.179 -                                         pl['rx_shmem_frame'])
  13.180 -            xc = Xc.new()
  13.181 -            self.evtchn = xc.evtchn_bind_interdomain(
  13.182 -                dom1=xend.netif.be_port.remote_dom,
  13.183 -                dom2=self.dom)
  13.184 -            msg = xend.utils.message(CMSG_NETIF_BE,
  13.185 -                                     CMSG_NETIF_BE_CONNECT, 0,
  13.186 -                                     { 'domid' : self.dom, 'netif_handle' : 0,
  13.187 -                                       'tx_shmem_frame' : tx_frame,
  13.188 -                                       'rx_shmem_frame' : rx_frame,
  13.189 -                                       'evtchn' : self.evtchn['port1'] })
  13.190 -            backend_tx_req(msg)
    14.1 --- a/tools/xend-old/lib/utils.c	Mon Jun 28 08:20:16 2004 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,1384 +0,0 @@
    14.4 -/******************************************************************************
    14.5 - * utils.c
    14.6 - * 
    14.7 - * Copyright (c) 2004, K A Fraser
    14.8 - */
    14.9 -
   14.10 -#include <Python.h>
   14.11 -#include <stdio.h>
   14.12 -#include <stdlib.h>
   14.13 -#include <string.h>
   14.14 -#include <sys/ioctl.h>
   14.15 -#include <sys/types.h>
   14.16 -#include <sys/wait.h>
   14.17 -#include <sys/stat.h>
   14.18 -#include <sys/socket.h>
   14.19 -#include <sys/mman.h>
   14.20 -#include <sys/poll.h>
   14.21 -#include <netinet/in.h>
   14.22 -#include <fcntl.h>
   14.23 -#include <unistd.h>
   14.24 -#include <errno.h>
   14.25 -#include <signal.h>
   14.26 -#include <xc.h>
   14.27 -
   14.28 -#include <hypervisor-if.h>
   14.29 -#include "domain_controller.h"
   14.30 -
   14.31 -#include <asm-xen/proc_cmd.h>
   14.32 -
   14.33 -/* Needed for Python versions earlier than 2.3. */
   14.34 -#ifndef PyMODINIT_FUNC
   14.35 -#define PyMODINIT_FUNC DL_EXPORT(void)
   14.36 -#endif
   14.37 -
   14.38 -/* NB. The following should be kept in sync with the kernel's evtchn driver. */
   14.39 -#define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
   14.40 -#define EVTCHN_DEV_MAJOR 10
   14.41 -#define EVTCHN_DEV_MINOR 200
   14.42 -#define PORT_NORMAL     0x0000   /* A standard event notification.      */ 
   14.43 -#define PORT_EXCEPTION  0x8000   /* An exceptional notification.        */
   14.44 -#define PORTIDX_MASK    0x7fff   /* Strip subtype to obtain port index. */
   14.45 -/* /dev/xen/evtchn ioctls: */
   14.46 -/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
   14.47 -#define EVTCHN_RESET  _IO('E', 1)
   14.48 -/* EVTCHN_BIND: Bind to teh specified event-channel port. */
   14.49 -#define EVTCHN_BIND   _IO('E', 2)
   14.50 -/* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
   14.51 -#define EVTCHN_UNBIND _IO('E', 3)
   14.52 -
   14.53 -/* Size of a machine page frame. */
   14.54 -#define PAGE_SIZE 4096
   14.55 -
   14.56 -
   14.57 -/*
   14.58 - * *********************** NOTIFIER ***********************
   14.59 - */
   14.60 -
   14.61 -typedef struct {
   14.62 -    PyObject_HEAD;
   14.63 -    int evtchn_fd;
   14.64 -} xu_notifier_object;
   14.65 -
   14.66 -static PyObject *xu_notifier_read(PyObject *self, PyObject *args)
   14.67 -{
   14.68 -    xu_notifier_object *xun = (xu_notifier_object *)self;
   14.69 -    u16 v;
   14.70 -    int bytes;
   14.71 -
   14.72 -    if ( !PyArg_ParseTuple(args, "") )
   14.73 -        return NULL;
   14.74 -    
   14.75 -    while ( (bytes = read(xun->evtchn_fd, &v, sizeof(v))) == -1 )
   14.76 -    {
   14.77 -        if ( errno == EINTR )
   14.78 -            continue;
   14.79 -        if ( errno == EAGAIN )
   14.80 -            goto none;
   14.81 -        return PyErr_SetFromErrno(PyExc_IOError);
   14.82 -    }
   14.83 -    
   14.84 -    if ( bytes == sizeof(v) )
   14.85 -        return Py_BuildValue("(i,i)", v&PORTIDX_MASK, v&~PORTIDX_MASK);
   14.86 -
   14.87 - none:
   14.88 -    Py_INCREF(Py_None);
   14.89 -    return Py_None;
   14.90 -}
   14.91 -
   14.92 -static PyObject *xu_notifier_unmask(PyObject *self, PyObject *args)
   14.93 -{
   14.94 -    xu_notifier_object *xun = (xu_notifier_object *)self;
   14.95 -    u16 v;
   14.96 -    int idx;
   14.97 -
   14.98 -    if ( !PyArg_ParseTuple(args, "i", &idx) )
   14.99 -        return NULL;
  14.100 -
  14.101 -    v = (u16)idx;
  14.102 -    
  14.103 -    (void)write(xun->evtchn_fd, &v, sizeof(v));
  14.104 -
  14.105 -    Py_INCREF(Py_None);
  14.106 -    return Py_None;
  14.107 -}
  14.108 -
  14.109 -static PyObject *xu_notifier_bind(PyObject *self, PyObject *args)
  14.110 -{
  14.111 -    xu_notifier_object *xun = (xu_notifier_object *)self;
  14.112 -    int idx;
  14.113 -
  14.114 -    if ( !PyArg_ParseTuple(args, "i", &idx) )
  14.115 -        return NULL;
  14.116 -
  14.117 -    if ( ioctl(xun->evtchn_fd, EVTCHN_BIND, idx) != 0 )
  14.118 -        return PyErr_SetFromErrno(PyExc_IOError);
  14.119 -
  14.120 -    Py_INCREF(Py_None);
  14.121 -    return Py_None;
  14.122 -}
  14.123 -
  14.124 -static PyObject *xu_notifier_unbind(PyObject *self, PyObject *args)
  14.125 -{
  14.126 -    xu_notifier_object *xun = (xu_notifier_object *)self;
  14.127 -    int idx;
  14.128 -
  14.129 -    if ( !PyArg_ParseTuple(args, "i", &idx) )
  14.130 -        return NULL;
  14.131 -
  14.132 -    if ( ioctl(xun->evtchn_fd, EVTCHN_UNBIND, idx) != 0 )
  14.133 -        return PyErr_SetFromErrno(PyExc_IOError);
  14.134 -
  14.135 -    Py_INCREF(Py_None);
  14.136 -    return Py_None;
  14.137 -}
  14.138 -
  14.139 -static PyObject *xu_notifier_fileno(PyObject *self, PyObject *args)
  14.140 -{
  14.141 -    xu_notifier_object *xun = (xu_notifier_object *)self;
  14.142 -    return PyInt_FromLong(xun->evtchn_fd);
  14.143 -}
  14.144 -
  14.145 -static PyMethodDef xu_notifier_methods[] = {
  14.146 -    { "read",
  14.147 -      (PyCFunction)xu_notifier_read,
  14.148 -      METH_VARARGS,
  14.149 -      "Read a (@port, @type) pair.\n" },
  14.150 -
  14.151 -    { "unmask", 
  14.152 -      (PyCFunction)xu_notifier_unmask,
  14.153 -      METH_VARARGS,
  14.154 -      "Unmask notifications for a @port.\n" },
  14.155 -
  14.156 -    { "bind", 
  14.157 -      (PyCFunction)xu_notifier_bind,
  14.158 -      METH_VARARGS,
  14.159 -      "Get notifications for a @port.\n" },
  14.160 -
  14.161 -    { "unbind", 
  14.162 -      (PyCFunction)xu_notifier_unbind,
  14.163 -      METH_VARARGS,
  14.164 -      "No longer get notifications for a @port.\n" },
  14.165 -
  14.166 -    { "fileno", 
  14.167 -      (PyCFunction)xu_notifier_fileno,
  14.168 -      METH_VARARGS,
  14.169 -      "Return the file descriptor for the notification channel.\n" },
  14.170 -
  14.171 -    { NULL, NULL, 0, NULL }
  14.172 -};
  14.173 -
  14.174 -staticforward PyTypeObject xu_notifier_type;
  14.175 -
  14.176 -static PyObject *xu_notifier_new(PyObject *self, PyObject *args)
  14.177 -{
  14.178 -    xu_notifier_object *xun;
  14.179 -
  14.180 -    if ( !PyArg_ParseTuple(args, "") )
  14.181 -        return NULL;
  14.182 -
  14.183 -    xun = PyObject_New(xu_notifier_object, &xu_notifier_type);
  14.184 -
  14.185 - reopen:
  14.186 -    xun->evtchn_fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
  14.187 -    if ( xun->evtchn_fd == -1 )
  14.188 -    {
  14.189 -        if ( (errno == ENOENT) &&
  14.190 -             ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
  14.191 -             (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600, 
  14.192 -                    (EVTCHN_DEV_MAJOR << 8) | EVTCHN_DEV_MINOR) == 0) )
  14.193 -            goto reopen;
  14.194 -        PyObject_Del((PyObject *)xun);
  14.195 -        return PyErr_SetFromErrno(PyExc_IOError);
  14.196 -    }
  14.197 -
  14.198 -    return (PyObject *)xun;
  14.199 -}
  14.200 -
  14.201 -static PyObject *xu_notifier_getattr(PyObject *obj, char *name)
  14.202 -{
  14.203 -    if ( strcmp(name, "EXCEPTION") == 0 )
  14.204 -        return PyInt_FromLong(PORT_EXCEPTION);
  14.205 -    if ( strcmp(name, "NORMAL") == 0 )
  14.206 -        return PyInt_FromLong(PORT_NORMAL);
  14.207 -    return Py_FindMethod(xu_notifier_methods, obj, name);
  14.208 -}
  14.209 -
  14.210 -static void xu_notifier_dealloc(PyObject *self)
  14.211 -{
  14.212 -    xu_notifier_object *xun = (xu_notifier_object *)self;
  14.213 -    (void)close(xun->evtchn_fd);
  14.214 -    PyObject_Del(self);
  14.215 -}
  14.216 -
  14.217 -static PyTypeObject xu_notifier_type = {
  14.218 -    PyObject_HEAD_INIT(&PyType_Type)
  14.219 -    0,
  14.220 -    "notifier",
  14.221 -    sizeof(xu_notifier_object),
  14.222 -    0,
  14.223 -    xu_notifier_dealloc, /* tp_dealloc     */
  14.224 -    NULL,                /* tp_print       */
  14.225 -    xu_notifier_getattr, /* tp_getattr     */
  14.226 -    NULL,                /* tp_setattr     */
  14.227 -    NULL,                /* tp_compare     */
  14.228 -    NULL,                /* tp_repr        */
  14.229 -    NULL,                /* tp_as_number   */
  14.230 -    NULL,                /* tp_as_sequence */
  14.231 -    NULL,                /* tp_as_mapping  */
  14.232 -    NULL                 /* tp_hash        */
  14.233 -};
  14.234 -
  14.235 -
  14.236 -
  14.237 -/*
  14.238 - * *********************** MESSAGE ***********************
  14.239 - */
  14.240 -
  14.241 -#define TYPE(_x,_y) (((_x)<<8)|(_y))
  14.242 -#define P2C(_struct, _field, _ctype)                                      \
  14.243 -    do {                                                                  \
  14.244 -        PyObject *obj;                                                    \
  14.245 -        if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL )     \
  14.246 -        {                                                                 \
  14.247 -            if ( PyInt_Check(obj) )                                       \
  14.248 -            {                                                             \
  14.249 -                ((_struct *)&xum->msg.msg[0])->_field =                   \
  14.250 -                  (_ctype)PyInt_AsLong(obj);                              \
  14.251 -                dict_items_parsed++;                                      \
  14.252 -            }                                                             \
  14.253 -            else if ( PyLong_Check(obj) )                                 \
  14.254 -            {                                                             \
  14.255 -                ((_struct *)&xum->msg.msg[0])->_field =                   \
  14.256 -                  (_ctype)PyLong_AsUnsignedLongLong(obj);                 \
  14.257 -                dict_items_parsed++;                                      \
  14.258 -            }                                                             \
  14.259 -        }                                                                 \
  14.260 -        xum->msg.length = sizeof(_struct);                                \
  14.261 -    } while ( 0 )
  14.262 -#define C2P(_struct, _field, _pytype, _ctype)                             \
  14.263 -    do {                                                                  \
  14.264 -        PyObject *obj = Py ## _pytype ## _From ## _ctype                  \
  14.265 -                        (((_struct *)&xum->msg.msg[0])->_field);          \
  14.266 -        if ( dict == NULL ) dict = PyDict_New();                          \
  14.267 -        PyDict_SetItemString(dict, #_field, obj);                         \
  14.268 -    } while ( 0 )
  14.269 -
  14.270 -typedef struct {
  14.271 -    PyObject_HEAD;
  14.272 -    control_msg_t msg;
  14.273 -} xu_message_object;
  14.274 -
  14.275 -static PyObject *xu_message_append_payload(PyObject *self, PyObject *args)
  14.276 -{
  14.277 -    xu_message_object *xum = (xu_message_object *)self;
  14.278 -    char *str;
  14.279 -    int len;
  14.280 -
  14.281 -    if ( !PyArg_ParseTuple(args, "s#", &str, &len) )
  14.282 -        return NULL;
  14.283 -
  14.284 -    if ( (len + xum->msg.length) > sizeof(xum->msg.msg) )
  14.285 -    {
  14.286 -        PyErr_SetString(PyExc_RuntimeError, "out of space in control message");
  14.287 -        return NULL;
  14.288 -    }
  14.289 -
  14.290 -    memcpy(&xum->msg.msg[xum->msg.length], str, len);
  14.291 -    xum->msg.length += len;
  14.292 -
  14.293 -    Py_INCREF(Py_None);
  14.294 -    return Py_None;
  14.295 -}
  14.296 -
  14.297 -static PyObject *xu_message_set_response_fields(PyObject *self, PyObject *args)
  14.298 -{
  14.299 -    xu_message_object *xum = (xu_message_object *)self;
  14.300 -    PyObject *payload;
  14.301 -    int dict_items_parsed = 0;
  14.302 -
  14.303 -    if ( !PyArg_ParseTuple(args, "O", &payload) )
  14.304 -        return NULL;
  14.305 -
  14.306 -    if ( !PyDict_Check(payload) )
  14.307 -    {
  14.308 -        PyErr_SetString(PyExc_TypeError, "payload is not a dictionary");
  14.309 -        return NULL;
  14.310 -    }
  14.311 -
  14.312 -    switch ( TYPE(xum->msg.type, xum->msg.subtype) )
  14.313 -    {
  14.314 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED):
  14.315 -        P2C(blkif_fe_driver_status_changed_t, nr_interfaces, u32);
  14.316 -        break;
  14.317 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS_CHANGED):
  14.318 -        P2C(netif_fe_driver_status_changed_t, nr_interfaces, u32);
  14.319 -        break;
  14.320 -    }
  14.321 -
  14.322 -    if ( dict_items_parsed != PyDict_Size(payload) )
  14.323 -    {
  14.324 -        PyErr_SetString(PyExc_TypeError, "payload contains bad items");
  14.325 -        return NULL;
  14.326 -    }
  14.327 -
  14.328 -    Py_INCREF(Py_None);
  14.329 -    return Py_None;
  14.330 -}
  14.331 -
  14.332 -static PyObject *xu_message_get_payload(PyObject *self, PyObject *args)
  14.333 -{
  14.334 -    xu_message_object *xum = (xu_message_object *)self;
  14.335 -    PyObject *dict = NULL;
  14.336 -
  14.337 -    if ( !PyArg_ParseTuple(args, "") )
  14.338 -        return NULL;
  14.339 -
  14.340 -    switch ( TYPE(xum->msg.type, xum->msg.subtype) )
  14.341 -    {
  14.342 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED):
  14.343 -        C2P(blkif_fe_interface_status_changed_t, handle, Int, Long);
  14.344 -        C2P(blkif_fe_interface_status_changed_t, status, Int, Long);
  14.345 -        C2P(blkif_fe_interface_status_changed_t, evtchn, Int, Long);
  14.346 -        return dict;
  14.347 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED):
  14.348 -        C2P(blkif_fe_driver_status_changed_t, status, Int, Long);
  14.349 -        return dict;
  14.350 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_CONNECT):
  14.351 -        C2P(blkif_fe_interface_connect_t, handle,      Int, Long);
  14.352 -        C2P(blkif_fe_interface_connect_t, shmem_frame, Int, Long);
  14.353 -        return dict;
  14.354 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_DISCONNECT):
  14.355 -        C2P(blkif_fe_interface_disconnect_t, handle, Int, Long);
  14.356 -        return dict;
  14.357 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE):
  14.358 -        C2P(blkif_be_create_t, domid,        Int, Long);
  14.359 -        C2P(blkif_be_create_t, blkif_handle, Int, Long);
  14.360 -        C2P(blkif_be_create_t, status,       Int, Long);
  14.361 -        return dict;
  14.362 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY):
  14.363 -        C2P(blkif_be_destroy_t, domid,        Int, Long);
  14.364 -        C2P(blkif_be_destroy_t, blkif_handle, Int, Long);
  14.365 -        C2P(blkif_be_destroy_t, status,       Int, Long);
  14.366 -        return dict;
  14.367 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT):
  14.368 -        C2P(blkif_be_connect_t, domid,        Int, Long);
  14.369 -        C2P(blkif_be_connect_t, blkif_handle, Int, Long);
  14.370 -        C2P(blkif_be_connect_t, shmem_frame,  Int, Long);
  14.371 -        C2P(blkif_be_connect_t, evtchn,       Int, Long);
  14.372 -        C2P(blkif_be_connect_t, status,       Int, Long);
  14.373 -        return dict;
  14.374 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT):
  14.375 -        C2P(blkif_be_disconnect_t, domid,        Int, Long);
  14.376 -        C2P(blkif_be_disconnect_t, blkif_handle, Int, Long);
  14.377 -        C2P(blkif_be_disconnect_t, status,       Int, Long);
  14.378 -        return dict;
  14.379 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE):
  14.380 -        C2P(blkif_be_vbd_create_t, domid,        Int, Long);
  14.381 -        C2P(blkif_be_vbd_create_t, blkif_handle, Int, Long);
  14.382 -        C2P(blkif_be_vbd_create_t, vdevice,      Int, Long);
  14.383 -        C2P(blkif_be_vbd_create_t, readonly,     Int, Long);
  14.384 -        C2P(blkif_be_vbd_create_t, status,       Int, Long);
  14.385 -        return dict;
  14.386 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_DESTROY):
  14.387 -        C2P(blkif_be_vbd_destroy_t, domid,        Int, Long);
  14.388 -        C2P(blkif_be_vbd_destroy_t, blkif_handle, Int, Long);
  14.389 -        C2P(blkif_be_vbd_destroy_t, vdevice,      Int, Long);
  14.390 -        C2P(blkif_be_vbd_destroy_t, status,       Int, Long);
  14.391 -        return dict;
  14.392 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_GROW):
  14.393 -        C2P(blkif_be_vbd_grow_t, domid,         Int, Long);
  14.394 -        C2P(blkif_be_vbd_grow_t, blkif_handle,  Int, Long);
  14.395 -        C2P(blkif_be_vbd_grow_t, vdevice,       Int, Long);
  14.396 -        C2P(blkif_be_vbd_grow_t, extent.sector_start, 
  14.397 -             Long, UnsignedLongLong);
  14.398 -        C2P(blkif_be_vbd_grow_t, extent.sector_length, 
  14.399 -             Long, UnsignedLongLong);
  14.400 -        C2P(blkif_be_vbd_grow_t, extent.device, Int, Long);
  14.401 -        C2P(blkif_be_vbd_grow_t, status,        Int, Long);
  14.402 -        return dict;
  14.403 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_SHRINK):
  14.404 -        C2P(blkif_be_vbd_shrink_t, domid,        Int, Long);
  14.405 -        C2P(blkif_be_vbd_shrink_t, blkif_handle, Int, Long);
  14.406 -        C2P(blkif_be_vbd_shrink_t, vdevice,      Int, Long);
  14.407 -        C2P(blkif_be_vbd_shrink_t, status,       Int, Long);
  14.408 -        return dict;
  14.409 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED):
  14.410 -        C2P(blkif_be_driver_status_changed_t, status, Int, Long);
  14.411 -        return dict;
  14.412 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED):
  14.413 -        C2P(netif_fe_interface_status_changed_t, handle, Int, Long);
  14.414 -        C2P(netif_fe_interface_status_changed_t, status, Int, Long);
  14.415 -        C2P(netif_fe_interface_status_changed_t, evtchn, Int, Long);
  14.416 -        return dict;
  14.417 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS_CHANGED):
  14.418 -        C2P(netif_fe_driver_status_changed_t, status,        Int, Long);
  14.419 -        C2P(netif_fe_driver_status_changed_t, nr_interfaces, Int, Long);
  14.420 -        return dict;
  14.421 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_CONNECT):
  14.422 -        C2P(netif_fe_interface_connect_t, handle,         Int, Long);
  14.423 -        C2P(netif_fe_interface_connect_t, tx_shmem_frame, Int, Long);
  14.424 -        C2P(netif_fe_interface_connect_t, rx_shmem_frame, Int, Long);
  14.425 -        return dict;
  14.426 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_DISCONNECT):
  14.427 -        C2P(netif_fe_interface_disconnect_t, handle, Int, Long);
  14.428 -        return dict;
  14.429 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE):
  14.430 -        C2P(netif_be_create_t, domid,        Int, Long);
  14.431 -        C2P(netif_be_create_t, netif_handle, Int, Long);
  14.432 -        C2P(netif_be_create_t, status,       Int, Long);
  14.433 -        return dict;
  14.434 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
  14.435 -        C2P(netif_be_destroy_t, domid,        Int, Long);
  14.436 -        C2P(netif_be_destroy_t, netif_handle, Int, Long);
  14.437 -        C2P(netif_be_destroy_t, status,       Int, Long);
  14.438 -        return dict;
  14.439 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT):
  14.440 -        C2P(netif_be_connect_t, domid,          Int, Long);
  14.441 -        C2P(netif_be_connect_t, netif_handle,   Int, Long);
  14.442 -        C2P(netif_be_connect_t, tx_shmem_frame, Int, Long);
  14.443 -        C2P(netif_be_connect_t, rx_shmem_frame, Int, Long);
  14.444 -        C2P(netif_be_connect_t, evtchn,         Int, Long);
  14.445 -        C2P(netif_be_connect_t, status,         Int, Long);
  14.446 -        return dict;
  14.447 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DISCONNECT):
  14.448 -        C2P(netif_be_disconnect_t, domid,        Int, Long);
  14.449 -        C2P(netif_be_disconnect_t, netif_handle, Int, Long);
  14.450 -        C2P(netif_be_disconnect_t, status,       Int, Long);
  14.451 -        return dict;
  14.452 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DRIVER_STATUS_CHANGED):
  14.453 -        C2P(netif_be_driver_status_changed_t, status, Int, Long);
  14.454 -        return dict;
  14.455 -    }
  14.456 -
  14.457 -    return PyString_FromStringAndSize(xum->msg.msg, xum->msg.length);
  14.458 -}
  14.459 -
  14.460 -static PyObject *xu_message_get_header(PyObject *self, PyObject *args)
  14.461 -{
  14.462 -    xu_message_object *xum = (xu_message_object *)self;
  14.463 -
  14.464 -    if ( !PyArg_ParseTuple(args, "") )
  14.465 -        return NULL;
  14.466 -
  14.467 -    return Py_BuildValue("{s:i,s:i,s:i}",
  14.468 -                         "type",    xum->msg.type,
  14.469 -                         "subtype", xum->msg.subtype,
  14.470 -                         "id",      xum->msg.id);
  14.471 -}
  14.472 -
  14.473 -static PyMethodDef xu_message_methods[] = {
  14.474 -    { "append_payload", 
  14.475 -      (PyCFunction)xu_message_append_payload,
  14.476 -      METH_VARARGS,
  14.477 -      "Append @str to the message payload.\n" },
  14.478 -
  14.479 -    { "set_response_fields",
  14.480 -      (PyCFunction)xu_message_set_response_fields,
  14.481 -      METH_VARARGS,
  14.482 -      "Fill in the response fields in a message that was passed to us.\n" },
  14.483 -
  14.484 -    { "get_payload",
  14.485 -      (PyCFunction)xu_message_get_payload,
  14.486 -      METH_VARARGS,
  14.487 -      "Return the message payload in string form.\n" },
  14.488 -
  14.489 -    { "get_header",
  14.490 -      (PyCFunction)xu_message_get_header,
  14.491 -      METH_VARARGS,
  14.492 -      "Returns a dictionary of values for @type, @subtype, and @id.\n" },
  14.493 -
  14.494 -    { NULL, NULL, 0, NULL }
  14.495 -};
  14.496 -
  14.497 -staticforward PyTypeObject xu_message_type;
  14.498 -
  14.499 -static PyObject *xu_message_new(PyObject *self, PyObject *args)
  14.500 -{
  14.501 -    xu_message_object *xum;
  14.502 -    int type, subtype, id, dict_items_parsed = 0;
  14.503 -    PyObject *payload = NULL;
  14.504 -
  14.505 -    if ( !PyArg_ParseTuple(args, "iii|O", &type, &subtype, &id, &payload) )
  14.506 -        return NULL;
  14.507 -
  14.508 -    xum = PyObject_New(xu_message_object, &xu_message_type);
  14.509 -
  14.510 -    xum->msg.type    = type;
  14.511 -    xum->msg.subtype = subtype;
  14.512 -    xum->msg.id      = id;
  14.513 -    xum->msg.length  = 0;
  14.514 -
  14.515 -    if ( payload == NULL )
  14.516 -        return (PyObject *)xum;
  14.517 -
  14.518 -    if ( !PyDict_Check(payload) )
  14.519 -    {
  14.520 -        PyErr_SetString(PyExc_TypeError, "payload is not a dictionary");
  14.521 -        PyObject_Del((PyObject *)xum);
  14.522 -        return NULL;
  14.523 -    }
  14.524 -
  14.525 -    switch ( TYPE(type, subtype) )
  14.526 -    {
  14.527 -    case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_STATUS_CHANGED):
  14.528 -        P2C(blkif_fe_interface_status_changed_t, handle, u32);
  14.529 -        P2C(blkif_fe_interface_status_changed_t, status, u32);
  14.530 -        P2C(blkif_fe_interface_status_changed_t, evtchn, u16);
  14.531 -        break;
  14.532 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE):
  14.533 -        P2C(blkif_be_create_t, domid,        u32);
  14.534 -        P2C(blkif_be_create_t, blkif_handle, u32);
  14.535 -        break;
  14.536 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY):
  14.537 -        P2C(blkif_be_destroy_t, domid,        u32);
  14.538 -        P2C(blkif_be_destroy_t, blkif_handle, u32);
  14.539 -        break;
  14.540 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT):
  14.541 -        P2C(blkif_be_connect_t, domid,        u32);
  14.542 -        P2C(blkif_be_connect_t, blkif_handle, u32);
  14.543 -        P2C(blkif_be_connect_t, shmem_frame,  memory_t);
  14.544 -        P2C(blkif_be_connect_t, evtchn,       u16);
  14.545 -        break;
  14.546 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT):
  14.547 -        P2C(blkif_be_disconnect_t, domid,        u32);
  14.548 -        P2C(blkif_be_disconnect_t, blkif_handle, u32);
  14.549 -        break;
  14.550 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE):
  14.551 -        P2C(blkif_be_vbd_create_t, domid,        u32);
  14.552 -        P2C(blkif_be_vbd_create_t, blkif_handle, u32);
  14.553 -        P2C(blkif_be_vbd_create_t, vdevice,      blkif_vdev_t);
  14.554 -        P2C(blkif_be_vbd_create_t, readonly,     u16);
  14.555 -        break;
  14.556 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_DESTROY):
  14.557 -        P2C(blkif_be_vbd_destroy_t, domid,        u32);
  14.558 -        P2C(blkif_be_vbd_destroy_t, blkif_handle, u32);
  14.559 -        P2C(blkif_be_vbd_destroy_t, vdevice,      blkif_vdev_t);
  14.560 -        break;
  14.561 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_GROW):
  14.562 -        P2C(blkif_be_vbd_grow_t, domid,                u32);
  14.563 -        P2C(blkif_be_vbd_grow_t, blkif_handle,         u32);
  14.564 -        P2C(blkif_be_vbd_grow_t, vdevice,              blkif_vdev_t);
  14.565 -        P2C(blkif_be_vbd_grow_t, extent.sector_start,  blkif_sector_t);
  14.566 -        P2C(blkif_be_vbd_grow_t, extent.sector_length, blkif_sector_t);
  14.567 -        P2C(blkif_be_vbd_grow_t, extent.device,        blkif_pdev_t);
  14.568 -        break;
  14.569 -    case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_SHRINK):
  14.570 -        P2C(blkif_be_vbd_shrink_t, domid,        u32);
  14.571 -        P2C(blkif_be_vbd_shrink_t, blkif_handle, u32);
  14.572 -        P2C(blkif_be_vbd_shrink_t, vdevice,      blkif_vdev_t);
  14.573 -        break;
  14.574 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_STATUS_CHANGED):
  14.575 -        P2C(netif_fe_interface_status_changed_t, handle, u32);
  14.576 -        P2C(netif_fe_interface_status_changed_t, status, u32);
  14.577 -        P2C(netif_fe_interface_status_changed_t, evtchn, u16);
  14.578 -        P2C(netif_fe_interface_status_changed_t, mac[0], u8);
  14.579 -        P2C(netif_fe_interface_status_changed_t, mac[1], u8);
  14.580 -        P2C(netif_fe_interface_status_changed_t, mac[2], u8);
  14.581 -        P2C(netif_fe_interface_status_changed_t, mac[3], u8);
  14.582 -        P2C(netif_fe_interface_status_changed_t, mac[4], u8);
  14.583 -        P2C(netif_fe_interface_status_changed_t, mac[5], u8);
  14.584 -        break;
  14.585 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE):
  14.586 -        P2C(netif_be_create_t, domid,        u32);
  14.587 -        P2C(netif_be_create_t, netif_handle, u32);
  14.588 -        P2C(netif_be_create_t, mac[0],       u8);
  14.589 -        P2C(netif_be_create_t, mac[1],       u8);
  14.590 -        P2C(netif_be_create_t, mac[2],       u8);
  14.591 -        P2C(netif_be_create_t, mac[3],       u8);
  14.592 -        P2C(netif_be_create_t, mac[4],       u8);
  14.593 -        P2C(netif_be_create_t, mac[5],       u8);
  14.594 -        break;
  14.595 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
  14.596 -        P2C(netif_be_destroy_t, domid,        u32);
  14.597 -        P2C(netif_be_destroy_t, netif_handle, u32);
  14.598 -        break;
  14.599 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT):
  14.600 -        P2C(netif_be_connect_t, domid,          u32);
  14.601 -        P2C(netif_be_connect_t, netif_handle,   u32);
  14.602 -        P2C(netif_be_connect_t, tx_shmem_frame, memory_t);
  14.603 -        P2C(netif_be_connect_t, rx_shmem_frame, memory_t);
  14.604 -        P2C(netif_be_connect_t, evtchn,         u16);
  14.605 -        break;
  14.606 -    case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DISCONNECT):
  14.607 -        P2C(netif_be_disconnect_t, domid,        u32);
  14.608 -        P2C(netif_be_disconnect_t, netif_handle, u32);
  14.609 -        break;
  14.610 -    case TYPE(CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS_CHANGED):
  14.611 -        P2C(netif_fe_driver_status_changed_t, status,        u32);
  14.612 -        P2C(netif_fe_driver_status_changed_t, nr_interfaces, u32);
  14.613 -        break;
  14.614 -    }
  14.615 -
  14.616 -    if ( dict_items_parsed != PyDict_Size(payload) )
  14.617 -    {
  14.618 -        PyErr_SetString(PyExc_TypeError, "payload contains bad items");
  14.619 -        PyObject_Del((PyObject *)xum);
  14.620 -        return NULL;
  14.621 -    }
  14.622 -
  14.623 -    return (PyObject *)xum;
  14.624 -}
  14.625 -
  14.626 -static PyObject *xu_message_getattr(PyObject *obj, char *name)
  14.627 -{
  14.628 -    xu_message_object *xum;
  14.629 -    if ( strcmp(name, "MAX_PAYLOAD") == 0 )
  14.630 -        return PyInt_FromLong(sizeof(xum->msg.msg));
  14.631 -    return Py_FindMethod(xu_message_methods, obj, name);
  14.632 -}
  14.633 -
  14.634 -static void xu_message_dealloc(PyObject *self)
  14.635 -{
  14.636 -    PyObject_Del(self);
  14.637 -}
  14.638 -
  14.639 -static PyTypeObject xu_message_type = {
  14.640 -    PyObject_HEAD_INIT(&PyType_Type)
  14.641 -    0,
  14.642 -    "message",
  14.643 -    sizeof(xu_message_object),
  14.644 -    0,
  14.645 -    xu_message_dealloc,   /* tp_dealloc     */
  14.646 -    NULL,                /* tp_print       */
  14.647 -    xu_message_getattr,   /* tp_getattr     */
  14.648 -    NULL,                /* tp_setattr     */
  14.649 -    NULL,                /* tp_compare     */
  14.650 -    NULL,                /* tp_repr        */
  14.651 -    NULL,                /* tp_as_number   */
  14.652 -    NULL,                /* tp_as_sequence */
  14.653 -    NULL,                /* tp_as_mapping  */
  14.654 -    NULL                 /* tp_hash        */
  14.655 -};
  14.656 -
  14.657 -
  14.658 -
  14.659 -/*
  14.660 - * *********************** PORT ***********************
  14.661 - */
  14.662 -
  14.663 -static control_if_t *map_control_interface(int fd, unsigned long pfn)
  14.664 -{
  14.665 -    char *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE,
  14.666 -                       MAP_SHARED, fd, pfn * PAGE_SIZE);
  14.667 -    if ( vaddr == MAP_FAILED )
  14.668 -        return NULL;
  14.669 -    return (control_if_t *)(vaddr + 2048);
  14.670 -}
  14.671 -static void unmap_control_interface(int fd, control_if_t *c)
  14.672 -{
  14.673 -    char *vaddr = (char *)c - 2048;
  14.674 -    (void)munmap(vaddr, PAGE_SIZE);
  14.675 -}
  14.676 -
  14.677 -typedef struct xu_port_object {
  14.678 -    PyObject_HEAD;
  14.679 -    int mem_fd;
  14.680 -    int xc_handle;
  14.681 -    u32 remote_dom;
  14.682 -    int local_port, remote_port;
  14.683 -    control_if_t    *interface;
  14.684 -    CONTROL_RING_IDX tx_req_cons, tx_resp_prod;
  14.685 -    CONTROL_RING_IDX rx_req_prod, rx_resp_cons;
  14.686 -} xu_port_object;
  14.687 -
  14.688 -static PyObject *port_error;
  14.689 -
  14.690 -static int xup_connect(xu_port_object *xup, domid_t dom,
  14.691 -                       int local_port, int remote_port){
  14.692 -    // From our prespective rx = producer, tx = consumer.
  14.693 -    int err = 0;
  14.694 -    printf("%s> dom=%u %d:%d\n", __FUNCTION__, (unsigned int)dom, 
  14.695 -           local_port, remote_port);
  14.696 -
  14.697 -    // Consumer = tx.
  14.698 -    //xup->interface->tx_resp_prod = 0;
  14.699 -    //xup->interface->tx_req_prod = 0;
  14.700 -    xup->tx_resp_prod = xup->interface->tx_resp_prod;
  14.701 -    xup->tx_req_cons = xup->interface->tx_resp_prod;
  14.702 -    printf("%s> tx: %u %u : %u %u\n", __FUNCTION__,
  14.703 -           (unsigned int)xup->interface->tx_resp_prod,
  14.704 -           (unsigned int)xup->tx_resp_prod,
  14.705 -           (unsigned int)xup->tx_req_cons,
  14.706 -           (unsigned int)xup->interface->tx_req_prod);
  14.707 -
  14.708 -    // Producer = rx.
  14.709 -    //xup->interface->rx_req_prod  = 0;
  14.710 -    //xup->interface->rx_resp_prod = 0;
  14.711 -    xup->rx_req_prod  = xup->interface->rx_req_prod;
  14.712 -    xup->rx_resp_cons = xup->interface->rx_resp_prod;
  14.713 -    printf("%s> rx: %u %u : %u %u\n", __FUNCTION__,
  14.714 -           (unsigned int)xup->rx_resp_cons,
  14.715 -           (unsigned int)xup->interface->rx_resp_prod,
  14.716 -           (unsigned int)xup->interface->rx_req_prod,
  14.717 -           (unsigned int)xup->rx_req_prod);
  14.718 -
  14.719 -    xup->remote_dom   = dom;
  14.720 -    xup->local_port   = local_port;
  14.721 -    xup->remote_port  = remote_port;
  14.722 -
  14.723 -    printf("%s< err=%d\n", __FUNCTION__, err);
  14.724 -    return err;
  14.725 -}
  14.726 -
  14.727 -static PyObject *xu_port_notify(PyObject *self, PyObject *args)
  14.728 -{
  14.729 -    xu_port_object *xup = (xu_port_object *)self;
  14.730 -
  14.731 -    if ( !PyArg_ParseTuple(args, "") )
  14.732 -        return NULL;
  14.733 -
  14.734 -    (void)xc_evtchn_send(xup->xc_handle, xup->local_port);
  14.735 -
  14.736 -    Py_INCREF(Py_None);
  14.737 -    return Py_None;
  14.738 -}
  14.739 -
  14.740 -static PyObject *xu_port_read_request(PyObject *self, PyObject *args)
  14.741 -{
  14.742 -    xu_port_object    *xup = (xu_port_object *)self;
  14.743 -    xu_message_object *xum;
  14.744 -    CONTROL_RING_IDX   c = xup->tx_req_cons;
  14.745 -    control_if_t      *cif = xup->interface;
  14.746 -    control_msg_t     *cmsg;
  14.747 -
  14.748 -    if ( !PyArg_ParseTuple(args, "") )
  14.749 -        return NULL;
  14.750 -
  14.751 -    if ( (c == cif->tx_req_prod) || 
  14.752 -         ((c - xup->tx_resp_prod) == CONTROL_RING_SIZE) )
  14.753 -    {
  14.754 -        PyErr_SetString(port_error, "no request to read");
  14.755 -        return NULL;
  14.756 -    }
  14.757 -
  14.758 -    cmsg = &cif->tx_ring[MASK_CONTROL_IDX(c)];
  14.759 -    xum = PyObject_New(xu_message_object, &xu_message_type);
  14.760 -    memcpy(&xum->msg, cmsg, sizeof(*cmsg));
  14.761 -    if ( xum->msg.length > sizeof(xum->msg.msg) )
  14.762 -        xum->msg.length = sizeof(xum->msg.msg);
  14.763 -    xup->tx_req_cons++;
  14.764 -    return (PyObject *)xum;
  14.765 -}
  14.766 -
  14.767 -static PyObject *xu_port_write_request(PyObject *self, PyObject *args)
  14.768 -{
  14.769 -    xu_port_object    *xup = (xu_port_object *)self;
  14.770 -    xu_message_object *xum;
  14.771 -    CONTROL_RING_IDX   p = xup->rx_req_prod;
  14.772 -    control_if_t      *cif = xup->interface;
  14.773 -    control_msg_t     *cmsg;
  14.774 -
  14.775 -    if ( !PyArg_ParseTuple(args, "O", (PyObject **)&xum) )
  14.776 -        return NULL;
  14.777 -
  14.778 -    if ( !PyObject_TypeCheck((PyObject *)xum, &xu_message_type) )
  14.779 -    {
  14.780 -        PyErr_SetString(PyExc_TypeError, "expected a xend.utils.message");
  14.781 -        return NULL;        
  14.782 -    }
  14.783 -
  14.784 -    if ( ((p - xup->rx_resp_cons) == CONTROL_RING_SIZE) )
  14.785 -    {
  14.786 -        PyErr_SetString(port_error, "no space to write request");
  14.787 -        return NULL;
  14.788 -    }
  14.789 -
  14.790 -    cmsg = &cif->rx_ring[MASK_CONTROL_IDX(p)];
  14.791 -    memcpy(cmsg, &xum->msg, sizeof(*cmsg));
  14.792 -
  14.793 -    xup->rx_req_prod = cif->rx_req_prod = p + 1;
  14.794 -
  14.795 -    Py_INCREF(Py_None);
  14.796 -    return Py_None;
  14.797 -}
  14.798 -
  14.799 -static PyObject *xu_port_read_response(PyObject *self, PyObject *args)
  14.800 -{
  14.801 -    xu_port_object    *xup = (xu_port_object *)self;
  14.802 -    xu_message_object *xum;
  14.803 -    CONTROL_RING_IDX   c = xup->rx_resp_cons;
  14.804 -    control_if_t      *cif = xup->interface;
  14.805 -    control_msg_t     *cmsg;
  14.806 -
  14.807 -    if ( !PyArg_ParseTuple(args, "") )
  14.808 -        return NULL;
  14.809 -
  14.810 -    if ( (c == cif->rx_resp_prod) || (c == xup->rx_req_prod) )
  14.811 -    {
  14.812 -        PyErr_SetString(port_error, "no response to read");
  14.813 -        return NULL;
  14.814 -    }
  14.815 -
  14.816 -    cmsg = &cif->rx_ring[MASK_CONTROL_IDX(c)];
  14.817 -    xum = PyObject_New(xu_message_object, &xu_message_type);
  14.818 -    memcpy(&xum->msg, cmsg, sizeof(*cmsg));
  14.819 -    if ( xum->msg.length > sizeof(xum->msg.msg) )
  14.820 -        xum->msg.length = sizeof(xum->msg.msg);
  14.821 -    xup->rx_resp_cons++;
  14.822 -    return (PyObject *)xum;
  14.823 -}
  14.824 -
  14.825 -static PyObject *xu_port_write_response(PyObject *self, PyObject *args)
  14.826 -{
  14.827 -    xu_port_object    *xup = (xu_port_object *)self;
  14.828 -    xu_message_object *xum;
  14.829 -    CONTROL_RING_IDX   p = xup->tx_resp_prod;
  14.830 -    control_if_t      *cif = xup->interface;
  14.831 -    control_msg_t     *cmsg;
  14.832 -
  14.833 -    if ( !PyArg_ParseTuple(args, "O", (PyObject **)&xum) )
  14.834 -        return NULL;
  14.835 -
  14.836 -    if ( !PyObject_TypeCheck((PyObject *)xum, &xu_message_type) )
  14.837 -    {
  14.838 -        PyErr_SetString(PyExc_TypeError, "expected a xend.utils.message");
  14.839 -        return NULL;        
  14.840 -    }
  14.841 -
  14.842 -    if ( p == xup->tx_req_cons )
  14.843 -    {
  14.844 -        PyErr_SetString(port_error, "no space to write response");
  14.845 -        return NULL;
  14.846 -    }
  14.847 -
  14.848 -    cmsg = &cif->tx_ring[MASK_CONTROL_IDX(p)];
  14.849 -    memcpy(cmsg, &xum->msg, sizeof(*cmsg));
  14.850 -
  14.851 -    xup->tx_resp_prod = cif->tx_resp_prod = p + 1;
  14.852 -
  14.853 -    Py_INCREF(Py_None);
  14.854 -    return Py_None;
  14.855 -}
  14.856 -
  14.857 -static PyObject *xu_port_request_to_read(PyObject *self, PyObject *args)
  14.858 -{
  14.859 -    xu_port_object    *xup = (xu_port_object *)self;
  14.860 -    CONTROL_RING_IDX   c = xup->tx_req_cons;
  14.861 -    control_if_t      *cif = xup->interface;
  14.862 -
  14.863 -    if ( !PyArg_ParseTuple(args, "") )
  14.864 -        return NULL;
  14.865 -
  14.866 -    if ( (c == cif->tx_req_prod) || 
  14.867 -         ((c - xup->tx_resp_prod) == CONTROL_RING_SIZE) )
  14.868 -        return PyInt_FromLong(0);
  14.869 -
  14.870 -    return PyInt_FromLong(1);
  14.871 -}
  14.872 -
  14.873 -static PyObject *xu_port_space_to_write_request(PyObject *self, PyObject *args)
  14.874 -{
  14.875 -    xu_port_object    *xup = (xu_port_object *)self;
  14.876 -    CONTROL_RING_IDX   p = xup->rx_req_prod;
  14.877 -
  14.878 -    if ( !PyArg_ParseTuple(args, "") )
  14.879 -        return NULL;
  14.880 -
  14.881 -    if ( ((p - xup->rx_resp_cons) == CONTROL_RING_SIZE) )
  14.882 -        return PyInt_FromLong(0);
  14.883 -
  14.884 -    return PyInt_FromLong(1);
  14.885 -}
  14.886 -
  14.887 -static PyObject *xu_port_response_to_read(PyObject *self, PyObject *args)
  14.888 -{
  14.889 -    xu_port_object    *xup = (xu_port_object *)self;
  14.890 -    CONTROL_RING_IDX   c = xup->rx_resp_cons;
  14.891 -    control_if_t      *cif = xup->interface;
  14.892 -
  14.893 -    if ( !PyArg_ParseTuple(args, "") )
  14.894 -        return NULL;
  14.895 -
  14.896 -    if ( (c == cif->rx_resp_prod) || (c == xup->rx_req_prod) )
  14.897 -        return PyInt_FromLong(0);
  14.898 -
  14.899 -    return PyInt_FromLong(1);
  14.900 -}
  14.901 -
  14.902 -static PyObject *xu_port_space_to_write_response(
  14.903 -    PyObject *self, PyObject *args)
  14.904 -{
  14.905 -    xu_port_object    *xup = (xu_port_object *)self;
  14.906 -    CONTROL_RING_IDX   p = xup->tx_resp_prod;
  14.907 -
  14.908 -    if ( !PyArg_ParseTuple(args, "") )
  14.909 -        return NULL;
  14.910 -
  14.911 -    if ( p == xup->tx_req_cons )
  14.912 -        return PyInt_FromLong(0);
  14.913 -
  14.914 -    return PyInt_FromLong(1);
  14.915 -}
  14.916 -
  14.917 -static PyMethodDef xu_port_methods[] = {
  14.918 -    { "notify",
  14.919 -      (PyCFunction)xu_port_notify,
  14.920 -      METH_VARARGS,
  14.921 -      "Send a notification to the remote end.\n" },
  14.922 -
  14.923 -    { "read_request",
  14.924 -      (PyCFunction)xu_port_read_request,
  14.925 -      METH_VARARGS,
  14.926 -      "Read a request message from the control interface.\n" },
  14.927 -
  14.928 -    { "write_request",
  14.929 -      (PyCFunction)xu_port_write_request,
  14.930 -      METH_VARARGS,
  14.931 -      "Write a request message to the control interface.\n" },
  14.932 -
  14.933 -    { "read_response",
  14.934 -      (PyCFunction)xu_port_read_response,
  14.935 -      METH_VARARGS,
  14.936 -      "Read a response message from the control interface.\n" },
  14.937 -
  14.938 -    { "write_response",
  14.939 -      (PyCFunction)xu_port_write_response,
  14.940 -      METH_VARARGS,
  14.941 -      "Write a response message to the control interface.\n" },
  14.942 -
  14.943 -    { "request_to_read",
  14.944 -      (PyCFunction)xu_port_request_to_read,
  14.945 -      METH_VARARGS,
  14.946 -      "Returns TRUE if there is a request message to read.\n" },
  14.947 -
  14.948 -    { "space_to_write_request",
  14.949 -      (PyCFunction)xu_port_space_to_write_request,
  14.950 -      METH_VARARGS,
  14.951 -      "Returns TRUE if there is space to write a request message.\n" },
  14.952 -
  14.953 -    { "response_to_read",
  14.954 -      (PyCFunction)xu_port_response_to_read,
  14.955 -      METH_VARARGS,
  14.956 -      "Returns TRUE if there is a response message to read.\n" },
  14.957 -
  14.958 -    { "space_to_write_response",
  14.959 -      (PyCFunction)xu_port_space_to_write_response,
  14.960 -      METH_VARARGS,
  14.961 -      "Returns TRUE if there is space to write a response message.\n" },
  14.962 -
  14.963 -    { NULL, NULL, 0, NULL }
  14.964 -};
  14.965 -
  14.966 -staticforward PyTypeObject xu_port_type;
  14.967 -
  14.968 -static PyObject *xu_port_new(PyObject *self, PyObject *args)
  14.969 -{
  14.970 -    xu_port_object *xup;
  14.971 -    u32 dom;
  14.972 -    int port1, port2;
  14.973 -    xc_dominfo_t info;
  14.974 -
  14.975 -    if ( !PyArg_ParseTuple(args, "i", &dom) )
  14.976 -        return NULL;
  14.977 -
  14.978 -    xup = PyObject_New(xu_port_object, &xu_port_type);
  14.979 -
  14.980 -    if ( (xup->mem_fd = open("/dev/mem", O_RDWR)) == -1 )
  14.981 -    {
  14.982 -        PyErr_SetString(port_error, "Could not open '/dev/mem'");
  14.983 -        goto fail1;
  14.984 -    }
  14.985 -
  14.986 -    /* Set the General-Purpose Subject whose page frame will be mapped. */
  14.987 -    (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)dom);
  14.988 -
  14.989 -    if ( (xup->xc_handle = xc_interface_open()) == -1 )
  14.990 -    {
  14.991 -        PyErr_SetString(port_error, "Could not open Xen control interface");
  14.992 -        goto fail2;
  14.993 -    }
  14.994 -
  14.995 -    if ( dom == 0 )
  14.996 -    {
  14.997 -        /*
  14.998 -         * The control-interface event channel for DOM0 is already set up.
  14.999 -         * We use an ioctl to discover the port at our end of the channel.
 14.1000 -         */
 14.1001 -        port1 = ioctl(xup->xc_handle, IOCTL_PRIVCMD_INITDOMAIN_EVTCHN, NULL);
 14.1002 -        port2 = -1; /* We don't need the remote end of the DOM0 link. */
 14.1003 -        if ( port1 < 0 )
 14.1004 -        {
 14.1005 -            PyErr_SetString(port_error, "Could not open channel to DOM0");
 14.1006 -            goto fail3;
 14.1007 -        }
 14.1008 -    }
 14.1009 -    else if ( xc_evtchn_bind_interdomain(xup->xc_handle, 
 14.1010 -                                         DOMID_SELF, dom, 
 14.1011 -                                         &port1, &port2) != 0 )
 14.1012 -    {
 14.1013 -        PyErr_SetString(port_error, "Could not open channel to domain");
 14.1014 -        goto fail3;
 14.1015 -    }
 14.1016 -
 14.1017 -    if ( (xc_domain_getinfo(xup->xc_handle, dom, 1, &info) != 1) ||
 14.1018 -         (info.domid != dom) )
 14.1019 -    {
 14.1020 -        PyErr_SetString(port_error, "Failed to obtain domain status");
 14.1021 -        goto fail4;
 14.1022 -    }
 14.1023 -
 14.1024 -    xup->interface = 
 14.1025 -        map_control_interface(xup->mem_fd, info.shared_info_frame);
 14.1026 -    if ( xup->interface == NULL )
 14.1027 -    {
 14.1028 -        PyErr_SetString(port_error, "Failed to map domain control interface");
 14.1029 -        goto fail4;
 14.1030 -    }
 14.1031 -
 14.1032 -    xup_connect(xup, dom, port1, port2);
 14.1033 -    return (PyObject *)xup;
 14.1034 -
 14.1035 -    
 14.1036 - fail4:
 14.1037 -    (void)xc_evtchn_close(xup->xc_handle, DOMID_SELF, port1);
 14.1038 - fail3:
 14.1039 -    (void)xc_interface_close(xup->xc_handle);
 14.1040 - fail2:
 14.1041 -    (void)close(xup->mem_fd);
 14.1042 - fail1:
 14.1043 -    PyObject_Del((PyObject *)xup);
 14.1044 -    return NULL;        
 14.1045 -}
 14.1046 -
 14.1047 -static PyObject *xu_port_getattr(PyObject *obj, char *name)
 14.1048 -{
 14.1049 -    xu_port_object *xup = (xu_port_object *)obj;
 14.1050 -    if ( strcmp(name, "local_port") == 0 )
 14.1051 -        return PyInt_FromLong(xup->local_port);
 14.1052 -    if ( strcmp(name, "remote_port") == 0 )
 14.1053 -        return PyInt_FromLong(xup->remote_port);
 14.1054 -    if ( strcmp(name, "remote_dom") == 0 )
 14.1055 -        return PyInt_FromLong(xup->remote_dom);
 14.1056 -    return Py_FindMethod(xu_port_methods, obj, name);
 14.1057 -}
 14.1058 -
 14.1059 -static void xu_port_dealloc(PyObject *self)
 14.1060 -{
 14.1061 -    xu_port_object *xup = (xu_port_object *)self;
 14.1062 -    unmap_control_interface(xup->mem_fd, xup->interface);
 14.1063 -    if ( xup->remote_dom != 0 )
 14.1064 -        (void)xc_evtchn_close(xup->xc_handle, DOMID_SELF, xup->local_port);
 14.1065 -    (void)xc_interface_close(xup->xc_handle);
 14.1066 -    (void)close(xup->mem_fd);
 14.1067 -    PyObject_Del(self);
 14.1068 -}
 14.1069 -
 14.1070 -static PyTypeObject xu_port_type = {
 14.1071 -    PyObject_HEAD_INIT(&PyType_Type)
 14.1072 -    0,
 14.1073 -    "port",
 14.1074 -    sizeof(xu_port_object),
 14.1075 -    0,
 14.1076 -    xu_port_dealloc,     /* tp_dealloc     */
 14.1077 -    NULL,                /* tp_print       */
 14.1078 -    xu_port_getattr,     /* tp_getattr     */
 14.1079 -    NULL,                /* tp_setattr     */
 14.1080 -    NULL,                /* tp_compare     */
 14.1081 -    NULL,                /* tp_repr        */
 14.1082 -    NULL,                /* tp_as_number   */
 14.1083 -    NULL,                /* tp_as_sequence */
 14.1084 -    NULL,                /* tp_as_mapping  */
 14.1085 -    NULL                 /* tp_hash        */
 14.1086 -};
 14.1087 -
 14.1088 -
 14.1089 -
 14.1090 -/*
 14.1091 - * *********************** BUFFER ***********************
 14.1092 - */
 14.1093 -
 14.1094 -#define BUFSZ 65536
 14.1095 -#define MASK_BUF_IDX(_i) ((_i)&(BUFSZ-1))
 14.1096 -typedef unsigned int BUF_IDX;
 14.1097 -
 14.1098 -typedef struct {
 14.1099 -    PyObject_HEAD;
 14.1100 -    char        *buf;
 14.1101 -    unsigned int prod, cons;
 14.1102 -} xu_buffer_object;
 14.1103 -
 14.1104 -static PyObject *__xu_buffer_peek(xu_buffer_object *xub, int max)
 14.1105 -{
 14.1106 -    PyObject *str1, *str2;
 14.1107 -    int len1, len2, c = MASK_BUF_IDX(xub->cons);
 14.1108 -
 14.1109 -    len1 = xub->prod - xub->cons;
 14.1110 -    if ( len1 > (BUFSZ - c) ) /* clip to ring wrap */
 14.1111 -        len1 = BUFSZ - c;
 14.1112 -    if ( len1 > max )         /* clip to specified maximum */
 14.1113 -        len1 = max;
 14.1114 -    if ( len1 < 0 )           /* sanity */
 14.1115 -        len1 = 0;
 14.1116 -
 14.1117 -    if ( (str1 = PyString_FromStringAndSize(&xub->buf[c], len1)) == NULL )
 14.1118 -        return NULL;
 14.1119 -
 14.1120 -    if ( (len1 < (xub->prod - xub->cons)) && (len1 < max) )
 14.1121 -    {
 14.1122 -        len2 = max - len1;
 14.1123 -        if ( len2 > MASK_BUF_IDX(xub->prod) )
 14.1124 -            len2 = MASK_BUF_IDX(xub->prod);
 14.1125 -        if ( len2 > 0 )
 14.1126 -        {
 14.1127 -            str2 = PyString_FromStringAndSize(&xub->buf[0], len2);
 14.1128 -            if ( str2 == NULL )
 14.1129 -                return NULL;
 14.1130 -            PyString_ConcatAndDel(&str1, str2);
 14.1131 -            if ( str1 == NULL )
 14.1132 -                return NULL;
 14.1133 -        }
 14.1134 -    }
 14.1135 -
 14.1136 -    return str1;
 14.1137 -}
 14.1138 -
 14.1139 -static PyObject *xu_buffer_peek(PyObject *self, PyObject *args)
 14.1140 -{
 14.1141 -    xu_buffer_object *xub = (xu_buffer_object *)self;
 14.1142 -    int max = 1024;
 14.1143 -
 14.1144 -    if ( !PyArg_ParseTuple(args, "|i", &max) )
 14.1145 -        return NULL;
 14.1146 -    
 14.1147 -    return __xu_buffer_peek(xub, max);
 14.1148 -}
 14.1149 -
 14.1150 -static PyObject *xu_buffer_read(PyObject *self, PyObject *args)
 14.1151 -{
 14.1152 -    xu_buffer_object *xub = (xu_buffer_object *)self;
 14.1153 -    PyObject *str;
 14.1154 -    int max = 1024;
 14.1155 -
 14.1156 -    if ( !PyArg_ParseTuple(args, "|i", &max) )
 14.1157 -        return NULL;
 14.1158 -
 14.1159 -    if ( (str = __xu_buffer_peek(xub, max)) != NULL )
 14.1160 -        xub->cons += PyString_Size(str);
 14.1161 -
 14.1162 -    return str;
 14.1163 -}
 14.1164 -
 14.1165 -static PyObject *xu_buffer_discard(PyObject *self, PyObject *args)
 14.1166 -{
 14.1167 -    xu_buffer_object *xub = (xu_buffer_object *)self;
 14.1168 -    int max, len;
 14.1169 -
 14.1170 -    if ( !PyArg_ParseTuple(args, "i", &max) )
 14.1171 -        return NULL;
 14.1172 -
 14.1173 -    len = xub->prod - xub->cons;
 14.1174 -    if ( len > max )
 14.1175 -        len = max;
 14.1176 -    if ( len < 0 )
 14.1177 -        len = 0;
 14.1178 -
 14.1179 -    xub->cons += len;
 14.1180 -
 14.1181 -    return PyInt_FromLong(len);
 14.1182 -}
 14.1183 -
 14.1184 -static PyObject *xu_buffer_write(PyObject *self, PyObject *args)
 14.1185 -{
 14.1186 -    xu_buffer_object *xub = (xu_buffer_object *)self;
 14.1187 -    char *str;
 14.1188 -    int len, len1, len2;
 14.1189 -
 14.1190 -    if ( !PyArg_ParseTuple(args, "s#", &str, &len) )
 14.1191 -        return NULL;
 14.1192 -
 14.1193 -    len1 = len;
 14.1194 -    if ( len1 > (BUFSZ - MASK_BUF_IDX(xub->prod)) )
 14.1195 -        len1 = BUFSZ - MASK_BUF_IDX(xub->prod);
 14.1196 -    if ( len1 > (BUFSZ - (xub->prod - xub->cons)) )
 14.1197 -        len1 = BUFSZ - (xub->prod - xub->cons);
 14.1198 -
 14.1199 -    if ( len1 == 0 )
 14.1200 -        return PyInt_FromLong(0);
 14.1201 -
 14.1202 -    memcpy(&xub->buf[MASK_BUF_IDX(xub->prod)], &str[0], len1);
 14.1203 -    xub->prod += len1;
 14.1204 -
 14.1205 -    if ( len1 < len )
 14.1206 -    {
 14.1207 -        len2 = len - len1;
 14.1208 -        if ( len2 > (BUFSZ - MASK_BUF_IDX(xub->prod)) )
 14.1209 -            len2 = BUFSZ - MASK_BUF_IDX(xub->prod);
 14.1210 -        if ( len2 > (BUFSZ - (xub->prod - xub->cons)) )
 14.1211 -            len2 = BUFSZ - (xub->prod - xub->cons);
 14.1212 -        if ( len2 != 0 )
 14.1213 -        {
 14.1214 -            memcpy(&xub->buf[MASK_BUF_IDX(xub->prod)], &str[len1], len2);
 14.1215 -            xub->prod += len2;
 14.1216 -            return PyInt_FromLong(len1 + len2);
 14.1217 -        }
 14.1218 -    }
 14.1219 -
 14.1220 -    return PyInt_FromLong(len1);
 14.1221 -}
 14.1222 -
 14.1223 -static PyObject *xu_buffer_empty(PyObject *self, PyObject *args)
 14.1224 -{
 14.1225 -    xu_buffer_object *xub = (xu_buffer_object *)self;
 14.1226 -
 14.1227 -    if ( !PyArg_ParseTuple(args, "") )
 14.1228 -        return NULL;
 14.1229 -
 14.1230 -    if ( xub->cons == xub->prod )
 14.1231 -        return PyInt_FromLong(1);
 14.1232 -
 14.1233 -    return PyInt_FromLong(0);
 14.1234 -}
 14.1235 -
 14.1236 -static PyObject *xu_buffer_full(PyObject *self, PyObject *args)
 14.1237 -{
 14.1238 -    xu_buffer_object *xub = (xu_buffer_object *)self;
 14.1239 -
 14.1240 -    if ( !PyArg_ParseTuple(args, "") )
 14.1241 -        return NULL;
 14.1242 -
 14.1243 -    if ( (xub->prod - xub->cons) == BUFSZ )
 14.1244 -        return PyInt_FromLong(1);
 14.1245 -
 14.1246 -    return PyInt_FromLong(0);
 14.1247 -}
 14.1248 -
 14.1249 -static PyMethodDef xu_buffer_methods[] = {
 14.1250 -    { "peek", 
 14.1251 -      (PyCFunction)xu_buffer_peek,
 14.1252 -      METH_VARARGS,
 14.1253 -      "Peek up to @max bytes from the buffer. Returns a string.\n" },
 14.1254 -
 14.1255 -    { "read", 
 14.1256 -      (PyCFunction)xu_buffer_read,
 14.1257 -      METH_VARARGS,
 14.1258 -      "Read up to @max bytes from the buffer. Returns a string.\n" },
 14.1259 -
 14.1260 -    { "discard", 
 14.1261 -      (PyCFunction)xu_buffer_discard,
 14.1262 -      METH_VARARGS,
 14.1263 -      "Discard up to @max bytes from the buffer. Returns number of bytes.\n" },
 14.1264 -
 14.1265 -    { "write", 
 14.1266 -      (PyCFunction)xu_buffer_write,
 14.1267 -      METH_VARARGS,
 14.1268 -      "Write @string into buffer. Return number of bytes written.\n" },
 14.1269 -
 14.1270 -    { "empty", 
 14.1271 -      (PyCFunction)xu_buffer_empty,
 14.1272 -      METH_VARARGS,
 14.1273 -      "Return TRUE if the buffer is empty.\n" },
 14.1274 -
 14.1275 -    { "full", 
 14.1276 -      (PyCFunction)xu_buffer_full,
 14.1277 -      METH_VARARGS,
 14.1278 -      "Return TRUE if the buffer is full.\n" },
 14.1279 -
 14.1280 -    { NULL, NULL, 0, NULL }
 14.1281 -};
 14.1282 -
 14.1283 -staticforward PyTypeObject xu_buffer_type;
 14.1284 -
 14.1285 -static PyObject *xu_buffer_new(PyObject *self, PyObject *args)
 14.1286 -{
 14.1287 -    xu_buffer_object *xub;
 14.1288 -
 14.1289 -    if ( !PyArg_ParseTuple(args, "") )
 14.1290 -        return NULL;
 14.1291 -
 14.1292 -    xub = PyObject_New(xu_buffer_object, &xu_buffer_type);
 14.1293 -
 14.1294 -    if ( (xub->buf = malloc(BUFSZ)) == NULL )
 14.1295 -    {
 14.1296 -        PyObject_Del((PyObject *)xub);
 14.1297 -        return NULL;
 14.1298 -    }
 14.1299 -
 14.1300 -    xub->prod = xub->cons = 0;
 14.1301 -
 14.1302 -    return (PyObject *)xub;
 14.1303 -}
 14.1304 -
 14.1305 -static PyObject *xu_buffer_getattr(PyObject *obj, char *name)
 14.1306 -{
 14.1307 -    return Py_FindMethod(xu_buffer_methods, obj, name);
 14.1308 -}
 14.1309 -
 14.1310 -static void xu_buffer_dealloc(PyObject *self)
 14.1311 -{
 14.1312 -    xu_buffer_object *xub = (xu_buffer_object *)self;
 14.1313 -    free(xub->buf);
 14.1314 -    PyObject_Del(self);
 14.1315 -}
 14.1316 -
 14.1317 -static PyTypeObject xu_buffer_type = {
 14.1318 -    PyObject_HEAD_INIT(&PyType_Type)
 14.1319 -    0,
 14.1320 -    "buffer",
 14.1321 -    sizeof(xu_buffer_object),
 14.1322 -    0,
 14.1323 -    xu_buffer_dealloc,   /* tp_dealloc     */
 14.1324 -    NULL,                /* tp_print       */
 14.1325 -    xu_buffer_getattr,   /* tp_getattr     */
 14.1326 -    NULL,                /* tp_setattr     */
 14.1327 -    NULL,                /* tp_compare     */
 14.1328 -    NULL,                /* tp_repr        */
 14.1329 -    NULL,                /* tp_as_number   */
 14.1330 -    NULL,                /* tp_as_sequence */
 14.1331 -    NULL,                /* tp_as_mapping  */
 14.1332 -    NULL                 /* tp_hash        */
 14.1333 -};
 14.1334 -
 14.1335 -
 14.1336 -
 14.1337 -/*
 14.1338 - * *********************** MODULE WRAPPER ***********************
 14.1339 - */
 14.1340 -
 14.1341 -static void handle_child_death(int dummy)
 14.1342 -{
 14.1343 -    while ( waitpid(-1, NULL, WNOHANG) > 0 )
 14.1344 -        continue;
 14.1345 -}
 14.1346 -
 14.1347 -static PyObject *xu_autoreap(PyObject *self, PyObject *args)
 14.1348 -{
 14.1349 -    struct sigaction sa;
 14.1350 -
 14.1351 -    if ( !PyArg_ParseTuple(args, "") )
 14.1352 -        return NULL;
 14.1353 -
 14.1354 -    memset(&sa, 0, sizeof(sa));
 14.1355 -    sa.sa_handler = handle_child_death;
 14.1356 -    sigemptyset(&sa.sa_mask);
 14.1357 -    sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
 14.1358 -    (void)sigaction(SIGCHLD, &sa, NULL);
 14.1359 -
 14.1360 -    Py_INCREF(Py_None);
 14.1361 -    return Py_None;
 14.1362 -}
 14.1363 -
 14.1364 -static PyMethodDef xu_methods[] = {
 14.1365 -    { "notifier", xu_notifier_new, METH_VARARGS, 
 14.1366 -      "Create a new notifier." },
 14.1367 -    { "message", xu_message_new, METH_VARARGS, 
 14.1368 -      "Create a new communications message." },
 14.1369 -    { "port", xu_port_new, METH_VARARGS, 
 14.1370 -      "Create a new communications port." },
 14.1371 -    { "buffer", xu_buffer_new, METH_VARARGS, 
 14.1372 -      "Create a new ring buffer." },
 14.1373 -    { "autoreap", xu_autoreap, METH_VARARGS,
 14.1374 -      "Ensure that zombie children are automatically reaped by the OS." },
 14.1375 -    { NULL, NULL, 0, NULL }
 14.1376 -};
 14.1377 -
 14.1378 -PyMODINIT_FUNC initutils(void)
 14.1379 -{
 14.1380 -    PyObject *m, *d;
 14.1381 -
 14.1382 -    m = Py_InitModule("xend.utils", xu_methods);
 14.1383 -
 14.1384 -    d = PyModule_GetDict(m);
 14.1385 -    port_error = PyErr_NewException("xend.utils.PortError", NULL, NULL);
 14.1386 -    PyDict_SetItemString(d, "PortError", port_error);
 14.1387 -}
    15.1 --- a/tools/xend-old/setup.py	Mon Jun 28 08:20:16 2004 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,19 +0,0 @@
    15.4 -
    15.5 -from distutils.core import setup, Extension
    15.6 -
    15.7 -utils = Extension("utils",
    15.8 -                  extra_compile_args   = ["-fno-strict-aliasing"],
    15.9 -                  include_dirs         = ["../xc/lib",
   15.10 -                                          "../../xen/include/hypervisor-ifs",
   15.11 -                                          "../../linux-xen-sparse/include"],
   15.12 -                  library_dirs         = ["../xc/lib"],
   15.13 -                  libraries            = ["xc"],
   15.14 -                  sources              = ["lib/utils.c"])
   15.15 -
   15.16 -setup(name = "xend",
   15.17 -      version = "1.0",
   15.18 -      packages = ["xend"],
   15.19 -      package_dir = { "xend" : "lib" },
   15.20 -      ext_package = "xend",
   15.21 -      ext_modules = [ utils ]
   15.22 -      )
    16.1 --- a/tools/xend-old/xend	Mon Jun 28 08:20:16 2004 +0000
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,22 +0,0 @@
    16.4 -#!/usr/bin/env python
    16.5 -
    16.6 -import os, sys, xend.main
    16.7 -
    16.8 -def main():
    16.9 -    if not sys.argv[1:]:
   16.10 -        print 'usage: %s {start|stop|restart}' % sys.argv[0]
   16.11 -    elif os.fork():
   16.12 -        pid, status = os.wait()
   16.13 -        return status >> 8
   16.14 -    elif sys.argv[1] == 'start':
   16.15 -        return xend.main.start_daemon()
   16.16 -    elif sys.argv[1] == 'stop':
   16.17 -        return xend.main.stop_daemon()
   16.18 -    elif sys.argv[1] == 'restart':
   16.19 -        return xend.main.stop_daemon() or xend.main.start_daemon()
   16.20 -    else:
   16.21 -        print 'not an option:', sys.argv[1]
   16.22 -    return 1
   16.23 -
   16.24 -if __name__ == '__main__':
   16.25 -    sys.exit(main())