Skip to content

Commit bd66cee

Browse files
authored
Centralize snapshot utilities into snapshot_store module (#24)
- refactor: centralize snapshot utilities into `snapshot_store` module - Moved snapshot-related logic (e.g., hashing, directory management, listing, deletion) into a new `snapshot_store` module for better modularity and cross-platform compatibility. - Updated imports and restructured functions like `compute_config_hash` and `snapshot_dir_for_hash` to use the new module. - Simplified platform-specific code paths in `cmd_snapshot` by isolating shared functionality in `snapshot_store`. - Ensured comprehensive tests for `snapshot_store`, including VZ and KVM integration scenarios. - add: enable CI support for Ubuntu 24.04 ARM configuration - fix: include runner architecture in cargo cache keys in CI workflow - add: architecture-specific serialization support for VM and vCPU state - Implemented conditional handling for `x86_64` and `aarch64` architectures in snapshot serialization/deserialization tests (`test_vcpu_state_serde_roundtrip`, `test_vm_snapshot_serde_roundtrip`). - Updated `capture_irqchip` and `restore_irqchip` functions to reduce unused variable warnings by changing parameter names to `_vm` and `_state`. - refactor: clean up unused imports and improve arch-specific KVM handling - Removed unnecessary `GuestMemoryMmap` import from `boot.rs`. - Updated `kvm_bindings` device type constants to use aliased names for consistency. - Enhanced vCPU configuration by initializing `kvm_vcpu_init` directly with `get_preferred_target`. - Added conditional `SYS_poll` and `SYS_epoll_wait` handling for better architecture support. - Fix kvm-bindings constant names (kvm_device_type_ prefix) - Fix get_preferred_target API (takes &mut kvm_vcpu_init) - Gate x86_64-only syscalls (SYS_epoll_wait, SYS_poll) with cfg - Remove unused import (GuestMemoryMmap) and variables - Make snapshot tests arch-conditional for VcpuState fields - Add runner.arch to CI cache keys to prevent cross-arch pollution - Add aarch64 cross-check instructions to AGENTS.md
1 parent cb2dd52 commit bd66cee

File tree

15 files changed

+719
-215
lines changed

15 files changed

+719
-215
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
rust: stable
2323
- os: ubuntu-latest
2424
rust: beta
25+
- os: ubuntu-24.04-arm
26+
rust: stable
2527
- os: macos-latest
2628
rust: stable
2729

@@ -38,19 +40,19 @@ jobs:
3840
uses: actions/cache@v4
3941
with:
4042
path: ~/.cargo/registry
41-
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
43+
key: ${{ runner.os }}-${{ runner.arch }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
4244

4345
- name: Cache cargo index
4446
uses: actions/cache@v4
4547
with:
4648
path: ~/.cargo/git
47-
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
49+
key: ${{ runner.os }}-${{ runner.arch }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
4850

4951
- name: Cache cargo build
5052
uses: actions/cache@v4
5153
with:
5254
path: target
53-
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
55+
key: ${{ runner.os }}-${{ runner.arch }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
5456

5557
- name: Run tests
5658
run: |
@@ -74,7 +76,7 @@ jobs:
7476
strategy:
7577
fail-fast: false
7678
matrix:
77-
os: [ubuntu-latest, macos-latest]
79+
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
7880

7981
steps:
8082
- uses: actions/checkout@v4
@@ -102,7 +104,7 @@ jobs:
102104
strategy:
103105
fail-fast: false
104106
matrix:
105-
os: [ubuntu-latest, macos-latest]
107+
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
106108
rust: [stable]
107109

108110
steps:
@@ -152,7 +154,7 @@ jobs:
152154
strategy:
153155
fail-fast: false
154156
matrix:
155-
os: [ubuntu-latest, macos-latest]
157+
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
156158

157159
steps:
158160
- uses: actions/checkout@v4

AGENTS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,30 @@ cargo clippy --workspace --all-targets --all-features -- -D warnings
343343
cargo test --workspace --all-features
344344
```
345345

346+
### aarch64 cross-check (required when touching `src/vmm/arch/aarch64/` or arch-neutral VMM code)
347+
348+
CI runs on native aarch64 (`ubuntu-24.04-arm`). To catch issues locally from an
349+
x86_64 host without waiting for CI:
350+
351+
```bash
352+
# One-time setup (Fedora):
353+
# sudo dnf install -y gcc-aarch64-linux-gnu sysroot-aarch64-fc43-glibc
354+
# rustup target add aarch64-unknown-linux-gnu
355+
356+
CFLAGS_aarch64_unknown_linux_gnu="--sysroot=/usr/aarch64-redhat-linux/sys-root/fc43" \
357+
RUSTFLAGS="-D warnings" \
358+
cargo check --target aarch64-unknown-linux-gnu -p void-box --lib --tests
359+
```
360+
361+
Common aarch64 pitfalls:
362+
- `kvm-bindings` constants use `kvm_device_type_` prefix (e.g.
363+
`kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V3`, not `KVM_DEV_TYPE_ARM_VGIC_V3`).
364+
- `kvm-ioctls` `get_preferred_target()` takes `&mut kvm_vcpu_init` out-param.
365+
- `libc::SYS_epoll_wait` and `libc::SYS_poll` don't exist on aarch64 — use
366+
`SYS_epoll_pwait` and `SYS_ppoll`.
367+
- Unused variables/imports that are only used on x86_64 become errors with
368+
`-D warnings` on aarch64.
369+
346370
### VM suites (required for VM/OCI/OpenClaw changes)
347371

348372
Linux (KVM):

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void-box-protocol = { path = "void-box-protocol" }
5353
voidbox-oci = { path = "voidbox-oci" }
5454
libc = "0.2"
5555
byteorder = "1"
56+
sha2 = "0.10"
5657

5758
# --- Linux-only dependencies ---
5859
[target.'cfg(target_os = "linux")'.dependencies]
@@ -71,9 +72,6 @@ event-manager = "0.4"
7172
# SLIRP networking (smoltcp-based user-mode networking)
7273
smoltcp = { version = "0.11", default-features = false, features = ["std", "medium-ethernet", "proto-ipv4", "socket-tcp", "socket-udp", "socket-dns"] }
7374

74-
# Stable hashing for OCI disk cache keys and snapshot config hashes
75-
sha2 = "0.10"
76-
7775
# Binary serialization for VM snapshot state
7876
bincode = "1"
7977

src/backend/mod.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,57 @@ pub struct BackendConfig {
7878
pub snapshot: Option<PathBuf>,
7979
}
8080

81+
impl BackendConfig {
82+
/// Create a minimal `BackendConfig` with sensible defaults.
83+
///
84+
/// Only requires the fields that have no reasonable default (kernel path,
85+
/// memory, vCPUs). Everything else is set to safe defaults with vsock
86+
/// enabled and the default command allowlist.
87+
pub fn minimal(kernel: impl Into<PathBuf>, memory_mb: usize, vcpus: usize) -> Self {
88+
let mut session_secret = [0u8; 32];
89+
getrandom::fill(&mut session_secret).expect("getrandom");
90+
Self {
91+
memory_mb,
92+
vcpus,
93+
kernel: kernel.into(),
94+
initramfs: None,
95+
rootfs: None,
96+
network: false,
97+
enable_vsock: true,
98+
shared_dir: None,
99+
mounts: Vec::new(),
100+
oci_rootfs: None,
101+
oci_rootfs_dev: None,
102+
oci_rootfs_disk: None,
103+
env: Vec::new(),
104+
security: BackendSecurityConfig {
105+
session_secret,
106+
command_allowlist: DEFAULT_COMMAND_ALLOWLIST
107+
.iter()
108+
.map(|s| s.to_string())
109+
.collect(),
110+
network_deny_list: Vec::new(),
111+
max_connections_per_second: 0,
112+
max_concurrent_connections: 0,
113+
seccomp: false,
114+
},
115+
snapshot: None,
116+
}
117+
}
118+
119+
/// Set the initramfs path.
120+
pub fn initramfs(mut self, path: impl Into<PathBuf>) -> Self {
121+
self.initramfs = Some(path.into());
122+
self
123+
}
124+
125+
/// Enable or disable networking.
126+
pub fn network(mut self, enabled: bool) -> Self {
127+
self.network = enabled;
128+
self
129+
}
130+
}
131+
81132
/// Security-relevant settings for the backend.
82133
#[derive(Debug, Clone)]
83134
pub struct BackendSecurityConfig {

0 commit comments

Comments
 (0)