From: Alyssa Ross <hi@alyssa.is>
To: devel@spectrum-os.org
Subject: [PATCH 02/22] host/start-vm: implement shared directories
Date: Mon, 10 Oct 2022 23:28:42 +0000 [thread overview]
Message-ID: <20221010232909.1953738-3-hi@alyssa.is> (raw)
In-Reply-To: <20221010232909.1953738-1-hi@alyssa.is>
Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
host/start-vm/lib.rs | 26 +++++++++++++
host/start-vm/tests/meson.build | 2 +
host/start-vm/tests/vm_command-shared-dir.rs | 41 ++++++++++++++++++++
3 files changed, 69 insertions(+)
create mode 100644 host/start-vm/tests/vm_command-shared-dir.rs
diff --git a/host/start-vm/lib.rs b/host/start-vm/lib.rs
index 9a92ab7..3959566 100644
--- a/host/start-vm/lib.rs
+++ b/host/start-vm/lib.rs
@@ -112,6 +112,32 @@ pub fn vm_command(dir: PathBuf, config_root: &Path) -> Result<Command, String> {
return Err("no block devices specified".to_string());
}
+ let shared_dirs_dir = config_dir.join("shared-dirs");
+ match shared_dirs_dir.read_dir().map(Iterator::peekable) {
+ Ok(mut entries) => {
+ if entries.peek().is_some() {
+ command.arg("--fs");
+ }
+
+ for result in entries {
+ let entry = result
+ .map_err(|e| format!("examining directory entry: {}", e))?
+ .file_name();
+
+ let mut arg = OsString::from("tag=");
+ arg.push(&entry);
+ arg.push(",socket=../");
+ arg.push(vm_name);
+ arg.push("-fs-");
+ arg.push(&entry);
+ arg.push("/env/virtiofsd.sock");
+ command.arg(arg);
+ }
+ }
+ Err(e) if e.kind() == ErrorKind::NotFound => {}
+ Err(e) => return Err(format!("reading directory {:?}: {}", shared_dirs_dir, e)),
+ }
+
command.arg("--serial").arg({
let mut serial = OsString::from("file=/run/");
serial.push(&vm_name);
diff --git a/host/start-vm/tests/meson.build b/host/start-vm/tests/meson.build
index 00bd33d..857414b 100644
--- a/host/start-vm/tests/meson.build
+++ b/host/start-vm/tests/meson.build
@@ -31,3 +31,5 @@ test('tap_open (name too long)', executable('tap_open-name-too-long',
test('vm_command-basic', executable('vm_command-basic',
'vm_command-basic.rs', link_with : [rust_lib, rust_helper]))
+test('vm_command-shared-dir', executable('vm_command-shared-dir',
+ 'vm_command-shared-dir.rs', link_with : [rust_lib, rust_helper]))
diff --git a/host/start-vm/tests/vm_command-shared-dir.rs b/host/start-vm/tests/vm_command-shared-dir.rs
new file mode 100644
index 0000000..2b13663
--- /dev/null
+++ b/host/start-vm/tests/vm_command-shared-dir.rs
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: EUPL-1.2+
+// SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+
+use std::fs::{create_dir, create_dir_all, File};
+use std::os::unix::fs::symlink;
+
+use start_vm::vm_command;
+use test_helper::TempDir;
+
+fn contains_seq<H: PartialEq<N>, N>(haystack: &[H], needle: &[N]) -> bool {
+ let start_indexes = 0..=(haystack.len() - needle.len());
+ let mut candidates = start_indexes.map(|i| &haystack[i..][..needle.len()]);
+ candidates.any(|c| c == needle)
+}
+
+fn main() -> std::io::Result<()> {
+ let tmp_dir = TempDir::new()?;
+
+ let service_dir = tmp_dir.path().join("testvm");
+ let vm_config = tmp_dir.path().join("svc/data/testvm");
+
+ create_dir(&service_dir)?;
+ create_dir_all(&vm_config)?;
+ File::create(vm_config.join("vmlinux"))?;
+ create_dir(vm_config.join("blk"))?;
+ symlink("/dev/null", vm_config.join("blk/root.img"))?;
+
+ create_dir(vm_config.join("shared-dirs"))?;
+ create_dir(vm_config.join("shared-dirs/root"))?;
+ symlink("/", vm_config.join("shared-dirs/root/dir"))?;
+
+ let expected_args = [
+ "--fs",
+ "tag=root,socket=../testvm-fs-root/env/virtiofsd.sock",
+ ];
+
+ let command = vm_command(service_dir, &tmp_dir.path().join("svc/data")).unwrap();
+ let args: Box<[_]> = command.get_args().collect();
+ assert!(contains_seq(&args, &expected_args));
+ Ok(())
+}
--
2.37.1
next prev parent reply other threads:[~2022-10-10 23:32 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 23:28 [PATCH 00/22] Implement managing VMs with Nix Alyssa Ross
2022-10-10 23:28 ` [PATCH 01/22] host/start-vm: use MAP_SHARED memory for VMs Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` Alyssa Ross [this message]
2023-02-26 19:17 ` [PATCH 02/22] host/start-vm: implement shared directories Alyssa Ross
2022-10-10 23:28 ` [PATCH 03/22] host/rootfs: generate virtiofsd services Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 04/22] Documentation: explain VM shared directories Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 05/22] vm-lib/make-vm.nix: support " Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 06/22] img/app: add support for testing virtiofs Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 07/22] img/app: don't block app startup on network online Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 08/22] img/app: auto-mount virtiofs0 filesystem Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 09/22] vm/app/mg.nix: init Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 10/22] vm/app/mg.nix: open virtio filesystem in dired Alyssa Ross
2023-02-26 19:17 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 11/22] host/rootfs: move ext mounting to s6-rc service Alyssa Ross
2022-11-14 1:14 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 12/22] host/rootfs: automatically grow user partition Alyssa Ross
2022-11-14 1:14 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 13/22] host/rootfs: use a bigger test ext partition Alyssa Ross
2022-11-14 1:14 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 14/22] host/initramfs/extfs.nix: tar2ext4 -> mkfs.ext4 -d Alyssa Ross
2022-11-14 1:14 ` Alyssa Ross
2022-10-10 23:28 ` [PATCH 15/22] host/start-vm: resolve VM symlinks with /ext root Alyssa Ross
2022-10-10 23:28 ` [PATCH 16/22] host/rootfs: " Alyssa Ross
2022-10-10 23:28 ` [PATCH 17/22] Documentation: explain /ext symlink resolution Alyssa Ross
2022-10-10 23:28 ` [PATCH 18/22] host/start-vm: increase memory size to 512M Alyssa Ross
2022-10-10 23:28 ` [PATCH 19/22] vm/app/nix: add Alyssa Ross
2022-10-10 23:29 ` [PATCH 20/22] vm-lib/make-vms.nix: add Alyssa Ross
2022-10-10 23:29 ` [PATCH 21/22] host/initramfs/extfs.nix: add example Nix-built VM Alyssa Ross
2022-10-10 23:29 ` [PATCH 22/22] Documentation: add how-to guide for Nix-built VMs Alyssa Ross
2022-10-10 23:29 ` [PATCH v2 0/6] Introduce a shared base for application VMs Alyssa Ross
2022-10-10 23:37 ` Alyssa Ross
2022-10-10 23:29 ` [PATCH v2 1/6] host/start-vm: support multiple block devices Alyssa Ross
2022-10-10 23:29 ` [PATCH v2 2/6] scripts/make-gpt.sh: add support for labels Alyssa Ross
2022-10-10 23:29 ` [PATCH v2 3/6] vm: build GPT images Alyssa Ross
2022-10-10 23:29 ` [PATCH v2 4/6] host/start-vm: boot using partition label Alyssa Ross
2022-10-10 23:29 ` [PATCH v2 5/6] release: rename from "img" Alyssa Ross
2022-10-10 23:29 ` [PATCH v2 6/6] img/app: extract from appvm-{lynx,catgirl} Alyssa Ross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221010232909.1953738-3-hi@alyssa.is \
--to=hi@alyssa.is \
--cc=devel@spectrum-os.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).