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};
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2019-03-07 13:56:43 +00:00
|
|
|
use vmm::vm::*;
|
|
|
|
|
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.")
|
|
|
|
.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")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-05-09 15:01:42 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("net")
|
|
|
|
.long("net")
|
vmm: Add support for letting the VMM create the TAP interface
Until now, the only way to get some networking with cloud-hypervisor
was to let the user create a TAP interface first, and then to provide
the name of this interface to the VMM.
This patch extend the previous behavior by adding the support for the
creation of a brand new TAP interface from the VMM itself. In case no
interface name is provided through "tap=<if_name>", we will assume
the user wants the VMM to create and set the interface on its behalf,
no matter the value of other parameters (ip, mask, and mac).
In this same scenario, because the user expects the VMM to create the
TAP interface, he can also provide the associated IP address and subnet
mask associated with it. In case those values are not provided, some
default ones will be picked.
No matter the value of "tap", the MAC address will always be set, and
if no value is provided, the VMM will come up with a default value for
it.
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2019-05-09 18:21:15 +00:00
|
|
|
.help("Network parameters \"tap=<if_name>,ip=<ip_addr>,mask=<net_mask>,mac=<mac_addr>\"")
|
2019-05-09 15:01:42 +00:00
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-03-11 16:36:27 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("cpus")
|
|
|
|
.long("cpus")
|
|
|
|
.help("Number of virtual CPUs")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-03-11 16:48:35 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("memory")
|
|
|
|
.long("memory")
|
|
|
|
.help("Amount of RAM (in MB)")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-05-09 05:01:48 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("rng")
|
|
|
|
.long("rng")
|
|
|
|
.help("Path to entropy source")
|
|
|
|
.default_value("/dev/urandom"),
|
|
|
|
)
|
2019-02-21 16:39:34 +00:00
|
|
|
.get_matches();
|
|
|
|
|
2019-03-07 13:56:43 +00:00
|
|
|
let kernel_arg = cmd_arguments
|
2019-02-21 16:39:34 +00:00
|
|
|
.value_of("kernel")
|
|
|
|
.map(PathBuf::from)
|
|
|
|
.expect("Missing argument: kernel");
|
2019-03-07 13:56:43 +00:00
|
|
|
let kernel_path = kernel_arg.as_path();
|
|
|
|
|
2019-05-06 20:24:57 +00:00
|
|
|
let cmdline = cmd_arguments
|
|
|
|
.value_of("cmdline")
|
|
|
|
.map(std::string::ToString::to_string)
|
|
|
|
.expect("Missing argument: cmdline");
|
|
|
|
|
2019-05-06 19:15:44 +00:00
|
|
|
let disk_arg = cmd_arguments
|
|
|
|
.value_of("disk")
|
|
|
|
.map(PathBuf::from)
|
|
|
|
.expect("Missing argument: disk");
|
|
|
|
let disk_path = disk_arg.as_path();
|
|
|
|
|
2019-05-09 15:01:42 +00:00
|
|
|
let mut net_params = None;
|
vmm: Add support for letting the VMM create the TAP interface
Until now, the only way to get some networking with cloud-hypervisor
was to let the user create a TAP interface first, and then to provide
the name of this interface to the VMM.
This patch extend the previous behavior by adding the support for the
creation of a brand new TAP interface from the VMM itself. In case no
interface name is provided through "tap=<if_name>", we will assume
the user wants the VMM to create and set the interface on its behalf,
no matter the value of other parameters (ip, mask, and mac).
In this same scenario, because the user expects the VMM to create the
TAP interface, he can also provide the associated IP address and subnet
mask associated with it. In case those values are not provided, some
default ones will be picked.
No matter the value of "tap", the MAC address will always be set, and
if no value is provided, the VMM will come up with a default value for
it.
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2019-05-09 18:21:15 +00:00
|
|
|
if cmd_arguments.is_present("net") {
|
|
|
|
if let Some(net) = cmd_arguments.value_of("net") {
|
|
|
|
net_params = Some(net.to_string());
|
|
|
|
} else {
|
|
|
|
net_params = Some(String::new())
|
|
|
|
}
|
2019-05-09 15:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 05:01:48 +00:00
|
|
|
let rng_path = match cmd_arguments.occurrences_of("rng") {
|
|
|
|
0 => None,
|
|
|
|
_ => Some(cmd_arguments.value_of("rng").unwrap().to_string()),
|
|
|
|
};
|
|
|
|
|
2019-03-11 16:36:27 +00:00
|
|
|
let mut vcpus = DEFAULT_VCPUS;
|
|
|
|
if let Some(cpus) = cmd_arguments.value_of("cpus") {
|
|
|
|
vcpus = cpus.parse::<u8>().unwrap();
|
|
|
|
}
|
|
|
|
|
2019-03-11 16:48:35 +00:00
|
|
|
let mut memory = DEFAULT_MEMORY;
|
|
|
|
if let Some(mem) = cmd_arguments.value_of("memory") {
|
|
|
|
memory = mem.parse::<u64>().unwrap();
|
|
|
|
}
|
|
|
|
|
2019-05-10 08:02:07 +00:00
|
|
|
println!(
|
|
|
|
"Cloud Hypervisor Guest\n\tvCPUs: {}\n\tMemory: {} MB\n\tKernel: {:?}\n\tKernel cmdline: {}\n\tDisk: {:?}",
|
|
|
|
vcpus, memory, kernel_path, cmdline, disk_path
|
|
|
|
);
|
2019-03-07 13:56:43 +00:00
|
|
|
|
2019-05-09 05:01:48 +00:00
|
|
|
let vm_config = VmConfig::new(
|
|
|
|
kernel_path,
|
|
|
|
disk_path,
|
|
|
|
rng_path,
|
|
|
|
cmdline,
|
|
|
|
net_params,
|
|
|
|
vcpus,
|
|
|
|
memory,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2019-02-22 16:05:02 +00:00
|
|
|
|
2019-03-07 13:56:43 +00:00
|
|
|
vmm::boot_kernel(vm_config).unwrap();
|
2019-02-21 16:04:44 +00:00
|
|
|
}
|