mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
bitkeeper revision 1.1159.1.36 (4119f27eonzahatd09ja80xf3ifOFw)
Documentation and some debug changes.
This commit is contained in:
1 parent
395b317a50
commit
d25ecc97bb
5 files changed
+72
-32
No files matched your search
@@ -472,7 +472,10 @@ class XendDomainInfo:
|
||||
# When creating or rebooting, a domain with my name should not exist.
|
||||
# When restoring, a domain with my name will exist, but it should have
|
||||
# my domain id.
|
||||
if dominfo and (not self.dom or dominfo.dom != self.dom):
|
||||
if not dominfo:
|
||||
return
|
||||
print 'check_name>', 'dom=', dominfo.name, dominfo.dom, 'self=', name, self.dom
|
||||
if not self.dom or (dominfo.dom != self.dom):
|
||||
raise VmError('vm name clash: ' + name)
|
||||
|
||||
def construct(self, config):
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
|
||||
"""Support for virtual block devices.
|
||||
"""
|
||||
|
||||
from twisted.internet import defer
|
||||
#defer.Deferred.debug = 1
|
||||
|
||||
@@ -247,7 +247,7 @@ class ControllerFactory(CtrlMsgRcvr):
|
||||
Maintains a table of instances.
|
||||
|
||||
@ivar instances: mapping of index to controller instance
|
||||
@type instances: {int: Controller}
|
||||
@type instances: {String: Controller}
|
||||
@ivar dom: domain
|
||||
@type dom: int
|
||||
"""
|
||||
@@ -274,6 +274,10 @@ class ControllerFactory(CtrlMsgRcvr):
|
||||
|
||||
def getInstanceByDom(self, dom):
|
||||
"""Get the controller instance for the given domain.
|
||||
|
||||
@param dom: domain id
|
||||
@type dom: int
|
||||
@return: controller or None
|
||||
"""
|
||||
for inst in self.instances.values():
|
||||
if inst.dom == dom:
|
||||
@@ -281,7 +285,9 @@ class ControllerFactory(CtrlMsgRcvr):
|
||||
return None
|
||||
|
||||
def delInstance(self, instance):
|
||||
"""Delete an instance from the table.
|
||||
"""Delete a controller instance from the table.
|
||||
|
||||
@param instance: controller instance
|
||||
"""
|
||||
if instance.idx in self.instances:
|
||||
del self.instances[instance.idx]
|
||||
@@ -293,16 +299,29 @@ class ControllerFactory(CtrlMsgRcvr):
|
||||
@type dom: int
|
||||
@param recreate: true if the instance is being recreated (after xend restart)
|
||||
@type recreate: int
|
||||
@return: controller instance
|
||||
@rtype: Controller (or subclass)
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def instanceClosed(self, instance):
|
||||
"""Callback called when an instance is closed (usually by the instance).
|
||||
|
||||
@param instance: controller instance
|
||||
"""
|
||||
self.delInstance(instance)
|
||||
|
||||
class Controller(CtrlMsgRcvr):
|
||||
"""Abstract class for a device controller attached to a domain.
|
||||
|
||||
@ivar factory: controller factory
|
||||
@type factory: ControllerFactory
|
||||
@ivar dom: domain
|
||||
@type dom: int
|
||||
@ivar channel: channel to the domain
|
||||
@type channel: Channel
|
||||
@ivar idx: channel index
|
||||
@type idx: String
|
||||
"""
|
||||
|
||||
def __init__(self, factory, dom):
|
||||
@@ -325,6 +344,13 @@ class Controller(CtrlMsgRcvr):
|
||||
|
||||
class Dev:
|
||||
"""Abstract class for a device attached to a device controller.
|
||||
|
||||
@ivar idx: identifier
|
||||
@type idx: String
|
||||
@ivar controller: device controller
|
||||
@type controller: DeviceController
|
||||
@ivar props: property table
|
||||
@type props: { String: value }
|
||||
"""
|
||||
|
||||
def __init__(self, idx, controller):
|
||||
@@ -349,6 +375,11 @@ class Dev:
|
||||
del self.props[k]
|
||||
|
||||
def sxpr(self):
|
||||
"""Get the s-expression for the deivice.
|
||||
Implement in a subclass.
|
||||
|
||||
@return: sxpr
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@@ -213,9 +213,6 @@ def packMsg(ty, params):
|
||||
args['mac[%d]' % i] = v[i]
|
||||
else:
|
||||
args[k] = v
|
||||
if DEBUG:
|
||||
for (k, v) in args.items():
|
||||
print 'packMsg>', k, v, type(v)
|
||||
msg = xu.message(major, minor, msgid, args)
|
||||
if DEBUG: print '<packMsg', msg.get_header()['id'], ty, params
|
||||
return msg
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
|
||||
"""Support for virtual network interfaces.
|
||||
"""
|
||||
|
||||
import random
|
||||
|
||||
@@ -27,8 +29,6 @@ class NetifControllerFactory(controller.ControllerFactory):
|
||||
self.majorTypes = [ CMSG_NETIF_BE ]
|
||||
|
||||
self.subTypes = {
|
||||
#CMSG_NETIF_BE_CREATE : self.recv_be_create,
|
||||
#CMSG_NETIF_BE_CONNECT: self.recv_be_connect,
|
||||
CMSG_NETIF_BE_DRIVER_STATUS_CHANGED: self.recv_be_driver_status_changed,
|
||||
}
|
||||
self.attached = 1
|
||||
@@ -37,10 +37,9 @@ class NetifControllerFactory(controller.ControllerFactory):
|
||||
def createInstance(self, dom, recreate=0):
|
||||
"""Create or find the network interface controller for a domain.
|
||||
|
||||
dom domain
|
||||
recreate if true this is a recreate (xend restarted)
|
||||
|
||||
returns netif controller
|
||||
@param dom: domain
|
||||
@param recreate: if true this is a recreate (xend restarted)
|
||||
@return: netif controller
|
||||
"""
|
||||
netif = self.getInstanceByDom(dom)
|
||||
if netif is None:
|
||||
@@ -51,9 +50,8 @@ class NetifControllerFactory(controller.ControllerFactory):
|
||||
def getDomainDevices(self, dom):
|
||||
"""Get the network device controllers for a domain.
|
||||
|
||||
dom domain
|
||||
|
||||
returns netif controller
|
||||
@param dom: domain
|
||||
@return: netif controller list
|
||||
"""
|
||||
netif = self.getInstanceByDom(dom)
|
||||
return (netif and netif.getDevices()) or []
|
||||
@@ -61,10 +59,9 @@ class NetifControllerFactory(controller.ControllerFactory):
|
||||
def getDomainDevice(self, dom, vif):
|
||||
"""Get a virtual network interface device for a domain.
|
||||
|
||||
dom domain
|
||||
vif virtual interface index
|
||||
|
||||
returns NetDev
|
||||
@param dom: domain
|
||||
@param vif: virtual interface index
|
||||
@return: NetDev
|
||||
"""
|
||||
netif = self.getInstanceByDom(dom)
|
||||
return (netif and netif.getDevice(vif)) or None
|
||||
@@ -72,8 +69,8 @@ class NetifControllerFactory(controller.ControllerFactory):
|
||||
def setControlDomain(self, dom, recreate=0):
|
||||
"""Set the 'back-end' device driver domain.
|
||||
|
||||
dom domain
|
||||
recreate if true this is a recreate (xend restarted)
|
||||
@param dom: domain
|
||||
@param recreate: if true this is a recreate (xend restarted)
|
||||
"""
|
||||
if self.dom == dom: return
|
||||
self.deregisterChannel()
|
||||
@@ -84,6 +81,8 @@ class NetifControllerFactory(controller.ControllerFactory):
|
||||
|
||||
def getControlDomain(self):
|
||||
"""Get the domain id of the back-end control domain.
|
||||
|
||||
@return domain id
|
||||
"""
|
||||
return self.dom
|
||||
|
||||
@@ -95,7 +94,7 @@ class NetifControllerFactory(controller.ControllerFactory):
|
||||
if netif:
|
||||
netif.send_interface_connected(vif)
|
||||
else:
|
||||
log.warning("respond_be_connect> unknown dom=%d vif=%d", dom, vif)
|
||||
log.warning("respond_be_connect> unknown vif dom=%d vif=%d", dom, vif)
|
||||
pass
|
||||
|
||||
def recv_be_driver_status_changed(self, msg, req):
|
||||
@@ -168,6 +167,8 @@ class NetDev(controller.Dev):
|
||||
return ':'.join(map(lambda x: "%02x" % x, self.mac))
|
||||
|
||||
def vifctl_params(self, vmname=None):
|
||||
"""Get the parameters to pass to vifctl.
|
||||
"""
|
||||
dom = self.controller.dom
|
||||
if vmname is None:
|
||||
xd = get_component('xen.xend.XendDomain')
|
||||
@@ -185,6 +186,11 @@ class NetDev(controller.Dev):
|
||||
|
||||
def vifctl(self, op, vmname=None):
|
||||
"""Bring the device up or down.
|
||||
The vmname is needed when bringing a device up for a new domain because
|
||||
the domain is not yet in the table so we can't look its name up.
|
||||
|
||||
@param op: operation name (up, down)
|
||||
@param vmname: vmname
|
||||
"""
|
||||
Vifctl.vifctl(op, **self.vifctl_params(vmname=vmname))
|
||||
vnet = XendVnet.instance().vnet_of_bridge(self.bridge)
|
||||
@@ -239,19 +245,17 @@ class NetifController(controller.Controller):
|
||||
def getDevice(self, vif):
|
||||
"""Get a device.
|
||||
|
||||
vif device index
|
||||
|
||||
returns device (or None)
|
||||
@param vif: device index
|
||||
@return: device (or None)
|
||||
"""
|
||||
return self.devices.get(vif)
|
||||
|
||||
def addDevice(self, vif, config):
|
||||
"""Add a network interface.
|
||||
|
||||
vif device index
|
||||
config device configuration
|
||||
|
||||
returns device
|
||||
@param vif: device index
|
||||
@param config: device configuration
|
||||
@return: device
|
||||
"""
|
||||
dev = NetDev(self, vif, config)
|
||||
self.devices[vif] = dev
|
||||
@@ -263,15 +267,18 @@ class NetifController(controller.Controller):
|
||||
self.destroyDevices()
|
||||
|
||||
def destroyDevices(self):
|
||||
"""Destroy all devices.
|
||||
"""
|
||||
for dev in self.getDevices():
|
||||
dev.destroy()
|
||||
|
||||
def attachDevice(self, vif, config, recreate=0):
|
||||
"""Attach a network device.
|
||||
If vmac is None a random mac address is assigned.
|
||||
|
||||
@param vif interface index
|
||||
@param vmac mac address (string)
|
||||
@param vif: interface index
|
||||
@param config: device configuration
|
||||
@param recreate: recreate flag (true after xend restart)
|
||||
@return: deferred
|
||||
"""
|
||||
self.addDevice(vif, config)
|
||||
d = defer.Deferred()
|
||||
|
||||