* [PATCH 0/4] Fix sporadic failures in do_wic_image
@ 2021-09-22 9:27 Felix Moessbauer
2021-09-22 9:27 ` [PATCH 1/4] fix typo in do_rootfs_finalize Felix Moessbauer
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Felix Moessbauer @ 2021-09-22 9:27 UTC (permalink / raw)
To: isar-users; +Cc: henning.schild, jan.kiszka, Felix Moessbauer
This patch series fixes mounting and task odering issues around do_wic_image.
These have previously been reported by H. Schild in "[PATCH v14 0/2] CPIO & OVA Images".
While patch 1,2 and 3 fix the issue, patch 4 splits the do_rootfs task to avoid open mountpoints
after the wic task.
Probably we do not want to integrate patch 4 until decisions on the mounting in general are made.
Best regards,
Felix
Felix Moessbauer (4):
fix typo in do_rootfs_finalize
execute do_wic_image under a lock to ensure mountpoints remain mounted
fix race by serialize rootfs_finalize and do_wic_image
split rootfs finalization and unmounting into two tasks
meta/classes/image.bbclass | 49 +++++++++++++++++++++++++-----------
meta/classes/wic-img.bbclass | 36 +++++++++++++++-----------
2 files changed, 56 insertions(+), 29 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/4] fix typo in do_rootfs_finalize
2021-09-22 9:27 [PATCH 0/4] Fix sporadic failures in do_wic_image Felix Moessbauer
@ 2021-09-22 9:27 ` Felix Moessbauer
2021-09-22 15:02 ` Henning Schild
2021-09-22 9:27 ` [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted Felix Moessbauer
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Felix Moessbauer @ 2021-09-22 9:27 UTC (permalink / raw)
To: isar-users; +Cc: henning.schild, jan.kiszka, Felix Moessbauer
This fixes a typo to make sure the same mountpoint is checked for
existence and unmounted.
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
meta/classes/image.bbclass | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index ec93cab..1f39690 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -200,7 +200,7 @@ do_rootfs_finalize() {
mountpoint -q '${ROOTFSDIR}/dev' && \
umount -l ${ROOTFSDIR}/dev
- mountpoint -q '${ROOTFSDIR}/sys' && \
+ mountpoint -q '${ROOTFSDIR}/proc' && \
umount -l ${ROOTFSDIR}/proc
mountpoint -q '${ROOTFSDIR}/sys' && \
umount -l ${ROOTFSDIR}/sys
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted
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 9:27 ` Felix Moessbauer
2021-09-22 15:04 ` 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 9:27 ` [PATCH 4/4] split rootfs finalization and unmounting into two tasks Felix Moessbauer
3 siblings, 1 reply; 10+ messages in thread
From: Felix Moessbauer @ 2021-09-22 9:27 UTC (permalink / raw)
To: isar-users; +Cc: henning.schild, jan.kiszka, Felix Moessbauer
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/4] fix race by serialize rootfs_finalize and do_wic_image
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 9:27 ` [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted Felix Moessbauer
@ 2021-09-22 9:27 ` Felix Moessbauer
2021-09-22 15:15 ` Henning Schild
2021-09-22 9:27 ` [PATCH 4/4] split rootfs finalization and unmounting into two tasks Felix Moessbauer
3 siblings, 1 reply; 10+ messages in thread
From: Felix Moessbauer @ 2021-09-22 9:27 UTC (permalink / raw)
To: isar-users; +Cc: henning.schild, jan.kiszka, Felix Moessbauer
The do_wic_image task requires a mounted buildchroot.
Prior to this patch, the wic_do_mounts task and do_rootfs_finalize
were not ordered. By that, the do_rootfs_finalize task could run
in parallel and unmount the buildchroot.
This is now fixed by adding the do_rootfs_finalize as a task dependency.
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
meta/classes/wic-img.bbclass | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
index e495c12..573537c 100644
--- a/meta/classes/wic-img.bbclass
+++ b/meta/classes/wic-img.bbclass
@@ -147,7 +147,7 @@ python do_wic_image() {
bb.build.exec_func("wic_undo_mounts", d)
bb.utils.unlockfile(lock)
}
-addtask wic_image before do_image after do_image_tools
+addtask wic_image before do_image after do_image_tools do_rootfs_finalize
wic_do_mounts() {
buildchroot_do_mounts
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/4] split rootfs finalization and unmounting into two tasks
2021-09-22 9:27 [PATCH 0/4] Fix sporadic failures in do_wic_image Felix Moessbauer
` (2 preceding siblings ...)
2021-09-22 9:27 ` [PATCH 3/4] fix race by serialize rootfs_finalize and do_wic_image Felix Moessbauer
@ 2021-09-22 9:27 ` Felix Moessbauer
2021-09-22 15:23 ` Henning Schild
3 siblings, 1 reply; 10+ messages in thread
From: Felix Moessbauer @ 2021-09-22 9:27 UTC (permalink / raw)
To: isar-users; +Cc: henning.schild, jan.kiszka, Felix Moessbauer
This patch separates the unmounting logic from do_rootfs_finalize
to inject tasks in between. By that, the do_wic_image tasks can
use the mount-points and finally everything is unmounted correctly.
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
meta/classes/image.bbclass | 49 +++++++++++++++++++++++++-----------
meta/classes/wic-img.bbclass | 4 +--
2 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 1f39690..988f0d7 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -190,21 +190,6 @@ do_rootfs_finalize() {
find "${ROOTFSDIR}/usr/bin" \
-maxdepth 1 -name 'qemu-*-static' -type f -delete
- mountpoint -q '${ROOTFSDIR}/isar-apt' && \
- umount -l ${ROOTFSDIR}/isar-apt
- rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/isar-apt
-
- mountpoint -q '${ROOTFSDIR}/base-apt' && \
- umount -l ${ROOTFSDIR}/base-apt
- rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/base-apt
-
- mountpoint -q '${ROOTFSDIR}/dev' && \
- umount -l ${ROOTFSDIR}/dev
- mountpoint -q '${ROOTFSDIR}/proc' && \
- umount -l ${ROOTFSDIR}/proc
- mountpoint -q '${ROOTFSDIR}/sys' && \
- umount -l ${ROOTFSDIR}/sys
-
rm -f "${ROOTFSDIR}/etc/apt/apt.conf.d/55isar-fallback.conf"
rm -f "${ROOTFSDIR}/etc/apt/sources.list.d/isar-apt.list"
@@ -219,5 +204,39 @@ EOSUDO
}
addtask rootfs_finalize before do_rootfs after do_rootfs_postprocess
+do_rootfs_unmount() {
+ sudo -s <<'EOSUDO'
+ ret=0
+ if mountpoint -q '${ROOTFSDIR}/isar-apt'; then
+ umount -vl ${ROOTFSDIR}/isar-apt || ret=1
+ fi
+ if test -d ${ROOTFSDIR}/isar-apt; then
+ rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/isar-apt || ret=1
+ fi
+
+ if mountpoint -q ${ROOTFSDIR}/base-apt; then
+ umount -vl ${ROOTFSDIR}/base-apt || ret=1
+ fi
+ if test -d ${ROOTFSDIR}/base-apt; then
+ rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/base-apt || ret=1
+ fi
+
+ if mountpoint -q ${ROOTFSDIR}/dev; then
+ umount -vl ${ROOTFSDIR}/dev || ret=1
+ fi
+ if mountpoint -q ${ROOTFSDIR}/proc; then
+ umount -vl ${ROOTFSDIR}/proc || ret=1
+ fi
+ if mountpoint -q '${ROOTFSDIR}/sys'; then
+ umount -vl ${ROOTFSDIR}/sys || ret=1
+ fi
+
+ if [$ret -ne 0]; then
+ bbwarn "could not unmount all mountpoints"
+ fi
+EOSUDO
+}
+addtask rootfs_unmount before do_build after do_rootfs_finalize
+
# Last so that the image type can overwrite tasks if needed
inherit ${IMAGE_TYPE}
diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
index 573537c..0f5932b 100644
--- a/meta/classes/wic-img.bbclass
+++ b/meta/classes/wic-img.bbclass
@@ -142,12 +142,12 @@ python do_wic_image() {
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)
+ bb.build.exec_func("check_for_wic_warnings", d)
}
-addtask wic_image before do_image after do_image_tools do_rootfs_finalize
+addtask wic_image before do_image do_rootfs_unmount after do_image_tools
wic_do_mounts() {
buildchroot_do_mounts
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/4] fix typo in do_rootfs_finalize
2021-09-22 9:27 ` [PATCH 1/4] fix typo in do_rootfs_finalize Felix Moessbauer
@ 2021-09-22 15:02 ` Henning Schild
0 siblings, 0 replies; 10+ messages in thread
From: Henning Schild @ 2021-09-22 15:02 UTC (permalink / raw)
To: Felix Moessbauer; +Cc: isar-users, jan.kiszka
ACK. Should go stand-alone in case discussions on the series take time.
But makes we wonder if we can write this as
for point in dev proc sys; do
...
done
that would probably shorten the whole thing, and the next addition of a
mointpoint will likely not make copy/paste mistakes
Henning
Am Wed, 22 Sep 2021 11:27:51 +0200
schrieb Felix Moessbauer <felix.moessbauer@siemens.com>:
> This fixes a typo to make sure the same mountpoint is checked for
> existence and unmounted.
>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
> meta/classes/image.bbclass | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> index ec93cab..1f39690 100644
> --- a/meta/classes/image.bbclass
> +++ b/meta/classes/image.bbclass
> @@ -200,7 +200,7 @@ do_rootfs_finalize() {
>
> mountpoint -q '${ROOTFSDIR}/dev' && \
> umount -l ${ROOTFSDIR}/dev
> - mountpoint -q '${ROOTFSDIR}/sys' && \
> + mountpoint -q '${ROOTFSDIR}/proc' && \
> umount -l ${ROOTFSDIR}/proc
> mountpoint -q '${ROOTFSDIR}/sys' && \
> umount -l ${ROOTFSDIR}/sys
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted
2021-09-22 9:27 ` [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted Felix Moessbauer
@ 2021-09-22 15:04 ` Henning Schild
0 siblings, 0 replies; 10+ messages in thread
From: Henning Schild @ 2021-09-22 15:04 UTC (permalink / raw)
To: Felix Moessbauer; +Cc: isar-users, jan.kiszka
LGTM
Henning
Am Wed, 22 Sep 2021 11:27:52 +0200
schrieb Felix Moessbauer <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
> }
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/4] fix race by serialize rootfs_finalize and do_wic_image
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
0 siblings, 1 reply; 10+ messages in thread
From: Henning Schild @ 2021-09-22 15:15 UTC (permalink / raw)
To: Felix Moessbauer; +Cc: isar-users, jan.kiszka
Am Wed, 22 Sep 2021 11:27:53 +0200
schrieb Felix Moessbauer <felix.moessbauer@siemens.com>:
> The do_wic_image task requires a mounted buildchroot.
> Prior to this patch, the wic_do_mounts task and do_rootfs_finalize
> were not ordered. By that, the do_rootfs_finalize task could run
> in parallel and unmount the buildchroot.
That is not just a mounting issue. The finalize should be done before
any imager goes to create an image. Because finalize contains quite a
bit of "rm -f".
If the actual imager task and finalize have not been serialized, we
need to look into that for all our imagers, not just wic.
The pattern we use is that imagers usually do
addtask <something>_image before do_image after do_image_tools
and it is also in ubifs cpiogz ext4 fit container ...
We need to touch all of them. Or play a global trick like
addtask image_tools after do_rootfs_finalize
to catch them all and possibly also catch the ones in layers.
Henning
> This is now fixed by adding the do_rootfs_finalize as a task
> dependency.
>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
> meta/classes/wic-img.bbclass | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/meta/classes/wic-img.bbclass
> b/meta/classes/wic-img.bbclass index e495c12..573537c 100644
> --- a/meta/classes/wic-img.bbclass
> +++ b/meta/classes/wic-img.bbclass
> @@ -147,7 +147,7 @@ python do_wic_image() {
> bb.build.exec_func("wic_undo_mounts", d)
> bb.utils.unlockfile(lock)
> }
> -addtask wic_image before do_image after do_image_tools
> +addtask wic_image before do_image after do_image_tools
> do_rootfs_finalize
> wic_do_mounts() {
> buildchroot_do_mounts
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/4] split rootfs finalization and unmounting into two tasks
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
0 siblings, 0 replies; 10+ messages in thread
From: Henning Schild @ 2021-09-22 15:23 UTC (permalink / raw)
To: Felix Moessbauer; +Cc: isar-users, jan.kiszka
That split is nice. But i would try and run it always after in a catch
block, not in another task.
That way it will become more robust while not having to touch the
task-chain ... which is not nice for layers that hook in "low".
I would not hold this one back for a series of "improved mounting" ...
divide and conquer! If it fixes an issue it is valid, only if you have
the time to do a full "mount rework" i would hold it back.
Henning
Am Wed, 22 Sep 2021 11:27:54 +0200
schrieb Felix Moessbauer <felix.moessbauer@siemens.com>:
> This patch separates the unmounting logic from do_rootfs_finalize
> to inject tasks in between. By that, the do_wic_image tasks can
> use the mount-points and finally everything is unmounted correctly.
>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
> meta/classes/image.bbclass | 49
> +++++++++++++++++++++++++----------- meta/classes/wic-img.bbclass |
> 4 +-- 2 files changed, 36 insertions(+), 17 deletions(-)
>
> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> index 1f39690..988f0d7 100644
> --- a/meta/classes/image.bbclass
> +++ b/meta/classes/image.bbclass
> @@ -190,21 +190,6 @@ do_rootfs_finalize() {
> find "${ROOTFSDIR}/usr/bin" \
> -maxdepth 1 -name 'qemu-*-static' -type f -delete
>
> - mountpoint -q '${ROOTFSDIR}/isar-apt' && \
> - umount -l ${ROOTFSDIR}/isar-apt
> - rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/isar-apt
> -
> - mountpoint -q '${ROOTFSDIR}/base-apt' && \
> - umount -l ${ROOTFSDIR}/base-apt
> - rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/base-apt
> -
> - mountpoint -q '${ROOTFSDIR}/dev' && \
> - umount -l ${ROOTFSDIR}/dev
> - mountpoint -q '${ROOTFSDIR}/proc' && \
> - umount -l ${ROOTFSDIR}/proc
> - mountpoint -q '${ROOTFSDIR}/sys' && \
> - umount -l ${ROOTFSDIR}/sys
> -
> rm -f "${ROOTFSDIR}/etc/apt/apt.conf.d/55isar-fallback.conf"
>
> rm -f "${ROOTFSDIR}/etc/apt/sources.list.d/isar-apt.list"
> @@ -219,5 +204,39 @@ EOSUDO
> }
> addtask rootfs_finalize before do_rootfs after do_rootfs_postprocess
>
> +do_rootfs_unmount() {
> + sudo -s <<'EOSUDO'
> + ret=0
> + if mountpoint -q '${ROOTFSDIR}/isar-apt'; then
> + umount -vl ${ROOTFSDIR}/isar-apt || ret=1
> + fi
> + if test -d ${ROOTFSDIR}/isar-apt; then
> + rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/isar-apt
> || ret=1
> + fi
> +
> + if mountpoint -q ${ROOTFSDIR}/base-apt; then
> + umount -vl ${ROOTFSDIR}/base-apt || ret=1
> + fi
> + if test -d ${ROOTFSDIR}/base-apt; then
> + rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/base-apt
> || ret=1
> + fi
> +
> + if mountpoint -q ${ROOTFSDIR}/dev; then
> + umount -vl ${ROOTFSDIR}/dev || ret=1
> + fi
> + if mountpoint -q ${ROOTFSDIR}/proc; then
> + umount -vl ${ROOTFSDIR}/proc || ret=1
> + fi
> + if mountpoint -q '${ROOTFSDIR}/sys'; then
> + umount -vl ${ROOTFSDIR}/sys || ret=1
> + fi
> +
> + if [$ret -ne 0]; then
> + bbwarn "could not unmount all mountpoints"
> + fi
> +EOSUDO
> +}
> +addtask rootfs_unmount before do_build after do_rootfs_finalize
> +
> # Last so that the image type can overwrite tasks if needed
> inherit ${IMAGE_TYPE}
> diff --git a/meta/classes/wic-img.bbclass
> b/meta/classes/wic-img.bbclass index 573537c..0f5932b 100644
> --- a/meta/classes/wic-img.bbclass
> +++ b/meta/classes/wic-img.bbclass
> @@ -142,12 +142,12 @@ python do_wic_image() {
> 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)
> + bb.build.exec_func("check_for_wic_warnings", d)
> }
> -addtask wic_image before do_image after do_image_tools
> do_rootfs_finalize +addtask wic_image before do_image
> do_rootfs_unmount after do_image_tools
> wic_do_mounts() {
> buildchroot_do_mounts
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [PATCH 3/4] fix race by serialize rootfs_finalize and do_wic_image
2021-09-22 15:15 ` Henning Schild
@ 2021-09-23 8:39 ` Moessbauer, Felix
0 siblings, 0 replies; 10+ messages in thread
From: Moessbauer, Felix @ 2021-09-23 8:39 UTC (permalink / raw)
To: isar-users; +Cc: jan.kiszka, henning.schild
Hi,
I had a second look at the task graph and this patch is wrong / redundant.
The do_image_tools task already depends on do_rootfs which itself depends on do_rootfs_finalize.
By that, also the splitting of the finalize / unmount in patch 4 does not work out.
This likely explains why we get a deadlock in do_container_image when building a container image which is then included into a regular wic image with this patch series.
What really helped is to have a look at the task dependency graph which can be exported as dot file:
bitbake -g recipe-name -u ncurses
xdot build/task-depends.dot
I'll send out a v2 soon, containing just the first two patches.
Best regards,
Felix
> -----Original Message-----
> From: Henning Schild <henning.schild@siemens.com>
> Sent: Wednesday, September 22, 2021 5:15 PM
> To: Moessbauer, Felix (T RDA IOT SES-DE)
> <felix.moessbauer@siemens.com>
> Cc: isar-users@googlegroups.com; Kiszka, Jan (T RDA IOT)
> <jan.kiszka@siemens.com>
> Subject: Re: [PATCH 3/4] fix race by serialize rootfs_finalize and
> do_wic_image
>
> Am Wed, 22 Sep 2021 11:27:53 +0200
> schrieb Felix Moessbauer <felix.moessbauer@siemens.com>:
>
> > The do_wic_image task requires a mounted buildchroot.
> > Prior to this patch, the wic_do_mounts task and do_rootfs_finalize
> > were not ordered. By that, the do_rootfs_finalize task could run in
> > parallel and unmount the buildchroot.
>
> That is not just a mounting issue. The finalize should be done before any
> imager goes to create an image. Because finalize contains quite a bit of "rm -
> f".
>
> If the actual imager task and finalize have not been serialized, we need to
> look into that for all our imagers, not just wic.
>
> The pattern we use is that imagers usually do
>
> addtask <something>_image before do_image after do_image_tools
>
> and it is also in ubifs cpiogz ext4 fit container ...
>
> We need to touch all of them. Or play a global trick like
>
> addtask image_tools after do_rootfs_finalize
>
> to catch them all and possibly also catch the ones in layers.
>
> Henning
>
> > This is now fixed by adding the do_rootfs_finalize as a task
> > dependency.
> >
> > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> > ---
> > meta/classes/wic-img.bbclass | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/meta/classes/wic-img.bbclass
> > b/meta/classes/wic-img.bbclass index e495c12..573537c 100644
> > --- a/meta/classes/wic-img.bbclass
> > +++ b/meta/classes/wic-img.bbclass
> > @@ -147,7 +147,7 @@ python do_wic_image() {
> > bb.build.exec_func("wic_undo_mounts", d)
> > bb.utils.unlockfile(lock)
> > }
> > -addtask wic_image before do_image after do_image_tools
> > +addtask wic_image before do_image after do_image_tools
> > do_rootfs_finalize
> > wic_do_mounts() {
> > buildchroot_do_mounts
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-09-23 8:39 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/4] execute do_wic_image under a lock to ensure mountpoints remain mounted Felix Moessbauer
2021-09-22 15:04 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox