From 996173d3644311b90cb20d1e3746afd90ff7c4bf Mon Sep 17 00:00:00 2001 From: debater-coder Date: Tue, 24 Nov 2026 18:17:50 +1100 Subject: [PATCH 1/3] Integrate with machine-locks-client Signed-off-by: debater-coder --- README.md | 129 +++++++++----------- flake.lock | 56 +++++++++ flake.nix | 19 +++ mq.sh | 5 +- scripts/enqueue | 26 ++-- scripts/lock | 314 +----------------------------------------------- 6 files changed, 151 insertions(+), 398 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/README.md b/README.md index 7753e47..e847472 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ and use these scripts to deploy their payloads onto our CI infrastructure; they are also used by GitHub's [CI Actions](https://github.com/seL4/ci-actions) for seL4. - Set Up ======== @@ -25,107 +24,93 @@ repository, and create a symlink from `mq.sh` to somewhere in your `$PATH`. For example, you can do: - ``` - git clone git@github.com:seL4/machine_queue.git - H=$(pwd)/mq.sh - cd ~/bin - ln -s $H mq - ``` + +``` +git clone git@github.com:seL4/machine_queue.git +H=$(pwd)/mq.sh +cd ~/bin +ln -s $H mq +``` The mq scripts assume a standard POSIX system, that `/bin/sh` is POSIX compliant, and that you can use `ssh` to reach -`tftp.keg.cse.unsw.edu.au` without password. To set up the latter, +`tftp.keg.cse.unsw.edu.au` without password. To set up the latter, add to your `~/.ssh/config`: - ``` - Host tftp.keg.cse.unsw.edu.au - ProxyJump login.trustworthy.systems - ControlMaster auto - ControlPersist 300 - ControlPath /home/%u/.ssh/controlmaster/%h-%p-%r.sock - ServerAliveInterval 60 - TCPKeepAlive yes - ``` -or clauses with similar effect. The script makes many `ssh` + +``` +Host tftp.keg.cse.unsw.edu.au + ProxyJump login.trustworthy.systems + ControlMaster auto + ControlPersist 300 + ControlPath /home/%u/.ssh/controlmaster/%h-%p-%r.sock + ServerAliveInterval 60 + TCPKeepAlive yes +``` + +or clauses with similar effect. The script makes many `ssh` connections in a row; without the control multiplexing this can get painfully slow. - Usage ====== `mq` has many subcommands: - * `run` --- run a payload on a system - * `systems` --- list available systems - * `sem` --- interact directly with locks - * `system-tsv` --- list available systems as tab-separated values - * `pool-tsv` --- list available pools of systems as tab-separated - values + +- `run` --- run a payload on a system +- `systems` --- list available systems +- `sem` --- interact directly with locks +- `system-tsv` --- list available systems as tab-separated values +- `pool-tsv` --- list available pools of systems as tab-separated + values `mq run` -------- + `mq.sh run -r|-c` __ `[-l ` _logfile_ `] -s` _system_ `[-w` _retry-time_ `] [-t `_retry-count_` ] [-n] [-a] [-d` _timeout_ `] [-e` __`] [-k `__`] [-L] -f `_file1_ `[-f `_file2_`] .. [-f` _filen_ `]` - Acquires a lock for the machine called _system_ (or a machine in - the pool called _system_), and, once locked, runs the specified job. +Acquires a lock for the machine called _system_ (or a machine in +the pool called _system_), and, once locked, runs the specified job. - Output from the machine is collected and passed back to the - user both on stdout and into an optional logfile. +Output from the machine is collected and passed back to the +user both on stdout and into an optional logfile. - Jobs can be cancelled at any time with ^C, which will notify the server - (if the job is running) and remove the job from the queue. +Jobs can be cancelled at any time with ^C, which will notify the server +(if the job is running) and remove the job from the queue. - Returns 0 on success, nonzero if something went wrong +Returns 0 on success, nonzero if something went wrong Options: -- `-r` Reserves the device. Will not reboot or run an image -- `-n` No lock changes. Checks that you have the lock, and then runs an image. Will not unlock afterwards. -- `-a` Keep the machine alive after completion or error text - detected. The console becomes read-write after the text has been found. -- `-c` _TEXT_ Image is run until the specified regular completion - text. -- `-e` _TEXT_ Image is run until the specified error text is found. -- `-d` _TIME_ Timeout (in seconds) to wait for the completion text (default -1 AKA no timeout) -- `-k` _KEY_ Key for obtaining the lock -- `-l` _FILE_ Optional location to write all the console output to -- `-L` This is a Linux image not seL4 -- `-s` _TEXT_ Specifies which machine this job is for -- `-f` _FILE_ [+] Files to use as the job image. Most systems need a - single image file; x86 currently expects two, the kernel and the root task. -- `-w` _TIME_ Number of seconds to wait between each attempt to acquire the lock (default 8) -- `-t` _RETRIES_ Number of retries to perform for acquiring the lock (default -1) +- `-r` Reserves the device. Will not reboot or run an image +- `-n` No lock changes. Checks that you have the lock, and then runs an image. Will not unlock afterwards. +- `-a` Keep the machine alive after completion or error text + detected. The console becomes read-write after the text has been found. +- `-c` _TEXT_ Image is run until the specified regular completion + text. +- `-e` _TEXT_ Image is run until the specified error text is found. +- `-d` _TIME_ Timeout (in seconds) to wait for the completion text (default -1 AKA no timeout) +- `-k` _KEY_ Key for obtaining the lock +- `-l` _FILE_ Optional location to write all the console output to +- `-L` This is a Linux image not seL4 +- `-s` _TEXT_ Specifies which machine this job is for +- `-f` _FILE_ [+] Files to use as the job image. Most systems need a + single image file; x86 currently expects two, the kernel and the root task. +- `-w` _TIME_ Number of seconds to wait between each attempt to acquire the lock (default 8) +- `-t` _RETRIES_ Number of retries to perform for acquiring the lock (default -1) - `--bitstream` _FILE_ Optional bitstream file to load to the FPGA. +`mq sem dumpall|info|acquire|release|help [`_options_`]` -`mq sem dumpall|-signal|-wait|-cancel|-info `__` [-f] [-w `_retry-time_` ] [-t `_retry-count_` ] [-k `_LOCK_\__KEY_` ] [-T` _timeout_`]` - - Manually manipulate locks for machines. The lock for each system - can be acquired or released. - - You can forcibly release a lock for a system that you do not - currently own by using the `-f` flag - - Options: - -- `-info` _SYSTEM_ Display lock information for the specified SYSTEM -- `-mr-info` _SYSTEM_ Display lock information for the specified SYSTEM in machine-readable format -- `-signal` _SYSTEM_ Release the lock for the specified SYSTEM -- `-wait` _SYSTEM_ Acquire the lock for the specified SYSTEM -- `-cancel` _SYSTEM_ Cancel `-wait` processes on the server that are waiting for specified SYSTEM and key -- `-w` _TIME_ Number of seconds to wait between each attempt to acquire the lock (default 8) -- `-t` _RETRIES_ Number of retries to perform for acquiring the - lock (default -1, which means infinity) -- `-f` Forcefully releases a lock even if you are not the owner -- `-k` _LOCK\_KEY_ Set a key inside the lock -- `-T` _timeout_ Allow lock to be reclaimed after _timeout_ seconds -- `dumpall` Prints all currently locked systems +Manually manipulate locks for machines. The lock for each system can be acquired +or released. This is a pass-through to `machine-locks-client sem ...`, read its +documentation +[here](https://github.com/au-ts/machine-locks/tree/main/machine_locks_client). `mq systems [help|simple]` -Print list of available systems. With `simple` just give their names +Print list of available systems. With `simple` just give their names Two other commands are more for use in scripts: `mq system-tsv` and `mq pool-tsv` take no arguments, and write to stdout all the systems, and all the pools (respectively). - diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c3cb6f7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,56 @@ +{ + "nodes": { + "machine-locks": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1795408474, + "narHash": "sha256-b+cmdw7SOvryriZ69EpwyjGhlrY65lOk9RAemKTjsYg=", + "owner": "au-ts", + "repo": "machine-locks", + "rev": "58ec7456a35377add2c9901ae380f5a4c3d28e70", + "type": "github" + }, + "original": { + "owner": "au-ts", + "repo": "machine-locks", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1794644783, + "narHash": "sha256-Qiji3lsueSxl/ngykvc6AEQJnqXRhOMDtUp66DPCxfw=", + "rev": "5d2b81a7a3be3e2f832879028e4d60abbf58e9a0", + "type": "tarball", + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1120695.5d2b81a7a3be/nixexprs.tar.zst" + }, + "original": { + "type": "tarball", + "url": "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1795371335, + "narHash": "sha256-3Xq+XlDu5l+UJ0cc+Jigs84+tz7Qu92NgXVHgJwC52M=", + "rev": "619c39f6eac5d1ed6b8f073a9414baf7034b2356", + "type": "tarball", + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1126808.619c39f6eac5/nixexprs.tar.zst" + }, + "original": { + "type": "tarball", + "url": "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst" + } + }, + "root": { + "inputs": { + "machine-locks": "machine-locks", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..cff0bc3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "Machine Queue scripts for remote access to our CI system"; + + inputs = { + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst"; + machine-locks.url = "github:au-ts/machine-locks"; + }; + + outputs = inputs: { + devShells = builtins.mapAttrs (system: pkgs: { + default = pkgs.mkShell { + packages = [ + inputs.machine-locks.packages.${system}.client + pkgs.jq + ]; + }; + }) inputs.nixpkgs.legacyPackages; + }; +} diff --git a/mq.sh b/mq.sh index 22d6d74..1be3c94 100755 --- a/mq.sh +++ b/mq.sh @@ -93,9 +93,8 @@ case "$command" in exit 1 ;; sem) - UserLock "$@" - # Should not get here - exit 1 + machine-locks-client sem "$@" + exit ;; help|*) Usage diff --git a/scripts/enqueue b/scripts/enqueue index 578a363..8e18105 100755 --- a/scripts/enqueue +++ b/scripts/enqueue @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright 2021 UNSW, Sydney +# Copyright 2026 UNSW, Sydney # # SPDX-License-Identifier: GPL-2.0-only @@ -49,8 +49,7 @@ EnqueueUsage() { Enqueue() { # Parse the command line file_count=0 - retry_period=8 - total_retries=-1 + total_retries="" logfile="" interact="" no_lock_mods=false @@ -137,10 +136,6 @@ Enqueue() { shift key="$1" ;; - -w) - shift - retry_period="$1" - ;; -t) shift total_retries="$1" @@ -216,9 +211,10 @@ Enqueue() { fi if ${no_lock_mods} ; then + # replace if ! LockIOwn "${system}"; then echo "Failed to run because you said you own the lock (-n flag), but you don't!" - LockSystemPrintInfo "${system}" + machine-locks-client sem info "${system}" exit 1 fi else @@ -226,13 +222,19 @@ Enqueue() { # Print out potentially useful information to the user about # the current status of the lock - LockSystemPrintInfo "${system}" + machine-locks-client sem info "${system}" # We can setup the trap early as we check if we actually own the # the lock before releasing it - trap "UnlockSystem \"${system}\" 0 \"${key}\"; exit 1" ${SIGNALS} + # replace + trap "machine-locks-client sem release --owner "$REMOTEUSER" "$system"; exit 1" ${SIGNALS} - if ! LockSystem "${system}" "${retry_period}" "${total_retries}" "${key}"; then + if ! machine-locks-client sem acquire \ + --owner "$REMOTEUSER" \ + ${total_retries:+--num-retries $total_retries} \ + ${timeout:+--timeout $timeout} \ + ${key:+--job-name "$key"} \ + "$system"; then echo "Failed to acquire lock for system (${system})" exit 2 fi @@ -260,7 +262,7 @@ Enqueue() { fi if ! ${no_lock_mods} ; then - UnlockSystem "${system}" 0 "${key}" + machine-locks-client sem release --owner "$REMOTEUSER" "$system" trap "exit 1" ${SIGNALS} fi diff --git a/scripts/lock b/scripts/lock index 949d179..3b28751 100755 --- a/scripts/lock +++ b/scripts/lock @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright 2021 UNSW, Sydney +# Copyright 2026 UNSW, Sydney # # SPDX-License-Identifier: GPL-2.0-only @@ -9,325 +9,17 @@ if [ ! "${SCRIPT_PATH}" ]; then exit 1 fi -LockName() { - echo "${BASE}/$1.lock" -} - -KeyName() { - echo "${BASE}/$1.key" -} - LockOwner() { - RemoteCommand "/bin/sh -c 'stat --format=\"%U\" $(LockName \"$1\") 2>/dev/null'" + machine-locks-client sem info "$1" --json | jq -r '.[0].owner//""' } -LockGetInfo() { - RemoteCommand "/bin/sh -c 'stat --format=\"%U,%y\" $(LockName \"$1\") 2>/dev/null'" -} - -LockGetKey() { - RemoteCommand cat "$(KeyName \"$1\") 2>/dev/null" -} LockIOwn() { owner="$(LockOwner "$1")" [ "${owner}" = "${REMOTEUSER}" ] } -LockTimeout() { - RemoteCommand "cat $(LockName \"$1\")" -} GetAllLockedSystems() { - RemoteCommand find ${BASE} -name '*.lock' -print0 | - xargs -0 -I {} basename {} .lock | - grep -F "`SystemList`" - echo -} - -LockSystemPrintInfo() { - system="$1" - - info="$(LockGetInfo "$system")" - owner=$(echo "$info" | cut -d ',' -f 1) - since=$(echo "$info" | cut -d ',' -f 2) - lockkey=$(LockGetKey "${system}") - - if [ ! "${owner}" ]; then - echo "Lock for $system currently free" - return; - fi - timeout=$(LockTimeout "$system") - printf "Lock for $system held by $owner since $since, timeout $timeout" - if [ "${lockkey}" != "0" ]; then - echo " with key '${lockkey}'" - else - echo "" - fi -} - -# This prints the status of the lock in a more machine-readable format -LockSystemDumpInfo() { - system="$1" - info=$(LockGetInfo "$1") - owner=$(echo "$info" | cut -d ',' -f 1) - since=$(echo "$info" | cut -d ',' -f 2) - lockkey=$(LockGetKey "${system}") - printf "$system" - if [ "${owner}" = "" ]; - then - printf " FREE" - else - printf " LOCKED" - printf " $owner" - printf " $since" - if [ "${lockkey}" != "0" ]; - then - printf " ${lockkey}" - fi - fi - echo -} - -LockSystemDumpAll() { - for x in $(GetAllLockedSystems) - do - LockSystemDumpInfo "$x" - done -} - -LockSystem() { - system="$1" - retry_period="$2" - total_retries="$3" - key="$4" - newtimeout="$5" - timeout="" - owner=$(LockOwner "${system}") - - # Error checking - the same person can't relock the same lock - # - if they are trying to, check if they are using a different key - if [ "${owner}" = "${REMOTEUSER}" ] - then - lockkey=$(LockGetKey "${system}") - if [ "${lockkey}" = "0" -a "${key}" = "0" ] - then - echo "Attempting to grab lock you already own. Please explicitly release" - return 1 - fi - if [ "${lockkey}" = "${key}" ] - then - echo "Attempting to grab lock you already own with the same key. Please explicitly release" - return 2 - fi - fi - if [ "${owner}" ] # race here! - then - # Ensure timeout is either an integer or ignored - # to avoid lockfile syntax errors - timeout="$(LockTimeout $system)" || timeout="" - case $timeout in - ''|*[!0-9]*) - # no valid timeout - timeout="" - ;; - *) - # valid timeout - timeout="-l ${timeout}" - ;; - esac - fi - lockname="$(LockName ${system})" - keyname="$(KeyName ${system})" - RemoteCommand "umask 0111 && lockfile -'${retry_period}' $timeout -r '${total_retries}' '$lockname' && rm -f '$keyname' && printf '${key}' > '$keyname' && chmod a-w,g+r '$keyname' && chmod u+w $lockname && printf '$newtimeout' > $lockname && chmod a-w $lockname" - - [ "$?" -ne 0 ] && return 3 - - return 0 -} - -UnlockSystem() { - system="$1" - force="$2" - key="$3" - - if [ "${force}" -ne 1 ]; then - owner=$(LockOwner "${system}") - if [ "${owner}" != "${REMOTEUSER}" ]; then - echo "Attempting to unlock system ${system} that you do not hold" - return; - fi - lockkey=$(LockGetKey "${system}") - if [ "${lockkey}" != "${key}" ]; then - echo "Attempting to unlock system ${system} with the wrong key!" - return; - fi - fi - RemoteCommand "rm -f '$(KeyName "${system}")'; sync; rm -f '$(LockName "${system}")'" -} - -# Kills (TERM) processes on the server that are waiting for specified lock and key. -# Only kills processes of the current user. -# This correctly signals to client that lock acquisition has failed, but also works -# when the client has already been killed and only the server process is left over. -CancelWait() { - system="$1" - key="$2" - - RemoteCommand "pkill -u ${REMOTEUSER} -f \"lockfile.*'${key}' > '$(KeyName "${system}")'\"" -} - -UserLockUsage() { - echo "$0 sem -signal|-wait|-cancel|-info SYSTEM [-f] [-w retry-time] [-t retry-count] [-k LOCK_KEY]" - echo "$0 sem dumpall" - echo - echo " Manually manipulate locks for machines. The lock for each system" - echo " can be acquired or released." - echo - echo " You can forcibly release a lock for a system that you do not" - echo " currently own by the -f flag" - echo - echo " Options:" - echo - echo " -info SYSTEM Display lock information for the specified SYSTEM" - echo " -mr-info SYSTEM Display lock information for the specified SYSTEM in machine-readable format" - echo " -signal SYSTEM Release the lock for the specified SYSTEM" - echo " -wait SYSTEM Acquire the lock for the specified SYSTEM" - echo " -cancel SYSTEM Cancel '-wait' processes on the server that are waiting for specified SYSTEM and key" - echo " -w TIME Number of seconds to wait between each attempt to acquire the lock (default 8)" - echo " -t RETRIES Number of retries to preform for acquiring the lock (default -1)" - echo " -f Forcefully releases a lock even if you are not the owner" - echo " -k LOCK_KEY Set a key inside the lock" - echo " -T timeout Allow lock to be reclaimed after timeout seconds" - echo " dumpall Prints all currently locked systems" - echo -} - -UserLock() { - retry_period=8 - total_retries=-1 - force=0 - key="0" - timeout=0 - while [ "$#" -ne 0 ]; do - case "$1" in - -info) - shift - system="$1" - action="-info" - ;; - -mr-info) - shift - system="$1" - action="-mr-info" - ;; - -signal) - shift - system="$1" - action="-signal" - ;; - -wait) - shift - system="$1" - action="-wait" - ;; - -cancel) - shift - system="$1" - action="-cancel" - ;; - -w) - shift - retry_period="$1" - ;; - -t) - shift - total_retries="$1" - ;; - -f) - force=1 - ;; - -k) - shift - key="$1" - ;; - -T) - shift - timeout="$1" - ;; - dumpall) - LockSystemDumpAll - exit $? - ;; - help) - UserLockUsage - exit 1 - ;; - --) - break - ;; - *) - echo "Unknown option $1" - UserLockUsage - exit 1 - ;; - esac - shift - done - - # Check that timeout is a positive integer - # If an empty string ends up in the lockfile, it can block - # further interaction - - case $timeout in - ''|*[!0-9]*) - echo "-T requires a positive integer" - exit 1 - ;; - *);; - esac - - IsSystemValid "${system}" - if [ $? -ne 0 ]; then - # If it's not a system, is it a pool? - IsPoolValid "${system}" - if [ $? -ne 0 ] ; then - echo "System or pool '$system' does not exist. Valid systems are" - SystemList - echo "Valid pools are" - PoolList - exit 1 - fi - # Select a system from the pool - pool=${system} - system=$(GetRandomSystemFromPool "${pool}") - echo "${system}" - fi - - case "${action}" in - -info) - LockSystemPrintInfo "${system}" - ;; - -mr-info) - LockSystemDumpInfo "${system}" - ;; - -signal) - UnlockSystem "${system}" "${force}" "${key}" - ;; - -wait) - if ! LockSystem "${system}" "${retry_period}" "${total_retries}" "${key}" $timeout; then - echo "Failed to acquire lock for system (${system})" - exit 2 - fi - ;; - -cancel) - CancelWait "${system}" "${key}" - ;; - *) - echo "Unknown usage" - UserLockUsage - exit 1 - ;; - esac - exit 0 + machine-locks-client machines list-locked --json | jq -r '.[].name' } From 47dc36395f1799dab3e1331693b4c5a4093a8440 Mon Sep 17 00:00:00 2001 From: debater-coder Date: Wed, 25 Nov 2026 10:24:16 +1100 Subject: [PATCH 2/3] trivial: Revert auto-format docs changes Signed-off-by: debater-coder --- README.md | 102 ++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index e847472..bcf3b56 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ and use these scripts to deploy their payloads onto our CI infrastructure; they are also used by GitHub's [CI Actions](https://github.com/seL4/ci-actions) for seL4. + Set Up ======== @@ -24,80 +25,76 @@ repository, and create a symlink from `mq.sh` to somewhere in your `$PATH`. For example, you can do: - -``` -git clone git@github.com:seL4/machine_queue.git -H=$(pwd)/mq.sh -cd ~/bin -ln -s $H mq -``` + ``` + git clone git@github.com:seL4/machine_queue.git + H=$(pwd)/mq.sh + cd ~/bin + ln -s $H mq + ``` The mq scripts assume a standard POSIX system, that `/bin/sh` is POSIX compliant, and that you can use `ssh` to reach -`tftp.keg.cse.unsw.edu.au` without password. To set up the latter, +`tftp.keg.cse.unsw.edu.au` without password. To set up the latter, add to your `~/.ssh/config`: - -``` -Host tftp.keg.cse.unsw.edu.au - ProxyJump login.trustworthy.systems - ControlMaster auto - ControlPersist 300 - ControlPath /home/%u/.ssh/controlmaster/%h-%p-%r.sock - ServerAliveInterval 60 - TCPKeepAlive yes -``` - -or clauses with similar effect. The script makes many `ssh` + ``` + Host tftp.keg.cse.unsw.edu.au + ProxyJump login.trustworthy.systems + ControlMaster auto + ControlPersist 300 + ControlPath /home/%u/.ssh/controlmaster/%h-%p-%r.sock + ServerAliveInterval 60 + TCPKeepAlive yes + ``` +or clauses with similar effect. The script makes many `ssh` connections in a row; without the control multiplexing this can get painfully slow. + Usage ====== `mq` has many subcommands: - -- `run` --- run a payload on a system -- `systems` --- list available systems -- `sem` --- interact directly with locks -- `system-tsv` --- list available systems as tab-separated values -- `pool-tsv` --- list available pools of systems as tab-separated - values + * `run` --- run a payload on a system + * `systems` --- list available systems + * `sem` --- interact directly with locks + * `system-tsv` --- list available systems as tab-separated values + * `pool-tsv` --- list available pools of systems as tab-separated + values `mq run` -------- - `mq.sh run -r|-c` __ `[-l ` _logfile_ `] -s` _system_ `[-w` _retry-time_ `] [-t `_retry-count_` ] [-n] [-a] [-d` _timeout_ `] [-e` __`] [-k `__`] [-L] -f `_file1_ `[-f `_file2_`] .. [-f` _filen_ `]` -Acquires a lock for the machine called _system_ (or a machine in -the pool called _system_), and, once locked, runs the specified job. + Acquires a lock for the machine called _system_ (or a machine in + the pool called _system_), and, once locked, runs the specified job. -Output from the machine is collected and passed back to the -user both on stdout and into an optional logfile. + Output from the machine is collected and passed back to the + user both on stdout and into an optional logfile. -Jobs can be cancelled at any time with ^C, which will notify the server -(if the job is running) and remove the job from the queue. + Jobs can be cancelled at any time with ^C, which will notify the server + (if the job is running) and remove the job from the queue. -Returns 0 on success, nonzero if something went wrong + Returns 0 on success, nonzero if something went wrong Options: -- `-r` Reserves the device. Will not reboot or run an image -- `-n` No lock changes. Checks that you have the lock, and then runs an image. Will not unlock afterwards. -- `-a` Keep the machine alive after completion or error text - detected. The console becomes read-write after the text has been found. -- `-c` _TEXT_ Image is run until the specified regular completion - text. -- `-e` _TEXT_ Image is run until the specified error text is found. -- `-d` _TIME_ Timeout (in seconds) to wait for the completion text (default -1 AKA no timeout) -- `-k` _KEY_ Key for obtaining the lock -- `-l` _FILE_ Optional location to write all the console output to -- `-L` This is a Linux image not seL4 -- `-s` _TEXT_ Specifies which machine this job is for -- `-f` _FILE_ [+] Files to use as the job image. Most systems need a - single image file; x86 currently expects two, the kernel and the root task. -- `-w` _TIME_ Number of seconds to wait between each attempt to acquire the lock (default 8) -- `-t` _RETRIES_ Number of retries to perform for acquiring the lock (default -1) +- `-r` Reserves the device. Will not reboot or run an image +- `-n` No lock changes. Checks that you have the lock, and then runs an image. Will not unlock afterwards. +- `-a` Keep the machine alive after completion or error text + detected. The console becomes read-write after the text has been found. +- `-c` _TEXT_ Image is run until the specified regular completion + text. +- `-e` _TEXT_ Image is run until the specified error text is found. +- `-d` _TIME_ Timeout (in seconds) to wait for the completion text (default -1 AKA no timeout) +- `-k` _KEY_ Key for obtaining the lock +- `-l` _FILE_ Optional location to write all the console output to +- `-L` This is a Linux image not seL4 +- `-s` _TEXT_ Specifies which machine this job is for +- `-f` _FILE_ [+] Files to use as the job image. Most systems need a + single image file; x86 currently expects two, the kernel and the root task. +- `-w` _TIME_ Number of seconds to wait between each attempt to acquire the lock (default 8) +- `-t` _RETRIES_ Number of retries to perform for acquiring the lock (default -1) - `--bitstream` _FILE_ Optional bitstream file to load to the FPGA. `mq sem dumpall|info|acquire|release|help [`_options_`]` @@ -109,8 +106,9 @@ documentation `mq systems [help|simple]` -Print list of available systems. With `simple` just give their names +Print list of available systems. With `simple` just give their names Two other commands are more for use in scripts: `mq system-tsv` and `mq pool-tsv` take no arguments, and write to stdout all the systems, and all the pools (respectively). + From 75a6f4b9d1b89512745e2af61c9bf8f3a4bbfd9d Mon Sep 17 00:00:00 2001 From: debater-coder Date: Wed, 25 Nov 2026 12:54:13 +1100 Subject: [PATCH 3/3] Properly package mq.sh with Nix and update installation instructions Signed-off-by: debater-coder --- README.md | 15 +++++++++++++++ flake.nix | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bcf3b56..9c1d17a 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,11 @@ For example, you can do: ln -s $H mq ``` +The mq scripts are dependent on the [`jq`](https://jqlang.org/download/) and +[`machine-locks-client`](https://github.com/au-ts/machine-locks/tree/main/machine_locks_client). +Follow the instructions at each of those links to download or compile them, and +add them to your `$PATH`. + The mq scripts assume a standard POSIX system, that `/bin/sh` is POSIX compliant, and that you can use `ssh` to reach `tftp.keg.cse.unsw.edu.au` without password. To set up the latter, @@ -49,6 +54,16 @@ or clauses with similar effect. The script makes many `ssh` connections in a row; without the control multiplexing this can get painfully slow. +Usage with Nix +================ + +You will need to enable the Nix 'flakes' feature. Then spawn a shell with: +``` +nix shell github:seL4/machine_queue +``` +Then, all `mq` dependencies will be accessible to `mq` automatically, and `mq.sh` +will be in your `$PATH`. You do not need to clone the repo or set up any symlinks. +You will still need to setup an appropriate SSH config. Usage ====== diff --git a/flake.nix b/flake.nix index cff0bc3..f5ac7db 100644 --- a/flake.nix +++ b/flake.nix @@ -6,14 +6,40 @@ machine-locks.url = "github:au-ts/machine-locks"; }; - outputs = inputs: { - devShells = builtins.mapAttrs (system: pkgs: { - default = pkgs.mkShell { - packages = [ - inputs.machine-locks.packages.${system}.client - pkgs.jq - ]; - }; - }) inputs.nixpkgs.legacyPackages; - }; + outputs = + inputs: + let + deps = system: pkgs: [ + inputs.machine-locks.packages.${system}.client + pkgs.jq + ]; + in + { + devShells = builtins.mapAttrs (system: pkgs: { + default = pkgs.mkShell { + packages = deps system pkgs; + }; + }) inputs.nixpkgs.legacyPackages; + packages = builtins.mapAttrs (system: pkgs: { + default = pkgs.stdenv.mkDerivation { + pname = "machine_queue"; + version = pkgs.lib.removeSuffix "\n" (builtins.readFile ./VERSION); + src = ./.; + + nativeBuildInputs = [ pkgs.makeWrapper ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp -r mq.sh scripts $out/bin/ + + wrapProgram $out/bin/mq.sh \ + --prefix PATH : ${pkgs.lib.makeBinPath (deps system pkgs)} + + runHook postInstall + ''; + }; + }) inputs.nixpkgs.legacyPackages; + }; }