From c235cb62beefd03087e7cfc7f7f55f0c7c6601c9 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 1 Aug 2026 00:00:00 +0000 Subject: Enter vmm A QEMU/KVM virtual machine manager in one POSIX shell script. Each VM is a directory of plain files under $VMMDIR, configured by a hand-edited KEY=VALUE file that is parsed rather than sourced, so nothing in it can inject a raw QEMU argument. Control is a QMP FIFO pair inside that directory, guarded by its permissions alone; nothing binds a TCP port. The tests are TAP without a framework and boot real guests where the host allows. --- tests/lock | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/lock (limited to 'tests/lock') diff --git a/tests/lock b/tests/lock new file mode 100644 index 0000000..09c357f --- /dev/null +++ b/tests/lock @@ -0,0 +1,51 @@ +# The VM directory is the mutex. + +"$VMM" create lk1 64M >/dev/null 2>&1 + +# Every mutating verb serialises, including the two that destroy data. +exec 9<"$VMMDIR/lk1" +flock -n 9 +exits 4 "start refuses while the lock is held" start lk1 +exits 4 "delete refuses while the lock is held" delete -f lk1 +exits 4 "clone refuses while the lock is held" clone lk1 lk9 +flock -u 9 +exec 9>&- + +# The kernel releases the lock when vmm exits on an error. +cfg lk1 </dev/null 2>&1 +cfg lk2 </dev/null 2>&1; then + "$VMM" stop lk2 >/dev/null 2>&1 & + stopper=$! + i=0 + while flock -n "$VMMDIR/lk2" true && [ "$i" -lt 5 ]; do + sleep 1 + i=$((i + 1)) + done + # That loop ends on the lock being taken or on running out of + # patience, and only the first of those says anything about vmm. + if flock -n "$VMMDIR/lk2" true; then + skip 1 "the backgrounded stop never took the lock" + else + exits 4 "a second vmm is refused while the first holds the lock" \ + start lk2 + fi + wait "$stopper" 2>/dev/null || : + holds "and the lock is available once the first is done" \ + flock -n "$VMMDIR/lk2" true +else + skip 2 "lk2 did not start" +fi -- cgit v1.2.3