[elbe-devel] [PATCH v3 5/5] hdimg: Use losetup wrapper for grubinstaller97

Torben Hohn torben.hohn at linutronix.de
Wed Apr 15 17:23:58 CEST 2020


On Sat, Apr 04, 2020 at 01:27:55PM -0400, Olivier Dion wrote:
> Instead of using fixed loop device /dev/loop0 and /dev/poop0,
> grubinstaller uses its losetup wrapper to dynamicaly get a device.
> This is because the fixed device could be busy, even though it has
> been detached.
> 
> Also add an exception catching and log it.  This is because the
> finally block can shadow an exception throwed in the try block.
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>

Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>

> ---
>  elbepack/hdimg.py | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
> index c33efa08..5478cbda 100644
> --- a/elbepack/hdimg.py
> +++ b/elbepack/hdimg.py
> @@ -238,14 +238,16 @@ class grubinstaller97(grubinstaller_base):
>          imagemnt = os.path.join(target, "imagemnt")
>          imagemntfs = Filesystem(imagemnt)
>          try:
> -            do('cp -a /dev/loop0 /dev/poop0')
> +            loopdev = self.losetup(self.fs['/'].filename)
> +            loopnum = loopdev.replace("/dev/loop", "")
> +            poopdev = "/dev/poop" + loopnum
>  
> -            do('losetup /dev/poop0 "%s"' % self.fs['/'].filename)
> -            do('kpartx -as /dev/poop0')
> +            do('cp -a %s %s' % (loopdev, poopdev))
> +            do('kpartx -as %s' % poopdev)
>  
>              for entry in self.fs.depthlist():
> -                do('mount /dev/mapper/poop0p%d %s' %
> -                   (entry.partnum, imagemntfs.fname(entry.mountpoint)))
> +                do('mount /dev/mapper/poop%sp%d %s' %
> +                   (loopnum, entry.partnum, imagemntfs.fname(entry.mountpoint)))
>  
>              do("mount --bind /dev %s" % imagemntfs.fname("dev"))
>              do("mount --bind /proc %s" % imagemntfs.fname("proc"))
> @@ -254,7 +256,7 @@ class grubinstaller97(grubinstaller_base):
>              do('mkdir -p "%s"' % imagemntfs.fname("boot/grub"))
>  
>              devmap = open(imagemntfs.fname("boot/grub/device.map"), "w")
> -            devmap.write("(hd0) /dev/poop0\n")
> +            devmap.write("(hd0) %s\n" % poopdev)
>              devmap.close()
>  
>              chroot(imagemnt, "update-initramfs -u -k all")
> @@ -268,8 +270,11 @@ class grubinstaller97(grubinstaller_base):
>  
>              chroot(imagemnt, "update-grub")
>  
> -            do("chroot %s grub-install --no-floppy /dev/poop0" %
> -               (imagemnt))
> +            do("chroot %s grub-install --no-floppy %s" %
> +               (imagemnt, poopdev))
> +
> +        except Exception as E:
> +            logging.exception(E)
>  
>          finally:
>              os.unlink(imagemntfs.fname("boot/grub/device.map"))
> @@ -278,11 +283,11 @@ class grubinstaller97(grubinstaller_base):
>              do("umount %s" % imagemntfs.fname("sys"), allow_fail=True)
>  
>              for entry in reversed(self.fs.depthlist()):
> -                do('umount /dev/mapper/poop0p%d' % entry.partnum,
> +                do('umount /dev/mapper/poop%sp%d' % (loopnum, entry.partnum),
>                     allow_fail=True)
>  
> -            do('kpartx -d /dev/poop0', allow_fail=True)
> -            do("losetup -d /dev/poop0", allow_fail=True)
> +            do("kpartx -d %s" % poopdev, allow_fail=True)
> +            do("losetup -d %s" % poopdev, allow_fail=True)
>  
>  
>  class simple_fstype(object):
> -- 
> 2.26.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list