ia64/xen-unstable
changeset 1524:63778f2314cb
bitkeeper revision 1.990.2.6 (40d6e660Z0vrxCNX22AQw744Qy70rw)
First cut at support for setting the domains for block and net backends.
First cut at support for setting the domains for block and net backends.
author | mjw@wray-m-3.hpl.hp.com |
---|---|
date | Mon Jun 21 13:45:04 2004 +0000 (2004-06-21) |
parents | b3df007a98da |
children | 1e52f4f43daa |
files | tools/xenmgr/lib/XendDomain.py tools/xenmgr/lib/XendDomainInfo.py tools/xenmgr/lib/server/blkif.py tools/xenmgr/lib/server/netif.py |
line diff
1.1 --- a/tools/xenmgr/lib/XendDomain.py Mon Jun 21 13:42:11 2004 +0000 1.2 +++ b/tools/xenmgr/lib/XendDomain.py Mon Jun 21 13:45:04 2004 +0000 1.3 @@ -18,6 +18,9 @@ import XendDomainInfo 1.4 import XendConsole 1.5 import EventServer 1.6 1.7 +from xenmgr.server import SrvConsoleServer 1.8 +xend = SrvConsoleServer.instance() 1.9 + 1.10 eserver = EventServer.instance() 1.11 1.12 __all__ = [ "XendDomain" ] 1.13 @@ -49,15 +52,16 @@ class XendDomain: 1.14 def initial_refresh(self): 1.15 """Refresh initial domain info from domain_db. 1.16 """ 1.17 - print "initial_refresh> db=", self.domain_db.values() 1.18 + print "initial_refresh>" 1.19 + for d in self.domain_db.values(): print 'db dom=', d 1.20 domlist = xc.domain_getinfo() 1.21 - print "doms=", domlist 1.22 + for d in domlist: print 'xc dom=', d 1.23 doms = {} 1.24 for d in domlist: 1.25 domid = str(d['dom']) 1.26 doms[domid] = d 1.27 for config in self.domain_db.values(): 1.28 - domid = int(sxp.child_value(config, 'id')) 1.29 + domid = str(sxp.child_value(config, 'id')) 1.30 print "dom=", domid, "config=", config 1.31 if domid in doms: 1.32 print "dom=", domid, "new" 1.33 @@ -141,7 +145,7 @@ class XendDomain: 1.34 config = None 1.35 image = None 1.36 newinfo = XendDomainInfo.XendDomainInfo( 1.37 - config, d['dom'], d['name'], d['mem_kb']/1024, image) 1.38 + config, d['dom'], d['name'], d['mem_kb']/1024, image=image, info=d) 1.39 self._add_domain(newinfo.id, newinfo) 1.40 # Remove entries for domains that no longer exist. 1.41 for d in self.domain.values(): 1.42 @@ -193,13 +197,13 @@ class XendDomain: 1.43 """ 1.44 dom = int(id) 1.45 eserver.inject('xend.domain.start', id) 1.46 - return xc.domain_start(dom=dom) 1.47 + return xend.domain_start(dom) 1.48 1.49 def domain_stop(self, id): 1.50 """Stop domain running. 1.51 """ 1.52 dom = int(id) 1.53 - return xc.domain_stop(dom=dom) 1.54 + return xend.domain_stop(dom) 1.55 1.56 def domain_shutdown(self, id): 1.57 """Shutdown domain (nicely). 1.58 @@ -208,7 +212,7 @@ class XendDomain: 1.59 if dom <= 0: 1.60 return 0 1.61 eserver.inject('xend.domain.shutdown', id) 1.62 - val = xc.domain_destroy(dom=dom, force=0) 1.63 + val = xend.domain_destroy(dom, force=0) 1.64 self.refresh() 1.65 return val 1.66 1.67 @@ -219,7 +223,7 @@ class XendDomain: 1.68 if dom <= 0: 1.69 return 0 1.70 eserver.inject('xend.domain.halt', id) 1.71 - val = xc.domain_destroy(dom=dom, force=1) 1.72 + val = xend.domain_destroy(dom, force=1) 1.73 self.refresh() 1.74 return val 1.75
2.1 --- a/tools/xenmgr/lib/XendDomainInfo.py Mon Jun 21 13:42:11 2004 +0000 2.2 +++ b/tools/xenmgr/lib/XendDomainInfo.py Mon Jun 21 13:45:04 2004 +0000 2.3 @@ -59,7 +59,7 @@ class VmError(ValueError): 2.4 class XendDomainInfo: 2.5 """Virtual machine object.""" 2.6 2.7 - def __init__(self, config, dom, name, memory, image=None, console=None): 2.8 + def __init__(self, config, dom, name, memory, image=None, console=None, info=None): 2.9 """Construct a virtual machine object. 2.10 2.11 config configuration 2.12 @@ -78,8 +78,10 @@ class XendDomainInfo: 2.13 self.console = console 2.14 self.devices = {} 2.15 self.configs = [] 2.16 - self.info = None 2.17 + self.info = info 2.18 self.ipaddrs = [] 2.19 + self.block_controller = 0 2.20 + self.net_controller = 0 2.21 2.22 #todo: state: running, suspended 2.23 self.state = 'running' 2.24 @@ -111,6 +113,7 @@ class XendDomainInfo: 2.25 ['name', self.name], 2.26 ['memory', self.memory] ] 2.27 if self.info: 2.28 + print 'info:', self.info 2.29 run = (self.info['running'] and 'r') or '-' 2.30 block = (self.info['blocked'] and 'b') or '-' 2.31 stop = (self.info['stopped'] and 's') or '-' 2.32 @@ -528,6 +531,18 @@ def vm_create_devices(vm, config): 2.33 print '<vm_create_devices' 2.34 return deferred 2.35 2.36 +def config_controllers(vm, config): 2.37 + for c in sxp.children(config, 'controller'): 2.38 + name = sxp.name(c) 2.39 + if name == 'block': 2.40 + vm.block_controller = 1 2.41 + xend.blkif_set_control_domain(vm.dom) 2.42 + elif name == 'net': 2.43 + vm.net_controller = 1 2.44 + xend.netif_set_control_domain(vm.dom) 2.45 + else: 2.46 + raise VmError('invalid controller type:' + str(name)) 2.47 + 2.48 def vm_configure(vm, config): 2.49 """Configure a vm. 2.50 2.51 @@ -536,7 +551,12 @@ def vm_configure(vm, config): 2.52 2.53 returns Deferred - calls callback with vm 2.54 """ 2.55 - d = xend.blkif_create(vm.dom) 2.56 + config_controllers(vm, config) 2.57 + if vm.block_controller: 2.58 + d = xend.blkif_create(vm.dom) 2.59 + else: 2.60 + d = defer.Deferred() 2.61 + d.callback(1) 2.62 d.addCallback(_vm_configure1, vm, config) 2.63 return d 2.64 2.65 @@ -653,8 +673,11 @@ def vm_dev_vif(vm, val, index): 2.66 val vif config 2.67 index vif index 2.68 """ 2.69 + if vm.net_controller: 2.70 + raise VmError('vif: vif in control domain') 2.71 vif = index #todo 2.72 vmac = sxp.child_value(val, "mac") 2.73 + bridge = sxp.child_value(val, "bridge") # todo 2.74 defer = make_vif(vm.dom, vif, vmac) 2.75 def fn(id): 2.76 dev = val + ['vif', vif] 2.77 @@ -671,6 +694,8 @@ def vm_dev_vbd(vm, val, index): 2.78 val vbd config 2.79 index vbd index 2.80 """ 2.81 + if vm.block_controller: 2.82 + raise VmError('vbd: vbd in control domain') 2.83 uname = sxp.child_value(val, 'uname') 2.84 if not uname: 2.85 raise VMError('vbd: Missing uname') 2.86 @@ -686,6 +711,16 @@ def vm_dev_vbd(vm, val, index): 2.87 defer.addCallback(fn) 2.88 return defer 2.89 2.90 +def parse_pci(val): 2.91 + if isinstance(val, StringType): 2.92 + radix = 10 2.93 + if val.startswith('0x') or val.startswith('0X'): 2.94 + radix = 16 2.95 + v = int(val, radix) 2.96 + else: 2.97 + v = val 2.98 + return v 2.99 + 2.100 def vm_dev_pci(vm, val, index): 2.101 bus = sxp.child_value(val, 'bus') 2.102 if not bus: 2.103 @@ -697,9 +732,9 @@ def vm_dev_pci(vm, val, index): 2.104 if not func: 2.105 raise VMError('pci: Missing func') 2.106 try: 2.107 - bus = int(bus, 16) 2.108 - dev = int(dev, 16) 2.109 - func = int(func, 16) 2.110 + bus = parse_pci(bus) 2.111 + dev = parse_pci(dev) 2.112 + func = parse_pci(func) 2.113 except: 2.114 raise VMError('pci: invalid parameter') 2.115 rc = xc.physdev_pci_access_modify(dom=vm.dom, bus=bus, dev=dev, func=func, enable=1)
3.1 --- a/tools/xenmgr/lib/server/blkif.py Mon Jun 21 13:42:11 2004 +0000 3.2 +++ b/tools/xenmgr/lib/server/blkif.py Mon Jun 21 13:45:04 2004 +0000 3.3 @@ -34,9 +34,9 @@ class BlkifControllerFactory(controller. 3.4 return d 3.5 3.6 def setControlDomain(self, dom): 3.7 - if self.channel: 3.8 - self.deregisterChannel() 3.9 - self.attached = 0 3.10 + if self.dom == dom: return 3.11 + self.deregisterChannel() 3.12 + self.attached = 0 3.13 self.dom = dom 3.14 self.registerChannel() 3.15 # 3.16 @@ -44,6 +44,9 @@ class BlkifControllerFactory(controller. 3.17 # xend.blkif.recovery = True 3.18 #xend.blkif.be_port = xend.main.port_from_dom(dom) 3.19 3.20 + def getControlDomain(self): 3.21 + return self.dom 3.22 + 3.23 def recv_be_create(self, msg, req): 3.24 #print 'recv_be_create>' 3.25 val = unpackMsg('blkif_be_create_t', msg) 3.26 @@ -81,15 +84,20 @@ class BlkifControllerFactory(controller. 3.27 blkif = self.getInstanceByDom(dom) 3.28 if blkif: 3.29 blkif.reattach_device(vdev) 3.30 + self.attached = self.devices_attached() 3.31 + if self.attached: 3.32 + self.reattached() 3.33 + 3.34 + def devices_attached(self): 3.35 + """Check if all devices are attached. 3.36 + """ 3.37 attached = 1 3.38 for blkif in self.getInstances(): 3.39 if not blkif.attached: 3.40 attached = 0 3.41 break 3.42 - self.attached = attached 3.43 - if self.attached: 3.44 - self.reattached() 3.45 - 3.46 + return attached 3.47 + 3.48 def reattached(self): 3.49 for blkif in self.getInstances(): 3.50 blkif.reattached() 3.51 @@ -149,12 +157,16 @@ class BlkifController(controller.Control 3.52 return self.factory.addDeferred() 3.53 3.54 def detach(self): 3.55 + """Detach all devices, when the back-end control domain has changed. 3.56 + """ 3.57 self.attached = 0 3.58 for dev in self.devices.values(): 3.59 dev.attached = 0 3.60 self.send_be_vbd_create(vdev) 3.61 3.62 def reattach_device(self, vdev): 3.63 + """Reattach a device, when the back-end control domain has changed. 3.64 + """ 3.65 dev = self.devices[vdev] 3.66 dev.attached = 1 3.67 attached = 1 3.68 @@ -166,6 +178,8 @@ class BlkifController(controller.Control 3.69 return self.attached 3.70 3.71 def reattached(self): 3.72 + """All devices have been reattached after the back-end control domain has changed. 3.73 + """ 3.74 msg = packMsg('blkif_fe_interface_status_changed_t', 3.75 { 'handle' : 0, 3.76 'status' : BLKIF_INTERFACE_STATUS_DISCONNECTED})
4.1 --- a/tools/xenmgr/lib/server/netif.py Mon Jun 21 13:42:11 2004 +0000 4.2 +++ b/tools/xenmgr/lib/server/netif.py Mon Jun 21 13:45:04 2004 +0000 4.3 @@ -35,6 +35,7 @@ class NetifControllerFactory(controller. 4.4 def setControlDomain(self, dom): 4.5 """Set the 'back-end' device driver domain. 4.6 """ 4.7 + if self.dom == dom: return 4.8 self.deregisterChannel() 4.9 self.attached = 0 4.10 self.dom = dom 4.11 @@ -44,7 +45,9 @@ class NetifControllerFactory(controller. 4.12 # xend.netif.recovery = True 4.13 # xend.netif.be_port = xend.main.port_from_dom(dom) 4.14 # 4.15 - pass 4.16 + 4.17 + def getControlDomain(self): 4.18 + return self.dom 4.19 4.20 def recv_be_create(self, msg, req): 4.21 self.callDeferred(0) 4.22 @@ -64,6 +67,8 @@ class NetifControllerFactory(controller. 4.23 val = unpackMsg('netif_be_driver_status_changed_t', msg) 4.24 status = val['status'] 4.25 if status == NETIF_DRIVER_STATUS_UP and not self.attached: 4.26 + # If we are not attached the driver domain was changed, and 4.27 + # this signals the new driver domain is ready. 4.28 for netif in self.getInstances(): 4.29 netif.reattach_devices() 4.30 self.attached = 1 4.31 @@ -149,6 +154,8 @@ class NetifController(controller.Control 4.32 return d 4.33 4.34 def reattach_devices(self): 4.35 + """Reattach all devices when the back-end control domain has changed. 4.36 + """ 4.37 d = self.factory.addDeferred() 4.38 self.send_be_create(vif) 4.39 self.attach_fe_devices(0) 4.40 @@ -182,10 +189,6 @@ class NetifController(controller.Control 4.41 'rx_shmem_frame' : val['rx_shmem_frame'] }) 4.42 self.factory.writeRequest(msg) 4.43 4.44 - #def recv_fe_interface_status_changed(self): 4.45 - # print 'recv_fe_interface_status_changed>' 4.46 - # pass 4.47 - 4.48 def send_interface_connected(self, vif): 4.49 dev = self.devices[vif] 4.50 msg = packMsg('netif_fe_interface_status_changed_t',