public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Felix Moessbauer <felix.moessbauer@siemens.com>
To: isar-users@googlegroups.com
Cc: henning.schild@siemens.com, jan.kiszka@siemens.com,
	Felix Moessbauer <felix.moessbauer@siemens.com>
Subject: [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted
Date: Wed, 22 Sep 2021 11:27:52 +0200	[thread overview]
Message-ID: <20210922092754.3649703-3-felix.moessbauer@siemens.com> (raw)
In-Reply-To: <20210922092754.3649703-1-felix.moessbauer@siemens.com>

This patch adds the isar.lock to the do_wic_image task to ensure that
the mountpoints are not unmounted by a simultaneously running wic task.
Further, it makes mounting more robust by executing the
wic task in a try / finally handler so that the mount points are
unmounted even if the task itself fails.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes/wic-img.bbclass | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
index d849ad9..e495c12 100644
--- a/meta/classes/wic-img.bbclass
+++ b/meta/classes/wic-img.bbclass
@@ -138,23 +138,40 @@ python check_for_wic_warnings() {
 
 do_wic_image[file-checksums] += "${WKS_FILE_CHECKSUM}"
 python do_wic_image() {
-    bb.build.exec_func("generate_wic_image", d)
-    bb.build.exec_func("check_for_wic_warnings", d)
+    lock = bb.utils.lockfile(d.getVar("REPO_ISAR_DIR") + "/isar.lock", shared=True)
+    bb.build.exec_func("wic_do_mounts", d)
+    try:
+        bb.build.exec_func("generate_wic_image", d)
+        bb.build.exec_func("check_for_wic_warnings", d)
+    finally:
+        bb.build.exec_func("wic_undo_mounts", d)
+        bb.utils.unlockfile(lock)
 }
 addtask wic_image before do_image after do_image_tools
 
-generate_wic_image() {
+wic_do_mounts() {
     buildchroot_do_mounts
     sudo -s <<'EOSUDO'
-        ( flock 9
         for dir in ${BBLAYERS} ${STAGING_DIR} ${SCRIPTSDIR} ${BITBAKEDIR}; do
             mkdir -p ${BUILDCHROOT_DIR}/$dir
             if ! mountpoint ${BUILDCHROOT_DIR}/$dir >/dev/null 2>&1; then
                 mount --bind --make-private $dir ${BUILDCHROOT_DIR}/$dir
             fi
         done
-        ) 9>${MOUNT_LOCKFILE}
 EOSUDO
+}
+
+wic_undo_mounts() {
+    sudo -s <<'EOSUDO'
+        for dir in ${BBLAYERS} ${STAGING_DIR} ${SCRIPTSDIR} ${BITBAKEDIR}; do
+            if mountpoint -q ${BUILDCHROOT_DIR}/$dir; then
+                umount ${BUILDCHROOT_DIR}/$dir
+            fi
+        done
+EOSUDO
+}
+
+generate_wic_image() {
     export FAKEROOTCMD=${FAKEROOTCMD}
     export BUILDDIR=${BUILDDIR}
     export MTOOLS_SKIP_CHECK=1
@@ -200,13 +217,4 @@ EOSUDO
     done
     rm -rf ${BUILDCHROOT_DIR}/${WICTMP}
     rm -rf ${IMAGE_ROOTFS}/../pseudo
-    sudo -s <<'EOSUDO'
-        ( flock 9
-        for dir in ${BBLAYERS} ${STAGING_DIR} ${SCRIPTSDIR} ${BITBAKEDIR}; do
-            if mountpoint -q ${BUILDCHROOT_DIR}/$dir; then
-                umount ${BUILDCHROOT_DIR}/$dir
-            fi
-        done
-        ) 9>${MOUNT_LOCKFILE}
-EOSUDO
 }
-- 
2.30.2


  parent reply	other threads:[~2021-09-22  9:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22  9:27 [PATCH 0/4] Fix sporadic failures in do_wic_image Felix Moessbauer
2021-09-22  9:27 ` [PATCH 1/4] fix typo in do_rootfs_finalize Felix Moessbauer
2021-09-22 15:02   ` Henning Schild
2021-09-22  9:27 ` Felix Moessbauer [this message]
2021-09-22 15:04   ` [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted Henning Schild
2021-09-22  9:27 ` [PATCH 3/4] fix race by serialize rootfs_finalize and do_wic_image Felix Moessbauer
2021-09-22 15:15   ` Henning Schild
2021-09-23  8:39     ` Moessbauer, Felix
2021-09-22  9:27 ` [PATCH 4/4] split rootfs finalization and unmounting into two tasks Felix Moessbauer
2021-09-22 15:23   ` Henning Schild

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=20210922092754.3649703-3-felix.moessbauer@siemens.com \
    --to=felix.moessbauer@siemens.com \
    --cc=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    --cc=jan.kiszka@siemens.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