diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/examples/xm_dom_create.py | 3 | ||||
-rw-r--r-- | tools/xend/lib/utils.c | 52 | ||||
-rwxr-xr-x | tools/xenmgr/lib/server/blkif.py | 7 | ||||
-rwxr-xr-x | tools/xenmgr/lib/server/channel.py | 56 | ||||
-rw-r--r-- | tools/xenmgr/lib/server/messages.py | 11 | ||||
-rwxr-xr-x | tools/xenmgr/lib/server/netif.py | 14 |
6 files changed, 92 insertions, 51 deletions
diff --git a/tools/examples/xm_dom_create.py b/tools/examples/xm_dom_create.py index c7cd8d6701..6c2f9674a7 100755 --- a/tools/examples/xm_dom_create.py +++ b/tools/examples/xm_dom_create.py @@ -254,6 +254,9 @@ def make_domain_config(): ['func', func] ] config_devs.append(['device', config_pci]) + # Add one vif with unspecified MAC. + config_devs.append(['device', ['vif']]) + config += config_devs config_vfr = ['vfr'] diff --git a/tools/xend/lib/utils.c b/tools/xend/lib/utils.c index 903bb9c274..ba38e065b4 100644 --- a/tools/xend/lib/utils.c +++ b/tools/xend/lib/utils.c @@ -670,7 +670,7 @@ static void unmap_control_interface(int fd, control_if_t *c) (void)munmap(vaddr, PAGE_SIZE); } -typedef struct { +typedef struct xu_port_object { PyObject_HEAD; int mem_fd; int xc_handle; @@ -683,6 +683,42 @@ typedef struct { static PyObject *port_error; +static int xup_connect(xu_port_object *xup, domid_t dom, + int local_port, int remote_port){ + // From our prespective rx = producer, tx = consumer. + int err = 0; + printf("%s> dom=%u %d:%d\n", __FUNCTION__, dom, local_port, remote_port); + + // Consumer = tx. + //xup->interface->tx_resp_prod = 0; + //xup->interface->tx_req_prod = 0; + xup->tx_resp_prod = xup->interface->tx_resp_prod; + xup->tx_req_cons = xup->interface->tx_resp_prod; + printf("%s> tx: %p %p : %p %p\n", __FUNCTION__, + xup->interface->tx_resp_prod, + xup->tx_resp_prod, + xup->tx_req_cons, + xup->interface->tx_req_prod); + + // Producer = rx. + //xup->interface->rx_req_prod = 0; + //xup->interface->rx_resp_prod = 0; + xup->rx_req_prod = xup->interface->rx_req_prod; + xup->rx_resp_cons = xup->interface->rx_resp_prod; + printf("%s> rx: %p %p : %p %p\n", __FUNCTION__, + xup->rx_resp_cons, + xup->interface->rx_resp_prod, + xup->interface->rx_req_prod, + xup->rx_req_prod); + + xup->remote_dom = dom; + xup->local_port = local_port; + xup->remote_port = remote_port; + + printf("%s< err=%d\n", __FUNCTION__, err); + return err; +} + static PyObject *xu_port_notify(PyObject *self, PyObject *args) { xu_port_object *xup = (xu_port_object *)self; @@ -988,19 +1024,7 @@ static PyObject *xu_port_new(PyObject *self, PyObject *args) goto fail4; } - xup->interface->tx_resp_prod = 0; - xup->interface->rx_req_prod = 0; - xup->interface->tx_req_prod = 0; - xup->interface->rx_resp_prod = 0; - - xup->tx_req_cons = 0; - xup->tx_resp_prod = 0; - xup->rx_req_prod = 0; - xup->rx_resp_cons = 0; - xup->remote_dom = dom; - xup->local_port = port1; - xup->remote_port = port2; - + xup_connect(xup, dom, port1, port2); return (PyObject *)xup; diff --git a/tools/xenmgr/lib/server/blkif.py b/tools/xenmgr/lib/server/blkif.py index 0ef8ff0ff3..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) @@ -98,7 +95,7 @@ class BlkifControllerFactory(controller.ControllerFactory): blkif.reattached() def recv_be_driver_status_changed(self, msg, req): - val = unpackMsg('blkif_be_driver_status_changed_t'. msg) + val = unpackMsg('blkif_be_driver_status_changed_t', msg) status = val['status'] if status == BLKIF_DRIVER_STATUS_UP and not self.attached: for blkif in self.getInstances(): 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: |