debuggers.hg
changeset 6706:0e2b1e04d4cb
g/c unused control message code.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Wed Sep 07 18:28:04 2005 +0000 (2005-09-07) |
parents | 549f4256ab3c |
children | 4e4aac33809f |
files | tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/event.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/tpmif.py tools/python/xen/xend/server/usbif.py |
line diff
1.1 --- a/tools/python/xen/xend/XendDomain.py Wed Sep 07 17:43:56 2005 +0000 1.2 +++ b/tools/python/xen/xend/XendDomain.py Wed Sep 07 18:28:04 2005 +0000 1.3 @@ -36,7 +36,6 @@ from xen.xend import EventServer; eserve 1.4 from xen.xend.XendError import XendError 1.5 from xen.xend.XendLogging import log 1.6 from xen.xend import scheduler 1.7 -from xen.xend.server import channel 1.8 from xen.xend.server import relocate 1.9 from xen.xend.uuid import getUuid 1.10 from xen.xend.xenstore import XenNode, DBMap
2.1 --- a/tools/python/xen/xend/XendDomainInfo.py Wed Sep 07 17:43:56 2005 +0000 2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Wed Sep 07 18:28:04 2005 +0000 2.3 @@ -34,8 +34,7 @@ from xen.util.blkif import blkdev_uname_ 2.4 2.5 from xen.xend.server import controller 2.6 from xen.xend.server import SrvDaemon; xend = SrvDaemon.instance() 2.7 -from xen.xend.server import messages 2.8 -from xen.xend.server.channel import EventChannel, channelFactory 2.9 +from xen.xend.server.channel import EventChannel 2.10 from xen.util.blkif import blkdev_name_to_number, expand_dev_name 2.11 2.12 from xen.xend import sxp 2.13 @@ -258,7 +257,6 @@ class XendDomainInfo: 2.14 2.15 self.target = None 2.16 2.17 - self.channel = None 2.18 self.store_channel = None 2.19 self.store_mfn = None 2.20 self.console_channel = None 2.21 @@ -296,8 +294,6 @@ class XendDomainInfo: 2.22 self.db.saveDB(save=save, sync=sync) 2.23 2.24 def exportToDB(self, save=False, sync=False): 2.25 - if self.channel: 2.26 - self.channel.saveToDB(self.db.addChild("channel"), save=save) 2.27 if self.store_channel: 2.28 self.store_channel.saveToDB(self.db.addChild("store_channel"), 2.29 save=save) 2.30 @@ -330,9 +326,6 @@ class XendDomainInfo: 2.31 def getName(self): 2.32 return self.name 2.33 2.34 - def getChannel(self): 2.35 - return self.channel 2.36 - 2.37 def getStoreChannel(self): 2.38 return self.store_channel 2.39 2.40 @@ -569,8 +562,6 @@ class XendDomainInfo: 2.41 sxpr.append(['up_time', str(up_time) ]) 2.42 sxpr.append(['start_time', str(self.start_time) ]) 2.43 2.44 - if self.channel: 2.45 - sxpr.append(self.channel.sxpr()) 2.46 if self.store_channel: 2.47 sxpr.append(self.store_channel.sxpr()) 2.48 if self.store_mfn: 2.49 @@ -761,12 +752,6 @@ class XendDomainInfo: 2.50 """ 2.51 self.state = STATE_VM_TERMINATED 2.52 self.release_devices() 2.53 - if self.channel: 2.54 - try: 2.55 - self.channel.close() 2.56 - self.channel = None 2.57 - except: 2.58 - pass 2.59 if self.store_channel: 2.60 try: 2.61 self.store_channel.close() 2.62 @@ -858,20 +843,6 @@ class XendDomainInfo: 2.63 id, self.name, self.memory) 2.64 self.setdom(id) 2.65 2.66 - def openChannel(self, key, local, remote): 2.67 - """Create a control channel to the domain. 2.68 - If saved info is available recreate the channel. 2.69 - 2.70 - @param key db key for the saved data (if any) 2.71 - @param local default local port 2.72 - @param remote default remote port 2.73 - """ 2.74 - db = self.db.addChild(key) 2.75 - chan = channelFactory().restoreFromDB(db, self.id, local, remote) 2.76 - #todo: save here? 2.77 - #chan.saveToDB(db) 2.78 - return chan 2.79 - 2.80 def eventChannel(self, key): 2.81 """Create an event channel to the domain. 2.82 If saved info is available recreate the channel. 2.83 @@ -884,7 +855,6 @@ class XendDomainInfo: 2.84 def create_channel(self): 2.85 """Create the channels to the domain. 2.86 """ 2.87 - self.channel = self.openChannel("channel", 0, 1) 2.88 self.store_channel = self.eventChannel("store_channel") 2.89 self.console_channel = self.eventChannel("console/console_channel") 2.90
3.1 --- a/tools/python/xen/xend/server/SrvDaemon.py Wed Sep 07 17:43:56 2005 +0000 3.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py Wed Sep 07 18:28:04 2005 +0000 3.3 @@ -17,8 +17,6 @@ import traceback 3.4 import time 3.5 import glob 3.6 3.7 -from xen.lowlevel import xu 3.8 - 3.9 from xen.xend import sxp 3.10 from xen.xend import PrettyPrint 3.11 from xen.xend import EventServer; eserver = EventServer.instance() 3.12 @@ -27,7 +25,6 @@ from xen.xend.server import SrvServer 3.13 from xen.xend.XendLogging import log 3.14 from xen.xend import XendRoot; xroot = XendRoot.instance() 3.15 3.16 -import channel 3.17 import controller 3.18 import event 3.19 import relocate 3.20 @@ -37,7 +34,6 @@ class Daemon: 3.21 """The xend daemon. 3.22 """ 3.23 def __init__(self): 3.24 - self.channelF = None 3.25 self.shutdown = 0 3.26 self.traceon = 0 3.27 self.tracefile = None 3.28 @@ -298,10 +294,8 @@ class Daemon: 3.29 _enforce_dom0_cpus() 3.30 try: 3.31 log.info("Xend Daemon started") 3.32 - self.createFactories() 3.33 event.listenEvent(self) 3.34 relocate.listenRelocation() 3.35 - self.listenChannels() 3.36 servers = SrvServer.create() 3.37 self.daemonize() 3.38 servers.start() 3.39 @@ -312,15 +306,7 @@ class Daemon: 3.40 log.exception("Exception starting xend (%s)" % ex) 3.41 self.exit(1) 3.42 3.43 - def createFactories(self): 3.44 - self.channelF = channel.channelFactory() 3.45 - 3.46 - def listenChannels(self): 3.47 - self.channelF.start() 3.48 - 3.49 def exit(self, rc=0): 3.50 - if self.channelF: 3.51 - self.channelF.stop() 3.52 # Calling sys.exit() raises a SystemExit exception, which only 3.53 # kills the current thread. Calling os._exit() makes the whole 3.54 # Python process exit immediately. There doesn't seem to be another
4.1 --- a/tools/python/xen/xend/server/blkif.py Wed Sep 07 17:43:56 2005 +0000 4.2 +++ b/tools/python/xen/xend/server/blkif.py Wed Sep 07 18:28:04 2005 +0000 4.3 @@ -27,9 +27,7 @@ from xen.xend import sxp 4.4 from xen.xend import Blkctl 4.5 from xen.xend.xenstore import DBVar 4.6 4.7 -from xen.xend.server import channel 4.8 -from xen.xend.server.controller import CtrlMsgRcvr, Dev, DevController 4.9 -from xen.xend.server.messages import * 4.10 +from xen.xend.server.controller import Dev, DevController 4.11 4.12 class BlkifBackend: 4.13 """ Handler for the 'back-end' channel to a block device driver domain 4.14 @@ -41,21 +39,15 @@ class BlkifBackend: 4.15 self.controller = controller 4.16 self.id = id 4.17 self.frontendDomain = self.controller.getDomain() 4.18 - self.frontendChannel = None 4.19 self.backendDomain = dom 4.20 - self.backendChannel = None 4.21 self.destroyed = False 4.22 self.connected = False 4.23 - self.evtchn = None 4.24 self.status = None 4.25 4.26 def init(self, recreate=False, reboot=False): 4.27 self.destroyed = False 4.28 self.status = BLKIF_INTERFACE_STATUS_DISCONNECTED 4.29 self.frontendDomain = self.controller.getDomain() 4.30 - self.frontendChannel = self.controller.getChannel() 4.31 - cf = channel.channelFactory() 4.32 - self.backendChannel = cf.openChannel(self.backendDomain) 4.33 4.34 def __str__(self): 4.35 return ('<BlkifBackend frontend=%d backend=%d id=%d>' 4.36 @@ -66,29 +58,6 @@ class BlkifBackend: 4.37 def getId(self): 4.38 return self.id 4.39 4.40 - def getEvtchn(self): 4.41 - return self.evtchn 4.42 - 4.43 - def closeEvtchn(self): 4.44 - if self.evtchn: 4.45 - channel.eventChannelClose(self.evtchn) 4.46 - self.evtchn = None 4.47 - 4.48 - def openEvtchn(self): 4.49 - self.evtchn = channel.eventChannel(self.backendDomain, self.frontendDomain) 4.50 - 4.51 - def getEventChannelBackend(self): 4.52 - val = 0 4.53 - if self.evtchn: 4.54 - val = self.evtchn['port1'] 4.55 - return val 4.56 - 4.57 - def getEventChannelFrontend(self): 4.58 - val = 0 4.59 - if self.evtchn: 4.60 - val = self.evtchn['port2'] 4.61 - return val 4.62 - 4.63 def connect(self, recreate=False): 4.64 """Connect to the blkif control interface. 4.65 4.66 @@ -98,83 +67,19 @@ class BlkifBackend: 4.67 if recreate or self.connected: 4.68 self.connected = True 4.69 pass 4.70 - else: 4.71 - self.send_be_create() 4.72 4.73 - def send_be_create(self): 4.74 - log.debug("send_be_create %s", str(self)) 4.75 - msg = packMsg('blkif_be_create_t', 4.76 - { 'domid' : self.frontendDomain, 4.77 - 'blkif_handle' : self.id }) 4.78 - msg = self.backendChannel.requestResponse(msg) 4.79 - #todo: check return status 4.80 - self.connected = True 4.81 - 4.82 def destroy(self, change=False, reboot=False): 4.83 """Disconnect from the blkif control interface and destroy it. 4.84 """ 4.85 - self.send_be_disconnect() 4.86 - self.send_be_destroy() 4.87 - self.closeEvtchn() 4.88 self.destroyed = True 4.89 # For change true need to notify front-end, or back-end will do it? 4.90 4.91 - def send_be_disconnect(self): 4.92 - msg = packMsg('blkif_be_disconnect_t', 4.93 - { 'domid' : self.frontendDomain, 4.94 - 'blkif_handle' : self.id }) 4.95 - self.backendChannel.requestResponse(msg) 4.96 - #todo: check return status 4.97 - self.connected = False 4.98 - 4.99 - def send_be_destroy(self): 4.100 - msg = packMsg('blkif_be_destroy_t', 4.101 - { 'domid' : self.frontendDomain, 4.102 - 'blkif_handle' : self.id }) 4.103 - self.backendChannel.requestResponse(msg) 4.104 - #todo: check return status 4.105 - 4.106 def connectInterface(self, val): 4.107 - self.openEvtchn() 4.108 - log.debug("Connecting blkif to event channel %s ports=%d:%d", 4.109 - str(self), self.evtchn['port1'], self.evtchn['port2']) 4.110 - msg = packMsg('blkif_be_connect_t', 4.111 - { 'domid' : self.frontendDomain, 4.112 - 'blkif_handle' : self.id, 4.113 - 'evtchn' : self.getEventChannelBackend(), 4.114 - 'shmem_frame' : val['shmem_frame'], 4.115 - 'shmem_ref' : val['shmem_ref'] }) 4.116 - msg = self.backendChannel.requestResponse(msg) 4.117 - #todo: check return status 4.118 - val = unpackMsg('blkif_be_connect_t', msg) 4.119 self.status = BLKIF_INTERFACE_STATUS_CONNECTED 4.120 - self.send_fe_interface_status() 4.121 4.122 - def send_fe_interface_status(self): 4.123 - msg = packMsg('blkif_fe_interface_status_t', 4.124 - { 'handle' : self.id, 4.125 - 'status' : self.status, 4.126 - 'domid' : self.backendDomain, 4.127 - 'evtchn' : self.getEventChannelFrontend() }) 4.128 - self.frontendChannel.writeRequest(msg) 4.129 - 4.130 def interfaceDisconnected(self): 4.131 self.status = BLKIF_INTERFACE_STATUS_DISCONNECTED 4.132 - #todo?: Close evtchn: 4.133 - #self.closeEvtchn() 4.134 - self.send_fe_interface_status() 4.135 4.136 - def interfaceChanged(self): 4.137 - """Notify the front-end that devices have been added or removed. 4.138 - The front-end should then probe for devices. 4.139 - """ 4.140 - msg = packMsg('blkif_fe_interface_status_t', 4.141 - { 'handle' : self.id, 4.142 - 'status' : BLKIF_INTERFACE_STATUS_CHANGED, 4.143 - 'domid' : self.backendDomain, 4.144 - 'evtchn' : 0 }) 4.145 - self.frontendChannel.writeRequest(msg) 4.146 - 4.147 class BlkDev(Dev): 4.148 """Info record for a block device. 4.149 """ 4.150 @@ -207,24 +112,17 @@ class BlkDev(Dev): 4.151 self.nr_sectors = None 4.152 4.153 self.frontendDomain = self.getDomain() 4.154 - self.frontendChannel = None 4.155 self.backendDomain = None 4.156 - self.backendChannel = None 4.157 self.backendId = 0 4.158 self.configure(self.config, recreate=recreate) 4.159 4.160 def exportToDB(self, save=False): 4.161 Dev.exportToDB(self, save=save) 4.162 backend = self.getBackend() 4.163 - if backend and backend.evtchn: 4.164 - db = self.db.addChild("evtchn") 4.165 - backend.evtchn.saveToDB(db, save=save) 4.166 4.167 def init(self, recreate=False, reboot=False): 4.168 self.frontendDomain = self.getDomain() 4.169 - self.frontendChannel = self.getChannel() 4.170 backend = self.getBackend() 4.171 - self.backendChannel = backend.backendChannel 4.172 self.backendId = backend.id 4.173 4.174 def configure(self, config, change=False, recreate=False): 4.175 @@ -351,7 +249,6 @@ class BlkDev(Dev): 4.176 self.destroyed = True 4.177 log.debug("Destroying vbd domain=%d id=%s", self.frontendDomain, 4.178 self.id) 4.179 - self.send_be_vbd_destroy() 4.180 if change: 4.181 self.interfaceChanged() 4.182 self.unbind() 4.183 @@ -367,30 +264,6 @@ class BlkDev(Dev): 4.184 4.185 """ 4.186 self.getBackend().connect() 4.187 - self.send_be_vbd_create() 4.188 - 4.189 - def send_be_vbd_create(self): 4.190 - msg = packMsg('blkif_be_vbd_create_t', 4.191 - { 'domid' : self.frontendDomain, 4.192 - 'blkif_handle' : self.backendId, 4.193 - 'pdevice' : self.device, 4.194 - 'dev_handle' : self.dev_handle, 4.195 - 'vdevice' : self.vdev, 4.196 - 'readonly' : self.readonly() }) 4.197 - msg = self.backendChannel.requestResponse(msg) 4.198 - 4.199 - val = unpackMsg('blkif_be_vbd_create_t', msg) 4.200 - status = val['status'] 4.201 - if status != BLKIF_BE_STATUS_OKAY: 4.202 - raise XendError("Creating vbd failed: device %s, error %d" 4.203 - % (sxp.to_string(self.config), status)) 4.204 - 4.205 - def send_be_vbd_destroy(self): 4.206 - msg = packMsg('blkif_be_vbd_destroy_t', 4.207 - { 'domid' : self.frontendDomain, 4.208 - 'blkif_handle' : self.backendId, 4.209 - 'vdevice' : self.vdev }) 4.210 - return self.backendChannel.writeRequest(msg) 4.211 4.212 class BlkifController(DevController): 4.213 """Block device interface controller. Handles all block devices 4.214 @@ -403,19 +276,9 @@ class BlkifController(DevController): 4.215 DevController.__init__(self, vm, recreate=recreate) 4.216 self.backends = {} 4.217 self.backendId = 0 4.218 - self.rcvr = None 4.219 4.220 def initController(self, recreate=False, reboot=False): 4.221 self.destroyed = False 4.222 - # Add our handlers for incoming requests. 4.223 - self.rcvr = CtrlMsgRcvr(self.getChannel()) 4.224 - self.rcvr.addHandler(CMSG_BLKIF_FE, 4.225 - CMSG_BLKIF_FE_DRIVER_STATUS, 4.226 - self.recv_fe_driver_status) 4.227 - self.rcvr.addHandler(CMSG_BLKIF_FE, 4.228 - CMSG_BLKIF_FE_INTERFACE_CONNECT, 4.229 - self.recv_fe_interface_connect) 4.230 - self.rcvr.registerChannel() 4.231 if reboot: 4.232 self.rebootBackends() 4.233 self.rebootDevices() 4.234 @@ -465,26 +328,7 @@ class BlkifController(DevController): 4.235 log.debug("Destroying blkif domain=%d", self.getDomain()) 4.236 self.destroyDevices(reboot=reboot) 4.237 self.destroyBackends(reboot=reboot) 4.238 - self.rcvr.deregisterChannel() 4.239 4.240 def destroyBackends(self, reboot=False): 4.241 for backend in self.backends.values(): 4.242 backend.destroy(reboot=reboot) 4.243 - 4.244 - def recv_fe_driver_status(self, msg): 4.245 - val = unpackMsg('blkif_fe_driver_status_t', msg) 4.246 - for backend in self.backends.values(): 4.247 - backend.interfaceDisconnected() 4.248 - 4.249 - def recv_fe_interface_connect(self, msg): 4.250 - val = unpackMsg('blkif_fe_interface_connect_t', msg) 4.251 - id = val['handle'] 4.252 - backend = self.getBackendById(id) 4.253 - if backend: 4.254 - try: 4.255 - backend.connectInterface(val) 4.256 - except IOError, ex: 4.257 - log.error("Exception connecting backend: %s", ex) 4.258 - else: 4.259 - log.error('interface connect on unknown interface: id=%d', id) 4.260 -
5.1 --- a/tools/python/xen/xend/server/channel.py Wed Sep 07 17:43:56 2005 +0000 5.2 +++ b/tools/python/xen/xend/server/channel.py Wed Sep 07 18:28:04 2005 +0000 5.3 @@ -23,8 +23,6 @@ from xen.lowlevel import xu 5.4 5.5 from xen.xend.XendLogging import log 5.6 5.7 -from messages import * 5.8 - 5.9 DEBUG = 0 5.10 5.11 RESPONSE_TIMEOUT = 20.0 5.12 @@ -132,473 +130,3 @@ def eventChannelClose(evtchn): 5.13 """ 5.14 if not evtchn: return 5.15 evtchn.close() 5.16 - 5.17 -class ChannelFactory: 5.18 - """Factory for creating control channels. 5.19 - Maintains a table of channels. 5.20 - """ 5.21 - 5.22 - """ Channels indexed by index. """ 5.23 - channels = None 5.24 - 5.25 - thread = None 5.26 - 5.27 - notifier = None 5.28 - 5.29 - def __init__(self): 5.30 - """Constructor - do not use. Use the channelFactory function.""" 5.31 - self.channels = {} 5.32 - self.notifier = xu.notifier() 5.33 - 5.34 - def start(self): 5.35 - """Fork a thread to read messages. 5.36 - """ 5.37 - if self.thread: return 5.38 - self.thread = threading.Thread(name="ChannelFactory", 5.39 - target=self.main) 5.40 - self.thread.setDaemon(True) 5.41 - self.thread.start() 5.42 - 5.43 - def stop(self): 5.44 - """Signal the thread to stop. 5.45 - """ 5.46 - self.thread = None 5.47 - 5.48 - def main(self): 5.49 - """Main routine for the thread. 5.50 - Reads the notifier and dispatches to channels. 5.51 - """ 5.52 - while True: 5.53 - if self.thread == None: return 5.54 - port = self.notifier.read() 5.55 - if port: 5.56 - self.msgReceived(port) 5.57 - else: 5.58 - select.select([self.notifier], [], [], 1.0) 5.59 - 5.60 - def msgReceived(self, port): 5.61 - # We run the message handlers in their own threads. 5.62 - # Note we use keyword args to lambda to save the values - 5.63 - # otherwise lambda will use the variables, which will get 5.64 - # assigned by the loop and the lambda will get the changed values. 5.65 - received = 0 5.66 - for chan in self.channels.values(): 5.67 - if self.thread == None: return 5.68 - msg = chan.readResponse() 5.69 - if msg: 5.70 - received += 1 5.71 - chan.responseReceived(msg) 5.72 - for chan in self.channels.values(): 5.73 - if self.thread == None: return 5.74 - msg = chan.readRequest() 5.75 - if msg: 5.76 - received += 1 5.77 - self.runInThread(lambda chan=chan, msg=msg: chan.requestReceived(msg)) 5.78 - if port and received == 0: 5.79 - log.warning("Port %s notified, but no messages found", port) 5.80 - 5.81 - def runInThread(self, thunk): 5.82 - thread = threading.Thread(target = thunk) 5.83 - thread.setDaemon(True) 5.84 - thread.start() 5.85 - 5.86 - def newChannel(self, dom, local_port, remote_port): 5.87 - """Create a new channel. 5.88 - """ 5.89 - return self.addChannel(Channel(self, dom, local_port, remote_port)) 5.90 - 5.91 - def addChannel(self, channel): 5.92 - """Add a channel. 5.93 - """ 5.94 - self.channels[channel.getKey()] = channel 5.95 - return channel 5.96 - 5.97 - def delChannel(self, channel): 5.98 - """Remove the channel. 5.99 - """ 5.100 - key = channel.getKey() 5.101 - if key in self.channels: 5.102 - del self.channels[key] 5.103 - 5.104 - def getChannel(self, dom, local_port, remote_port): 5.105 - """Get the channel with the given domain and ports (if any). 5.106 - """ 5.107 - key = (dom, local_port, remote_port) 5.108 - return self.channels.get(key) 5.109 - 5.110 - def findChannel(self, dom, local_port=0, remote_port=0): 5.111 - """Find a channel. Ports given as zero are wildcards. 5.112 - 5.113 - dom domain 5.114 - 5.115 - returns channel 5.116 - """ 5.117 - chan = self.getChannel(dom, local_port, remote_port) 5.118 - if chan: return chan 5.119 - if local_port and remote_port: 5.120 - return None 5.121 - for c in self.channels.values(): 5.122 - if c.dom != dom: continue 5.123 - if local_port and local_port != c.getLocalPort(): continue 5.124 - if remote_port and remote_port != c.getRemotePort(): continue 5.125 - return c 5.126 - return None 5.127 - 5.128 - def openChannel(self, dom, local_port=0, remote_port=0): 5.129 - chan = self.findChannel(dom, local_port=local_port, 5.130 - remote_port=remote_port) 5.131 - if chan: 5.132 - return chan 5.133 - chan = self.newChannel(dom, local_port, remote_port) 5.134 - return chan 5.135 - 5.136 - 5.137 - def createPort(self, dom, local_port=0, remote_port=0): 5.138 - """Create a port for a channel to the given domain. 5.139 - If only the domain is specified, a new channel with new port ids is 5.140 - created. If one port id is specified and the given port id is in use, 5.141 - the other port id is filled. If one port id is specified and the 5.142 - given port id is not in use, a new channel is created with one port 5.143 - id equal to the given id and a new id for the other end. If both 5.144 - port ids are specified, a port is reconnected using the given port 5.145 - ids. 5.146 - 5.147 - @param dom: domain 5.148 - @param local: local port id to use 5.149 - @type local: int 5.150 - @param remote: remote port id to use 5.151 - @type remote: int 5.152 - @return: port object 5.153 - """ 5.154 - return xu.port(dom, local_port=local_port, remote_port=remote_port) 5.155 - 5.156 - def restoreFromDB(self, db, dom, local, remote): 5.157 - """Create a channel using ports restored from the db (if available). 5.158 - Otherwise use the given ports. This is the inverse operation to 5.159 - saveToDB() on a channel. 5.160 - 5.161 - @param db db 5.162 - @param dom domain the channel connects to 5.163 - @param local default local port 5.164 - @param remote default remote port 5.165 - """ 5.166 - try: 5.167 - local_port = int(db['local_port']) 5.168 - except: 5.169 - local_port = local 5.170 - try: 5.171 - remote_port = int(db['remote_port']) 5.172 - except: 5.173 - remote_port = remote 5.174 - try: 5.175 - chan = self.openChannel(dom, local_port, remote_port) 5.176 - except: 5.177 - return None 5.178 - return chan 5.179 - 5.180 -def channelFactory(): 5.181 - """Singleton constructor for the channel factory. 5.182 - Use this instead of the class constructor. 5.183 - """ 5.184 - global inst 5.185 - try: 5.186 - inst 5.187 - except: 5.188 - inst = ChannelFactory() 5.189 - return inst 5.190 - 5.191 -class Channel: 5.192 - """Control channel to a domain. 5.193 - Maintains a list of device handlers to dispatch requests to, based 5.194 - on the request type. 5.195 - """ 5.196 - 5.197 - def __init__(self, factory, dom, local_port, remote_port): 5.198 - self.factory = factory 5.199 - self.dom = int(dom) 5.200 - # Registered device handlers. 5.201 - self.devs = [] 5.202 - # Handlers indexed by the message types they handle. 5.203 - self.devs_by_type = {} 5.204 - self.port = self.factory.createPort(self.dom, 5.205 - local_port=local_port, 5.206 - remote_port=remote_port) 5.207 - self.closed = False 5.208 - # Queue of waiters for responses to requests. 5.209 - self.queue = ResponseQueue(self) 5.210 - # Make sure the port will deliver all the messages. 5.211 - self.port.register(TYPE_WILDCARD) 5.212 - 5.213 - def saveToDB(self, db, save=False): 5.214 - """Save the channel ports to the db so the channel can be restored later, 5.215 - using restoreFromDB() on the factory. 5.216 - 5.217 - @param db db 5.218 - """ 5.219 - if self.closed: return 5.220 - db['local_port'] = str(self.getLocalPort()) 5.221 - db['remote_port'] = str(self.getRemotePort()) 5.222 - db.saveDB(save=save) 5.223 - 5.224 - def getKey(self): 5.225 - """Get the channel key. 5.226 - """ 5.227 - return (self.dom, self.getLocalPort(), self.getRemotePort()) 5.228 - 5.229 - def sxpr(self): 5.230 - val = ['channel'] 5.231 - val.append(['domain', self.dom]) 5.232 - if self.port: 5.233 - val.append(['local_port', self.port.local_port]) 5.234 - val.append(['remote_port', self.port.remote_port]) 5.235 - return val 5.236 - 5.237 - def close(self): 5.238 - """Close the channel. 5.239 - """ 5.240 - if DEBUG: 5.241 - print 'Channel>close>', self 5.242 - if self.closed: return 5.243 - self.closed = True 5.244 - self.factory.delChannel(self) 5.245 - for d in self.devs[:]: 5.246 - d.lostChannel(self) 5.247 - self.devs = [] 5.248 - self.devs_by_type = {} 5.249 - if self.port: 5.250 - self.port.close() 5.251 - #self.port = None 5.252 - 5.253 - def getDomain(self): 5.254 - return self.dom 5.255 - 5.256 - def getLocalPort(self): 5.257 - """Get the local port. 5.258 - 5.259 - @return: local port 5.260 - @rtype: int 5.261 - """ 5.262 - if self.closed: return -1 5.263 - return self.port.local_port 5.264 - 5.265 - def getRemotePort(self): 5.266 - """Get the remote port. 5.267 - 5.268 - @return: remote port 5.269 - @rtype: int 5.270 - """ 5.271 - if self.closed: return -1 5.272 - return self.port.remote_port 5.273 - 5.274 - def __repr__(self): 5.275 - return ('<Channel dom=%d ports=%d:%d>' 5.276 - % (self.dom, 5.277 - self.getLocalPort(), 5.278 - self.getRemotePort())) 5.279 - 5.280 - 5.281 - def registerDevice(self, types, dev): 5.282 - """Register a device message handler. 5.283 - 5.284 - @param types: message types handled 5.285 - @type types: array of ints 5.286 - @param dev: device handler 5.287 - """ 5.288 - if self.closed: return 5.289 - self.devs.append(dev) 5.290 - for ty in types: 5.291 - self.devs_by_type[ty] = dev 5.292 - 5.293 - def deregisterDevice(self, dev): 5.294 - """Remove the registration for a device handler. 5.295 - 5.296 - @param dev: device handler 5.297 - """ 5.298 - if dev in self.devs: 5.299 - self.devs.remove(dev) 5.300 - types = [ ty for (ty, d) in self.devs_by_type.items() if d == dev ] 5.301 - for ty in types: 5.302 - del self.devs_by_type[ty] 5.303 - 5.304 - def getDevice(self, type): 5.305 - """Get the handler for a message type. 5.306 - 5.307 - @param type: message type 5.308 - @type type: int 5.309 - @return: controller or None 5.310 - @rtype: device handler 5.311 - """ 5.312 - return self.devs_by_type.get(type) 5.313 - 5.314 - def requestReceived(self, msg): 5.315 - """A request has been received on the channel. 5.316 - Disptach it to the device handlers. 5.317 - Called from the channel factory thread. 5.318 - """ 5.319 - if DEBUG: 5.320 - print 'Channel>requestReceived>', self, 5.321 - printMsg(msg) 5.322 - (ty, subty) = getMessageType(msg) 5.323 - responded = False 5.324 - dev = self.getDevice(ty) 5.325 - if dev: 5.326 - responded = dev.requestReceived(msg, ty, subty) 5.327 - elif DEBUG: 5.328 - print "Channel>requestReceived> No device handler", self, 5.329 - printMsg(msg) 5.330 - else: 5.331 - pass 5.332 - if not responded: 5.333 - self.writeResponse(msg) 5.334 - 5.335 - def writeRequest(self, msg): 5.336 - """Write a request to the channel. 5.337 - """ 5.338 - if DEBUG: 5.339 - print 'Channel>writeRequest>', self, 5.340 - printMsg(msg, all=True) 5.341 - if self.closed: return -1 5.342 - self.port.write_request(msg) 5.343 - return 1 5.344 - 5.345 - def writeResponse(self, msg): 5.346 - """Write a response to the channel. 5.347 - """ 5.348 - if DEBUG: 5.349 - print 'Channel>writeResponse>', self, 5.350 - printMsg(msg, all=True) 5.351 - if self.port: 5.352 - self.port.write_response(msg) 5.353 - return 1 5.354 - 5.355 - def readRequest(self): 5.356 - """Read a request from the channel. 5.357 - Called internally. 5.358 - """ 5.359 - if self.closed: 5.360 - val = None 5.361 - else: 5.362 - val = self.port.read_request() 5.363 - return val 5.364 - 5.365 - def readResponse(self): 5.366 - """Read a response from the channel. 5.367 - Called internally. 5.368 - """ 5.369 - if self.closed: 5.370 - val = None 5.371 - else: 5.372 - val = self.port.read_response() 5.373 - if DEBUG and val: 5.374 - print 'Channel>readResponse>', self, 5.375 - printMsg(val, all=True) 5.376 - return val 5.377 - 5.378 - def requestResponse(self, msg, timeout=None): 5.379 - """Write a request and wait for a response. 5.380 - Raises IOError on timeout. 5.381 - 5.382 - @param msg request message 5.383 - @param timeout timeout (0 is forever) 5.384 - @return response message 5.385 - """ 5.386 - if self.closed: 5.387 - raise IOError("closed") 5.388 - if self.closed: 5.389 - return None 5.390 - if timeout is None: 5.391 - timeout = RESPONSE_TIMEOUT 5.392 - elif timeout <= 0: 5.393 - timeout = None 5.394 - return self.queue.call(msg, timeout) 5.395 - 5.396 - def responseReceived(self, msg): 5.397 - """A response has been received, look for a waiter to 5.398 - give it to. 5.399 - Called internally. 5.400 - """ 5.401 - if DEBUG: 5.402 - print 'Channel>responseReceived>', self, 5.403 - printMsg(msg) 5.404 - self.queue.response(getMessageId(msg), msg) 5.405 - 5.406 -class Response: 5.407 - """Entry in the response queue. 5.408 - Used to signal a response to a message. 5.409 - """ 5.410 - 5.411 - def __init__(self, mid): 5.412 - self.mid = mid 5.413 - self.msg = None 5.414 - self.ready = threading.Event() 5.415 - 5.416 - def response(self, msg): 5.417 - """Signal arrival of a response to a waiting thread. 5.418 - Passing msg None cancels the wait with an IOError. 5.419 - """ 5.420 - if msg: 5.421 - self.msg = msg 5.422 - else: 5.423 - self.mid = -1 5.424 - self.ready.set() 5.425 - 5.426 - def wait(self, timeout): 5.427 - """Wait up to 'timeout' seconds for a response. 5.428 - Returns the response or raises an IOError. 5.429 - """ 5.430 - self.ready.wait(timeout) 5.431 - if self.mid < 0: 5.432 - raise IOError("wait canceled") 5.433 - if self.msg is None: 5.434 - raise IOError("response timeout") 5.435 - return self.msg 5.436 - 5.437 -class ResponseQueue: 5.438 - """Response queue. Manages waiters for responses to messages. 5.439 - """ 5.440 - 5.441 - def __init__(self, channel): 5.442 - self.channel = channel 5.443 - self.lock = threading.Lock() 5.444 - self.responses = {} 5.445 - 5.446 - def add(self, mid): 5.447 - r = Response(mid) 5.448 - self.responses[mid] = r 5.449 - return r 5.450 - 5.451 - def get(self, mid): 5.452 - return self.responses.get(mid) 5.453 - 5.454 - def remove(self, mid): 5.455 - r = self.responses.get(mid) 5.456 - if r: 5.457 - del self.responses[mid] 5.458 - return r 5.459 - 5.460 - def response(self, mid, msg): 5.461 - """Process a response - signals any waiter that a response 5.462 - has arrived. 5.463 - """ 5.464 - try: 5.465 - self.lock.acquire() 5.466 - r = self.remove(mid) 5.467 - finally: 5.468 - self.lock.release() 5.469 - if r: 5.470 - r.response(msg) 5.471 - 5.472 - def call(self, msg, timeout): 5.473 - """Send the message and wait for 'timeout' seconds for a response. 5.474 - Returns the response. 5.475 - Raises IOError on timeout. 5.476 - """ 5.477 - mid = getMessageId(msg) 5.478 - try: 5.479 - self.lock.acquire() 5.480 - r = self.add(mid) 5.481 - finally: 5.482 - self.lock.release() 5.483 - self.channel.writeRequest(msg) 5.484 - return r.wait(timeout) 5.485 -
6.1 --- a/tools/python/xen/xend/server/controller.py Wed Sep 07 17:43:56 2005 +0000 6.2 +++ b/tools/python/xen/xend/server/controller.py Wed Sep 07 18:28:04 2005 +0000 6.3 @@ -21,107 +21,9 @@ for a domain. 6.4 6.5 from xen.xend.XendError import XendError 6.6 from xen.xend.xenstore import DBVar 6.7 -from xen.xend.server.messages import msgTypeName, printMsg, getMessageType 6.8 6.9 DEBUG = 0 6.10 6.11 -class CtrlMsgRcvr: 6.12 - """Utility class to dispatch messages on a control channel. 6.13 - Once I{registerChannel} has been called, our message types are registered 6.14 - with the channel. The channel will call I{requestReceived} 6.15 - when a request arrives if it has one of our message types. 6.16 - 6.17 - @ivar channel: channel to a domain 6.18 - @type channel: Channel 6.19 - @ivar majorTypes: major message types we are interested in 6.20 - @type majorTypes: {int:{int:method}} 6.21 - 6.22 - """ 6.23 - 6.24 - def __init__(self, channel): 6.25 - self.majorTypes = {} 6.26 - self.channel = channel 6.27 - 6.28 - def getHandler(self, type, subtype): 6.29 - """Get the method for a type and subtype. 6.30 - 6.31 - @param type: major message type 6.32 - @param subtype: minor message type 6.33 - @return: method or None 6.34 - """ 6.35 - method = None 6.36 - subtypes = self.majorTypes.get(type) 6.37 - if subtypes: 6.38 - method = subtypes.get(subtype) 6.39 - return method 6.40 - 6.41 - def addHandler(self, type, subtype, method): 6.42 - """Add a method to handle a message type and subtype. 6.43 - 6.44 - @param type: major message type 6.45 - @param subtype: minor message type 6.46 - @param method: method 6.47 - """ 6.48 - subtypes = self.majorTypes.get(type) 6.49 - if not subtypes: 6.50 - subtypes = {} 6.51 - self.majorTypes[type] = subtypes 6.52 - subtypes[subtype] = method 6.53 - 6.54 - def getMajorTypes(self): 6.55 - """Get the list of major message types handled. 6.56 - """ 6.57 - return self.majorTypes.keys() 6.58 - 6.59 - def requestReceived(self, msg, type, subtype): 6.60 - """Dispatch a request message to handlers. 6.61 - Called by the channel for requests with one of our types. 6.62 - 6.63 - @param msg: message 6.64 - @type msg: xu message 6.65 - @param type: major message type 6.66 - @type type: int 6.67 - @param subtype: minor message type 6.68 - @type subtype: int 6.69 - """ 6.70 - if DEBUG: 6.71 - print 'requestReceived>', 6.72 - printMsg(msg, all=True) 6.73 - responded = 0 6.74 - method = self.getHandler(type, subtype) 6.75 - if method: 6.76 - responded = method(msg) 6.77 - elif DEBUG: 6.78 - print ('requestReceived> No handler: Message type %s %d:%d' 6.79 - % (msgTypeName(type, subtype), type, subtype)), self 6.80 - return responded 6.81 - 6.82 - 6.83 - def lostChannel(self): 6.84 - """Called when the channel to the domain is lost. 6.85 - """ 6.86 - if DEBUG: 6.87 - print 'CtrlMsgRcvr>lostChannel>', 6.88 - self.channel = None 6.89 - 6.90 - def registerChannel(self): 6.91 - """Register interest in our major message types with the 6.92 - channel to our domain. Once we have registered, the channel 6.93 - will call requestReceived for our messages. 6.94 - """ 6.95 - if DEBUG: 6.96 - print 'CtrlMsgRcvr>registerChannel>', self.channel, self.getMajorTypes() 6.97 - if self.channel: 6.98 - self.channel.registerDevice(self.getMajorTypes(), self) 6.99 - 6.100 - def deregisterChannel(self): 6.101 - """Deregister interest in our major message types with the 6.102 - channel to our domain. After this the channel won't call 6.103 - us any more. 6.104 - """ 6.105 - if self.channel: 6.106 - self.channel.deregisterDevice(self) 6.107 - 6.108 class DevControllerTable: 6.109 """Table of device controller classes, indexed by type name. 6.110 """ 6.111 @@ -232,10 +134,6 @@ class DevController: 6.112 def getDomainName(self): 6.113 return self.vm.getName() 6.114 6.115 - def getChannel(self): 6.116 - chan = self.vm.getChannel() 6.117 - return chan 6.118 - 6.119 def getDomainInfo(self): 6.120 return self.vm 6.121 6.122 @@ -433,9 +331,6 @@ class Dev: 6.123 def getDomainName(self): 6.124 return self.controller.getDomainName() 6.125 6.126 - def getChannel(self): 6.127 - return self.controller.getChannel() 6.128 - 6.129 def getDomainInfo(self): 6.130 return self.controller.getDomainInfo() 6.131
7.1 --- a/tools/python/xen/xend/server/event.py Wed Sep 07 17:43:56 2005 +0000 7.2 +++ b/tools/python/xen/xend/server/event.py Wed Sep 07 18:28:04 2005 +0000 7.3 @@ -174,11 +174,6 @@ class EventProtocol(protocol.Protocol): 7.4 else: 7.5 logging.removeLogStderr() 7.6 7.7 - def op_debug_msg(self, name, v): 7.8 - mode = v[1] 7.9 - import messages 7.10 - messages.DEBUG = (mode == 'on') 7.11 - 7.12 def op_debug_controller(self, name, v): 7.13 mode = v[1] 7.14 import controller
8.1 --- a/tools/python/xen/xend/server/messages.py Wed Sep 07 17:43:56 2005 +0000 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,462 +0,0 @@ 8.4 -#============================================================================ 8.5 -# This library is free software; you can redistribute it and/or 8.6 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 8.7 -# License as published by the Free Software Foundation. 8.8 -# 8.9 -# This library is distributed in the hope that it will be useful, 8.10 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 8.11 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8.12 -# Lesser General Public License for more details. 8.13 -# 8.14 -# You should have received a copy of the GNU Lesser General Public 8.15 -# License along with this library; if not, write to the Free Software 8.16 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 8.17 -#============================================================================ 8.18 -# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com> 8.19 -#============================================================================ 8.20 - 8.21 -import sys 8.22 -import struct 8.23 -import types 8.24 - 8.25 -from xen.lowlevel import xu 8.26 - 8.27 -DEBUG = False 8.28 - 8.29 -#PORT_WILDCARD = 0xefffffff 8.30 - 8.31 -"""Wildcard for the control message types.""" 8.32 -TYPE_WILDCARD = 0xffff 8.33 - 8.34 -""" All message formats. 8.35 -Added to incrementally for the various message types. 8.36 -See below. 8.37 -""" 8.38 -msg_formats = {} 8.39 - 8.40 -#============================================================================ 8.41 -# Block interface message types. 8.42 -#============================================================================ 8.43 - 8.44 -CMSG_BLKIF_BE = 1 8.45 -CMSG_BLKIF_FE = 2 8.46 - 8.47 -CMSG_BLKIF_FE_INTERFACE_STATUS = 0 8.48 -CMSG_BLKIF_FE_DRIVER_STATUS = 32 8.49 -CMSG_BLKIF_FE_INTERFACE_CONNECT = 33 8.50 -CMSG_BLKIF_FE_INTERFACE_DISCONNECT = 34 8.51 -CMSG_BLKIF_FE_INTERFACE_QUERY = 35 8.52 - 8.53 -CMSG_BLKIF_BE_CREATE = 0 8.54 -CMSG_BLKIF_BE_DESTROY = 1 8.55 -CMSG_BLKIF_BE_CONNECT = 2 8.56 -CMSG_BLKIF_BE_DISCONNECT = 3 8.57 -CMSG_BLKIF_BE_VBD_CREATE = 4 8.58 -CMSG_BLKIF_BE_VBD_DESTROY = 5 8.59 -CMSG_BLKIF_BE_DRIVER_STATUS = 32 8.60 - 8.61 -BLKIF_DRIVER_STATUS_DOWN = 0 8.62 -BLKIF_DRIVER_STATUS_UP = 1 8.63 - 8.64 -BLKIF_INTERFACE_STATUS_CLOSED = 0 #/* Interface doesn't exist. */ 8.65 -BLKIF_INTERFACE_STATUS_DISCONNECTED = 1 #/* Exists but is disconnected. */ 8.66 -BLKIF_INTERFACE_STATUS_CONNECTED = 2 #/* Exists and is connected. */ 8.67 -BLKIF_INTERFACE_STATUS_CHANGED = 3 #/* A device has been added or removed. */ 8.68 - 8.69 -BLKIF_BE_STATUS_OKAY = 0 8.70 -BLKIF_BE_STATUS_ERROR = 1 8.71 -BLKIF_BE_STATUS_INTERFACE_EXISTS = 2 8.72 -BLKIF_BE_STATUS_INTERFACE_NOT_FOUND = 3 8.73 -BLKIF_BE_STATUS_INTERFACE_CONNECTED = 4 8.74 -BLKIF_BE_STATUS_VBD_EXISTS = 5 8.75 -BLKIF_BE_STATUS_VBD_NOT_FOUND = 6 8.76 -BLKIF_BE_STATUS_OUT_OF_MEMORY = 7 8.77 -BLKIF_BE_STATUS_PHYSDEV_NOT_FOUND = 8 8.78 -BLKIF_BE_STATUS_MAPPING_ERROR = 9 8.79 - 8.80 -blkif_formats = { 8.81 - 'blkif_be_connect_t': 8.82 - (CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT), 8.83 - # Connect be to fe (in response to blkif_fe_interface_connect_t). 8.84 - 8.85 - 'blkif_be_create_t': 8.86 - (CMSG_BLKIF_BE, CMSG_BLKIF_BE_CREATE), 8.87 - # Create be. 8.88 - 8.89 - 'blkif_be_disconnect_t': 8.90 - (CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT), 8.91 - # Disconnect be from fe. 8.92 - 8.93 - 'blkif_be_destroy_t': 8.94 - (CMSG_BLKIF_BE, CMSG_BLKIF_BE_DESTROY), 8.95 - # Destroy be (after disconnect). 8.96 - # Make be do this even if no disconnect (and destroy all vbd too). 8.97 - 8.98 - 'blkif_be_vbd_create_t': 8.99 - (CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_CREATE), 8.100 - # Create a vbd device. 8.101 - 8.102 - 'blkif_be_vbd_destroy_t': 8.103 - (CMSG_BLKIF_BE, CMSG_BLKIF_BE_VBD_DESTROY), 8.104 - # Destroy a vbd. 8.105 - 8.106 - # Add message to query be for state and vbds. 8.107 - 8.108 - 'blkif_fe_interface_status_t': 8.109 - (CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_STATUS), 8.110 - # Notify device status to fe. 8.111 - # Also used to notify 'any' device change with status BLKIF_INTERFACE_STATUS_CHANGED. 8.112 - 8.113 - 'blkif_fe_driver_status_t': 8.114 - (CMSG_BLKIF_FE, CMSG_BLKIF_FE_DRIVER_STATUS), 8.115 - # Comes from fe, treated as notifying that fe has come up/changed. 8.116 - # Xend sets be(s) to BLKIF_INTERFACE_STATUS_DISCONNECTED, 8.117 - # sends blkif_fe_interface_status_t to fe (from each be). 8.118 - # 8.119 - # Reply with i/f count. 8.120 - # The i/f sends probes (using -ve trick), we reply with the info. 8.121 - 8.122 - 'blkif_fe_interface_connect_t': 8.123 - (CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_CONNECT), 8.124 - # Comes from fe, passing shmem frame to use for be. 8.125 - # fe sends when gets blkif_fe_interface_status_t with state NETIF_INTERFACE_STATUS_DISCONNECTED. 8.126 - # Xend creates event channel and notifies be. 8.127 - # Then notifies fe of event channel with blkif_fe_interface_status_t. 8.128 - 8.129 - # Add message to kick fe to probe for devices. 8.130 - # Just report new devices to fe? 8.131 - 8.132 - # 8.133 - # Add message for fe to probe a device. 8.134 - # And probing with id -1 should return first. 8.135 - # And probing with id -n should return first device with id > n. 8.136 - 8.137 - # Add message to query fe for state and vbds. 8.138 -} 8.139 - 8.140 -msg_formats.update(blkif_formats) 8.141 - 8.142 -#============================================================================ 8.143 -# Network interface message types. 8.144 -#============================================================================ 8.145 - 8.146 -CMSG_NETIF_BE = 3 8.147 -CMSG_NETIF_FE = 4 8.148 - 8.149 -CMSG_NETIF_FE_INTERFACE_STATUS = 0 8.150 -CMSG_NETIF_FE_DRIVER_STATUS = 32 8.151 -CMSG_NETIF_FE_INTERFACE_CONNECT = 33 8.152 -CMSG_NETIF_FE_INTERFACE_DISCONNECT = 34 8.153 -CMSG_NETIF_FE_INTERFACE_QUERY = 35 8.154 - 8.155 -CMSG_NETIF_BE_CREATE = 0 8.156 -CMSG_NETIF_BE_DESTROY = 1 8.157 -CMSG_NETIF_BE_CONNECT = 2 8.158 -CMSG_NETIF_BE_DISCONNECT = 3 8.159 -CMSG_NETIF_BE_CREDITLIMIT = 4 8.160 -CMSG_NETIF_BE_DRIVER_STATUS = 32 8.161 - 8.162 -NETIF_INTERFACE_STATUS_CLOSED = 0 #/* Interface doesn't exist. */ 8.163 -NETIF_INTERFACE_STATUS_DISCONNECTED = 1 #/* Exists but is disconnected. */ 8.164 -NETIF_INTERFACE_STATUS_CONNECTED = 2 #/* Exists and is connected. */ 8.165 -NETIF_INTERFACE_STATUS_CHANGED = 3 #/* A device has been added or removed. */ 8.166 - 8.167 -NETIF_DRIVER_STATUS_DOWN = 0 8.168 -NETIF_DRIVER_STATUS_UP = 1 8.169 - 8.170 -netif_formats = { 8.171 - 'netif_be_connect_t': 8.172 - (CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT), 8.173 - 8.174 - 'netif_be_create_t': 8.175 - (CMSG_NETIF_BE, CMSG_NETIF_BE_CREATE), 8.176 - 8.177 - 'netif_be_disconnect_t': 8.178 - (CMSG_NETIF_BE, CMSG_NETIF_BE_DISCONNECT), 8.179 - 8.180 - 'netif_be_destroy_t': 8.181 - (CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY), 8.182 - 8.183 - 'netif_be_creditlimit_t': 8.184 - (CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT), 8.185 - 8.186 - 'netif_be_driver_status_t': 8.187 - (CMSG_NETIF_BE, CMSG_NETIF_BE_DRIVER_STATUS), 8.188 - 8.189 - 'netif_fe_driver_status_t': 8.190 - (CMSG_NETIF_FE, CMSG_NETIF_FE_DRIVER_STATUS), 8.191 - 8.192 - 'netif_fe_interface_connect_t': 8.193 - (CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_CONNECT), 8.194 - 8.195 - 'netif_fe_interface_status_t': 8.196 - (CMSG_NETIF_FE, CMSG_NETIF_FE_INTERFACE_STATUS), 8.197 - } 8.198 - 8.199 -msg_formats.update(netif_formats) 8.200 - 8.201 -#============================================================================ 8.202 -# USB interface message types. 8.203 -#============================================================================ 8.204 - 8.205 -CMSG_USBIF_BE = 8 8.206 -CMSG_USBIF_FE = 9 8.207 - 8.208 -CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED = 0 8.209 - 8.210 -CMSG_USBIF_FE_DRIVER_STATUS_CHANGED = 32 8.211 -CMSG_USBIF_FE_INTERFACE_CONNECT = 33 8.212 -CMSG_USBIF_FE_INTERFACE_DISCONNECT = 34 8.213 - 8.214 -USBIF_DRIVER_STATUS_DOWN = 0 8.215 -USBIF_DRIVER_STATUS_UP = 1 8.216 - 8.217 -USBIF_INTERFACE_STATUS_DESTROYED = 0 #/* Interface doesn't exist. */ 8.218 -USBIF_INTERFACE_STATUS_DISCONNECTED = 1 #/* Exists but is disconnected. */ 8.219 -USBIF_INTERFACE_STATUS_CONNECTED = 2 #/* Exists and is connected. */ 8.220 - 8.221 -CMSG_USBIF_BE_CREATE = 0 8.222 -CMSG_USBIF_BE_DESTROY = 1 8.223 -CMSG_USBIF_BE_CONNECT = 2 8.224 - 8.225 -CMSG_USBIF_BE_DISCONNECT = 3 8.226 -CMSG_USBIF_BE_CLAIM_PORT = 4 8.227 -CMSG_USBIF_BE_RELEASE_PORT = 5 8.228 - 8.229 -CMSG_USBIF_BE_DRIVER_STATUS_CHANGED = 32 8.230 - 8.231 -USBIF_BE_STATUS_OKAY = 0 8.232 -USBIF_BE_STATUS_ERROR = 1 8.233 - 8.234 -USBIF_BE_STATUS_INTERFACE_EXISTS = 2 8.235 -USBIF_BE_STATUS_INTERFACE_NOT_FOUND = 3 8.236 -USBIF_BE_STATUS_INTERFACE_CONNECTED = 4 8.237 -USBIF_BE_STATUS_OUT_OF_MEMORY = 7 8.238 -USBIF_BE_STATUS_MAPPING_ERROR = 9 8.239 - 8.240 -usbif_formats = { 8.241 - 'usbif_be_create_t': 8.242 - (CMSG_USBIF_BE, CMSG_USBIF_BE_CREATE), 8.243 - 8.244 - 'usbif_be_destroy_t': 8.245 - (CMSG_USBIF_BE, CMSG_USBIF_BE_DESTROY), 8.246 - 8.247 - 'usbif_be_connect_t': 8.248 - (CMSG_USBIF_BE, CMSG_USBIF_BE_CONNECT), 8.249 - 8.250 - 'usbif_be_disconnect_t': 8.251 - (CMSG_USBIF_BE, CMSG_USBIF_BE_DISCONNECT), 8.252 - 8.253 - 'usbif_be_claim_port_t': 8.254 - (CMSG_USBIF_BE, CMSG_USBIF_BE_CLAIM_PORT), 8.255 - 8.256 - 'usbif_be_release_port_t': 8.257 - (CMSG_USBIF_BE, CMSG_USBIF_BE_RELEASE_PORT), 8.258 - 8.259 - 'usbif_fe_interface_status_changed_t': 8.260 - (CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED), 8.261 - 8.262 - 'usbif_fe_driver_status_changed_t': 8.263 - (CMSG_USBIF_FE, CMSG_USBIF_FE_DRIVER_STATUS_CHANGED), 8.264 - 8.265 - 'usbif_fe_interface_connect_t': 8.266 - (CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_CONNECT), 8.267 - 8.268 - 'usbif_fe_interface_disconnect_t': 8.269 - (CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_DISCONNECT), 8.270 - 8.271 - } 8.272 - 8.273 -msg_formats.update(usbif_formats) 8.274 - 8.275 -#============================================================================ 8.276 -# Domain shutdown message types. 8.277 -#============================================================================ 8.278 - 8.279 -CMSG_SHUTDOWN = 6 8.280 - 8.281 -CMSG_SHUTDOWN_POWEROFF = 0 8.282 -CMSG_SHUTDOWN_REBOOT = 1 8.283 -CMSG_SHUTDOWN_SUSPEND = 2 8.284 -CMSG_SHUTDOWN_SYSRQ = 3 8.285 - 8.286 -STOPCODE_shutdown = 0 8.287 -STOPCODE_reboot = 1 8.288 -STOPCODE_suspend = 2 8.289 -STOPCODE_sysrq = 3 8.290 - 8.291 -shutdown_formats = { 8.292 - 'shutdown_poweroff_t': 8.293 - (CMSG_SHUTDOWN, CMSG_SHUTDOWN_POWEROFF), 8.294 - 8.295 - 'shutdown_reboot_t': 8.296 - (CMSG_SHUTDOWN, CMSG_SHUTDOWN_REBOOT), 8.297 - 8.298 - 'shutdown_suspend_t': 8.299 - (CMSG_SHUTDOWN, CMSG_SHUTDOWN_SUSPEND), 8.300 - 8.301 - 'shutdown_sysrq_t': 8.302 - (CMSG_SHUTDOWN, CMSG_SHUTDOWN_SYSRQ) 8.303 - } 8.304 - 8.305 -msg_formats.update(shutdown_formats) 8.306 - 8.307 -#============================================================================ 8.308 -# Domain memory reservation message. 8.309 -#============================================================================ 8.310 - 8.311 -CMSG_MEM_REQUEST = 7 8.312 -CMSG_MEM_REQUEST_SET = 0 8.313 - 8.314 -mem_request_formats = { 8.315 - 'mem_request_t': 8.316 - (CMSG_MEM_REQUEST, CMSG_MEM_REQUEST_SET) 8.317 - } 8.318 - 8.319 -msg_formats.update(mem_request_formats) 8.320 - 8.321 -#============================================================================ 8.322 -# Domain vcpu hotplug message. 8.323 -#============================================================================ 8.324 - 8.325 -CMSG_VCPU_HOTPLUG = 10 8.326 -CMSG_VCPU_HOTPLUG_OFF = 0 8.327 -CMSG_VCPU_HOTPLUG_ON = 1 8.328 - 8.329 -vcpu_hotplug_formats = { 8.330 - 'vcpu_hotplug_off_t': 8.331 - (CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF), 8.332 - 8.333 - 'vcpu_hotplug_on_t': 8.334 - (CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON) 8.335 - } 8.336 - 8.337 -msg_formats.update(vcpu_hotplug_formats) 8.338 - 8.339 -#============================================================================ 8.340 -class Msg: 8.341 - pass 8.342 - 8.343 -_next_msgid = 0 8.344 - 8.345 -def nextid(): 8.346 - """Generate the next message id. 8.347 - 8.348 - @return: message id 8.349 - @rtype: int 8.350 - """ 8.351 - global _next_msgid 8.352 - _next_msgid += 1 8.353 - return _next_msgid 8.354 - 8.355 -def packMsg(ty, params): 8.356 - """Pack a message. 8.357 - Any I{mac} parameter is passed in as an int[6] array and converted. 8.358 - 8.359 - @param ty: message type name 8.360 - @type ty: string 8.361 - @param params: message parameters 8.362 - @type params: dicy 8.363 - @return: message 8.364 - @rtype: xu message 8.365 - """ 8.366 - msgid = nextid() 8.367 - if DEBUG: print '>packMsg', msgid, ty, params 8.368 - (major, minor) = msg_formats[ty] 8.369 - args = {} 8.370 - for (k, v) in params.items(): 8.371 - if k in ['mac', 'be_mac']: 8.372 - for i in range(0, 6): 8.373 - args['%s[%d]' % (k, i)] = v[i] 8.374 - else: 8.375 - args[k] = v 8.376 - msg = xu.message(major, minor, msgid, args) 8.377 - if DEBUG: print '<packMsg', msg.get_header()['id'], ty, args 8.378 - return msg 8.379 - 8.380 -def unpackMsg(ty, msg): 8.381 - """Unpack a message. 8.382 - Any mac addresses in the message are converted to int[6] array 8.383 - in the return dict. 8.384 - 8.385 - @param ty: message type 8.386 - @type ty: string 8.387 - @param msg: message 8.388 - @type msg: xu message 8.389 - @return: parameters 8.390 - @rtype: dict 8.391 - """ 8.392 - args = msg.get_payload() 8.393 - if DEBUG: print '>unpackMsg', args 8.394 - if isinstance(args, types.StringType): 8.395 - args = {'value': args} 8.396 - else: 8.397 - mac = [0, 0, 0, 0, 0, 0] 8.398 - macs = [] 8.399 - for (k, v) in args.items(): 8.400 - if k.startswith('mac['): 8.401 - macs.append(k) 8.402 - i = int(k[4:5]) 8.403 - mac[i] = v 8.404 - else: 8.405 - pass 8.406 - if macs: 8.407 - args['mac'] = mac 8.408 - #print 'macs=', macs 8.409 - #print 'args=', args 8.410 - for k in macs: 8.411 - del args[k] 8.412 - if DEBUG: 8.413 - msgid = msg.get_header()['id'] 8.414 - print '<unpackMsg', msgid, ty, args 8.415 - return args 8.416 - 8.417 -def msgTypeName(ty, subty): 8.418 - """Convert a message type, subtype pair to a message type name. 8.419 - 8.420 - @param ty: message type 8.421 - @type ty: int 8.422 - @param subty: message subtype 8.423 - @type ty: int 8.424 - @return: message type name (or None) 8.425 - @rtype: string or None 8.426 - """ 8.427 - for (name, info) in msg_formats.items(): 8.428 - if info[0] == ty and info[1] == subty: 8.429 - return name 8.430 - return None 8.431 - 8.432 -def printMsg(msg, out=sys.stdout, all=False): 8.433 - """Print a message. 8.434 - 8.435 - @param msg: message 8.436 - @type msg: xu message 8.437 - @param out: where to print to 8.438 - @type out: stream 8.439 - @param all: print payload if true 8.440 - @type all: bool 8.441 - """ 8.442 - hdr = msg.get_header() 8.443 - major = hdr['type'] 8.444 - minor = hdr['subtype'] 8.445 - msgid = hdr['id'] 8.446 - ty = msgTypeName(major, minor) 8.447 - print >>out, 'message:', 'type=', ty, '%d:%d' % (major, minor), 'id=%d' % msgid 8.448 - if all: 8.449 - print >>out, 'payload=', msg.get_payload() 8.450 - 8.451 - 8.452 -def getMessageType(msg): 8.453 - """Get a 2-tuple of the message type and subtype. 8.454 - 8.455 - @param msg: message 8.456 - @type msg: xu message 8.457 - @return: type info 8.458 - @rtype: (int, int) 8.459 - """ 8.460 - hdr = msg.get_header() 8.461 - return (hdr['type'], hdr.get('subtype')) 8.462 - 8.463 -def getMessageId(msg): 8.464 - hdr = msg.get_header() 8.465 - return hdr['id']
9.1 --- a/tools/python/xen/xend/server/netif.py Wed Sep 07 17:43:56 2005 +0000 9.2 +++ b/tools/python/xen/xend/server/netif.py Wed Sep 07 18:28:04 2005 +0000 9.3 @@ -30,9 +30,7 @@ from xen.xend import XendVnet 9.4 from xen.xend.XendRoot import get_component 9.5 from xen.xend.xenstore import DBVar 9.6 9.7 -from xen.xend.server import channel 9.8 -from xen.xend.server.controller import CtrlMsgRcvr, Dev, DevController 9.9 -from xen.xend.server.messages import * 9.10 +from xen.xend.server.controller import Dev, DevController 9.11 9.12 class NetDev(Dev): 9.13 """A network device. 9.14 @@ -90,12 +88,9 @@ class NetDev(Dev): 9.15 def __init__(self, controller, id, config, recreate=False): 9.16 Dev.__init__(self, controller, id, config, recreate=recreate) 9.17 self.vif = int(self.id) 9.18 - self.evtchn = None 9.19 self.status = None 9.20 self.frontendDomain = self.getDomain() 9.21 - self.frontendChannel = None 9.22 self.backendDomain = None 9.23 - self.backendChannel = None 9.24 self.credit = None 9.25 self.period = None 9.26 self.mac = None 9.27 @@ -109,17 +104,11 @@ class NetDev(Dev): 9.28 9.29 def exportToDB(self, save=False): 9.30 Dev.exportToDB(self, save=save) 9.31 - if self.evtchn: 9.32 - db = self.db.addChild("evtchn") 9.33 - self.evtchn.saveToDB(db, save=save) 9.34 9.35 def init(self, recreate=False, reboot=False): 9.36 self.destroyed = False 9.37 self.status = NETIF_INTERFACE_STATUS_DISCONNECTED 9.38 self.frontendDomain = self.getDomain() 9.39 - self.frontendChannel = self.getChannel() 9.40 - cf = channel.channelFactory() 9.41 - self.backendChannel = cf.openChannel(self.backendDomain) 9.42 9.43 def _get_config_mac(self, config): 9.44 vmac = sxp.child_value(config, 'mac') 9.45 @@ -287,10 +276,6 @@ class NetDev(Dev): 9.46 val.append(['credit', self.credit]) 9.47 if self.period: 9.48 val.append(['period', self.period]) 9.49 - if self.evtchn: 9.50 - val.append(['evtchn', 9.51 - self.evtchn['port1'], 9.52 - self.evtchn['port2']]) 9.53 return val 9.54 9.55 def get_vifname(self): 9.56 @@ -348,42 +333,11 @@ class NetDev(Dev): 9.57 if recreate: 9.58 pass 9.59 else: 9.60 - self.send_be_create() 9.61 if self.credit and self.period: 9.62 - self.send_be_creditlimit(self.credit, self.period) 9.63 + #self.send_be_creditlimit(self.credit, self.period) 9.64 + pass 9.65 self.vifctl('up', vmname=self.getDomainName()) 9.66 9.67 - def closeEvtchn(self): 9.68 - if self.evtchn: 9.69 - channel.eventChannelClose(self.evtchn) 9.70 - self.evtchn = None 9.71 - 9.72 - def openEvtchn(self): 9.73 - self.evtchn = channel.eventChannel(self.backendDomain, self.frontendDomain) 9.74 - 9.75 - def getEventChannelBackend(self): 9.76 - val = 0 9.77 - if self.evtchn: 9.78 - val = self.evtchn['port1'] 9.79 - return val 9.80 - 9.81 - def getEventChannelFrontend(self): 9.82 - val = 0 9.83 - if self.evtchn: 9.84 - val = self.evtchn['port2'] 9.85 - return val 9.86 - 9.87 - def send_be_create(self): 9.88 - msg = packMsg('netif_be_create_t', 9.89 - { 'domid' : self.frontendDomain, 9.90 - 'netif_handle' : self.vif, 9.91 - 'be_mac' : self.be_mac or [0, 0, 0, 0, 0, 0], 9.92 - 'mac' : self.mac, 9.93 - #'vifname' : self.vifname 9.94 - }) 9.95 - msg = self.backendChannel.requestResponse(msg) 9.96 - # todo: check return status 9.97 - 9.98 def destroy(self, change=False, reboot=False): 9.99 """Destroy the device's resources and disconnect from the back-end 9.100 device controller. If 'change' is true notify the front-end interface. 9.101 @@ -393,47 +347,14 @@ class NetDev(Dev): 9.102 self.destroyed = True 9.103 self.status = NETIF_INTERFACE_STATUS_CLOSED 9.104 log.debug("Destroying vif domain=%d vif=%d", self.frontendDomain, self.vif) 9.105 - self.closeEvtchn() 9.106 self.vifctl('down') 9.107 - self.send_be_disconnect() 9.108 - self.send_be_destroy() 9.109 if change: 9.110 self.reportStatus() 9.111 9.112 - def send_be_disconnect(self): 9.113 - msg = packMsg('netif_be_disconnect_t', 9.114 - { 'domid' : self.frontendDomain, 9.115 - 'netif_handle' : self.vif }) 9.116 - self.backendChannel.requestResponse(msg) 9.117 - #todo: check return status 9.118 - 9.119 - def send_be_destroy(self, response=None): 9.120 - msg = packMsg('netif_be_destroy_t', 9.121 - { 'domid' : self.frontendDomain, 9.122 - 'netif_handle' : self.vif }) 9.123 - self.backendChannel.requestResponse(msg) 9.124 - #todo: check return status 9.125 - 9.126 - def recv_fe_interface_connect(self, val): 9.127 - self.openEvtchn() 9.128 - msg = packMsg('netif_be_connect_t', 9.129 - { 'domid' : self.frontendDomain, 9.130 - 'netif_handle' : self.vif, 9.131 - 'evtchn' : self.getEventChannelBackend(), 9.132 - 'tx_shmem_frame' : val['tx_shmem_frame'], 9.133 - 'tx_shmem_ref' : val['tx_shmem_ref'], 9.134 - 'rx_shmem_frame' : val['rx_shmem_frame'], 9.135 - 'rx_shmem_ref' : val['rx_shmem_ref'] }) 9.136 - msg = self.backendChannel.requestResponse(msg) 9.137 - #todo: check return status 9.138 - self.status = NETIF_INTERFACE_STATUS_CONNECTED 9.139 - self.reportStatus() 9.140 - 9.141 def setCreditLimit(self, credit, period): 9.142 #todo: these params should be in sxpr and vif config. 9.143 self.credit = credit 9.144 self.period = period 9.145 - self.send_be_creditlimit(credit, period) 9.146 9.147 def getCredit(self): 9.148 return self.credit 9.149 @@ -441,31 +362,10 @@ class NetDev(Dev): 9.150 def getPeriod(self): 9.151 return self.period 9.152 9.153 - def send_be_creditlimit(self, credit, period): 9.154 - msg = packMsg('netif_be_creditlimit_t', 9.155 - { 'domid' : self.frontendDomain, 9.156 - 'netif_handle' : self.vif, 9.157 - 'credit_bytes' : credit, 9.158 - 'period_usec' : period }) 9.159 - msg = self.backendChannel.requestResponse(msg) 9.160 - # todo: check return status 9.161 - 9.162 - def reportStatus(self, resp=False): 9.163 - msg = packMsg('netif_fe_interface_status_t', 9.164 - { 'handle' : self.vif, 9.165 - 'status' : self.status, 9.166 - 'evtchn' : self.getEventChannelFrontend(), 9.167 - 'domid' : self.backendDomain, 9.168 - 'mac' : self.mac }) 9.169 - if resp: 9.170 - self.frontendChannel.writeResponse(msg) 9.171 - else: 9.172 - self.frontendChannel.writeRequest(msg) 9.173 - 9.174 def interfaceChanged(self): 9.175 """Notify the front-end that a device has been added or removed. 9.176 """ 9.177 - self.reportStatus() 9.178 + pass 9.179 9.180 class NetifController(DevController): 9.181 """Network interface controller. Handles all network devices for a domain. 9.182 @@ -473,25 +373,9 @@ class NetifController(DevController): 9.183 9.184 def __init__(self, vm, recreate=False): 9.185 DevController.__init__(self, vm, recreate=recreate) 9.186 - self.channel = None 9.187 - self.rcvr = None 9.188 - self.channel = None 9.189 9.190 def initController(self, recreate=False, reboot=False): 9.191 self.destroyed = False 9.192 - self.channel = self.getChannel() 9.193 - # Register our handlers for incoming requests. 9.194 - self.rcvr = CtrlMsgRcvr(self.channel) 9.195 - self.rcvr.addHandler(CMSG_NETIF_FE, 9.196 - CMSG_NETIF_FE_DRIVER_STATUS, 9.197 - self.recv_fe_driver_status) 9.198 - self.rcvr.addHandler(CMSG_NETIF_FE, 9.199 - CMSG_NETIF_FE_INTERFACE_STATUS, 9.200 - self.recv_fe_interface_status) 9.201 - self.rcvr.addHandler(CMSG_NETIF_FE, 9.202 - CMSG_NETIF_FE_INTERFACE_CONNECT, 9.203 - self.recv_fe_interface_connect) 9.204 - self.rcvr.registerChannel() 9.205 if reboot: 9.206 self.rebootDevices() 9.207 9.208 @@ -501,8 +385,6 @@ class NetifController(DevController): 9.209 self.destroyed = True 9.210 log.debug("Destroying netif domain=%d", self.getDomain()) 9.211 self.destroyDevices(reboot=reboot) 9.212 - if self.rcvr: 9.213 - self.rcvr.deregisterChannel() 9.214 9.215 def sxpr(self): 9.216 val = ['netif', ['dom', self.getDomain()]] 9.217 @@ -524,57 +406,3 @@ class NetifController(DevController): 9.218 9.219 dev = self.devices[vif] 9.220 return dev.setCreditLimit(credit, period) 9.221 - 9.222 - def recv_fe_driver_status(self, msg): 9.223 - msg = packMsg('netif_fe_driver_status_t', 9.224 - { 'status' : NETIF_DRIVER_STATUS_UP, 9.225 - ## FIXME: max_handle should be max active interface id 9.226 - 'max_handle' : self.getDeviceCount() 9.227 - #'max_handle' : self.getMaxDeviceId() 9.228 - }) 9.229 - # Two ways of doing it: 9.230 - # 1) front-end requests driver status, we reply with the interface count, 9.231 - # front-end polls the interfaces, 9.232 - # front-end checks they are all up 9.233 - # 2) front-end requests driver status, we reply (with anything), 9.234 - # we notify the interfaces, 9.235 - # we notify driver status up with the count 9.236 - # front-end checks they are all up 9.237 - # 9.238 - # We really want to use 1), but at the moment the xenU kernel panics 9.239 - # in that mode, so we're sticking to 2) for now. 9.240 - resp = False 9.241 - if resp: 9.242 - self.channel.writeResponse(msg) 9.243 - else: 9.244 - for dev in self.devices.values(): 9.245 - dev.reportStatus() 9.246 - self.channel.writeRequest(msg) 9.247 - return resp 9.248 - 9.249 - def recv_fe_interface_status(self, msg): 9.250 - val = unpackMsg('netif_fe_interface_status_t', msg) 9.251 - vif = val['handle'] 9.252 - dev = self.findDevice(vif) 9.253 - if dev: 9.254 - dev.reportStatus(resp=True) 9.255 - else: 9.256 - log.error('Received netif_fe_interface_status for unknown vif: dom=%d vif=%d', 9.257 - self.getDomain(), vif) 9.258 - msg = packMsg('netif_fe_interface_status_t', 9.259 - { 'handle' : -1, 9.260 - 'status' : NETIF_INTERFACE_STATUS_CLOSED, 9.261 - }); 9.262 - self.channel.writeResponse(msg) 9.263 - return True 9.264 - 9.265 - def recv_fe_interface_connect(self, msg): 9.266 - val = unpackMsg('netif_fe_interface_connect_t', msg) 9.267 - vif = val['handle'] 9.268 - dev = self.getDevice(vif) 9.269 - if dev: 9.270 - dev.recv_fe_interface_connect(val) 9.271 - else: 9.272 - log.error('Received netif_fe_interface_connect for unknown vif: dom=%d vif=%d', 9.273 - self.getDomain(), vif) 9.274 -
10.1 --- a/tools/python/xen/xend/server/tpmif.py Wed Sep 07 17:43:56 2005 +0000 10.2 +++ b/tools/python/xen/xend/server/tpmif.py Wed Sep 07 18:28:04 2005 +0000 10.3 @@ -13,9 +13,7 @@ from xen.xend.XendLogging import log 10.4 from xen.xend.XendRoot import get_component 10.5 from xen.xend.xenstore import DBVar 10.6 10.7 -from xen.xend.server import channel 10.8 -from xen.xend.server.controller import CtrlMsgRcvr, Dev, DevController 10.9 -from xen.xend.server.messages import * 10.10 +from xen.xend.server.controller import Dev, DevController 10.11 10.12 class TPMifController(DevController): 10.13 """TPM interface controller. Handles all TPM devices for a domain. 10.14 @@ -23,20 +21,15 @@ class TPMifController(DevController): 10.15 10.16 def __init__(self, vm, recreate=False): 10.17 DevController.__init__(self, vm, recreate=recreate) 10.18 - self.rcvr = None 10.19 - self.channel = None 10.20 10.21 def initController(self, recreate=False, reboot=False): 10.22 self.destroyed = False 10.23 - self.channel = self.getChannel() 10.24 10.25 def destroyController(self, reboot=False): 10.26 """Destroy the controller and all devices. 10.27 """ 10.28 self.destroyed = True 10.29 self.destroyDevices(reboot=reboot) 10.30 - if self.rcvr: 10.31 - self.rcvr.deregisterChannel() 10.32 10.33 def sxpr(self): 10.34 val = ['tpmif', ['dom', self.getDomain()]]
11.1 --- a/tools/python/xen/xend/server/usbif.py Wed Sep 07 17:43:56 2005 +0000 11.2 +++ b/tools/python/xen/xend/server/usbif.py Wed Sep 07 18:28:04 2005 +0000 11.3 @@ -9,9 +9,7 @@ from xen.xend.XendLogging import log 11.4 from xen.xend.XendError import XendError 11.5 from xen.xend.xenstore import DBVar 11.6 11.7 -from xen.xend.server import channel 11.8 from xen.xend.server.controller import Dev, DevController 11.9 -from xen.xend.server.messages import * 11.10 11.11 class UsbBackend: 11.12 """Handler for the 'back-end' channel to a USB device driver domain 11.13 @@ -25,40 +23,16 @@ class UsbBackend: 11.14 self.connecting = False 11.15 self.frontendDomain = self.controller.getDomain() 11.16 self.backendDomain = dom 11.17 - self.frontendChannel = None 11.18 - self.backendChannel = None 11.19 11.20 def init(self, recreate=False, reboot=False): 11.21 - self.frontendChannel = self.controller.getChannel() 11.22 - cf = channel.channelFactory() 11.23 - self.backendChannel = cf.openChannel(self.backendDomain) 11.24 - 11.25 + pass 11.26 + 11.27 def __str__(self): 11.28 return ('<UsbifBackend frontend=%d backend=%d id=%d>' 11.29 % (self.frontendDomain, 11.30 self.backendDomain, 11.31 self.id)) 11.32 11.33 - def closeEvtchn(self): 11.34 - if self.evtchn: 11.35 - channel.eventChannelClose(self.evtchn) 11.36 - self.evtchn = None 11.37 - 11.38 - def openEvtchn(self): 11.39 - self.evtchn = channel.eventChannel(self.backendDomain, self.frontendDomain) 11.40 - 11.41 - def getEventChannelBackend(self): 11.42 - val = 0 11.43 - if self.evtchn: 11.44 - val = self.evtchn['port1'] 11.45 - return val 11.46 - 11.47 - def getEventChannelFrontend(self): 11.48 - val = 0 11.49 - if self.evtchn: 11.50 - val = self.evtchn['port2'] 11.51 - return val 11.52 - 11.53 def connect(self, recreate=False): 11.54 """Connect the controller to the usbif control interface. 11.55 11.56 @@ -67,78 +41,14 @@ class UsbBackend: 11.57 log.debug("Connecting usbif %s", str(self)) 11.58 if recreate or self.connected or self.connecting: 11.59 pass 11.60 - else: 11.61 - self.send_be_create() 11.62 11.63 - def send_be_create(self): 11.64 - msg = packMsg('usbif_be_create_t', 11.65 - { 'domid' : self.frontendDomain }) 11.66 - msg = self.backendChannel.requestResponse(msg) 11.67 - val = unpackMsg('usbif_be_create_t', msg) 11.68 - log.debug('>UsbifBackendController>respond_be_create> %s', str(val)) 11.69 - self.connected = True 11.70 - 11.71 def destroy(self, reboot=False): 11.72 """Disconnect from the usbif control interface and destroy it. 11.73 """ 11.74 self.destroyed = True 11.75 - self.send_be_disconnect() 11.76 - self.send_be_destroy() 11.77 - self.closeEvtchn() 11.78 11.79 - def send_be_disconnect(self): 11.80 - log.debug('>UsbifBackendController>send_be_disconnect> %s', str(self)) 11.81 - msg = packMsg('usbif_be_disconnect_t', 11.82 - { 'domid' : self.frontendDomain }) 11.83 - self.backendChannel.requestResponse(msg) 11.84 - 11.85 - def send_be_destroy(self, response=None): 11.86 - log.debug('>UsbifBackendController>send_be_destroy> %s', str(self)) 11.87 - msg = packMsg('usbif_be_destroy_t', 11.88 - { 'domid' : self.frontendDomain }) 11.89 - self.backendChannel.requestResponse(msg) 11.90 - #todo: check return status 11.91 - 11.92 - 11.93 - def connectInterface(self, val): 11.94 - self.openEvtchn() 11.95 - log.debug(">UsbifBackendController>connectInterface> connecting usbif to event channel %s ports=%d:%d", 11.96 - str(self), 11.97 - self.getEventChannelBackend(), 11.98 - self.getEventChannelFrontend()) 11.99 - msg = packMsg('usbif_be_connect_t', 11.100 - { 'domid' : self.frontendDomain, 11.101 - 'evtchn' : self.getEventChannelBackend(), 11.102 - 'shmem_frame' : val['shmem_frame'], 11.103 - 'bandwidth' : 500 # XXX fix bandwidth! 11.104 - }) 11.105 - msg = self.backendChannel.requestResponse(msg) 11.106 - self.respond_be_connect(msg) 11.107 - 11.108 - def respond_be_connect(self, msg): 11.109 - """Response handler for a be_connect message. 11.110 - 11.111 - @param msg: message 11.112 - @type msg: xu message 11.113 - """ 11.114 - val = unpackMsg('usbif_be_connect_t', msg) 11.115 - log.debug('>UsbifBackendController>respond_be_connect> %s, %s', str(self), str(val)) 11.116 - self.send_fe_interface_status_changed() 11.117 - log.debug(">UsbifBackendController> Successfully connected USB interface for domain %d" % self.frontendDomain) 11.118 - self.controller.claim_ports() 11.119 - 11.120 - def send_fe_interface_status_changed(self): 11.121 - msg = packMsg('usbif_fe_interface_status_changed_t', 11.122 - { 'status' : USBIF_INTERFACE_STATUS_CONNECTED, 11.123 - 'domid' : self.backendDomain, 11.124 - 'evtchn' : self.getEventChannelFrontend(), 11.125 - 'bandwidth' : 500, 11.126 - 'num_ports' : len(self.controller.devices) 11.127 - }) 11.128 - self.frontendChannel.writeRequest(msg) 11.129 - 11.130 def interfaceChanged(self): 11.131 - self.send_fe_interface_status_changed() 11.132 + pass 11.133 11.134 11.135 class UsbDev(Dev): 11.136 @@ -153,17 +63,12 @@ class UsbDev(Dev): 11.137 self.port = id 11.138 self.path = None 11.139 self.frontendDomain = self.getDomain() 11.140 - self.frontendChannel = None 11.141 self.backendDomain = 0 11.142 - self.backendChannel = None 11.143 self.configure(self.config, recreate=recreate) 11.144 11.145 def init(self, recreate=False, reboot=False): 11.146 self.destroyed = False 11.147 self.frontendDomain = self.getDomain() 11.148 - self.frontendChannel = self.getChannel() 11.149 - backend = self.getBackend() 11.150 - self.backendChannel = backend.backendChannel 11.151 11.152 def configure(self, config, change=False, recreate=False): 11.153 if change: 11.154 @@ -204,7 +109,6 @@ class UsbDev(Dev): 11.155 """ 11.156 self.destroyed = True 11.157 log.debug("Destroying usb domain=%d id=%s", self.frontendDomain, self.id) 11.158 - self.send_be_release_port() 11.159 if change: 11.160 self.interfaceChanged() 11.161 11.162 @@ -220,27 +124,6 @@ class UsbDev(Dev): 11.163 """ 11.164 self.getBackend().connect() 11.165 11.166 - def send_be_claim_port(self): 11.167 - log.debug(">UsbifBackendController>send_be_claim_port> about to claim port %s" % self.path) 11.168 - msg = packMsg('usbif_be_claim_port_t', 11.169 - { 'domid' : self.frontendDomain, 11.170 - 'path' : self.path, 11.171 - 'usbif_port' : self.port, 11.172 - 'status' : 0}) 11.173 - self.backendChannel.writeRequest(msg) 11.174 - log.debug(">UsbifBackendController> Claim port completed") 11.175 - # No need to add any callbacks, since the guest polls its virtual ports 11.176 - # anyhow, somewhat like a UHCI controller ;-) 11.177 - 11.178 - def send_be_release_port(self): 11.179 - msg = packMsg('usbif_be_release_port_t', 11.180 - { 'domid' : self.frontendDomain, 11.181 - 'path' : self.path }) 11.182 - self.backendChannel.writeRequest(msg) 11.183 - log.debug(">UsbifBackendController> Release port completed") 11.184 - # No need to add any callbacks, since the guest polls its virtual ports 11.185 - # anyhow, somewhat like a UHCI controller ;-) 11.186 - 11.187 class UsbifController(DevController): 11.188 """USB device interface controller. Handles all USB devices 11.189 for a domain. 11.190 @@ -252,18 +135,9 @@ class UsbifController(DevController): 11.191 DevController.__init__(self, vm, recreate=recreate) 11.192 self.backends = {} 11.193 self.backendId = 0 11.194 - self.rcvr = None 11.195 11.196 def init(self, recreate=False, reboot=False): 11.197 self.destroyed = False 11.198 - self.rcvr = CtrlMsgRcvr(self.getChannel()) 11.199 - self.rcvr.addHandler(CMSG_USBIF_FE, 11.200 - CMSG_USBIF_FE_DRIVER_STATUS_CHANGED, 11.201 - self.recv_fe_driver_status_changed) 11.202 - self.rcvr.addHandler(CMSG_USBIF_FE, 11.203 - CMSG_USBIF_FE_INTERFACE_CONNECT, 11.204 - self.recv_fe_interface_connect) 11.205 - self.rcvr.registerChannel() 11.206 if reboot: 11.207 self.rebootBackends() 11.208 self.rebootDevices() 11.209 @@ -283,8 +157,6 @@ class UsbifController(DevController): 11.210 log.debug("Destroying blkif domain=%d", self.getDomain()) 11.211 self.destroyDevices(reboot=reboot) 11.212 self.destroyBackends(reboot=reboot) 11.213 - if self.rcvr: 11.214 - self.rcvr.deregisterChannel() 11.215 11.216 def rebootBackends(self): 11.217 for backend in self.backends.values(): 11.218 @@ -311,40 +183,3 @@ class UsbifController(DevController): 11.219 def destroyBackends(self, reboot=False): 11.220 for backend in self.backends.values(): 11.221 backend.destroy(reboot=reboot) 11.222 - 11.223 - def recv_fe_driver_status_changed(self, msg): 11.224 - val = unpackMsg('usbif_fe_driver_status_changed_t', msg) 11.225 - log.debug('>UsbifController>recv_fe_driver_status_changed> %s', str(val)) 11.226 - #todo: FIXME: For each backend? 11.227 - msg = packMsg('usbif_fe_interface_status_changed_t', 11.228 - { 'status' : USBIF_INTERFACE_STATUS_DISCONNECTED, 11.229 - 'domid' : 0, #todo: FIXME: should be domid of backend 11.230 - 'evtchn' : 0 }) 11.231 - msg = self.getChannel().requestResponse(msg) 11.232 - self.disconnected_resp(msg) 11.233 - 11.234 - def disconnected_resp(self, msg): 11.235 - val = unpackMsg('usbif_fe_interface_status_changed_t', msg) 11.236 - if val['status'] != USBIF_INTERFACE_STATUS_DISCONNECTED: 11.237 - log.error(">UsbifController>disconnected_resp> unexpected status change") 11.238 - else: 11.239 - log.debug(">UsbifController>disconnected_resp> interface disconnected OK") 11.240 - 11.241 - def recv_fe_interface_connect(self, msg): 11.242 - val = unpackMsg('usbif_fe_interface_status_changed_t', msg) 11.243 - log.debug(">UsbifController>recv_fe_interface_connect> notifying backend") 11.244 - #todo: FIXME: generalise to more than one backend. 11.245 - id = 0 11.246 - backend = self.getBackendById(id) 11.247 - if backend: 11.248 - try: 11.249 - backend.connectInterface(val) 11.250 - except IOError, ex: 11.251 - log.error("Exception connecting backend: %s", ex) 11.252 - else: 11.253 - log.error('interface connect on unknown interface: id=%d', id) 11.254 - 11.255 - def claim_ports(self): 11.256 - for dev in self.devices.values(): 11.257 - dev.send_be_claim_port() 11.258 -