This code re-factors the image.py class, unifying the paravirt and fullvirt
cases to a large degree. Both PV & FV now have a 'device model' - provided
by same QEMU-DM binary in both cases. We pass -M xenpv, or -M xenfv as needed.
The args for VNC, SDL etc are shared by both. HVM adds a bunch of extra args
for disks & NICs mostly. The vfbif.py class no longer needs to start its
own daemon for the paravirt framebuffer, since this is taken care of by the
QEMU now. XendDomainInfo is tweaked so that it also starts the device model
when restoring a paravirt guest.
XendDomainInfo.py | 7 -
image.py | 367 +++++++++++++++++++++++++++---------------------------
server/vfbif.py | 59 --------
3 files changed, 192 insertions(+), 241 deletions(-)
Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
Dan.
diff -r fda4d94ca31d tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py Tue Aug 14 19:55:04 2007 -0400
+++ b/tools/python/xen/xend/image.py Wed Aug 15 11:25:20 2007 -0400
@@ -56,10 +56,9 @@ class ImageHandler:
defining in a subclass.
The method createDeviceModel() is called to create the domain device
- model if it needs one. The default is to do nothing.
+ model.
The method destroy() is called when the domain is destroyed.
- The default is to do nothing.
"""
ostype = None
@@ -91,6 +90,17 @@ class ImageHandler:
("image/cmdline", self.cmdline),
("image/ramdisk", self.ramdisk))
+ self.dmargs = self.parseDeviceModelArgs(vmConfig)
+ self.device_model = vmConfig['platform'].get('device_model')
+ if not self.device_model:
+ self.device_model = xen.util.auxbin.pathTo("qemu-dm")
+
+ self.display = vmConfig['platform'].get('display')
+ self.xauthority = vmConfig['platform'].get('xauthority')
+ self.vncconsole = vmConfig['platform'].get('vncconsole')
+ self.pid = None
+
+
def cleanupBootloading(self):
if self.bootloader:
@@ -173,25 +183,135 @@ class ImageHandler:
"""Build the domain. Define in subclass."""
raise NotImplementedError()
+ # Return a list of cmd line args to the device models based on the
+ # xm config file
+ def parseDeviceModelArgs(self, vmConfig):
+ ret = ["-domain-name", str(self.vm.info['name_label'])]
+
+ # Find RFB console device, and if it exists, make QEMU enable
+ # the VNC console.
+ if int(vmConfig['platform'].get('nographic', 0)) != 0:
+ # skip vnc init if nographic is set
+ ret.append('-nographic')
+ return ret
+
+ vnc_config = {}
+ has_vnc = int(vmConfig['platform'].get('vnc', 0)) != 0
+ has_sdl = int(vmConfig['platform'].get('sdl', 0)) != 0
+ for dev_uuid in vmConfig['console_refs']:
+ dev_type, dev_info = vmConfig['devices'][dev_uuid]
+ if dev_type == 'vfb':
+ vnc_config = dev_info.get('other_config', {})
+ has_vnc = True
+ break
+
+ keymap = vmConfig['platform'].get("keymap")
+ if keymap:
+ ret.append("-k")
+ ret.append(keymap)
+
+ if has_vnc:
+ if not vnc_config:
+ for key in ('vncunused', 'vnclisten', 'vncdisplay',
+ 'vncpasswd'):
+ if key in vmConfig['platform']:
+ vnc_config[key] = vmConfig['platform'][key]
+
+ vnclisten = vnc_config.get('vnclisten',
+ xenopts().get_vnclisten_address())
+ vncdisplay = vnc_config.get('vncdisplay', 0)
+ ret.append('-vnc')
+ ret.append("%s:%d" % (vnclisten, vncdisplay))
+
+ if vnc_config.get('vncunused', 0):
+ ret.append('-vncunused')
+
+ # Store vncpassword in xenstore
+ vncpasswd = vnc_config.get('vncpasswd')
+ if not vncpasswd:
+ vncpasswd = xenopts().get_vncpasswd_default()
+
+ if vncpasswd is None:
+ raise VmError('vncpasswd is not setup in vmconfig or '
+ 'xend-config.sxp')
+
+ if vncpasswd != '':
+ self.vm.storeVm('vncpasswd', vncpasswd)
+ elif has_sdl:
+ # SDL is default in QEMU.
+ pass
+ else:
+ ret.append('-nographic')
+
+ if int(vmConfig['platform'].get('monitor', 0)) != 0:
+ ret = ret + ['-monitor', 'vc']
+ return ret
+
+ def getDeviceModelArgs(self, restore = False):
+ args = [self.device_model]
+ args = args + ([ "-d", "%d" % self.vm.getDomid() ])
+ args = args + self.dmargs
+ return args
+
def createDeviceModel(self, restore = False):
- """Create device model for the domain (define in subclass if
needed)."""
- pass
-
+ if self.pid:
+ return
+ # Execute device model.
+ #todo: Error handling
+ args = self.getDeviceModelArgs(restore)
+ env = dict(os.environ)
+ if self.display:
+ env['DISPLAY'] = self.display
+ if self.xauthority:
+ env['XAUTHORITY'] = self.xauthority
+ if self.vncconsole:
+ args = args + ([ "-vncviewer" ])
+ log.info("spawning device models: %s %s", self.device_model, args)
+ # keep track of pid and spawned options to kill it later
+ self.pid = os.spawnve(os.P_NOWAIT, self.device_model, args, env)
+ self.vm.storeDom("image/device-model-pid", self.pid)
+ log.info("device model pid: %d", self.pid)
+
def saveDeviceModel(self):
- """Save device model for the domain (define in subclass if needed)."""
- pass
+ # Signal the device model to pause itself and save its state
+ xstransact.Store("/local/domain/0/device-model/%i"
+ % self.vm.getDomid(), ('command', 'save'))
+ # Wait for confirmation. Could do this with a watch but we'd
+ # still end up spinning here waiting for the watch to fire.
+ state = ''
+ count = 0
+ while state != 'paused':
+ state = xstransact.Read("/local/domain/0/device-model/%i/state"
+ % self.vm.getDomid())
+ time.sleep(0.1)
+ count += 1
+ if count > 100:
+ raise VmError('Timed out waiting for device model to save')
def resumeDeviceModel(self):
- """Unpause device model for the domain (define in subclass if
needed)."""
- pass
-
- def destroy(self):
- """Extra cleanup on domain destroy (define in subclass if needed)."""
- pass
-
+ # Signal the device model to resume activity after pausing to save.
+ xstransact.Store("/local/domain/0/device-model/%i"
+ % self.vm.getDomid(), ('command', 'continue'))
def recreate(self):
- pass
+ self.pid = self.vm.gatherDom(('image/device-model-pid', int))
+
+ def destroy(self, suspend = False):
+ if self.pid and not suspend:
+ try:
+ os.kill(self.pid, signal.SIGKILL)
+ except OSError, exn:
+ log.exception(exn)
+ try:
+ os.waitpid(self.pid, 0)
+ except OSError, exn:
+ # This is expected if Xend has been restarted within the
+ # life of this domain. In this case, we can kill the process,
+ # but we can't wait for it because it's not our child.
+ pass
+ self.pid = None
+ state = xstransact.Remove("/local/domain/0/device-model/%i"
+ % self.vm.getDomid())
class LinuxImageHandler(ImageHandler):
@@ -223,6 +343,19 @@ class LinuxImageHandler(ImageHandler):
ramdisk = self.ramdisk,
features = self.vm.getFeatures())
+ def parseDeviceModelArgs(self, vmConfig):
+ ret = ImageHandler.parseDeviceModelArgs(self, vmConfig)
+ # Equivalent to old xenconsoled behaviour. Should make
+ # it configurable in future
+ ret = ret + ["-serial", "pty"]
+ return ret
+
+ def getDeviceModelArgs(self, restore = False):
+ args = ImageHandler.getDeviceModelArgs(self, restore)
+ args = args + ([ "-M", "xenpv"])
+ return args
+
+
class PPC_LinuxImageHandler(LinuxImageHandler):
ostype = "linux"
@@ -256,15 +389,6 @@ class HVMImageHandler(ImageHandler):
if 'hvm' not in info['xen_caps']:
raise HVMRequired()
- self.dmargs = self.parseDeviceModelArgs(vmConfig)
- self.device_model = vmConfig['platform'].get('device_model')
- if not self.device_model:
- raise VmError("hvm: missing device model")
-
- self.display = vmConfig['platform'].get('display')
- self.xauthority = vmConfig['platform'].get('xauthority')
- self.vncconsole = vmConfig['platform'].get('vncconsole')
-
rtc_timeoffset = vmConfig['platform'].get('rtc_timeoffset')
self.vm.storeVm(("image/dmargs", " ".join(self.dmargs)),
@@ -272,46 +396,17 @@ class HVMImageHandler(ImageHandler):
("image/display", self.display))
self.vm.storeVm(("rtc/timeoffset", rtc_timeoffset))
- self.pid = None
-
self.pae = int(vmConfig['platform'].get('pae', 0))
self.apic = int(vmConfig['platform'].get('apic', 0))
self.acpi = int(vmConfig['platform'].get('acpi', 0))
-
-
- def buildDomain(self):
- store_evtchn = self.vm.getStorePort()
-
- mem_mb = self.getRequiredInitialReservation() / 1024
-
- log.debug("domid = %d", self.vm.getDomid())
- log.debug("image = %s", self.kernel)
- log.debug("store_evtchn = %d", store_evtchn)
- log.debug("memsize = %d", mem_mb)
- log.debug("vcpus = %d", self.vm.getVCpuCount())
- log.debug("pae = %d", self.pae)
- log.debug("acpi = %d", self.acpi)
- log.debug("apic = %d", self.apic)
-
- rc = xc.hvm_build(domid = self.vm.getDomid(),
- image = self.kernel,
- store_evtchn = store_evtchn,
- memsize = mem_mb,
- vcpus = self.vm.getVCpuCount(),
- pae = self.pae,
- acpi = self.acpi,
- apic = self.apic)
- rc['notes'] = { 'SUSPEND_CANCEL': 1 }
- return rc
-
- # Return a list of cmd line args to the device models based on the
- # xm config file
+
def parseDeviceModelArgs(self, vmConfig):
+ ret = ImageHandler.parseDeviceModelArgs(self, vmConfig)
+ ret = ret + ['-vcpus', str(self.vm.getVCpuCount())]
+
dmargs = [ 'boot', 'fda', 'fdb', 'soundhw',
'localtime', 'serial', 'stdvga', 'isa',
- 'acpi', 'usb', 'usbdevice', 'keymap' ]
-
- ret = ['-vcpus', str(self.vm.getVCpuCount())]
+ 'acpi', 'usb', 'usbdevice' ]
for a in dmargs:
v = vmConfig['platform'].get(a)
@@ -340,7 +435,6 @@ class HVMImageHandler(ImageHandler):
# Handle disk/network related options
mac = None
- ret = ret + ["-domain-name", str(self.vm.info['name_label'])]
nics = 0
for devuuid in vmConfig['vbd_refs']:
@@ -369,130 +463,40 @@ class HVMImageHandler(ImageHandler):
ret.append("-net")
ret.append("tap,vlan=%d,bridge=%s" % (nics, bridge))
-
- #
- # Find RFB console device, and if it exists, make QEMU enable
- # the VNC console.
- #
- if int(vmConfig['platform'].get('nographic', 0)) != 0:
- # skip vnc init if nographic is set
- ret.append('-nographic')
- return ret
-
- vnc_config = {}
- has_vnc = int(vmConfig['platform'].get('vnc', 0)) != 0
- has_sdl = int(vmConfig['platform'].get('sdl', 0)) != 0
- for dev_uuid in vmConfig['console_refs']:
- dev_type, dev_info = vmConfig['devices'][dev_uuid]
- if dev_type == 'vfb':
- vnc_config = dev_info.get('other_config', {})
- has_vnc = True
- break
-
- if has_vnc:
- if not vnc_config:
- for key in ('vncunused', 'vnclisten', 'vncdisplay',
- 'vncpasswd'):
- if key in vmConfig['platform']:
- vnc_config[key] = vmConfig['platform'][key]
-
- vnclisten = vnc_config.get('vnclisten',
- xenopts().get_vnclisten_address())
- vncdisplay = vnc_config.get('vncdisplay', 0)
- ret.append('-vnc')
- ret.append("%s:%d" % (vnclisten, vncdisplay))
-
- if vnc_config.get('vncunused', 0):
- ret.append('-vncunused')
-
- # Store vncpassword in xenstore
- vncpasswd = vnc_config.get('vncpasswd')
- if not vncpasswd:
- vncpasswd = xenopts().get_vncpasswd_default()
-
- if vncpasswd is None:
- raise VmError('vncpasswd is not setup in vmconfig or '
- 'xend-config.sxp')
-
- if vncpasswd != '':
- self.vm.storeVm('vncpasswd', vncpasswd)
- elif has_sdl:
- # SDL is default in QEMU.
- pass
- else:
- ret.append('-nographic')
-
- if int(vmConfig['platform'].get('monitor', 0)) != 0:
- ret = ret + ['-monitor', 'vc']
return ret
- def createDeviceModel(self, restore = False):
- if self.pid:
- return
- # Execute device model.
- #todo: Error handling
- args = [self.device_model]
- args = args + ([ "-d", "%d" % self.vm.getDomid() ])
- if arch.type == "ia64":
- args = args + ([ "-m", "%s" %
- (self.getRequiredInitialReservation() / 1024) ])
- args = args + self.dmargs
+ def getDeviceModelArgs(self, restore = False):
+ args = ImageHandler.getDeviceModelArgs(self, restore)
+ args = args + ([ "-M", "xenfv"])
if restore:
args = args + ([ "-loadvm", "/var/lib/xen/qemu-save.%d" %
self.vm.getDomid() ])
- env = dict(os.environ)
- if self.display:
- env['DISPLAY'] = self.display
- if self.xauthority:
- env['XAUTHORITY'] = self.xauthority
- if self.vncconsole:
- args = args + ([ "-vncviewer" ])
- log.info("spawning device models: %s %s", self.device_model, args)
- # keep track of pid and spawned options to kill it later
- self.pid = os.spawnve(os.P_NOWAIT, self.device_model, args, env)
- self.vm.storeDom("image/device-model-pid", self.pid)
- log.info("device model pid: %d", self.pid)
-
- def saveDeviceModel(self):
- # Signal the device model to pause itself and save its state
- xstransact.Store("/local/domain/0/device-model/%i"
- % self.vm.getDomid(), ('command', 'save'))
- # Wait for confirmation. Could do this with a watch but we'd
- # still end up spinning here waiting for the watch to fire.
- state = ''
- count = 0
- while state != 'paused':
- state = xstransact.Read("/local/domain/0/device-model/%i/state"
- % self.vm.getDomid())
- time.sleep(0.1)
- count += 1
- if count > 100:
- raise VmError('Timed out waiting for device model to save')
-
- def resumeDeviceModel(self):
- # Signal the device model to resume activity after pausing to save.
- xstransact.Store("/local/domain/0/device-model/%i"
- % self.vm.getDomid(), ('command', 'continue'))
-
- def recreate(self):
- self.pid = self.vm.gatherDom(('image/device-model-pid', int))
-
- def destroy(self, suspend = False):
- if self.pid and not suspend:
- try:
- os.kill(self.pid, signal.SIGKILL)
- except OSError, exn:
- log.exception(exn)
- try:
- os.waitpid(self.pid, 0)
- except OSError, exn:
- # This is expected if Xend has been restarted within the
- # life of this domain. In this case, we can kill the process,
- # but we can't wait for it because it's not our child.
- pass
- self.pid = None
- state = xstransact.Remove("/local/domain/0/device-model/%i"
- % self.vm.getDomid())
+ return args
+
+ def buildDomain(self):
+ store_evtchn = self.vm.getStorePort()
+
+ mem_mb = self.getRequiredInitialReservation() / 1024
+
+ log.debug("domid = %d", self.vm.getDomid())
+ log.debug("image = %s", self.kernel)
+ log.debug("store_evtchn = %d", store_evtchn)
+ log.debug("memsize = %d", mem_mb)
+ log.debug("vcpus = %d", self.vm.getVCpuCount())
+ log.debug("pae = %d", self.pae)
+ log.debug("acpi = %d", self.acpi)
+ log.debug("apic = %d", self.apic)
+
+ rc = xc.hvm_build(domid = self.vm.getDomid(),
+ image = self.kernel,
+ store_evtchn = store_evtchn,
+ memsize = mem_mb,
+ vcpus = self.vm.getVCpuCount(),
+ pae = self.pae,
+ acpi = self.acpi,
+ apic = self.apic)
+ rc['notes'] = { 'SUSPEND_CANCEL': 1 }
+ return rc
class IA64_HVM_ImageHandler(HVMImageHandler):
@@ -514,6 +518,13 @@ class IA64_HVM_ImageHandler(HVMImageHand
def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
# Explicit shadow memory is not a concept
return 0
+
+ def getDeviceModelArgs(self, restore = False):
+ args = HVMImageHandler.getDeviceModelArgs(self, restore)
+ args = args + ([ "-m", "%s" %
+ (self.getRequiredInitialReservation() / 1024) ])
+ return args
+
class X86_HVM_ImageHandler(HVMImageHandler):
diff -r fda4d94ca31d tools/python/xen/xend/server/vfbif.py
--- a/tools/python/xen/xend/server/vfbif.py Tue Aug 14 19:55:04 2007 -0400
+++ b/tools/python/xen/xend/server/vfbif.py Wed Aug 15 11:18:05 2007 -0400
@@ -5,14 +5,6 @@ import xen.xend
import xen.xend
import os
-def spawn_detached(path, args, env):
- p = os.fork()
- if p == 0:
- os.spawnve(os.P_NOWAIT, path, args, env)
- os._exit(0)
- else:
- os.waitpid(p, 0)
-
CONFIG_ENTRIES = ['type', 'vncdisplay', 'vnclisten', 'vncpasswd', 'vncunused',
'display', 'xauthority', 'keymap',
'uuid', 'location', 'protocol']
@@ -42,57 +34,6 @@ class VfbifController(DevController):
return dict([(CONFIG_ENTRIES[i], devinfo[i])
for i in range(len(CONFIG_ENTRIES))
if devinfo[i] is not None])
-
-
- def createDevice(self, config):
- DevController.createDevice(self, config)
- if self.vm.info.is_hvm():
- # is HVM, so qemu-dm will handle the vfb.
- return
-
- args = [ xen.util.auxbin.pathTo("qemu-dm"),
- "-M", "xenpv",
- "-d", "%d" % self.vm.getDomid(),
- "-domain-name", self.vm.getName() ]
- t = config.get("type", None)
- if t == "vnc":
- passwd = None
- if config.has_key("vncpasswd"):
- passwd = config["vncpasswd"]
- else:
- passwd =
xen.xend.XendOptions.instance().get_vncpasswd_default()
- if passwd:
- self.vm.storeVm("vncpasswd", passwd)
- log.debug("Stored a VNC password for vfb access")
- else:
- log.debug("No VNC passwd configured for vfb access")
-
- vnclisten = config.get('vnclisten',
-
xen.xend.XendOptions.instance().get_vnclisten_address())
- vncdisplay = config.get('vncdisplay', 0)
- args += ['-vnc', "%s:%d" % (vnclisten, vncdisplay)]
-
- if config.get('vncunused', 0):
- args += ['-vncunused']
-
- if config.has_key("keymap"):
- args += ["-k", "%s" % config["keymap"]]
- else:
- xoptions = xen.xend.XendOptions.instance()
- if xoptions.get_keymap():
- args += ["-k", "%s" % xoptions.get_keymap()]
-
- spawn_detached(args[0], args, os.environ)
- elif t == "sdl":
- env = dict(os.environ)
- if config.has_key("display"):
- env['DISPLAY'] = config["display"]
- if config.has_key("xauthority"):
- env['XAUTHORITY'] = config["xauthority"]
- spawn_detached(args[0], args, env)
- else:
- raise VmError('Unknown vfb type %s (%s)' % (t, repr(config)))
-
def waitForDevice(self, devid):
if self.vm.info.get('HVM_boot_policy'):
diff -r 04c80f1aa008 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py Wed Aug 15 14:17:34 2007 -0400
+++ b/tools/python/xen/xend/XendDomainInfo.py Wed Aug 15 15:28:38 2007 -0400
@@ -1638,10 +1638,9 @@ class XendDomainInfo:
self.console_mfn = console_mfn
self._introduceDomain()
- if self.info.is_hvm():
- self.image = image.create(self, self.info)
- if self.image:
- self.image.createDeviceModel(True)
+ self.image = image.create(self, self.info)
+ if self.image:
+ self.image.createDeviceModel(True)
self._storeDomDetails()
self._registerWatches()
self.refreshShutdown()
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|