From: Kurt Garloff Subject: Re: [PATCH 1/3] domUloader Date: Tue, 17 Jan 2006 00:43:48 +0100 Message-ID: <20060116234348.GD17087@tpkurt.wlan.garloff.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1952206785==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Xen development list List-Id: xen-devel@lists.xenproject.org --===============1952206785== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="gKijDXBCEH69PxaN" Content-Disposition: inline --gKijDXBCEH69PxaN Content-Type: multipart/mixed; boundary="eMnpOGXCMazMAbfp" Content-Disposition: inline --eMnpOGXCMazMAbfp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Mon, Jan 16, 2006 at 11:26:09PM +0000, Kurt Garloff wrote: > (1) A patch to xend/XenDomainInfo.py, xend/XenBootloader.py and=20 > xm/create.py, making sure that all the needed info is passed > to the bootloader and also stored for reuse on rebooting. Some more remarks: XendBootloader.py misses a timeout and waits for the bootloader to finish forever; I just made a TODO. One of the problems it causes though is that the xenbl FIFO may stay laying around. To avoid clashes, I have added some randomness to the name. Apart from the, the patch does add storing and passing --disks=3D --root=3D --entry=3D to the bootloader call. In the reboot code, I reconstruct the disks list in the form it's created on initial creation (4-tuples) from the sxpr; I'm not very happy with the way that's done. If someone with intimate sxp knowledge wants to send a followup patch that makes the code more beautiful here, I would appreciate it. Best, --=20 Kurt Garloff, Head Architect, Director SUSE Labs (act.), Novell Inc. --eMnpOGXCMazMAbfp Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="xen-domUloader.diff" Content-Transfer-Encoding: quoted-printable --- xen/xm/create.py.orig 2005-12-07 21:23:58.000000000 +0100 +++ xen/xm/create.py 2006-01-16 21:20:00.000000000 +0100 @@ -552,13 +552,11 @@ def configure_vmx(config_image, vals): def run_bootloader(vals): if not os.access(vals.bootloader, os.X_OK): err("Bootloader isn't executable") - if len(vals.disk) < 1: + if not vals.disk: err("No disks configured and boot loader requested") - (uname, dev, mode, backend) =3D vals.disk[0] - file =3D blkif.blkdev_uname_to_file(uname) =20 - return bootloader(vals.bootloader, file, not vals.console_autoconnect, - vals.vcpus, vals.bootentry) + return bootloader(vals.bootloader, vals.disk, not vals.console_autocon= nect, + vals.vcpus, vals.bootentry, vals.root) =20 def make_config(vals): """Create the domain configuration. @@ -572,7 +570,8 @@ def make_config(vals): if v: config.append([n, v]) =20 - map(add_conf, ['name', 'memory', 'ssidref', 'maxmem', 'restart', + map(add_conf, ['name', 'memory', 'ssidref', 'maxmem',=20 + 'root', 'bootloader', 'bootentry', 'restart', 'on_poweroff', 'on_reboot', 'on_crash']) =20 if vals.cpu is not None: @@ -587,9 +586,10 @@ def make_config(vals): config.append(['backend', ['netif']]) if vals.tpmif: config.append(['backend', ['tpmif']]) + if vals.root: + config.append(['root', vals.root]) =20 if vals.bootloader: - config.append(['bootloader', vals.bootloader]) config_image =3D run_bootloader(vals) else: config_image =3D configure_image(vals) @@ -742,7 +742,7 @@ def spawn_vnc(display): vncpid =3D os.spawnvp(os.P_NOWAIT, "vncviewer", vncargs) =20 return VNC_BASE_PORT + display - =20 + def preprocess_vnc(vals): """If vnc was specified, spawn a vncviewer in listen mode and pass its address to the domain on the kernel command line. @@ -758,7 +758,7 @@ def preprocess_vnc(vals): vnc_host =3D get_host_addr() vnc =3D 'VNC_VIEWER=3D%s:%d' % (vnc_host, vnc_port) vals.extra =3D vnc + ' ' + vals.extra - =20 + def preprocess(vals): if not vals.kernel and not vals.bootloader: err("No kernel specified") @@ -770,7 +770,7 @@ def preprocess(vals): preprocess_nfs(vals) preprocess_vnc(vals) preprocess_vtpm(vals) - =20 + def make_domain(opts, config): """Create, build and start a domain. =20 --- xen/xend/XendDomainInfo.py.orig 2005-12-14 21:03:29.000000000 +0100 +++ xen/xend/XendDomainInfo.py 2006-01-16 22:20:15.000000000 +0100 @@ -31,7 +31,6 @@ import threading =20 import xen.lowlevel.xc from xen.util import asserts -from xen.util.blkif import blkdev_uname_to_file =20 import balloon import image @@ -126,6 +125,8 @@ ROUNDTRIPPING_CONFIG_ENTRIES =3D [ ('memory', int), ('maxmem', int), ('bootloader', str), + ('bootentry', str), + ('root', str), ] =20 ROUNDTRIPPING_CONFIG_ENTRIES +=3D VM_CONFIG_PARAMS @@ -552,6 +553,8 @@ class XendDomainInfo: defaultInfo('memory', lambda: 0) defaultInfo('maxmem', lambda: 0) defaultInfo('bootloader', lambda: None) + defaultInfo('bootentry', lambda: None) + defaultInfo('root', lambda: None) defaultInfo('backend', lambda: []) defaultInfo('device', lambda: []) defaultInfo('image', lambda: None) @@ -1489,17 +1492,29 @@ class XendDomainInfo: if not self.info['bootloader']: return # if we're restarting with a bootloader, we need to run it - # FIXME: this assumes the disk is the first device and - # that we're booting from the first disk blcfg =3D None config =3D self.sxpr() - # FIXME: this assumes that we want to use the first disk - dev =3D sxp.child_value(config, "device") - if dev: - disk =3D sxp.child_value(dev, "uname") - fn =3D blkdev_uname_to_file(disk) - blcfg =3D bootloader(self.info['bootloader'], fn, 1, - self.info['vcpus']) + devices =3D sxp.children(config, "device") + # bootloader expects disks in config file format: + # [(uname, dev, mode, backend), (...), ...] + # FIXME: Ugly, we use knowledge on the internal sxp storage fmt + # We should use better suited sxp. functions instead. + vbds =3D [] + for dev in devices: + if dev[1][0] !=3D 'vbd': + continue + vbds.append([sxp.child_value(dev[1], "uname"), + sxp.child_value(dev[1], "dev"), + sxp.child_value(dev[1], "mode"), + sxp.child_value(dev[1], "backend")]) + log.debug("bootloader(%s, %s, 1, %s, %s, %s)" % \ + (self.info['bootloader'], str(vbds), + self.info['vcpus'], self.info['bootentry'], + self.info['root'])) + if vbds: + blcfg =3D bootloader(self.info['bootloader'], vbds, 1, + self.info['vcpus'], self.info['bootentry'], + self.info['root']) if blcfg is None: msg =3D "Had a bootloader specified, but can't find disk" log.error(msg) --- xen/xend/XendBootloader.py.orig 2005-12-07 21:23:58.000000000 +0100 +++ xen/xend/XendBootloader.py 2006-01-16 22:25:54.000000000 +0100 @@ -12,32 +12,39 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # =20 -import os, select, errno +import os, select, errno, random import sxp =20 from XendLogging import log from XendError import VmError +from xen.util.blkif import blkdev_uname_to_file =20 -BL_FIFO =3D "/var/lib/xen/xenbl" - -def bootloader(blexec, disk, quiet =3D 0, vcpus =3D None, entry =3D None): +def bootloader(blexec, disks, quiet =3D 0, vcpus =3D None, entry =3D None,= root =3D None): """Run the boot loader executable on the given disk and return a config image. @param blexec Binary to use as the boot loader - @param disk Disk to run the boot loader on. - @param quiet Run in non-interactive mode, just booting the default. - @param vcpus Number of vcpus for the domain. - @param entry Default entry to boot.""" + @param disks Disks for the domain, in [uname, dev, mode, backend] tu= ples. + @param quiet Run in non-interactive mode, just booting the default. + @param vcpus Number of vcpus for the domain. + @param entry Default entry to boot. + @param root Device with root FS (root=3D param).""" =20 if not os.access(blexec, os.X_OK): msg =3D "Bootloader isn't executable" log.error(msg) raise VmError(msg) - if not os.access(disk, os.R_OK): - msg =3D "Disk isn't accessible" + + firstdisk =3D disks[0][0] + #firstdisk =3D sxp.child_value(disks, "uname") + firstdisk =3D blkdev_uname_to_file(firstdisk) + + if not os.access(firstdisk, os.R_OK): + msg =3D "First disk isn't accessible" log.error(msg) raise VmError(msg) =20 + BL_FIFO =3D "/var/lib/xen/xenbl.%5i" % + random.randint(0, 99999) + os.mkfifo(BL_FIFO, 0600) =20 child =3D os.fork() @@ -45,10 +52,14 @@ def bootloader(blexec, disk, quiet =3D 0,=20 args =3D [ blexec ] if quiet: args.append("-q") - args.append("--output=3D%s" %(BL_FIFO,)) + args.append("--output=3D%s" % BL_FIFO) if entry is not None: - args.append("--entry=3D%s" %(entry,)) - args.append(disk) + args.append("--entry=3D%s" % entry) + args.append("--disks=3D\"%s\"" % str(disks)) + if root is not None: + root =3D root[:root.find(" ")] + args.append("--root=3D%s" % root) + args.append(firstdisk) =20 try: os.execvp(args[0], args) @@ -65,6 +76,7 @@ def bootloader(blexec, disk, quiet =3D 0,=20 continue break ret =3D "" + # TODO: Add timeout, cleanup and raise VmError if it occurs while 1: select.select([r], [], []) s =3D os.read(r, 1024) --eMnpOGXCMazMAbfp-- --gKijDXBCEH69PxaN Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFDzC+0xmLh6hyYd04RAgrCAJ0fbL6Vi8DsunyMusuaH2zRpux9YgCguNgx UCJ72Z/p3Jc5nIlDI5bYB0E= =4Ri8 -----END PGP SIGNATURE----- --gKijDXBCEH69PxaN-- --===============1952206785== 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 --===============1952206785==--