-
Notifications
You must be signed in to change notification settings - Fork 109
Uhyve mounts in arbitrary paths #1976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jounathaen
wants to merge
5
commits into
main
Choose a base branch
from
uhyve-mounts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
edd28b9
fs: Added a recursive create_dir function
jounathaen 54c52ed
fs: Allow multiple Uhyve mounts at arbitrary paths given by fdt
jounathaen 6d214f0
Update src/fs/uhyve.rs
jounathaen b1a9370
Apply suggestion from @mkroening
jounathaen 23f09cc
Apply suggestion from @mkroening
jounathaen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use alloc::borrow::ToOwned; | ||
use alloc::boxed::Box; | ||
use alloc::ffi::CString; | ||
use alloc::string::{String, ToString}; | ||
|
@@ -14,10 +15,11 @@ use uhyve_interface::parameters::{ | |
use uhyve_interface::{GuestPhysAddr, GuestVirtAddr, Hypercall}; | ||
|
||
use crate::arch::mm::paging; | ||
use crate::env::is_uhyve; | ||
use crate::env::{self, is_uhyve}; | ||
use crate::errno::Errno; | ||
use crate::fs::{ | ||
self, AccessPermission, FileAttr, NodeKind, ObjectInterface, OpenOption, SeekWhence, VfsNode, | ||
create_dir_recursive, | ||
}; | ||
use crate::io; | ||
use crate::syscalls::interfaces::uhyve::uhyve_hypercall; | ||
|
@@ -231,15 +233,48 @@ impl VfsNode for UhyveDirectory { | |
pub(crate) fn init() { | ||
info!("Try to initialize uhyve filesystem"); | ||
if is_uhyve() { | ||
let mount_point = hermit_var_or!("UHYVE_MOUNT", "/root").to_string(); | ||
info!("Mounting uhyve filesystem at {mount_point}"); | ||
fs::FILESYSTEM | ||
.get() | ||
.unwrap() | ||
.mount( | ||
&mount_point, | ||
Box::new(UhyveDirectory::new(Some(mount_point.clone()))), | ||
) | ||
.expect("Mount failed. Duplicate mount_point?"); | ||
let mount_str = env::fdt().and_then(|fdt| { | ||
fdt.find_node("/uhyve,mounts") | ||
.and_then(|node| node.property("mounts")) | ||
.and_then(|property| property.as_str()) | ||
}); | ||
if let Some(mount_str) = mount_str { | ||
assert_ne!(mount_str.len(), 0, "Invalid /uhyve,mounts node in FDT"); | ||
for mount_point in mount_str.trim_end_matches('\0').split('\0') { | ||
info!("Mounting uhyve filesystem at {mount_point}"); | ||
|
||
if let Err(errno) = fs::FILESYSTEM.get().unwrap().mount( | ||
mount_point, | ||
Box::new(UhyveDirectory::new(Some(mount_point.to_owned()))), | ||
) { | ||
debug!( | ||
"Mounting of {mount_point} failed with {errno:?}. Creating missing parent folders" | ||
); | ||
Comment on lines
+250
to
+252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check the error and only attempt recovery on |
||
let (parent, _file_name) = path.rsplit_once('/').unwrap(); | ||
create_dir_recursive(parent_path, AccessPermission::S_IRWXU).unwrap(); | ||
|
||
fs::FILESYSTEM | ||
.get() | ||
.unwrap() | ||
.mount( | ||
mount_point, | ||
Box::new(UhyveDirectory::new(Some(mount_point.to_owned()))), | ||
) | ||
.unwrap(); | ||
} | ||
} | ||
} else { | ||
// No FDT -> Uhyve legacy mounting (to /root) | ||
let mount_point = hermit_var_or!("UHYVE_MOUNT", "/root").to_string(); | ||
info!("Mounting uhyve filesystem at {mount_point}"); | ||
fs::FILESYSTEM | ||
.get() | ||
.unwrap() | ||
.mount( | ||
&mount_point, | ||
Box::new(UhyveDirectory::new(Some(mount_point.clone()))), | ||
) | ||
.expect("Mount failed. Duplicate mount_point?"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already done in
as_str
in my previous suggestion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work, as the last element in
mount_str
also ends on\0
, thus creating an empy string formount_point
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I mentioned the previous suggestion.
as_str
removes the trailing null.