From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Daniel P. Berrange" Subject: Re: PATCH 3/3: XenD changes for HVM kernel boot Date: Thu, 31 Jan 2008 17:55:12 +0000 Message-ID: <20080131175512.GE19721@redhat.com> References: <20080131174850.GB19721@redhat.com> Reply-To: "Daniel P. Berrange" Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="RIYY1s2vRbPFwWeW" Return-path: Content-Disposition: inline In-Reply-To: <20080131174850.GB19721@redhat.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --RIYY1s2vRbPFwWeW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This patch provides the tools support for direct kernel boot of HVM guests. Currently the config files in /etc/xen support the args 'kernel', 'ramdisk' and 'extra'. For PV guests these have the obvious meaning. Unfortunately HVM guest configs hijacked the 'kernel' parameter and use it to refer to the path of the HVM firmware. So, this patch adds a new config file parameter called 'loader' which is used to refer to the HVM firmware instead. The conventions for loading the initrd image say that it should live at the end of memory. This requires QEMU to know the size of the guest's initial RAM allocation, so image.py is changed to pass the '-m' flag to QEMU. The HVMImageHandler class in image.py is changed so that if the 'kernel', 'ramdisk' or 'extra' params were given in the config these are passed to QEMU with the '-kernel', '-initrd' and '-append' flags respectively. Finally, the 'loader' param is used as the arg to 'xc_hvm_build' instead of the old 'kernel' param. For the sake of compatability with old HVM guest config files, if the config file has a 'kernel' param whose path matches that of the HVM firmware, then we automatically convert this 'kernel' param into the 'loader' param. This ensures existing HVM guests work without changes required. For the purposes of testing, my guest looks like this: name = "hvmdemo" builder = "hvm" memory = "500" disk = [ "file:/var/lib/xen/images/hvmdemo.img,hda,w" ] uuid = "0a696059-d2e8-2691-86e7-1daeed939649" device_model = "/usr/lib/xen/bin/qemu-dm" loader = "/usr/lib/xen/boot/hvmloader" kernel = "/root/install/vmlinuz-f8-i386" ramdisk = "/root/install/initrd.img-f8-i386" extra = "console=ttyS0 console=tty0" serial = "file:/tmp/hvmdemo.log" vnc=1 vncunused=1 apic=0 acpi=0 pae=0 Note, here we demonstrate a useful advantage of direct kernel boot by telling the guest kernel to send its output to the first serial device, which we then connect to a file for logging. xend/XendConfig.py | 13 ++++++++++++- xend/image.py | 24 +++++++++++++++++++----- xm/create.py | 6 ++++++ 3 files changed, 37 insertions(+), 6 deletions(-) Signed-off-by: Daniel P. Berrange Regards, Dan. -- |=- 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 -=| --RIYY1s2vRbPFwWeW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="xen-hvm-kernel-boot-xend.patch" diff -r 5f997b5b8a58 tools/python/xen/xend/XendConfig.py --- a/tools/python/xen/xend/XendConfig.py Wed Jan 30 15:19:22 2008 +0000 +++ b/tools/python/xen/xend/XendConfig.py Thu Jan 31 12:50:30 2008 -0500 @@ -124,7 +124,7 @@ LEGACY_CFG_TO_XENAPI_CFG = reverse_dict( LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(XENAPI_CFG_TO_LEGACY_CFG) # Platform configuration keys. -XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'display', +XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'loader', 'display', 'fda', 'fdb', 'keymap', 'isa', 'localtime', 'monitor', 'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl', 'soundhw','stdvga', 'usb', 'usbdevice', 'vnc', @@ -404,6 +404,17 @@ class XendConfig(dict): self['platform']['device_model'] = xen.util.auxbin.pathTo("qemu-dm") if self.is_hvm(): + if 'loader' not in self['platform']: + log.debug("No loader present") + # Old configs may have hvmloder set as PV_kernel param, + # so lets migrate them.... + if self['PV_kernel'] == "/usr/lib/xen/boot/hvmloader": + self['platform']['loader'] = self['PV_kernel'] + log.debug("Loader copied from kernel %s" % str(self['platform']['loader'])) + else: + self['platform']['loader'] = "/usr/lib/xen/boot/hvmloader" + log.debug("Loader %s" % str(self['platform']['loader'])) + # Compatibility hack, can go away soon. if 'soundhw' not in self['platform'] and \ self['platform'].get('enable_audio'): diff -r 5f997b5b8a58 tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Wed Jan 30 15:19:22 2008 +0000 +++ b/tools/python/xen/xend/image.py Thu Jan 31 12:50:30 2008 -0500 @@ -127,7 +127,7 @@ class ImageHandler: """ # Set params and call buildDomain(). - if not os.path.isfile(self.kernel): + if self.kernel and not os.path.isfile(self.kernel): raise VmError('Kernel image does not exist: %s' % self.kernel) if self.ramdisk and not os.path.isfile(self.ramdisk): raise VmError('Kernel ramdisk does not exist: %s' % self.ramdisk) @@ -186,6 +186,10 @@ class ImageHandler: # xm config file def parseDeviceModelArgs(self, vmConfig): ret = ["-domain-name", str(self.vm.info['name_label'])] + + # Tell QEMU how large the guest's memory allocation is + # to help it when loading the initrd (if neccessary) + ret += ["-m", str(self.getRequiredInitialReservation() / 1024)] # Find RFB console device, and if it exists, make QEMU enable # the VNC console. @@ -420,8 +424,7 @@ class HVMImageHandler(ImageHandler): def configure(self, vmConfig): ImageHandler.configure(self, vmConfig) - if not self.kernel: - self.kernel = '/usr/lib/xen/boot/hvmloader' + self.loader = vmConfig['platform'].get('loader') info = xc.xeninfo() if 'hvm' not in info['xen_caps']: @@ -445,6 +448,17 @@ class HVMImageHandler(ImageHandler): def parseDeviceModelArgs(self, vmConfig): ret = ImageHandler.parseDeviceModelArgs(self, vmConfig) ret = ret + ['-vcpus', str(self.vm.getVCpuCount())] + + if self.kernel and self.kernel != "/usr/lib/xen/boot/hvmloader": + log.debug("kernel = %s", self.kernel) + ret = ret + ['-kernel', self.kernel] + if self.ramdisk: + log.debug("ramdisk = %s", self.ramdisk) + ret = ret + ['-initrd', self.ramdisk] + if self.cmdline: + log.debug("cmdline = %s", self.cmdline) + ret = ret + ['-append', self.cmdline] + dmargs = [ 'boot', 'fda', 'fdb', 'soundhw', 'localtime', 'serial', 'stdvga', 'isa', @@ -521,7 +535,7 @@ class HVMImageHandler(ImageHandler): mem_mb = self.getRequiredInitialReservation() / 1024 log.debug("domid = %d", self.vm.getDomid()) - log.debug("image = %s", self.kernel) + log.debug("image = %s", self.loader) log.debug("store_evtchn = %d", store_evtchn) log.debug("memsize = %d", mem_mb) log.debug("vcpus = %d", self.vm.getVCpuCount()) @@ -529,7 +543,7 @@ class HVMImageHandler(ImageHandler): log.debug("apic = %d", self.apic) rc = xc.hvm_build(domid = self.vm.getDomid(), - image = self.kernel, + image = self.loader, memsize = mem_mb, vcpus = self.vm.getVCpuCount(), acpi = self.acpi, diff -r 5f997b5b8a58 tools/python/xen/xm/create.py --- a/tools/python/xen/xm/create.py Wed Jan 30 15:19:22 2008 +0000 +++ b/tools/python/xen/xm/create.py Thu Jan 31 12:50:30 2008 -0500 @@ -158,6 +158,10 @@ gopts.var('ramdisk', val='FILE', fn=set_value, default='', use="Path to ramdisk.") +gopts.var('loader', val='FILE', + fn=set_value, default='', + use="Path to HVM firmware.") + gopts.var('features', val='FEATURES', fn=set_value, default='', use="Features to enable in guest kernel") @@ -561,6 +565,8 @@ def configure_image(vals): config_image.append([ 'kernel', os.path.abspath(vals.kernel) ]) if vals.ramdisk: config_image.append([ 'ramdisk', os.path.abspath(vals.ramdisk) ]) + if vals.loader: + config_image.append([ 'loader', os.path.abspath(vals.loader) ]) if vals.cmdline_ip: cmdline_ip = strip('ip=', vals.cmdline_ip) config_image.append(['ip', cmdline_ip]) --RIYY1s2vRbPFwWeW Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --RIYY1s2vRbPFwWeW--