Skip to content

Commit

Permalink
feat(isolation): rework file map cli structure
Browse files Browse the repository at this point in the history
- Rename --file_map to --mount
- Temporarily remove short parameter
- Temporarily remove environment variable
- Don't split file_map params with commas
- Change documentation, remove references to file_map variable
  • Loading branch information
n0toose committed Nov 12, 2024
1 parent 6a11855 commit 678b672
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
12 changes: 5 additions & 7 deletions src/bin/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ struct Args {

/// Paths that the kernel should be able to view, read or write.
///
/// Files and directories are separated using commas.
/// Desired mount paths must be explicitly defined after a colon.
///
/// Example: --file_map host_directory:/root/guest_directory,file.txt:/root/my_file.txt
#[arg(value_delimiter = ',')]
#[clap(long, env = "HERMIT_FILE_MAP")]
file_map: Option<Vec<String>>,
/// Example: --mount host_dir:guest_dir --mount file.txt:guest_file.txt
#[clap(long)]
mount: Option<Vec<String>>,

/// The kernel to execute
#[clap(value_parser)]
Expand Down Expand Up @@ -253,7 +251,7 @@ impl From<Args> for Params {
},
#[cfg(target_os = "linux")]
gdb_port,
file_map,
mount,
kernel: _,
kernel_args,
} = args;
Expand All @@ -267,7 +265,7 @@ impl From<Args> for Params {
cpu_count,
#[cfg(target_os = "linux")]
pit,
file_map,
mount,
#[cfg(target_os = "linux")]
gdb_port,
#[cfg(target_os = "macos")]
Expand Down
2 changes: 1 addition & 1 deletion src/hypercall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn open(mem: &MmapMemory, sysopen: &mut OpenParams, file_map: &Option<UhyveF
// TODO: We could keep track of the file descriptors internally, in case the kernel doesn't close them.
let requested_path = mem.host_address(sysopen.name).unwrap() as *const i8;

// If the file_map doesn't exist, full host filesystem access will be provided.
// If the file map doesn't exist, full host filesystem access will be provided.
if let Some(file_map) = file_map {
// Rust deals in UTF-8. C doesn't provide such a guarantee.
// In that case, converting a CStr to str will return a Utf8Error.
Expand Down
2 changes: 1 addition & 1 deletion src/linux/x86_64/kvm_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl VirtualCPU for KvmCpu {
Hypercall::FileOpen(sysopen) => hypercall::open(
&self.parent_vm.mem,
sysopen,
&self.parent_vm.file_map,
&self.parent_vm.mount,
),
Hypercall::FileRead(sysread) => {
hypercall::read(&self.parent_vm.mem, sysread)
Expand Down
2 changes: 1 addition & 1 deletion src/macos/aarch64/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl VirtualCPU for XhyveCpu {
Hypercall::FileOpen(sysopen) => hypercall::open(
&self.parent_vm.mem,
sysopen,
&self.parent_vm.file_map,
&self.parent_vm.mount,
),
Hypercall::FileRead(sysread) => {
hypercall::read(&self.parent_vm.mem, sysread)
Expand Down
8 changes: 3 additions & 5 deletions src/macos/x86_64/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,9 @@ impl VirtualCPU for XhyveCpu {
}
Hypercall::FileClose(sysclose) => hypercall::close(sysclose),
Hypercall::FileLseek(syslseek) => hypercall::lseek(syslseek),
Hypercall::FileOpen(sysopen) => hypercall::open(
&self.parent_vm.mem,
sysopen,
&self.parent_vm.file_map,
),
Hypercall::FileOpen(sysopen) => {
hypercall::open(&self.parent_vm.mem, sysopen, &self.parent_vm.mount)
}
Hypercall::FileRead(sysread) => {
hypercall::read(&self.parent_vm.mem, sysread)
}
Expand Down
4 changes: 2 additions & 2 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Params {
pub kernel_args: Vec<String>,

/// Paths that should be mounted on-device
pub file_map: Option<Vec<String>>,
pub mount: Option<Vec<String>>,
}

#[allow(clippy::derivable_impls)]
Expand All @@ -54,7 +54,7 @@ impl Default for Params {
pit: false,
cpu_count: Default::default(),
gdb_port: Default::default(),
file_map: Default::default(),
mount: Default::default(),
kernel_args: Default::default(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct UhyveVm<VCpuType: VirtualCPU = VcpuDefault> {
pub virtio_device: Arc<Mutex<VirtioNetPciDevice>>,
#[allow(dead_code)] // gdb is not supported on macos
pub(super) gdb_port: Option<u16>,
pub(crate) file_map: Option<UhyveFileMap>,
pub(crate) mount: Option<UhyveFileMap>,
_vcpu_type: PhantomData<VCpuType>,
}
impl<VCpuType: VirtualCPU> UhyveVm<VCpuType> {
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<VCpuType: VirtualCPU> UhyveVm<VCpuType> {
"gdbstub is only supported with one CPU"
);

let file_map = params.file_map.as_deref().and_then(UhyveFileMap::new);
let mount = params.mount.as_deref().and_then(UhyveFileMap::new);

let mut vm = Self {
offset: 0,
Expand All @@ -165,7 +165,7 @@ impl<VCpuType: VirtualCPU> UhyveVm<VCpuType> {
verbose: params.verbose,
virtio_device,
gdb_port: params.gdb_port,
file_map,
mount,
_vcpu_type: PhantomData,
};

Expand Down

0 comments on commit 678b672

Please sign in to comment.