summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-06-27 09:10:37 +0000
committerAlyssa Ross <hi@alyssa.is>2023-06-27 09:17:31 +0000
commit370ef778176261532448b92539c65c871b080399 (patch)
tree3ed08e1c483da0559e96725f324b1f514d21f0f5
parent94cb97efb43f6bcb5b2c2d2b0b69177686c74900 (diff)
downloadspectrum-370ef778176261532448b92539c65c871b080399.tar
spectrum-370ef778176261532448b92539c65c871b080399.tar.gz
spectrum-370ef778176261532448b92539c65c871b080399.tar.bz2
spectrum-370ef778176261532448b92539c65c871b080399.tar.lz
spectrum-370ef778176261532448b92539c65c871b080399.tar.xz
spectrum-370ef778176261532448b92539c65c871b080399.tar.zst
spectrum-370ef778176261532448b92539c65c871b080399.zip
Never block mdevd on /etc/mdev/listen
In the case of img/app's virtio-fs handler, this could lead to
deadlocks if the application didn't actually care about virtio-fs and
therefore never ran /etc/mdev/wait for it.  In the case of
host/rootfs, it probably just slightly slowed down boot, because the
ext listener would always be started along with mdevd.

This is a common class of bug.  Another recent fix was
afaa30c ("host/rootfs: don't block mdevd waiting for weston").
Possibly /etc/mdev/listen should background itself, but I'm not sure,
because usually other preparation of the device also doesn't need to
block mdevd, so can also be backgrounded.  We'll see how things
develop.  If these bugs keep happening, we should probably make
/etc/mdev/listen auto-background.

Fixes: f7c3146 ("host/rootfs: let ext partition be overridden")
Fixes: 933e91a ("img/app: auto-mount virtiofs0 filesystem")
Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rwxr-xr-xhost/rootfs/etc/mdev/block/add56
-rwxr-xr-ximg/app/etc/mdev/virtiofs16
2 files changed, 38 insertions, 34 deletions
diff --git a/host/rootfs/etc/mdev/block/add b/host/rootfs/etc/mdev/block/add
index 3e24355..64e7726 100755
--- a/host/rootfs/etc/mdev/block/add
+++ b/host/rootfs/etc/mdev/block/add
@@ -1,38 +1,40 @@
 #!/bin/execlineb -P
 # SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022-2023 Alyssa Ross <hi@alyssa.is>
 
-cd /dev
-importas -i devname DEVNAME
+background {
+  cd /dev
+  importas -i devname DEVNAME
 
-backtick -E ext {
-  backtick -x extspec { redirfd -w 2 /dev/null cat /run/param/ext }
-  ifelse { redirfd -w 1 /dev/null printenv extspec }
+  backtick -E ext {
+    backtick -x extspec { redirfd -w 2 /dev/null cat /run/param/ext }
+    ifelse { redirfd -w 1 /dev/null printenv extspec }
 
-  {
-    importas -iu extspec extspec
-    findfs $extspec
-  }
+    {
+      importas -iu extspec extspec
+      findfs $extspec
+    }
 
-  pipeline {
-    backtick -E diskpath {
-      pipeline { lsblk -lnpo KNAME,PKNAME }
-      backtick -E rootpart {
-        pipeline { veritysetup status root-verity }
-        awk -F ":[[:blank:]]*" "$1 ~ /^[[:blank:]]*data device$/ {print $2; exit}"
+    pipeline {
+      backtick -E diskpath {
+	pipeline { lsblk -lnpo KNAME,PKNAME }
+	backtick -E rootpart {
+	  pipeline { veritysetup status root-verity }
+	  awk -F ":[[:blank:]]*" "$1 ~ /^[[:blank:]]*data device$/ {print $2; exit}"
+	}
+	awk -v rootpart=${rootpart} "$1 == rootpart {print $2; exit}"
       }
-      awk -v rootpart=${rootpart} "$1 == rootpart {print $2; exit}"
+      lsblk -lnpo PARTTYPE,NAME $diskpath
     }
-    lsblk -lnpo PARTTYPE,NAME $diskpath
+    awk "$1 == \"9293e1ff-cee4-4658-88be-898ec863944f\" {print $2; exit}"
   }
-  awk "$1 == \"9293e1ff-cee4-4658-88be-898ec863944f\" {print $2; exit}"
-}
 
-if {
-  backtick -E extinode { redirfd -w 2 /dev/null stat -Lc %d:%i $ext }
-  backtick -E inode { stat -Lc %d:%i $devname }
-  test $inode = $extinode
-}
+  if {
+    backtick -E extinode { redirfd -w 2 /dev/null stat -Lc %d:%i $ext }
+    backtick -E inode { stat -Lc %d:%i $devname }
+    test $inode = $extinode
+  }
 
-if { ln -s $devname ext }
-/etc/mdev/listen ext
+  if { ln -s $devname ext }
+  /etc/mdev/listen ext
+}
diff --git a/img/app/etc/mdev/virtiofs b/img/app/etc/mdev/virtiofs
index a028002..c1fd283 100755
--- a/img/app/etc/mdev/virtiofs
+++ b/img/app/etc/mdev/virtiofs
@@ -1,10 +1,12 @@
 #!/bin/execlineb -P
 # SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022-2023 Alyssa Ross <hi@alyssa.is>
 
-# There's currently no kernel mechanism to let us enumerate available
-# virtiofs filesystems, so we only supported a single, hardcoded
-# filesystem tag for now.
-if { mkdir -p /run/virtiofs/virtiofs0 }
-if { mount -t virtiofs virtiofs0 /run/virtiofs/virtiofs0 }
-/etc/mdev/listen virtiofs0
+background {
+  # There's currently no kernel mechanism to let us enumerate available
+  # virtiofs filesystems, so we only supported a single, hardcoded
+  # filesystem tag for now.
+  if { mkdir -p /run/virtiofs/virtiofs0 }
+  if { mount -t virtiofs virtiofs0 /run/virtiofs/virtiofs0 }
+  /etc/mdev/listen virtiofs0
+}