ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
b7dd4d
From e6cd875a767ba23b218cdca395307ac6fb7fd882 Mon Sep 17 00:00:00 2001
b7dd4d
From: Michal Sekletar <msekleta@redhat.com>
b7dd4d
Date: Mon, 30 May 2022 14:50:05 +0200
b7dd4d
Subject: [PATCH] tests: make sure we delay running mount start jobs when
b7dd4d
 /p/s/mountinfo is rate limited
b7dd4d
b7dd4d
(cherry picked from commit 9e15be6c8d55abd800bf33f9776dd0e307ed37bc)
b7dd4d
b7dd4d
Related: #2095744
b7dd4d
---
b7dd4d
 test/TEST-60-MOUNT-RATELIMIT/testsuite.sh | 53 +++++++++++++++++++++++
b7dd4d
 test/test-functions                       |  2 +-
b7dd4d
 2 files changed, 54 insertions(+), 1 deletion(-)
b7dd4d
b7dd4d
diff --git a/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh b/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh
b7dd4d
index 6211050faf..84fe9640e1 100755
b7dd4d
--- a/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh
b7dd4d
+++ b/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh
b7dd4d
@@ -2,6 +2,56 @@
b7dd4d
 set -eux
b7dd4d
 set -o pipefail
b7dd4d
 
b7dd4d
+test_issue_20329() {
b7dd4d
+    local tmpdir unit
b7dd4d
+    tmpdir="$(mktemp -d)"
b7dd4d
+    unit=$(systemd-escape --suffix mount --path "$tmpdir")
b7dd4d
+
b7dd4d
+    # Set up test mount unit
b7dd4d
+    cat > /run/systemd/system/"$unit" <
b7dd4d
+[Mount]
b7dd4d
+What=tmpfs
b7dd4d
+Where=$tmpdir
b7dd4d
+Type=tmpfs
b7dd4d
+Options=defaults,nofail
b7dd4d
+EOF
b7dd4d
+
b7dd4d
+    # Start the unit
b7dd4d
+    systemctl daemon-reload
b7dd4d
+    systemctl start "$unit"
b7dd4d
+
b7dd4d
+    [[ "$(systemctl show --property SubState --value "$unit")" = "mounted" ]] || {
b7dd4d
+        echo >&2 "Test mount \"$unit\" unit isn't mounted"
b7dd4d
+        return 1
b7dd4d
+    }
b7dd4d
+    mountpoint -q "$tmpdir"
b7dd4d
+
b7dd4d
+    trap 'systemctl stop $unit' RETURN
b7dd4d
+
b7dd4d
+    # Trigger the mount ratelimiting
b7dd4d
+    cd "$(mktemp -d)"
b7dd4d
+    mkdir foo
b7dd4d
+    for ((i=0;i<50;++i)); do
b7dd4d
+        mount --bind foo foo
b7dd4d
+        umount foo
b7dd4d
+    done
b7dd4d
+
b7dd4d
+    # Unmount the test mount and start it immediately again via systemd
b7dd4d
+    umount "$tmpdir"
b7dd4d
+    systemctl start "$unit"
b7dd4d
+
b7dd4d
+    # Make sure it is seen as mounted by systemd and it actually is mounted
b7dd4d
+    [[ "$(systemctl show --property SubState --value "$unit")" = "mounted" ]] || {
b7dd4d
+        echo >&2 "Test mount \"$unit\" unit isn't in \"mounted\" state"
b7dd4d
+        return 1
b7dd4d
+    }
b7dd4d
+
b7dd4d
+    mountpoint -q "$tmpdir" || {
b7dd4d
+        echo >&2 "Test mount \"$unit\" is in \"mounted\" state, actually is not mounted"
b7dd4d
+        return 1
b7dd4d
+    }
b7dd4d
+}
b7dd4d
+
b7dd4d
 systemd-analyze log-level debug
b7dd4d
 systemd-analyze log-target journal
b7dd4d
 
b7dd4d
@@ -85,6 +135,9 @@ if systemctl list-units -t mount tmp-meow* | grep -q tmp-meow; then
b7dd4d
     exit 42
b7dd4d
 fi
b7dd4d
 
b7dd4d
+# test that handling of mount start jobs is delayed when /proc/self/mouninfo monitor is rate limited
b7dd4d
+test_issue_20329
b7dd4d
+
b7dd4d
 systemd-analyze log-level info
b7dd4d
 
b7dd4d
 echo OK >/testok
b7dd4d
diff --git a/test/test-functions b/test/test-functions
b7dd4d
index 4d7832b1fb..ed8ab98173 100644
b7dd4d
--- a/test/test-functions
b7dd4d
+++ b/test/test-functions
b7dd4d
@@ -23,7 +23,7 @@ fi
b7dd4d
 
b7dd4d
 PATH_TO_INIT=$ROOTLIBDIR/systemd
b7dd4d
 
b7dd4d
-BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs env"
b7dd4d
+BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs env mktemp mountpoint"
b7dd4d
 DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
b7dd4d
 
b7dd4d
 STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"