diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-10-09 11:40:31 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2022-11-13 23:58:25 +0000 |
commit | 4ad855540f183d4ce39e57f3e1b6f6bc006cae95 (patch) | |
tree | f51f213451fe6b6410f97a1e72f6b8cba0210502 /host | |
parent | 435a82a9d09e6aaca27402a45756de1abd37437f (diff) | |
download | spectrum-4ad855540f183d4ce39e57f3e1b6f6bc006cae95.tar spectrum-4ad855540f183d4ce39e57f3e1b6f6bc006cae95.tar.gz spectrum-4ad855540f183d4ce39e57f3e1b6f6bc006cae95.tar.bz2 spectrum-4ad855540f183d4ce39e57f3e1b6f6bc006cae95.tar.lz spectrum-4ad855540f183d4ce39e57f3e1b6f6bc006cae95.tar.xz spectrum-4ad855540f183d4ce39e57f3e1b6f6bc006cae95.tar.zst spectrum-4ad855540f183d4ce39e57f3e1b6f6bc006cae95.zip |
host/start-vm: support multiple block devices
This is the first step to being able to do things like having a static base image for an application VM, and another image containing the application to run. When we actually use multiple images we'll need to change how we boot so we know the kernel is booting from the right image — probably by PARTUUID or PARTLABEL — because we can't guarantee how the kernel orders disks inside the VM. Signed-off-by: Alyssa Ross <hi@alyssa.is> Message-Id: <20221009114036.463071-2-hi@alyssa.is>
Diffstat (limited to 'host')
-rw-r--r-- | host/start-vm/lib.rs | 36 | ||||
-rw-r--r-- | host/start-vm/tests/vm_command-basic.rs | 4 |
2 files changed, 32 insertions, 8 deletions
diff --git a/host/start-vm/lib.rs b/host/start-vm/lib.rs index 1230a6e..5d43a3e 100644 --- a/host/start-vm/lib.rs +++ b/host/start-vm/lib.rs @@ -81,12 +81,36 @@ pub fn vm_command(dir: PathBuf, config_root: &Path) -> Result<Command, String> { Err(e) => return Err(format!("reading directory {:?}: {}", net_providers_dir, e)), } - command.arg("--disk").arg({ - let mut disk = OsString::from("path=/ext/svc/data/"); - disk.push(&vm_name); - disk.push("/rootfs.ext4,readonly=on"); - disk - }); + command.arg("--disk"); + + let blk_dir = config_dir.join("blk"); + match blk_dir.read_dir() { + Ok(entries) => { + for result in entries { + let entry = result + .map_err(|e| format!("examining directory entry: {}", e))? + .path(); + + if entry.extension() != Some(OsStr::new("img")) { + continue; + } + + if entry.as_os_str().as_bytes().contains(&b',') { + return Err(format!("illegal ',' character in path {:?}", entry)); + } + + let mut arg = OsString::from("path="); + arg.push(entry); + arg.push(",readonly=on"); + command.arg(arg); + } + } + Err(e) => return Err(format!("reading directory {:?}: {}", blk_dir, e)), + } + + if command.get_args().last() == Some(OsStr::new("--disk")) { + return Err("no block devices specified".to_string()); + } command.arg("--serial").arg({ let mut serial = OsString::from("file=/run/"); diff --git a/host/start-vm/tests/vm_command-basic.rs b/host/start-vm/tests/vm_command-basic.rs index b2edb7c..a577a71 100644 --- a/host/start-vm/tests/vm_command-basic.rs +++ b/host/start-vm/tests/vm_command-basic.rs @@ -14,7 +14,7 @@ fn main() -> std::io::Result<()> { create_dir(&service_dir)?; let kernel_path = tmp_dir.path().join("svc/data/testvm/vmlinux"); - let image_path = tmp_dir.path().join("svc/data/testvm/rootfs.ext4"); + let image_path = tmp_dir.path().join("svc/data/testvm/blk/root.img"); create_dir_all(kernel_path.parent().unwrap())?; create_dir_all(image_path.parent().unwrap())?; @@ -43,7 +43,7 @@ fn main() -> std::io::Result<()> { OsStr::new("--kernel"), kernel_path.as_os_str(), OsStr::new("--disk"), - OsStr::new("path=/ext/svc/data/testvm/rootfs.ext4,readonly=on"), + &expected_disk_arg, OsStr::new("--serial"), OsStr::new("file=/run/testvm.log"), ]; |