Support host:guest mount syntax with WORKINGDIR resolution
CI / build (pull_request) Successful in 12s
CI / build (pull_request) Successful in 12s
--mount now accepts <host-path>:<guest-path> (Docker-style). When the guest path is omitted, the host path is used. Non-absolute guest paths are resolved against the image WORKINGDIR, which is written to /slim/workdir at build time and read by slim-init.sh at boot. Changes: - qemu.rs: Parse host:guest spec, pass guest path (not host path) on the kernel cmdline as slim.mount=<tag>:<base64(guest_path)> - inject.rs: Accept working_dir param, write /slim/workdir into rootfs - build.rs: Pass config.working_dir to inject() - slim-init.sh: Read /slim/workdir, resolve relative guest paths against it before mounting - test.sh: Test host:guest absolute paths (multi-mount) and relative guest path resolved against WORKINGDIR Addresses PR #9 review comment from @hulthe.
This commit is contained in:
+51
-9
@@ -107,9 +107,13 @@ test_mount() {
|
||||
echo "=== Testing --mount (9p shares) ==="
|
||||
|
||||
work="$(mktemp -d)"
|
||||
|
||||
# --- Image 1: no WORKINGDIR, test host:guest and multi-mount ---
|
||||
img="slim-test-mount"
|
||||
share_dir="$work/share"
|
||||
share_dir2="$work/share2"
|
||||
guest_dir="/mnt/guest"
|
||||
guest_dir2="/mnt/guest2"
|
||||
|
||||
mkdir -p "$share_dir" "$share_dir2"
|
||||
echo "hello from host" > "$share_dir/testfile.txt"
|
||||
@@ -120,7 +124,7 @@ FROM alpine:latest
|
||||
CMD ["/bin/sh", "-c", "poweroff -f"]
|
||||
EOF
|
||||
|
||||
echo "-- Building container image..."
|
||||
echo "-- Building container image (no WORKINGDIR)..."
|
||||
if ! podman build --network=none -t "$img" -f "$work/Containerfile" >/dev/null 2>&1; then
|
||||
report fail "--mount (podman build failed)"
|
||||
rm -rf "$work"
|
||||
@@ -135,25 +139,63 @@ EOF
|
||||
return
|
||||
fi
|
||||
|
||||
# The 9p share appears at the same path inside the VM as on the host.
|
||||
# Use --cmd to run the verification snippet with the canonical path.
|
||||
share_canon=$(readlink -f "$share_dir")
|
||||
share_canon2=$(readlink -f "$share_dir2")
|
||||
|
||||
echo "-- Booting VM with --mount $share_dir --mount $share_dir2 ..."
|
||||
echo "-- Test 1: --mount host:guest (absolute guest path, multi-mount)..."
|
||||
output=$(timeout "$TIMEOUT" "$SLIM_BIN" run "$img" \
|
||||
--mount "$share_dir" \
|
||||
--mount "$share_dir2" \
|
||||
--cmd "echo Available 9p shares:; for f in /sys/bus/virtio/drivers/9pnet_virtio/virtio*/mount_tag; do [ -f \"\$f\" ] && echo \"\$f: \$(tr -d '\\0' < \"\$f\")\"; done; echo Mounts:; mount -v; cat \"${share_canon}/testfile.txt\" 2>/dev/null || echo NO_FILE; cat \"${share_canon2}/testfile2.txt\" 2>/dev/null || echo NO_FILE2; echo MOUNT_VERIFY_DONE; poweroff -f" \
|
||||
--mount "${share_dir}:${guest_dir}" \
|
||||
--mount "${share_dir2}:${guest_dir2}" \
|
||||
--cmd "for f in /sys/bus/virtio/drivers/9pnet_virtio/virtio*/mount_tag; do [ -f \"\$f\" ] && echo \"\$f: \$(tr -d '\\0' < \"\$f\")\"; done; mount -v; cat ${guest_dir}/testfile.txt 2>/dev/null || echo NO_FILE; cat ${guest_dir2}/testfile2.txt 2>/dev/null || echo NO_FILE2; echo MOUNT_VERIFY_DONE; poweroff -f" \
|
||||
2>&1 || true)
|
||||
|
||||
check_output "$output" "mount_tag: slim0" "--mount 9p share detected"
|
||||
check_output "$output" "mount_tag: slim1" "--mount second 9p share detected"
|
||||
check_output "$output" "type 9p" "--mount 9p filesystem in mount list"
|
||||
check_output "$output" "hello from host" "--mount file accessible in VM"
|
||||
check_output "$output" "second share" "--mount second share file accessible in VM"
|
||||
check_output "$output" "hello from host" "--mount file accessible at guest path"
|
||||
check_output "$output" "second share" "--mount second file accessible at guest path"
|
||||
check_output "$output" "MOUNT_VERIFY_DONE" "--mount VM ran to completion"
|
||||
|
||||
cleanup "$img" "$img"
|
||||
|
||||
# --- Image 2: with WORKINGDIR, test relative guest path ---
|
||||
img="slim-test-mount-wd"
|
||||
share_dir3="$work/share3"
|
||||
|
||||
mkdir -p "$share_dir3"
|
||||
echo "relative share" > "$share_dir3/relfile.txt"
|
||||
|
||||
cat > "$work/Containerfile.wd" <<'EOF'
|
||||
FROM alpine:latest
|
||||
WORKDIR /app
|
||||
CMD ["/bin/sh", "-c", "poweroff -f"]
|
||||
EOF
|
||||
|
||||
echo "-- Building container image (WORKINGDIR /app)..."
|
||||
if ! podman build --network=none -t "$img" -f "$work/Containerfile.wd" >/dev/null 2>&1; then
|
||||
report fail "--mount relative (podman build failed)"
|
||||
rm -rf "$work"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "-- Building slim VM..."
|
||||
if ! "$SLIM_BIN" build qcow2 "$img" >/dev/null 2>&1; then
|
||||
report fail "--mount relative (slim build failed)"
|
||||
cleanup "$img" "$img"
|
||||
rm -rf "$work"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "-- Test 2: --mount host:relative-guest (resolved against WORKINGDIR)..."
|
||||
output=$(timeout "$TIMEOUT" "$SLIM_BIN" run "$img" \
|
||||
--mount "${share_dir3}:data" \
|
||||
--cmd "mount -v; cat /app/data/relfile.txt 2>/dev/null || echo NO_REL_FILE; echo REL_VERIFY_DONE; poweroff -f" \
|
||||
2>&1 || true)
|
||||
|
||||
check_output "$output" "type 9p" "--mount relative 9p filesystem in mount list"
|
||||
check_output "$output" "relative share" "--mount relative file accessible at WORKINGDIR/data"
|
||||
check_output "$output" "REL_VERIFY_DONE" "--mount relative VM ran to completion"
|
||||
|
||||
cleanup "$img" "$img"
|
||||
rm -rf "$work"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user