From 4db252b418030da3a11b09b3e5fe4cfc8817e29c Mon Sep 17 00:00:00 2001 From: Damjan Georgievski Date: Sun, 15 Mar 2020 18:51:17 +0100 Subject: [PATCH] main, vmm: add --initramfs cli option currently unused, the initramfs argument is added to the cli, and stored in vmm::config:VmConfig as an Option(InitramfsConfig(PathBuf)) Signed-off-by: Damjan Georgievski --- src/main.rs | 11 ++++++++++- vmm/src/config.rs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index eed3cd7ed..36a944a43 100755 --- a/src/main.rs +++ b/src/main.rs @@ -113,6 +113,13 @@ fn create_app<'a, 'b>( .takes_value(true) .group("vm-config"), ) + .arg( + Arg::with_name("initramfs") + .long("initramfs") + .help("Path to initramfs image") + .takes_value(true) + .group("vm-config"), + ) .arg( Arg::with_name("cmdline") .long("cmdline") @@ -273,11 +280,12 @@ fn start_vmm(cmd_arguments: ArgMatches) { println!( "Cloud Hypervisor Guest\n\tAPI server: {}\n\tvCPUs: {}\n\tMemory: {} MB\n\tKernel: \ - {:?}\n\tKernel cmdline: {}\n\tDisk(s): {:?}", + {:?}\n\tInitramfs: {:?}\n\tKernel cmdline: {}\n\tDisk(s): {:?}", api_socket_path, vm_config.cpus.boot_vcpus, vm_config.memory.size >> 20, vm_config.kernel, + vm_config.initramfs, vm_config.cmdline.args.as_str(), vm_config.disks, ); @@ -477,6 +485,7 @@ mod unit_tests { hotplug_size: None, }, kernel: None, + initramfs: None, cmdline: CmdlineConfig { args: String::from(""), }, diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 0cc4ee30b..ac1328892 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -116,6 +116,7 @@ pub struct VmParams<'a> { pub cpus: &'a str, pub memory: &'a str, pub kernel: Option<&'a str>, + pub initramfs: Option<&'a str>, pub cmdline: Option<&'a str>, pub disks: Option>, pub net: Option>, @@ -137,6 +138,7 @@ impl<'a> VmParams<'a> { let serial = args.value_of("serial").unwrap(); let kernel = args.value_of("kernel"); + let initramfs = args.value_of("initramfs"); let cmdline = args.value_of("cmdline"); let disks: Option> = args.values_of("disk").map(|x| x.collect()); @@ -151,6 +153,7 @@ impl<'a> VmParams<'a> { cpus, memory, kernel, + initramfs, cmdline, disks, net, @@ -348,6 +351,11 @@ pub struct KernelConfig { pub path: PathBuf, } +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct InitramfsConfig { + pub path: PathBuf, +} + #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)] pub struct CmdlineConfig { pub args: String, @@ -1031,6 +1039,7 @@ pub struct VmConfig { #[serde(default)] pub memory: MemoryConfig, pub kernel: Option, + pub initramfs: Option, #[serde(default)] pub cmdline: CmdlineConfig, pub disks: Option>, @@ -1152,10 +1161,18 @@ impl VmConfig { }); } + let mut initramfs: Option = None; + if let Some(k) = vm_params.initramfs { + initramfs = Some(InitramfsConfig { + path: PathBuf::from(k), + }); + } + Ok(VmConfig { cpus: CpusConfig::parse(vm_params.cpus)?, memory: MemoryConfig::parse(vm_params.memory)?, kernel, + initramfs, cmdline: CmdlineConfig::parse(vm_params.cmdline)?, disks, net,