ryantimwilson / rpms / systemd

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