2019-02-21 16:39:34 +00:00
|
|
|
// Copyright © 2019 Intel Corporation
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
2019-02-22 16:05:02 +00:00
|
|
|
extern crate vmm;
|
|
|
|
|
2019-02-21 16:39:34 +00:00
|
|
|
#[macro_use(crate_version, crate_authors)]
|
|
|
|
extern crate clap;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
2019-05-23 19:48:05 +00:00
|
|
|
use std::process;
|
|
|
|
use vmm::config;
|
2019-03-07 13:56:43 +00:00
|
|
|
|
2019-02-21 16:04:44 +00:00
|
|
|
fn main() {
|
2019-02-21 16:39:34 +00:00
|
|
|
let cmd_arguments = App::new("cloud-hypervisor")
|
|
|
|
.version(crate_version!())
|
|
|
|
.author(crate_authors!())
|
|
|
|
.about("Launch a cloud-hypervisor VMM.")
|
2019-05-23 19:48:05 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("cpus")
|
|
|
|
.long("cpus")
|
|
|
|
.help("Number of virtual CPUs")
|
|
|
|
.default_value(config::DEFAULT_VCPUS),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("memory")
|
|
|
|
.long("memory")
|
|
|
|
.help("Amount of RAM (in MiB)")
|
|
|
|
.default_value(config::DEFAULT_MEMORY),
|
|
|
|
)
|
2019-02-21 16:39:34 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("kernel")
|
|
|
|
.long("kernel")
|
|
|
|
.help("Path to kernel image (vmlinux)")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-05-06 20:24:57 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("cmdline")
|
|
|
|
.long("cmdline")
|
|
|
|
.help("Kernel command line")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-05-06 19:15:44 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("disk")
|
|
|
|
.long("disk")
|
|
|
|
.help("Path to VM disk image")
|
2019-05-22 13:56:22 +00:00
|
|
|
.takes_value(true)
|
|
|
|
.min_values(1),
|
2019-05-06 19:15:44 +00:00
|
|
|
)
|
2019-05-09 15:01:42 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("net")
|
|
|
|
.long("net")
|
2019-05-23 19:48:05 +00:00
|
|
|
.help(
|
|
|
|
"Network parameters \"tap=<if_name>,\
|
|
|
|
ip=<ip_addr>,mask=<net_mask>,mac=<mac_addr>\"",
|
|
|
|
)
|
2019-03-11 16:48:35 +00:00
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-05-09 05:01:48 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("rng")
|
|
|
|
.long("rng")
|
|
|
|
.help("Path to entropy source")
|
2019-05-23 19:48:05 +00:00
|
|
|
.default_value(config::DEFAULT_RNG_SOURCE),
|
2019-05-09 05:01:48 +00:00
|
|
|
)
|
2019-02-21 16:39:34 +00:00
|
|
|
.get_matches();
|
|
|
|
|
2019-05-23 19:48:05 +00:00
|
|
|
// These .unwrap()s cannot fail as there is a default value defined
|
|
|
|
let cpus = cmd_arguments.value_of("cpus").unwrap();
|
|
|
|
let memory = cmd_arguments.value_of("memory").unwrap();
|
|
|
|
|
|
|
|
let kernel = cmd_arguments
|
2019-02-21 16:39:34 +00:00
|
|
|
.value_of("kernel")
|
|
|
|
.expect("Missing argument: kernel");
|
2019-03-07 13:56:43 +00:00
|
|
|
|
2019-05-23 19:48:05 +00:00
|
|
|
let cmdline = cmd_arguments.value_of("cmdline");
|
|
|
|
|
|
|
|
let disks: Vec<&str> = cmd_arguments
|
2019-05-22 13:56:22 +00:00
|
|
|
.values_of("disk")
|
2019-05-23 19:48:05 +00:00
|
|
|
.expect("Missing argument: disk. Provide at least one")
|
2019-05-22 13:56:22 +00:00
|
|
|
.collect();
|
2019-05-06 19:15:44 +00:00
|
|
|
|
2019-05-23 19:48:05 +00:00
|
|
|
let net = cmd_arguments.value_of("net");
|
2019-05-10 09:52:15 +00:00
|
|
|
|
2019-05-23 19:48:05 +00:00
|
|
|
// This .unwrap() cannot fail as there is a default value defined
|
|
|
|
let rng = cmd_arguments.value_of("rng").unwrap();
|
2019-05-09 15:01:42 +00:00
|
|
|
|
2019-05-23 19:48:05 +00:00
|
|
|
let vm_config = match config::VmConfig::parse(config::VmParams {
|
|
|
|
cpus,
|
|
|
|
memory,
|
|
|
|
kernel,
|
|
|
|
cmdline,
|
|
|
|
disks,
|
|
|
|
rng,
|
|
|
|
net,
|
|
|
|
}) {
|
|
|
|
Ok(config) => config,
|
|
|
|
Err(e) => {
|
|
|
|
println!("Failed parsing parameters {:?}", e);
|
|
|
|
process::exit(1);
|
|
|
|
}
|
2019-05-09 05:01:48 +00:00
|
|
|
};
|
|
|
|
|
2019-05-10 08:02:07 +00:00
|
|
|
println!(
|
2019-05-23 19:48:05 +00:00
|
|
|
"Cloud Hypervisor Guest\n\tvCPUs: {}\n\tMemory: {} MB\
|
|
|
|
\n\tKernel: {:?}\n\tKernel cmdline: {}\n\tDisk(s): {:?}",
|
|
|
|
u8::from(&vm_config.cpus),
|
|
|
|
u64::from(&vm_config.memory),
|
|
|
|
vm_config.kernel.path,
|
|
|
|
vm_config.cmdline.args.as_str(),
|
|
|
|
vm_config.disks,
|
2019-05-10 08:02:07 +00:00
|
|
|
);
|
2019-03-07 13:56:43 +00:00
|
|
|
|
2019-05-10 08:46:27 +00:00
|
|
|
if let Err(e) = vmm::boot_kernel(vm_config) {
|
|
|
|
println!("Guest boot failed: {}", e);
|
2019-05-23 19:48:05 +00:00
|
|
|
process::exit(1);
|
2019-05-10 08:46:27 +00:00
|
|
|
}
|
2019-02-21 16:04:44 +00:00
|
|
|
}
|