Skip to content

Commit

Permalink
Merge pull request #283 from stlankes/virtiofsd
Browse files Browse the repository at this point in the history
add virtiofsd support
  • Loading branch information
stlankes authored Sep 27, 2023
2 parents b0d2505 + b53e797 commit 46435b7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ pub fn get_qemu_args(
.map(|s| s.to_string())
.collect(),
);
} else {
exec_args.append(
&mut [
"-chardev",
"socket,id=char0,path=/run/vhostqemu",
"-device",
"vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=mnt",
"-object",
"memory-backend-file,id=mem,size=1G,mem-path=/dev/shm,share=on",
"-numa",
"node,memdev=mem",
]
.iter()
.map(|s| s.to_string())
.collect(),
);
}

let mut args_string = match netconf {
Expand Down
43 changes: 43 additions & 0 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,49 @@ fn init_stage_child(args: SetupArgs) -> ! {
nix::unistd::close(fifo_fd).expect("Could not close exec fifo O_PATH fd!");
nix::unistd::close(init_pipe.into_raw_fd()).expect("Could not close init pipe fd!");

if args.config.is_hermit_container {
let micro_vm: u32 = env::var("RUNH_MICRO_VM")
.unwrap_or_else(|_| "0".to_string())
.parse()
.expect("RUNH_MICRO_VM was not an unsigned integer!");

if micro_vm == 0 {
info!("Initialize virtiofsd");
let virtiofsd_args: Vec<String> = [
"virtiofsd",
"--socket-path=/run/vhostqemu",
"--shared-dir",
"/mnt",
"--announce-submounts",
"--sandbox",
"none",
"--seccomp",
"none",
"--inode-file-handles=never",
]
.iter()
.map(|s| s.to_string())
.collect();

let virtiofsd_path_rel = PathBuf::from(
virtiofsd_args
.get(0)
.expect("Container spec does not contain any args!"),
);
let virtiofsd_path_abs = paths::find_in_path(virtiofsd_path_rel, None)
.expect("Could not determine location of args-executable!");

let mut cmd = std::process::Command::new(virtiofsd_path_abs);
cmd.arg0(virtiofsd_args.get(0).unwrap());
if virtiofsd_args.len() > 1 {
cmd.args(virtiofsd_args.get(1..).unwrap());
}
cmd.envs(std::env::vars());

let _child = cmd.spawn().expect("Unable to virtiofsd");
}
}

let mut cmd = std::process::Command::new(exec_path_abs);
cmd.arg0(exec_args.get(0).unwrap());
if exec_args.len() > 1 {
Expand Down
3 changes: 3 additions & 0 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ use std::path;
pub fn create_spec(bundle: path::PathBuf, args: Vec<String>) {
let mut config_file = bundle;
config_file.push("config.json");
let mut root = runtime::Root::default();
root.set_readonly(false.into());
let spec: runtime::Spec = runtime::SpecBuilder::default()
.process(
runtime::ProcessBuilder::default()
.args(args)
.build()
.unwrap(),
)
.root(root)
.build()
.unwrap();
spec.save(config_file.to_str().unwrap())
Expand Down

0 comments on commit 46435b7

Please sign in to comment.