mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
bitkeeper revision 1.1662.1.5 (42a46588UuohS0CHY1F3XZtrchaAwA)
Many files: Remove device indexing. Signed-off-by: Mike Wray <mike.wray@hp.com> Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
1 parent
94a75e0212
commit
54c1b7d5a1
7 files changed
+34
-81
No files matched your search
@@ -650,13 +650,13 @@ class XendDomain:
|
||||
@return: device object (or None)
|
||||
"""
|
||||
dominfo = self.domain_lookup(id)
|
||||
return dominfo.getDeviceByIndex(type, devid)
|
||||
return dominfo.getDevice(type, devid)
|
||||
|
||||
def domain_vif_limit_set(self, id, vif, credit, period):
|
||||
"""Limit the vif's transmission rate
|
||||
"""
|
||||
dominfo = self.domain_lookup(id)
|
||||
dev = dominfo.getDeviceById('vif', vif)
|
||||
dev = dominfo.getDevice('vif', vif)
|
||||
if not dev:
|
||||
raise XendError("invalid vif")
|
||||
return dev.setCreditLimit(credit, period)
|
||||
|
||||
@@ -353,7 +353,7 @@ class XendDomainInfo:
|
||||
self.controllers[type] = ctrl
|
||||
return ctrl
|
||||
|
||||
def createDevice(self, type, devconfig, recreate=False):
|
||||
def createDevice(self, type, devconfig):
|
||||
ctrl = self.findDeviceController(type)
|
||||
return ctrl.createDevice(devconfig, recreate=self.recreate)
|
||||
|
||||
@@ -369,30 +369,14 @@ class XendDomainInfo:
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.deleteDevice(id)
|
||||
|
||||
def getDevice(self, type, id):
|
||||
def getDevice(self, type, id, error=True):
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.getDevice(id)
|
||||
return ctrl.getDevice(id, error=error)
|
||||
|
||||
def getDeviceByIndex(self, type, idx):
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.getDeviceByIndex(idx)
|
||||
|
||||
def getDeviceConfig(self, type, id):
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.getDeviceConfig(id)
|
||||
|
||||
def getDeviceIds(self, type):
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.getDeviceIds()
|
||||
|
||||
def getDeviceIndexes(self, type):
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.getDeviceIndexes()
|
||||
|
||||
def getDeviceConfigs(self, type):
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.getDeviceConfigs()
|
||||
|
||||
def getDeviceSxprs(self, type):
|
||||
ctrl = self.getDeviceController(type)
|
||||
return ctrl.getDeviceSxprs()
|
||||
@@ -578,24 +562,23 @@ class XendDomainInfo:
|
||||
devices.append(dev)
|
||||
return devices
|
||||
|
||||
def get_device_savedinfo(self, type, index):
|
||||
def get_device_savedinfo(self, type, id):
|
||||
val = None
|
||||
if self.savedinfo is None:
|
||||
return val
|
||||
devices = sxp.child(self.savedinfo, 'devices')
|
||||
if devices is None:
|
||||
return val
|
||||
index = str(index)
|
||||
for d in sxp.children(devices, type):
|
||||
dindex = sxp.child_value(d, 'index')
|
||||
if dindex is None: continue
|
||||
if str(dindex) == index:
|
||||
did = sxp.child_value(d, 'id')
|
||||
if did is None: continue
|
||||
if int(did) == id:
|
||||
val = d
|
||||
break
|
||||
return val
|
||||
|
||||
def get_device_recreate(self, type, index):
|
||||
return self.get_device_savedinfo(type, index) or self.recreate
|
||||
def get_device_recreate(self, type, id):
|
||||
return self.get_device_savedinfo(type, id) or self.recreate
|
||||
|
||||
def add_config(self, val):
|
||||
"""Add configuration data to a virtual machine.
|
||||
@@ -765,7 +748,6 @@ class XendDomainInfo:
|
||||
|
||||
def create_configured_devices(self):
|
||||
devices = sxp.children(self.config, 'device')
|
||||
indexes = {}
|
||||
for d in devices:
|
||||
dev_config = sxp.child0(d)
|
||||
if dev_config is None:
|
||||
@@ -774,13 +756,7 @@ class XendDomainInfo:
|
||||
ctrl_type = get_device_handler(dev_type)
|
||||
if ctrl_type is None:
|
||||
raise VmError('unknown device type: ' + dev_type)
|
||||
# Keep track of device indexes by type, so we can fish
|
||||
# out saved info for recreation.
|
||||
idx = indexes.get(dev_type, -1)
|
||||
idx += 1
|
||||
indexes[ctrl_type] = idx
|
||||
recreate = self.get_device_recreate(dev_type, idx)
|
||||
self.createDevice(ctrl_type, dev_config, recreate=recreate)
|
||||
self.createDevice(ctrl_type, dev_config)
|
||||
|
||||
def create_devices(self):
|
||||
"""Create the devices for a vm.
|
||||
@@ -840,16 +816,14 @@ class XendDomainInfo:
|
||||
self.config.append(['device', dev.getConfig()])
|
||||
return dev.sxpr()
|
||||
|
||||
def device_configure(self, dev_config, idx):
|
||||
def device_configure(self, dev_config, id):
|
||||
"""Configure an existing device.
|
||||
|
||||
@param dev_config: device configuration
|
||||
@param idx: device index
|
||||
@param id: device id
|
||||
"""
|
||||
type = sxp.name(dev_config)
|
||||
dev = self.getDeviceByIndex(type, idx)
|
||||
if not dev:
|
||||
raise VmError('invalid device: %s %s' % (type, idx))
|
||||
dev = self.getDevice(type, id)
|
||||
old_config = dev.getConfig()
|
||||
new_config = dev.configure(dev_config, change=True)
|
||||
# Patch new config into vm config.
|
||||
@@ -859,26 +833,22 @@ class XendDomainInfo:
|
||||
self.config[old_index] = new_full_config
|
||||
return new_config
|
||||
|
||||
def device_refresh(self, type, idx):
|
||||
def device_refresh(self, type, id):
|
||||
"""Refresh a device.
|
||||
|
||||
@param type: device type
|
||||
@param idx: device index
|
||||
@param id: device id
|
||||
"""
|
||||
dev = self.getDeviceByIndex(type, idx)
|
||||
if not dev:
|
||||
raise VmError('invalid device: %s %s' % (type, idx))
|
||||
dev = self.getDevice(type, id)
|
||||
dev.refresh()
|
||||
|
||||
def device_delete(self, type, idx):
|
||||
def device_delete(self, type, id):
|
||||
"""Destroy and remove a device.
|
||||
|
||||
@param type: device type
|
||||
@param idx: device index
|
||||
@param id: device id
|
||||
"""
|
||||
dev = self.getDeviceByIndex(type, idx)
|
||||
if not dev:
|
||||
raise VmError('invalid device: %s %s' % (type, idx))
|
||||
dev = self.getDevice(type, id)
|
||||
dev_config = dev.getConfig()
|
||||
if dev_config:
|
||||
self.config.remove(['device', dev_config])
|
||||
|
||||
@@ -293,7 +293,6 @@ class BlkDev(Dev):
|
||||
val.append(['uname', self.uname])
|
||||
if self.node:
|
||||
val.append(['node', self.node])
|
||||
val.append(['index', self.getIndex()])
|
||||
return val
|
||||
|
||||
def getBackend(self):
|
||||
|
||||
@@ -129,7 +129,6 @@ class ConsoleDev(Dev, protocol.ServerFactory):
|
||||
val.append(['local_port', self.getLocalPort() ])
|
||||
val.append(['remote_port', self.getRemotePort() ])
|
||||
val.append(['console_port', self.console_port ])
|
||||
val.append(['index', self.getIndex()])
|
||||
if self.addr:
|
||||
val.append(['connected', self.addr[0], self.addr[1]])
|
||||
finally:
|
||||
|
||||
@@ -228,19 +228,20 @@ class DevController:
|
||||
If change is true the device is a change to an existing domain,
|
||||
i.e. it is being added at runtime rather than when the domain is created.
|
||||
"""
|
||||
dev = self.newDevice(self.nextDeviceId(), config, recreate=recreate)
|
||||
# skanky hack: we use the device ids to maybe find the savedinfo
|
||||
# of the device...
|
||||
id = self.nextDeviceId()
|
||||
if recreate:
|
||||
recreate = self.vm.get_device_savedinfo(self.getType(), id)
|
||||
dev = self.newDevice(id, config, recreate=recreate)
|
||||
dev.init(recreate=recreate)
|
||||
self.addDevice(dev)
|
||||
idx = self.getDeviceIndex(dev)
|
||||
recreate = self.vm.get_device_recreate(self.getType(), idx)
|
||||
dev.attach(recreate=recreate, change=change)
|
||||
|
||||
def configureDevice(self, id, config, change=False):
|
||||
"""Reconfigure an existing device.
|
||||
May be defined in subclass."""
|
||||
dev = self.getDevice(id)
|
||||
if not dev:
|
||||
raise XendError("invalid device id: " + id)
|
||||
dev = self.getDevice(id, error=True)
|
||||
dev.configure(config, change=change)
|
||||
|
||||
def destroyDevice(self, id, change=False, reboot=False):
|
||||
@@ -251,9 +252,7 @@ class DevController:
|
||||
|
||||
The device is not deleted, since it may be recreated later.
|
||||
"""
|
||||
dev = self.getDevice(id)
|
||||
if not dev:
|
||||
raise XendError("invalid device id: " + id)
|
||||
dev = self.getDevice(id, error=True)
|
||||
dev.destroy(change=change, reboot=reboot)
|
||||
return dev
|
||||
|
||||
@@ -278,24 +277,15 @@ class DevController:
|
||||
def isDestroyed(self):
|
||||
return self.destroyed
|
||||
|
||||
def getDevice(self, id):
|
||||
return self.devices.get(id)
|
||||
|
||||
def getDeviceByIndex(self, idx):
|
||||
if 0 <= idx < len(self.device_order):
|
||||
return self.device_order[idx]
|
||||
else:
|
||||
return None
|
||||
|
||||
def getDeviceIndex(self, dev):
|
||||
return self.device_order.index(dev)
|
||||
def getDevice(self, id, error=False):
|
||||
dev = self.devices.get(id)
|
||||
if error and not dev:
|
||||
raise XendError("invalid device id: " + id)
|
||||
return dev
|
||||
|
||||
def getDeviceIds(self):
|
||||
return [ dev.getId() for dev in self.device_order ]
|
||||
|
||||
def getDeviceIndexes(self):
|
||||
return range(0, len(self.device_order))
|
||||
|
||||
def getDevices(self):
|
||||
return self.device_order
|
||||
|
||||
@@ -380,9 +370,6 @@ class Dev:
|
||||
def getId(self):
|
||||
return self.id
|
||||
|
||||
def getIndex(self):
|
||||
return self.controller.getDeviceIndex(self)
|
||||
|
||||
def getConfig(self):
|
||||
return self.config
|
||||
|
||||
|
||||
@@ -199,7 +199,6 @@ class NetDev(Dev):
|
||||
val.append(['evtchn',
|
||||
self.evtchn['port1'],
|
||||
self.evtchn['port2']])
|
||||
val.append(['index', self.getIndex()])
|
||||
return val
|
||||
|
||||
def get_vifname(self):
|
||||
|
||||
@@ -186,7 +186,6 @@ class UsbDev(Dev):
|
||||
['port', self.port],
|
||||
['path', self.path],
|
||||
]
|
||||
val.append(['index', self.getIndex()])
|
||||
return val
|
||||
|
||||
def getBackend(self):
|
||||
|
||||