Skip to content

Commit 54c52ed

Browse files
committed
fs: Allow multiple Uhyve mounts at arbitrary paths given by fdt
1 parent edd28b9 commit 54c52ed

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

src/fs/uhyve.rs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::borrow::ToOwned;
12
use alloc::boxed::Box;
23
use alloc::ffi::CString;
34
use alloc::string::{String, ToString};
@@ -14,10 +15,11 @@ use uhyve_interface::parameters::{
1415
use uhyve_interface::{GuestPhysAddr, GuestVirtAddr, Hypercall};
1516

1617
use crate::arch::mm::paging;
17-
use crate::env::is_uhyve;
18+
use crate::env::{self, is_uhyve};
1819
use crate::errno::Errno;
1920
use crate::fs::{
2021
self, AccessPermission, FileAttr, NodeKind, ObjectInterface, OpenOption, SeekWhence, VfsNode,
22+
create_dir_recursive,
2123
};
2224
use crate::io;
2325
use crate::syscalls::interfaces::uhyve::uhyve_hypercall;
@@ -231,15 +233,49 @@ impl VfsNode for UhyveDirectory {
231233
pub(crate) fn init() {
232234
info!("Try to initialize uhyve filesystem");
233235
if is_uhyve() {
234-
let mount_point = hermit_var_or!("UHYVE_MOUNT", "/root").to_string();
235-
info!("Mounting uhyve filesystem at {mount_point}");
236-
fs::FILESYSTEM
237-
.get()
238-
.unwrap()
239-
.mount(
240-
&mount_point,
241-
Box::new(UhyveDirectory::new(Some(mount_point.clone()))),
242-
)
243-
.expect("Mount failed. Duplicate mount_point?");
236+
let mount_str = env::fdt().and_then(|fdt| {
237+
fdt.find_node("/uhyve,mounts").and_then(|node| {
238+
node.property("mounts")
239+
.and_then(|property| str::from_utf8(property.value).ok())
240+
})
241+
});
242+
if let Some(mount_str) = mount_str {
243+
assert_ne!(mount_str.len(), 0, "Invalid /uhyve,mounts node in FDT");
244+
for mount_point in mount_str.trim_end_matches('\0').split('\0') {
245+
info!("Mounting uhyve filesystem at {mount_point}");
246+
247+
if let Err(errno) = fs::FILESYSTEM.get().unwrap().mount(
248+
mount_point,
249+
Box::new(UhyveDirectory::new(Some(mount_point.to_owned()))),
250+
) {
251+
debug!(
252+
"Mounting of {mount_point} failed with {errno:?}. Creating missing parent folders"
253+
);
254+
let parent_path = &mount_point[0..mount_point.rfind('/').unwrap()];
255+
create_dir_recursive(parent_path, AccessPermission::S_IRWXU).unwrap();
256+
257+
fs::FILESYSTEM
258+
.get()
259+
.unwrap()
260+
.mount(
261+
mount_point,
262+
Box::new(UhyveDirectory::new(Some(mount_point.to_owned()))),
263+
)
264+
.unwrap();
265+
}
266+
}
267+
} else {
268+
// No FDT -> Uhyve legacy mounting (to /root)
269+
let mount_point = hermit_var_or!("UHYVE_MOUNT", "/root").to_string();
270+
info!("Mounting uhyve filesystem at {mount_point}");
271+
fs::FILESYSTEM
272+
.get()
273+
.unwrap()
274+
.mount(
275+
&mount_point,
276+
Box::new(UhyveDirectory::new(Some(mount_point.clone()))),
277+
)
278+
.expect("Mount failed. Duplicate mount_point?");
279+
}
244280
}
245281
}

0 commit comments

Comments
 (0)