aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/xenmgr/lib/server/blkif.py5
-rwxr-xr-xtools/xenmgr/lib/server/channel.py56
-rw-r--r--tools/xenmgr/lib/server/messages.py11
-rwxr-xr-xtools/xenmgr/lib/server/netif.py14
4 files changed, 50 insertions, 36 deletions
diff --git a/tools/xenmgr/lib/server/blkif.py b/tools/xenmgr/lib/server/blkif.py
index 5c533f82cf..ae2736da43 100755
--- a/tools/xenmgr/lib/server/blkif.py
+++ b/tools/xenmgr/lib/server/blkif.py
@@ -4,12 +4,9 @@ from messages import *
class BlkifControllerFactory(controller.ControllerFactory):
"""Factory for creating block device interface controllers.
- Also handles the 'back-end' channel to dom0.
+ Also handles the 'back-end' channel to the device driver domain.
"""
- # todo: add support for setting dom controlling blkifs (don't assume 0).
- # todo: add support for 'recovery'.
-
def __init__(self):
controller.ControllerFactory.__init__(self)
diff --git a/tools/xenmgr/lib/server/channel.py b/tools/xenmgr/lib/server/channel.py
index 7678e1807f..04f7441f7a 100755
--- a/tools/xenmgr/lib/server/channel.py
+++ b/tools/xenmgr/lib/server/channel.py
@@ -9,13 +9,17 @@ class ChannelFactory:
"""Factory for creating channels.
Maintains a table of channels.
"""
-
+
+ """ Channels indexed by index. """
channels = {}
def __init__(self):
+ """Constructor - do not use. Use the channelFactory function."""
self.notifier = xend.utils.notifier()
def addChannel(self, channel):
+ """Add a channel.
+ """
idx = channel.idx
self.channels[idx] = channel
self.notifier.bind(idx)
@@ -24,14 +28,20 @@ class ChannelFactory:
#channel.notify()
def getChannel(self, idx):
+ """Get the channel with the given index (if any).
+ """
return self.channels.get(idx)
def delChannel(self, idx):
+ """Remove the channel with the given index (if any).
+ """
if idx in self.channels:
del self.channels[idx]
self.notifier.unbind(idx)
def domChannel(self, dom):
+ """Get the channel for the given domain.
+ """
for chan in self.channels.values():
if chan.dom == dom:
return chan
@@ -40,12 +50,19 @@ class ChannelFactory:
return chan
def channelClosed(self, channel):
+ """The given channel has been closed - remove it.
+ """
self.delChannel(channel.idx)
def createPort(self, dom):
+ """Create a port for a channel to the given domain.
+ """
return xend.utils.port(dom)
def channelFactory():
+ """Singleton constructor for the channel factory.
+ Use this instead of the class constructor.
+ """
global inst
try:
inst
@@ -59,6 +76,8 @@ class Channel:
"""
def __init__(self, factory, dom):
+ """Create a channel to the given domain using the given factory.
+ """
self.factory = factory
self.dom = dom
self.port = self.factory.createPort(dom)
@@ -69,15 +88,24 @@ class Channel:
self.queue = []
def getIndex(self):
+ """Get the channel index.
+ """
return self.idx
def getLocalPort(self):
+ """Get the local port.
+ """
return self.port.local_port
def getRemotePort(self):
+ """Get the remote port.
+ """
return self.port.remote_port
def close(self):
+ """Close the channel. Calls lostChannel() on all its devices and
+ channelClosed() on the factory.
+ """
for d in self.devs:
d.lostChannel()
self.factory.channelClosed(self)
@@ -114,6 +142,8 @@ class Channel:
return self.devs_by_type.get(type)
def getMessageType(self, msg):
+ """Get a 2-tuple of the message type and subtype.
+ """
hdr = msg.get_header()
return (hdr['type'], hdr.get('subtype'))
@@ -142,25 +172,19 @@ class Channel:
#print 'notificationReceived<', work
def notify(self):
- #print 'notify>', self
self.port.notify()
def handleRequests(self):
- #print 'handleRequests>'
work = 0
while 1:
- #print 'handleRequests>', work
msg = self.readRequest()
- #print 'handleRequests> msg=', msg
if not msg: break
self.requestReceived(msg)
work += 1
- #print 'handleRequests<', work
return work
def requestReceived(self, msg):
(ty, subty) = self.getMessageType(msg)
- #print 'requestReceived>', ty, subty, self
#todo: Must respond before writing any more messages.
#todo: Should automate this (respond on write)
self.port.write_response(msg)
@@ -172,21 +196,16 @@ class Channel:
% (msgTypeName(ty, subty), ty, subty)), self
def handleResponses(self):
- #print 'handleResponses>', self
work = 0
while 1:
- #print 'handleResponses>', work
msg = self.readResponse()
- #print 'handleResponses> msg=', msg
if not msg: break
self.responseReceived(msg)
work += 1
- #print 'handleResponses<', work
return work
def responseReceived(self, msg):
(ty, subty) = self.getMessageType(msg)
- #print 'responseReceived>', ty, subty
dev = self.getDevice(ty)
if dev:
dev.responseReceived(msg, ty, subty)
@@ -195,23 +214,18 @@ class Channel:
% (msgTypeName(ty, subty), ty, subty)), self
def handleWrites(self):
- #print 'handleWrites>', self
work = 0
# Pull data from producers.
- #print 'handleWrites> pull...'
for dev in self.devs:
work += dev.produceRequests()
# Flush the queue.
- #print 'handleWrites> flush...'
while self.queue and self.port.space_to_write_request():
msg = self.queue.pop(0)
self.port.write_request(msg)
work += 1
- #print 'handleWrites<', work
return work
def writeRequest(self, msg, notify=1):
- #print 'writeRequest>', self
if self.closed:
val = -1
elif self.writeReady():
@@ -221,11 +235,9 @@ class Channel:
else:
self.queue.append(msg)
val = 0
- #print 'writeRequest<', val
return val
def writeResponse(self, msg):
- #print 'writeResponse>', self
if self.closed: return -1
self.port.write_response(msg)
return 1
@@ -235,25 +247,19 @@ class Channel:
return self.port.space_to_write_request()
def readRequest(self):
- #print 'readRequest>', self
if self.closed:
- #print 'readRequest> closed'
return None
if self.port.request_to_read():
val = self.port.read_request()
else:
val = None
- #print 'readRequest< ', val
return val
def readResponse(self):
- #print 'readResponse>', self
if self.closed:
- #print 'readResponse> closed'
return None
if self.port.response_to_read():
val = self.port.read_response()
else:
val = None
- #print 'readResponse<', val
return val
diff --git a/tools/xenmgr/lib/server/messages.py b/tools/xenmgr/lib/server/messages.py
index b45a5004de..f918e5d440 100644
--- a/tools/xenmgr/lib/server/messages.py
+++ b/tools/xenmgr/lib/server/messages.py
@@ -2,6 +2,8 @@ import struct
import xend.utils
+DEBUG = 0
+
""" All message formats.
Added to incrementally for the various message types.
See below.
@@ -145,7 +147,7 @@ class Msg:
pass
def packMsg(ty, params):
- print '>packMsg', ty, params
+ if DEBUG: print '>packMsg', ty, params
(major, minor, packing) = msg_formats[ty]
args = {}
for (k, v) in params.items():
@@ -154,8 +156,9 @@ def packMsg(ty, params):
args['mac[%d]' % i] = v[i]
else:
args[k] = v
- for (k, v) in args.items():
- print 'packMsg>', k, v, type(v)
+ if DEBUG:
+ for (k, v) in args.items():
+ print 'packMsg>', k, v, type(v)
msgid = 0
msg = xend.utils.message(major, minor, msgid, args)
return msg
@@ -175,7 +178,7 @@ def unpackMsg(ty, msg):
args['mac'] = mac
for k in macs:
del args[k]
- print '<unpackMsg', ty, args
+ if DEBUG: print '<unpackMsg', ty, args
return args
def msgTypeName(ty, subty):
diff --git a/tools/xenmgr/lib/server/netif.py b/tools/xenmgr/lib/server/netif.py
index a6b1c99b19..7403054409 100755
--- a/tools/xenmgr/lib/server/netif.py
+++ b/tools/xenmgr/lib/server/netif.py
@@ -6,10 +6,8 @@ from messages import *
class NetifControllerFactory(controller.ControllerFactory):
"""Factory for creating network interface controllers.
- Also handles the 'back-end' channel to dom0.
+ Also handles the 'back-end' channel to the device driver domain.
"""
- # todo: add support for setting dom controlling blkifs (don't assume 0).
- # todo: add support for 'recovery'.
def __init__(self):
controller.ControllerFactory.__init__(self)
@@ -25,6 +23,8 @@ class NetifControllerFactory(controller.ControllerFactory):
self.registerChannel()
def createInstance(self, dom):
+ """Create or find the network interface controller for a domain.
+ """
#print 'netif>createInstance> dom=', dom
netif = self.getInstanceByDom(dom)
if netif is None:
@@ -33,6 +33,8 @@ class NetifControllerFactory(controller.ControllerFactory):
return netif
def setControlDomain(self, dom):
+ """Set the 'back-end' device driver domain.
+ """
self.deregisterChannel()
self.attached = 0
self.dom = dom
@@ -129,6 +131,12 @@ class NetifController(controller.Controller):
return mac
def attach_device(self, vif, vmac):
+ """Attach a network device.
+ If vmac is None a random mac address is assigned.
+
+ @param vif interface index
+ @param vmac mac address (string)
+ """
if vmac is None:
mac = self.randomMAC()
else: