public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH v5 3/5] image: Add reference counter
Date: Tue, 17 Aug 2021 15:38:06 +0300	[thread overview]
Message-ID: <20210817123808.3563834-4-amikan@ilbers.de> (raw)
In-Reply-To: <20210817123808.3563834-1-amikan@ilbers.de>

Image generation can be also executed in parallel, so we need to control
the usage of image_do_mounts / image_undo_mounts.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 meta/classes/image.bbclass | 39 ++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 12d1616..b2a828c 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -52,23 +52,54 @@ DEPENDS += "${IMAGE_INSTALL}"
 ISAR_RELEASE_CMD_DEFAULT = "git -C ${LAYERDIR_core} describe --tags --dirty --match 'v[0-9].[0-9]*'"
 ISAR_RELEASE_CMD ?= "${ISAR_RELEASE_CMD_DEFAULT}"
 
+IMG_MOUNT_CNT = "${BUILDCHROOT_DIR}_image.mount"
+
 image_do_mounts() {
-    sudo flock ${MOUNT_LOCKFILE} -c ' \
+    sudo -s <<'EOSUDO'
+        ( flock 9
+        set -e
+
+        count="1"
+        if [ -f "${IMG_MOUNT_CNT}" ]; then
+            count=$(($(cat "${IMG_MOUNT_CNT}") + 1))
+        fi
+        echo $count > "${IMG_MOUNT_CNT}"
+        if [ $count -gt 1 ]; then
+            exit 0
+        fi
+
         mkdir -p "${BUILDROOT_DEPLOY}" "${BUILDROOT_ROOTFS}" "${BUILDROOT_WORK}"
         mount --bind "${DEPLOY_DIR_IMAGE}" "${BUILDROOT_DEPLOY}"
         mount --bind "${IMAGE_ROOTFS}" "${BUILDROOT_ROOTFS}"
         mount --bind "${WORKDIR}" "${BUILDROOT_WORK}"
-    '
+
+        ) 9>'${MOUNT_LOCKFILE}'
+EOSUDO
     buildchroot_do_mounts
 }
 
 image_undo_mounts() {
     buildchroot_undo_mounts
-    sudo flock ${MOUNT_LOCKFILE} -c ' \
+    sudo -s <<'EOSUDO'
+        ( flock 9
+        set -e
+
+        count="0"
+        if [ -f "${IMG_MOUNT_CNT}" ]; then
+            count=$(($(cat "${IMG_MOUNT_CNT}") - 1))
+            echo $count > "${IMG_MOUNT_CNT}"
+        fi
+        if [ $count -gt 0 ]; then
+            exit 0
+        fi
+        rm -f "${IMG_MOUNT_CNT}"
+
         umount "${BUILDROOT_DEPLOY}"
         umount "${BUILDROOT_ROOTFS}"
         umount "${BUILDROOT_WORK}"
-    '
+
+        ) 9>'${MOUNT_LOCKFILE}'
+EOSUDO
 }
 
 ROOTFSDIR = "${IMAGE_ROOTFS}"
-- 
2.25.1


  parent reply	other threads:[~2021-08-17 12:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 12:38 [PATCH v5 0/5] Restore downstream mounts compatibility Anton Mikanovich
2021-08-17 12:38 ` [PATCH v5 1/5] Revert "dpkg: Make mount buildroot reliable" Anton Mikanovich
2021-08-17 12:38 ` [PATCH v5 2/5] dpkg: Limit unmount loop Anton Mikanovich
2021-08-17 12:38 ` Anton Mikanovich [this message]
2021-08-17 12:38 ` [PATCH v5 4/5] dpkg-base: Clean up unmounting in do_dpkg_build() Anton Mikanovich
2021-08-17 12:38 ` [PATCH v5 5/5] events: Do not warn on left mounts by default Anton Mikanovich
2021-08-18 16:24 ` [PATCH v5 0/5] Restore downstream mounts compatibility Jan Kiszka
2021-08-18 17:39   ` Jan Kiszka
2021-08-20  8:12     ` Anton Mikanovich
2021-08-20  9:51       ` Jan Kiszka

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=20210817123808.3563834-4-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --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