From f8e7aedeb2ec6c7081872affd998854db6e56928 Mon Sep 17 00:00:00 2001 From: Thales Maciel Date: Thu, 29 Jan 2026 14:47:09 -0300 Subject: [PATCH] Move VM dirs under state/vms --- README.md | 2 +- kill.sh | 2 +- list.sh | 2 +- ps.sh | 2 +- rm.sh | 2 +- run.sh | 7 ++++--- stop.sh | 2 +- verify.sh | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5d6105f..34ef433 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ reboot ``` ## VM Info File -Each VM writes a metadata file at `state/vm-*/info` with the following fields: +Each VM writes a metadata file at `state/vms//info` with the following fields: - `id`: unique identifier for the VM instance. - `pid`: Firecracker process ID. - `created_at`: timestamp when the VM was launched. diff --git a/kill.sh b/kill.sh index 0ced0bc..155179d 100755 --- a/kill.sh +++ b/kill.sh @@ -23,7 +23,7 @@ find_vm_info() { local query="$1" local info match_count=0 match="" - for info in state/vm-*/info; do + for info in state/vms/*/info; do [[ -f "$info" ]] || continue local id name id="$(get_prop "$info" "id")" diff --git a/list.sh b/list.sh index 8f73d22..cce4012 100755 --- a/list.sh +++ b/list.sh @@ -9,7 +9,7 @@ get_prop() { awk -F= -v k="$key" '$1==k {print $2}' "$info" } -for info in state/vm-*/info; do +for info in state/vms/*/info; do id="$(get_prop "$info" "id")" name="$(get_prop "$info" "name")" created_at="$(get_prop "$info" "created_at")" diff --git a/ps.sh b/ps.sh index aad6d59..dbc1a2a 100755 --- a/ps.sh +++ b/ps.sh @@ -9,7 +9,7 @@ get_prop() { awk -F= -v k="$key" '$1==k {print $2}' "$info" } -for info in state/vm-*/info; do +for info in state/vms/*/info; do id="$(get_prop "$info" "id")" name="$(get_prop "$info" "name")" created_at="$(get_prop "$info" "created_at")" diff --git a/rm.sh b/rm.sh index 84630e6..737d60b 100755 --- a/rm.sh +++ b/rm.sh @@ -23,7 +23,7 @@ find_vm_info() { local query="$1" local info match_count=0 match="" - for info in state/vm-*/info; do + for info in state/vms/*/info; do [[ -f "$info" ]] || continue local id name id="$(get_prop "$info" "id")" diff --git a/run.sh b/run.sh index 9832eab..105e8b6 100755 --- a/run.sh +++ b/run.sh @@ -22,7 +22,8 @@ log "starting" DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" STATE="$DIR/state" -mkdir -p "$STATE" +VM_ROOT="$STATE/vms" +mkdir -p "$VM_ROOT" FC_BIN="$DIR/firecracker" KERNEL="$DIR/vmlinux" @@ -52,7 +53,7 @@ shopt -s nullglob name_taken() { local candidate="$1" local info existing_name - for info in "$STATE"/vm-*/info; do + for info in "$VM_ROOT"/*/info; do existing_name="$(awk -F= '$1=="name"{print $2}' "$info")" if [[ "$existing_name" == "$candidate" ]]; then return 0 @@ -165,7 +166,7 @@ fi VM_ID="$(head -c 32 /dev/urandom | xxd -p -c 256)" VM_TAG="${VM_ID:0:8}" -VM_DIR="$STATE/vm-$VM_ID" +VM_DIR="$VM_ROOT/$VM_ID" mkdir -p "$VM_DIR" API_SOCK="$STATE/fc-$VM_TAG.sock" diff --git a/stop.sh b/stop.sh index c5b32b9..41c53fc 100755 --- a/stop.sh +++ b/stop.sh @@ -23,7 +23,7 @@ find_vm_info() { local query="$1" local info match_count=0 match="" - for info in state/vm-*/info; do + for info in state/vms/*/info; do [[ -f "$info" ]] || continue local id name id="$(get_prop "$info" "id")" diff --git a/verify.sh b/verify.sh index ef7c9ee..22bfc04 100755 --- a/verify.sh +++ b/verify.sh @@ -30,7 +30,7 @@ if ! ./run.sh; then exit 1 fi -VM_DIR="$(find state -maxdepth 1 -type d -name 'vm-*' -printf '%T@ %p\n' 2>/dev/null | sort -nr | head -n 1 | awk '{print $2}')" +VM_DIR="$(find state/vms -maxdepth 1 -mindepth 1 -type d -printf '%T@ %p\n' 2>/dev/null | sort -nr | head -n 1 | awk '{print $2}')" if [[ -z "$VM_DIR" ]]; then log "no VM state directory found" exit 1