From d3dc3b2c98bf33814222a7543b7cf9a31485e4a3 Mon Sep 17 00:00:00 2001 From: Daniele Debernardi Date: Sat, 9 May 2020 00:45:39 +0200 Subject: [PATCH] pmb.chroot.shutdown: losetup with auto_init=False (MR 1912) Do not go through the pmb.chroot.init() code path when running pmb.install.losetup.umount() inside pmb.chroot.shutdown(). This is not necessary, as pmb.install.losetup.umount() only gets called if the chroot is already initialized and /dev/loop-control is mounted inside the chroot. Not going through this code path is important for the upcoming workdir migration patch. Without this fix, it will fail with the following if running "pmbootstrap install" before the work migration: ERROR: Could not figure out on which release channel the 'native' chroot is --- pmb/chroot/shutdown.py | 2 +- pmb/install/losetup.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pmb/chroot/shutdown.py b/pmb/chroot/shutdown.py index ed486ab8..6e6d4d26 100644 --- a/pmb/chroot/shutdown.py +++ b/pmb/chroot/shutdown.py @@ -65,7 +65,7 @@ def shutdown(args, only_install_related=False): pattern = chroot + "/home/pmos/rootfs/*.img" for path_outside in glob.glob(pattern): path = path_outside[len(chroot):] - pmb.install.losetup.umount(args, path) + pmb.install.losetup.umount(args, path, auto_init=False) # Umount device rootfs chroot chroot_rootfs = args.work + "/chroot_rootfs_" + args.device diff --git a/pmb/install/losetup.py b/pmb/install/losetup.py index 80b18f66..5f6739c5 100644 --- a/pmb/install/losetup.py +++ b/pmb/install/losetup.py @@ -50,14 +50,14 @@ def mount(args, img_path): raise RuntimeError("Failed to mount loop device: " + img_path) -def device_by_back_file(args, back_file): +def device_by_back_file(args, back_file, auto_init=True): """ Get the /dev/loopX device, that points to a specific image file. """ # Get list from losetup - losetup_output = pmb.chroot.root(args, ["losetup", "--json", - "--list"], output_return=True) + losetup_output = pmb.chroot.root(args, ["losetup", "--json", "--list"], + output_return=True, auto_init=auto_init) if not losetup_output: return None @@ -69,12 +69,12 @@ def device_by_back_file(args, back_file): return None -def umount(args, img_path): +def umount(args, img_path, auto_init=True): """ :param img_path: Path to the img file inside native chroot. """ - device = device_by_back_file(args, img_path) + device = device_by_back_file(args, img_path, auto_init) if not device: return logging.debug("(native) umount " + device) - pmb.chroot.root(args, ["losetup", "-d", device]) + pmb.chroot.root(args, ["losetup", "-d", device], auto_init=auto_init)