]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rcutorture: Prevent concurrent kvm.sh runs on same source tree
authorJoel Fernandes <joelagnelf@nvidia.com>
Thu, 1 Jan 2026 16:34:16 +0000 (11:34 -0500)
committerBoqun Feng <boqun.feng@gmail.com>
Sun, 4 Jan 2026 10:50:59 +0000 (18:50 +0800)
Add flock-based locking to kvm.sh to prevent multiple instances from
running concurrently on the same source tree. This prevents build
failures caused by one instance's "make clean" deleting generated files
while another instance is building causing build failures.

The lock file is placed in the rcutorture directory and added to
.gitignore.

Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
Tested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
tools/testing/selftests/rcutorture/.gitignore
tools/testing/selftests/rcutorture/bin/kvm.sh

index f6cbce77460b6026b2a1fe278a32991661b8f7f6..b8fd42547a6e8f5b0b422953b9f1cc0ae9758b7d 100644 (file)
@@ -3,3 +3,4 @@ initrd
 b[0-9]*
 res
 *.swp
+.kvm.sh.lock
index fff15821c44c9605843f9ff3854fe2ddcdbfe416..d1fbd092e22a11cbb40451354c0a290554b5aee5 100755 (executable)
@@ -275,6 +275,23 @@ do
        shift
 done
 
+# Prevent concurrent kvm.sh runs on the same source tree.  The flock
+# is automatically released when the script exits, even if killed.
+TORTURE_LOCK="$RCUTORTURE/.kvm.sh.lock"
+if test -z "$dryrun"
+then
+       # Create a file descriptor and flock it, so that when kvm.sh (and its
+       # children) exit, the flock is released by the kernel automatically.
+       exec 9>"$TORTURE_LOCK"
+       if ! flock -n 9
+       then
+               echo "ERROR: Another kvm.sh instance is already running on this tree."
+               echo "       Lock file: $TORTURE_LOCK"
+               echo "       To run kvm.sh, kill all existing kvm.sh runs first."
+               exit 1
+       fi
+fi
+
 if test -n "$dryrun" || test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
 then
        :