Skip to content

Commit

Permalink
feat(uhyve): change --mount to --file-mapping
Browse files Browse the repository at this point in the history
Tests and documentation was also amended accordingly.
  • Loading branch information
n0toose committed Nov 28, 2024
1 parent cfaf8fb commit 6e5b798
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/bin/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ struct Args {

/// Paths that the kernel should be able to view, read or write.
///
/// Desired mount paths must be explicitly defined after a colon.
/// Desired paths must be explicitly defined after a colon.
///
/// Example: --mount host_dir:guest_dir --mount file.txt:guest_file.txt
/// Example: --file-mapping host_dir:guest_dir --file-mapping file.txt:guest_file.txt
#[clap(long)]
mount: Vec<String>,
file_mapping: Vec<String>,

/// The kernel to execute
#[clap(value_parser)]
Expand Down Expand Up @@ -256,7 +256,7 @@ impl From<Args> for Params {
},
#[cfg(target_os = "linux")]
gdb_port,
mount,
file_mapping,
kernel: _,
kernel_args,
output,
Expand All @@ -271,7 +271,7 @@ impl From<Args> for Params {
cpu_count,
#[cfg(target_os = "linux")]
pit,
mount,
file_mapping,
#[cfg(target_os = "linux")]
gdb_port,
#[cfg(target_os = "macos")]
Expand Down
4 changes: 2 additions & 2 deletions src/linux/x86_64/kvm_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl VirtualCPU for KvmCpu {
Hypercall::FileOpen(sysopen) => hypercall::open(
&self.parent_vm.mem,
sysopen,
&mut self.parent_vm.mount.lock().unwrap(),
&mut self.parent_vm.file_mapping.lock().unwrap(),
&self.parent_vm.tempdir,
),
Hypercall::FileRead(sysread) => {
Expand All @@ -461,7 +461,7 @@ impl VirtualCPU for KvmCpu {
Hypercall::FileUnlink(sysunlink) => hypercall::unlink(
&self.parent_vm.mem,
sysunlink,
&mut self.parent_vm.mount.lock().unwrap(),
&mut self.parent_vm.file_mapping.lock().unwrap(),
),
Hypercall::SerialWriteByte(buf) => self
.parent_vm
Expand Down
4 changes: 2 additions & 2 deletions src/macos/aarch64/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl VirtualCPU for XhyveCpu {
Hypercall::FileOpen(sysopen) => hypercall::open(
&self.parent_vm.mem,
sysopen,
&mut self.parent_vm.mount.lock().unwrap(),
&mut self.parent_vm.file_mapping.lock().unwrap(),
&self.parent_vm.tempdir,
),
Hypercall::FileRead(sysread) => {
Expand All @@ -251,7 +251,7 @@ impl VirtualCPU for XhyveCpu {
Hypercall::FileUnlink(sysunlink) => hypercall::unlink(
&self.parent_vm.mem,
sysunlink,
&mut self.parent_vm.mount.lock().unwrap(),
&mut self.parent_vm.file_mapping.lock().unwrap(),
),
_ => {
panic! {"Hypercall {hypercall:?} not implemented on macos-aarch64"}
Expand Down
4 changes: 2 additions & 2 deletions src/macos/x86_64/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ impl VirtualCPU for XhyveCpu {
Hypercall::FileOpen(sysopen) => hypercall::open(
&self.parent_vm.mem,
sysopen,
&mut self.parent_vm.mount.lock().unwrap(),
&mut self.parent_vm.file_mapping.lock().unwrap(),
&self.parent_vm.tempdir,
),
Hypercall::FileRead(sysread) => {
Expand All @@ -789,7 +789,7 @@ impl VirtualCPU for XhyveCpu {
Hypercall::FileUnlink(sysunlink) => hypercall::unlink(
&self.parent_vm.mem,
sysunlink,
&mut self.parent_vm.mount.lock().unwrap(),
&mut self.parent_vm.file_mapping.lock().unwrap(),
),

Hypercall::SerialWriteByte(buf) => {
Expand Down
6 changes: 3 additions & 3 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct Params {
/// Arguments to forward to the kernel
pub kernel_args: Vec<String>,

/// Paths that should be mounted on-device
pub mount: Vec<String>,
/// Mapped paths between the guest and host OS
pub file_mapping: Vec<String>,

/// Kernel output handling
pub output: Output,
Expand All @@ -58,7 +58,7 @@ impl Default for Params {
pit: false,
cpu_count: Default::default(),
gdb_port: Default::default(),
mount: Default::default(),
file_mapping: Default::default(),
kernel_args: Default::default(),
output: Default::default(),
stats: false,
Expand Down
8 changes: 4 additions & 4 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub struct UhyveVm<VirtBackend: VirtualizationBackend> {
pub virtio_device: Arc<Mutex<VirtioNetPciDevice>>,
#[allow(dead_code)] // gdb is not supported on macos
pub(super) gdb_port: Option<u16>,
pub(crate) mount: Mutex<UhyveFileMap>,
pub(crate) file_mapping: Mutex<UhyveFileMap>,
pub(crate) virt_backend: VirtBackend,
params: Params,
pub output: Output,
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
);

let tempdir = create_temp_dir();
let mount = Mutex::new(UhyveFileMap::new(&params.mount));
let file_mapping = Mutex::new(UhyveFileMap::new(&params.file_mapping));

let output = match params.output {
params::Output::None => Output::None,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
boot_info: ptr::null(),
virtio_device,
gdb_port: params.gdb_port,
mount,
file_mapping,
virt_backend,
params,
output,
Expand Down Expand Up @@ -388,7 +388,7 @@ impl<VirtIf: VirtualizationBackend> fmt::Debug for UhyveVm<VirtIf> {
.field("boot_info", &self.boot_info)
.field("virtio_device", &self.virtio_device)
.field("params", &self.params)
.field("mount", &self.mount)
.field("file_mapping", &self.file_mapping)
.field("tempdir", &self.tempdir)
.finish()
}
Expand Down
4 changes: 2 additions & 2 deletions tests/fs-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn uhyvefilemap_test() {
.unwrap()
.try_into()
.unwrap(),
mount: vec!["foo.txt:wrong.txt".to_string()],
file_mapping: vec!["foo.txt:wrong.txt".to_string()],
..Default::default()
};

Expand All @@ -52,7 +52,7 @@ fn uhyvefilemap_test() {
assert_eq!(res.code, 0);
assert!(!output_path.exists());

params.mount = vec!["foo.txt:foo.txt".to_string()];
params.file_mapping = vec!["foo.txt:foo.txt".to_string()];
vm = UhyveVm::new(bin_path, params).unwrap();
res = vm.run(None);
assert_eq!(res.code, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn serial_file_output_test() {
.try_into()
.unwrap(),
output: Output::File(output_path.clone()),
mount: vec!["testserialout.txt:testserialout.txt".to_string()],
file_mapping: vec!["testserialout.txt:testserialout.txt".to_string()],
..Default::default()
};
let vm = UhyveVm::new(bin_path, params).unwrap();
Expand Down

0 comments on commit 6e5b798

Please sign in to comment.