diff --git a/hypervisor/src/hypervisor/config.rs b/hypervisor/src/hypervisor/config.rs index 4fd0f22..1ec5ed9 100644 --- a/hypervisor/src/hypervisor/config.rs +++ b/hypervisor/src/hypervisor/config.rs @@ -38,6 +38,8 @@ pub struct Partition { pub devices: Vec, #[serde(default)] pub hm_table: PartitionHMTable, + #[serde(default)] + pub mounts: Vec<(PathBuf, PathBuf)>, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/hypervisor/src/hypervisor/partition.rs b/hypervisor/src/hypervisor/partition.rs index 5901078..a3ff787 100644 --- a/hypervisor/src/hypervisor/partition.rs +++ b/hypervisor/src/hypervisor/partition.rs @@ -174,7 +174,7 @@ impl Run { Partition::release_fds(&keep).unwrap(); // Mount the required mounts - let mounts = [ + let mut mounts = vec![ // Mount working directory as tmpfs FileMounter { source: None, @@ -222,6 +222,34 @@ impl Run { }, ]; + for m in &base.mounts { + let source = m.0.clone(); + let mut target = m.1.clone(); + + if !source.exists() { + panic!("File/Directory {} not existent", m.0.display()); + } + + if target.is_absolute() { + // Convert absolute paths into relative ones. + // Otherwise we will receive a permission error. + // TODO: Make this a function? + target = target.strip_prefix("/").unwrap().into(); + assert!(target.is_relative()); + } + + mounts.push(FileMounter { + source: Some(source), + target: target, + fstype: None, + flags: MsFlags::MS_BIND, + data: None, + is_dir: m.0.is_dir(), + }); + } + + // TODO: Check for duplicate mounts + for m in mounts { debug!("mounting {:?}", &m); m.mount(base.working_dir.path()).unwrap(); @@ -449,6 +477,7 @@ pub(crate) struct Base { hm: PartitionHMTable, id: i64, bin: PathBuf, + mounts: Vec<(PathBuf, PathBuf)>, cgroup: CGroup, sampling_channel: HashMap, duration: Duration, @@ -517,6 +546,7 @@ impl Partition { id: config.id, cgroup, bin: config.image, + mounts: config.mounts, duration: config.duration, period: config.period, working_dir,