From 4a3a64bd519914d18e5f0a454272d99b2169c450 Mon Sep 17 00:00:00 2001 From: Jonathan Klimt Date: Mon, 13 Oct 2025 17:25:00 +0200 Subject: [PATCH] fs: added feature to delegate /tmp to uhyve --- Cargo.toml | 1 + src/fs/mod.rs | 12 +++++++----- src/fs/uhyve.rs | 13 +++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9005fcda3..e233f16b91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,7 @@ smp = [] strace = [] tcp = ["net", "smoltcp", "smoltcp/socket-tcp"] trace = ["smoltcp?/log", "smoltcp?/verbose"] +uhyve-tmp = [] udp = ["net", "smoltcp", "smoltcp/socket-udp"] vga = [] virtio = ["dep:virtio"] diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 9b7a9245d3..4e46851fbf 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -340,11 +340,13 @@ pub(crate) fn init() { const UTC_BUILT_TIME: &str = build_time::build_time_utc!(); FILESYSTEM.set(Filesystem::new()).unwrap(); - FILESYSTEM - .get() - .unwrap() - .mkdir("/tmp", AccessPermission::from_bits(0o777).unwrap()) - .expect("Unable to create /tmp"); + if !(crate::env::is_uhyve() && cfg!(feature = "uhyve-tmp")) { + FILESYSTEM + .get() + .unwrap() + .mkdir("/tmp", AccessPermission::from_bits(0o777).unwrap()) + .expect("Unable to create /tmp"); + } FILESYSTEM .get() .unwrap() diff --git a/src/fs/uhyve.rs b/src/fs/uhyve.rs index dce0a4fe58..44d9674786 100644 --- a/src/fs/uhyve.rs +++ b/src/fs/uhyve.rs @@ -276,4 +276,17 @@ pub(crate) fn init() { ) .expect("Mount failed. Duplicate mount_point?"); } + + #[cfg(feature = "uhyve-tmp")] + { + info!("Mounting /tmp as uhyve filesystem"); + fs::FILESYSTEM + .get() + .unwrap() + .mount( + "/tmp", + Box::new(UhyveDirectory::new(Some("/tmp".to_string()))), + ) + .unwrap(); + } }