naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
8d419f
From 94f643c328cd2d3c7376219573e0bc5dedea10d8 Mon Sep 17 00:00:00 2001
8d419f
From: Michal Sekletar <msekleta@redhat.com>
8d419f
Date: Mon, 30 May 2022 14:50:05 +0200
8d419f
Subject: [PATCH] tests: make sure we delay running mount start jobs when
8d419f
 /p/s/mountinfo is rate limited
8d419f
8d419f
(cherry picked from commit 9e15be6c8d55abd800bf33f9776dd0e307ed37bc)
8d419f
8d419f
Related: #2087652
8d419f
---
8d419f
 test/units/testsuite-60.sh | 53 ++++++++++++++++++++++++++++++++++++++
8d419f
 1 file changed, 53 insertions(+)
8d419f
8d419f
diff --git a/test/units/testsuite-60.sh b/test/units/testsuite-60.sh
8d419f
index 239d7b0d4c..8cb3f466b6 100755
8d419f
--- a/test/units/testsuite-60.sh
8d419f
+++ b/test/units/testsuite-60.sh
8d419f
@@ -3,6 +3,56 @@
8d419f
 set -eux
8d419f
 set -o pipefail
8d419f
 
8d419f
+test_issue_20329() {
8d419f
+    local tmpdir unit
8d419f
+    tmpdir="$(mktemp -d)"
8d419f
+    unit=$(systemd-escape --suffix mount --path "$tmpdir")
8d419f
+
8d419f
+    # Set up test mount unit
8d419f
+    cat > /run/systemd/system/"$unit" <
8d419f
+[Mount]
8d419f
+What=tmpfs
8d419f
+Where=$tmpdir
8d419f
+Type=tmpfs
8d419f
+Options=defaults,nofail
8d419f
+EOF
8d419f
+
8d419f
+    # Start the unit
8d419f
+    systemctl daemon-reload
8d419f
+    systemctl start "$unit"
8d419f
+
8d419f
+    [[ "$(systemctl show --property SubState --value "$unit")" = "mounted" ]] || {
8d419f
+        echo >&2 "Test mount \"$unit\" unit isn't mounted"
8d419f
+        return 1
8d419f
+    }
8d419f
+    mountpoint -q "$tmpdir"
8d419f
+
8d419f
+    trap 'systemctl stop $unit' RETURN
8d419f
+
8d419f
+    # Trigger the mount ratelimiting
8d419f
+    cd "$(mktemp -d)"
8d419f
+    mkdir foo
8d419f
+    for ((i=0;i<50;++i)); do
8d419f
+        mount --bind foo foo
8d419f
+        umount foo
8d419f
+    done
8d419f
+
8d419f
+    # Unmount the test mount and start it immediately again via systemd
8d419f
+    umount "$tmpdir"
8d419f
+    systemctl start "$unit"
8d419f
+
8d419f
+    # Make sure it is seen as mounted by systemd and it actually is mounted
8d419f
+    [[ "$(systemctl show --property SubState --value "$unit")" = "mounted" ]] || {
8d419f
+        echo >&2 "Test mount \"$unit\" unit isn't in \"mounted\" state"
8d419f
+        return 1
8d419f
+    }
8d419f
+
8d419f
+    mountpoint -q "$tmpdir" || {
8d419f
+        echo >&2 "Test mount \"$unit\" is in \"mounted\" state, actually is not mounted"
8d419f
+        return 1
8d419f
+    }
8d419f
+}
8d419f
+
8d419f
 systemd-analyze log-level debug
8d419f
 systemd-analyze log-target journal
8d419f
 
8d419f
@@ -87,6 +137,9 @@ if systemctl list-units -t mount tmp-meow* | grep -q tmp-meow; then
8d419f
     exit 42
8d419f
 fi
8d419f
 
8d419f
+# test that handling of mount start jobs is delayed when /proc/self/mouninfo monitor is rate limited
8d419f
+test_issue_20329
8d419f
+
8d419f
 systemd-analyze log-level info
8d419f
 
8d419f
 echo OK >/testok