From: Alexander Smirnov <asmirnov@ilbers.de>
To: Christian Storm <christian.storm@siemens.com>,
isar-users@googlegroups.com
Subject: Re: [PATCH] isar-image-base: fix some dangling mounts
Date: Mon, 13 Nov 2017 16:53:18 +0300 [thread overview]
Message-ID: <875ca5fe-4116-ac26-bef6-20b6225aa809@ilbers.de> (raw)
In-Reply-To: <20171113122239.19792-1-christian.storm@siemens.com>
Hi,
On 11/13/2017 03:22 PM, Christian Storm wrote:
> As bitbake/lib/bb/build.py's shell_trap_code() injects
> `set -e` into scripts, the premature end of scripts leaves
> dangling mounts around. Fix these dangling mounts by hooking
> into the EXIT trap handler also setup by shell_trap_code().
>
Thank you for the explanation (in another main), now I've got the idea!
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
> meta-isar/recipes-core/images/isar-image-base.bb | 10 ++++++++--
> meta/classes/dpkg-base.bbclass | 10 ++++++++--
> meta/classes/ext4-img.bbclass | 10 ++++++++--
> meta/recipes-devtools/buildchroot/buildchroot.bb | 10 ++++++++--
> 4 files changed, 32 insertions(+), 8 deletions(-)
>
> diff --git a/meta-isar/recipes-core/images/isar-image-base.bb b/meta-isar/recipes-core/images/isar-image-base.bb
> index 42aaea3..c2150b1 100644
> --- a/meta-isar/recipes-core/images/isar-image-base.bb
> +++ b/meta-isar/recipes-core/images/isar-image-base.bb
> @@ -52,8 +52,14 @@ do_rootfs() {
> -e 's|##ISAR_DISTRO_SUITE##|${DEBDISTRONAME}|g' \
> "${WORKDIR}/multistrap.conf.in" > "${WORKDIR}/multistrap.conf"
>
> - install -d -m 555 ${IMAGE_ROOTFS}/proc
> + [ ! -d ${IMAGE_ROOTFS}/proc ] && install -d -m 555 ${IMAGE_ROOTFS}/proc
> sudo mount -t proc none ${IMAGE_ROOTFS}/proc
> + _do_rootfs_cleanup() {
> + ret=$?
> + sudo umount ${IMAGE_ROOTFS}/proc 2>/dev/null || true
> + (exit $ret) || bb_exit_handler
> + }
> + trap '_do_rootfs_cleanup' EXIT
>
> # Create root filesystem
> sudo multistrap -a ${DISTRO_ARCH} -d "${IMAGE_ROOTFS}" -f "${WORKDIR}/multistrap.conf"
> @@ -62,7 +68,7 @@ do_rootfs() {
> sudo chroot ${IMAGE_ROOTFS} /${DISTRO_CONFIG_SCRIPT} ${MACHINE_SERIAL} ${BAUDRATE_TTY} \
> ${ROOTFS_DEV}
> sudo rm "${IMAGE_ROOTFS}/${DISTRO_CONFIG_SCRIPT}"
> - sudo umount ${IMAGE_ROOTFS}/proc
> + _do_rootfs_cleanup
> }
>
> addtask rootfs before do_build after do_populate
> diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
> index 9ded3ae..35af6d5 100644
> --- a/meta/classes/dpkg-base.bbclass
> +++ b/meta/classes/dpkg-base.bbclass
> @@ -21,9 +21,15 @@ dpkg_runbuild() {
> do_build() {
> mkdir -p ${BUILDROOT}
> sudo mount --bind ${WORKDIR} ${BUILDROOT}
> + _do_build_cleanup() {
> + ret=$?
> + sudo umount ${BUILDROOT} 2>/dev/null || true
> + sudo rmdir ${BUILDROOT} 2>/dev/null || true
> + (exit $ret) || bb_exit_handler
> + }
> + trap '_do_build_cleanup' EXIT
> dpkg_runbuild
> - sudo umount ${BUILDROOT}
> - rm -rf ${BUILDROOT}
> + _do_build_cleanup
> }
>
> # Install package to dedicated deploy directory
> diff --git a/meta/classes/ext4-img.bbclass b/meta/classes/ext4-img.bbclass
> index 18a74ca..83cb137 100644
> --- a/meta/classes/ext4-img.bbclass
> +++ b/meta/classes/ext4-img.bbclass
> @@ -19,9 +19,15 @@ do_ext4_image() {
>
> mkdir -p ${WORKDIR}/mnt
> sudo mount -o loop ${EXT4_IMAGE_FILE} ${WORKDIR}/mnt
> + _do_ext4_image_cleanup() {
> + ret=$?
> + sudo umount ${WORKDIR}/mnt 2>/dev/null || true
> + sudo rmdir ${WORKDIR}/mnt 2>/dev/null || true
> + (exit $ret) || bb_exit_handler
> + }
> + trap '_do_ext4_image_cleanup' EXIT
> sudo cp -r ${IMAGE_ROOTFS}/* ${WORKDIR}/mnt
> - sudo umount ${WORKDIR}/mnt
> - rm -r ${WORKDIR}/mnt
> + _do_ext4_image_cleanup
> }
>
> addtask ext4_image before do_build after do_copy_boot_files
> diff --git a/meta/recipes-devtools/buildchroot/buildchroot.bb b/meta/recipes-devtools/buildchroot/buildchroot.bb
> index ace64ba..4cae9fc 100644
> --- a/meta/recipes-devtools/buildchroot/buildchroot.bb
> +++ b/meta/recipes-devtools/buildchroot/buildchroot.bb
> @@ -52,8 +52,14 @@ do_build() {
> -e 's|##DIR_HOOKS##|./'"$WORKDIR_REL"'/hooks_multistrap|g' \
> "${WORKDIR}/multistrap.conf.in" > "${WORKDIR}/multistrap.conf"
>
> - install -d -m 555 ${BUILDCHROOT_DIR}/proc
> + [ ! -d ${BUILDCHROOT_DIR}/proc ] && install -d -m 555 ${BUILDCHROOT_DIR}/proc
> sudo mount -t proc none ${BUILDCHROOT_DIR}/proc
> + _do_build_cleanup() {
> + ret=$?
> + sudo umount ${BUILDCHROOT_DIR}/proc 2>/dev/null || true
> + (exit $ret) || bb_exit_handler
> + }
> + trap '_do_build_cleanup' EXIT
>
> # Create root filesystem
> sudo multistrap -a ${DISTRO_ARCH} -d "${BUILDCHROOT_DIR}" -f "${WORKDIR}/multistrap.conf"
> @@ -63,5 +69,5 @@ do_build() {
>
> # Configure root filesystem
> sudo chroot ${BUILDCHROOT_DIR} /configscript.sh
> - sudo umount ${BUILDCHROOT_DIR}/proc
> + _do_build_cleanup
> }
>
Here I see that you insert quite similar patterns across the Isar code,
would it be better to have one global clean up function like?
do_isar_mount_cleanup () {
if [ -d "${WORKDIR}/mnt" ]; then
# umount and remove
fi
if [ -d "${WORKDIR}/rootfs/proc" ]; then
# umount and remove
fi
if [ -d "${BUILDCHROOT_DIR}/proc" ]; then
# umount and remove
fi
etc...
}
This approach will significantly simplify maintenance of clean up traps
and adding of new possible mounts to Isar. What do you think?
Alex
next prev parent reply other threads:[~2017-11-13 13:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-13 12:22 Christian Storm
2017-11-13 12:50 ` Alexander Smirnov
2017-11-13 12:57 ` Christian Storm
2017-11-13 13:53 ` Alexander Smirnov [this message]
2017-11-13 14:24 ` Christian Storm
2017-11-13 14:47 ` Alexander Smirnov
2017-11-14 7:36 ` Christian Storm
2017-11-14 7:48 ` Alexander Smirnov
2017-11-14 8:58 ` Christian Storm
2017-11-13 13:57 ` Henning Schild
2017-11-14 16:01 ` Alexander Smirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875ca5fe-4116-ac26-bef6-20b6225aa809@ilbers.de \
--to=asmirnov@ilbers.de \
--cc=christian.storm@siemens.com \
--cc=isar-users@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox