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 v3 2/8] isar-events: Unhide mounts left behind
Date: Fri, 11 Oct 2024 13:00:44 +0300	[thread overview]
Message-ID: <20241011100050.322686-3-amikan@ilbers.de> (raw)
In-Reply-To: <20241011100050.322686-1-amikan@ilbers.de>

Fail the existing build testcases on mounts left behind by calling the
cleanup handler once per build (controlled by a new variable).

Specifically:

1. Execute cleanup handler only once per build.
2. Output error messages in case of umount failure.
3. Unmount /proc/mounts in reverse order to unmount subdirectories first.
4. Introduce ISAR_FAIL_ON_CLEANUP bitbake variable:
   - 0 or unset: Output a warning, unmount, build succeeds (default).
   - 1: Output a warning, keep mounts left behind, build fails.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 RECIPE-API-CHANGELOG.md          |  9 +++++++
 meta/classes/isar-events.bbclass | 40 +++++++++++++++++++++++++-------
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 8eeaf325..608d0cc3 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -665,3 +665,12 @@ package on an `amd64` host: you would expect the -native variant to produce
 an `amd64` package and -compat an 'armhf` package: it will however remain
 `arm64` and build of dependent recipes (image or dpkg) may fail because of
 the architecture mismatch.
+
+### Changes in cleanup handler
+
+Bitbake BuildCompleted event handler is now executed only once per build and
+always outputs a warning if mounts are left behind after the build.
+
+Bitbake exit status depends on ISAR_FAIL_ON_CLEANUP bitbake variable:
+ - 0 or unset: Output a warning, unmount, build succeeds (default).
+ - 1: Output a warning, keep mounts left behind, build fails.
diff --git a/meta/classes/isar-events.bbclass b/meta/classes/isar-events.bbclass
index f5061a8b..76b713c7 100644
--- a/meta/classes/isar-events.bbclass
+++ b/meta/classes/isar-events.bbclass
@@ -4,6 +4,10 @@
 # Copyright (C) 2015-2017 ilbers GmbH
 # Copyright (c) Siemens AG, 2018
 
+# If set to 1, the build will fail on mounts found during cleanup,
+# keeping those mounts left behind
+ISAR_FAIL_ON_CLEANUP ?= "0"
+
 addhandler build_started
 
 python build_started() {
@@ -48,17 +52,37 @@ python build_completed() {
     if not tmpdir:
         return
 
+    # bitbake calls cleanup for every multiconfig listed in BBMULTICONFIG plus
+    # one for the entire build. E.g., if BBMULTICONFIG="mc1 mc2 mc3", we call
+    # "bitbake mc1 mc2", the following cleanups would be called:
+    # "c1 c2 c3 cdefault".
+    # Skip running cleanup for additional multiconfigs
+    mc = d.getVar('BB_CURRENT_MC')
+    if mc != 'default':
+        return
+
+    fail_on_cleanup = bb.utils.to_boolean(d.getVar('ISAR_FAIL_ON_CLEANUP'))
+
     basepath = tmpdir + '/work/'
 
-    with open('/proc/mounts') as f:
-        for line in f.readlines():
-            if basepath in line:
-                bb.debug(1, '%s left mounted, unmounting...' % line.split()[1])
-                subprocess.call(
-                    ["sudo", "umount", line.split()[1]],
-                    stdout=subprocess.DEVNULL,
-                    stderr=subprocess.DEVNULL,
+    for line in reversed(list(open('/proc/mounts'))):
+        if basepath not in line:
+            continue
+        msg_line = f"{line.split()[1]} left mounted"
+        # If bitbake is started manually, bb.warn and bb.error go to stdout;
+        # with bb.error, bitbake additionally fails the build. Under CI,
+        # bb.warn and bb.error currently go to a file.
+        if fail_on_cleanup:
+            bb.error(msg_line)
+        else:
+            msg_line += ', unmounting...'
+            bb.warn(msg_line)
+            try:
+                subprocess.run(
+                    f"sudo umount {line.split()[1]}", shell=True, check=True
                 )
+            except subprocess.CalledProcessError as e:
+                bb.error(str(e))
 
     # Cleanup build UUID, the next bitbake run will generate new one
     bb.persist_data.persist('BB_ISAR_UUID_DATA', d).clear()
-- 
2.34.1

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/isar-users/20241011100050.322686-3-amikan%40ilbers.de.

  parent reply	other threads:[~2024-10-11 10:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 10:00 [PATCH v3 0/8] Hanging mount fixes Anton Mikanovich
2024-10-11 10:00 ` [PATCH v3 1/8] CI: Do not lose output on bitbake / qemu exit Anton Mikanovich
2024-10-11 10:00 ` Anton Mikanovich [this message]
2024-10-11 10:00 ` [PATCH v3 3/8] CI: Pass ISAR_FAIL_ON_CLEANUP from environment to bitbake Anton Mikanovich
2024-10-11 10:00 ` [PATCH v3 4/8] image: Avoid breaking the build when mounts are no longer present on umount Anton Mikanovich
2024-10-11 10:00 ` [PATCH v3 5/8] rootfs: Provide rootfs_do_umounts Anton Mikanovich
2024-10-11 10:00 ` [PATCH v3 6/8] initramfs: Add missing umounts after generation Anton Mikanovich
2024-10-11 10:00 ` [PATCH v3 7/8] rootfs: Add missing umounts in rootfs_postprocess() and rootfs_install() Anton Mikanovich
2024-10-11 10:00 ` [PATCH v3 8/8] image: Do not call rootfs_do_umounts twice Anton Mikanovich
2024-10-15  9:23 ` [PATCH v3 0/8] Hanging mount fixes Baurzhan Ismagulov
2024-10-16 16:06 ` Uladzimir Bely

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=20241011100050.322686-3-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