From 1d479e5e08f591ffdc13920a2b9da8dbf3bf2f84 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 14 Oct 2020 10:48:50 +0200 Subject: [PATCH] vmm: Introduce new --balloon parameter This introduces a new way of defining the virtio-balloon device. Instead of going through the --memory parameter, the idea is to consider balloon as a standalone virtio device. Signed-off-by: Sebastien Boeuf --- src/main.rs | 8 +++++ vmm/src/api/openapi/cloud-hypervisor.yaml | 11 +++++++ vmm/src/config.rs | 37 +++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/src/main.rs b/src/main.rs index d74b32da3..25e00e208 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,6 +180,13 @@ fn create_app<'a, 'b>( .default_value(&default_rng) .group("vm-config"), ) + .arg( + Arg::with_name("balloon") + .long("balloon") + .help(config::BalloonConfig::SYNTAX) + .takes_value(true) + .group("vm-config"), + ) .arg( Arg::with_name("fs") .long("fs") @@ -582,6 +589,7 @@ mod unit_tests { src: PathBuf::from("/dev/urandom"), iommu: false, }, + balloon: None, fs: None, pmem: None, serial: ConsoleConfig { diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index 998e586da..cc1cbb21d 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -410,6 +410,8 @@ components: $ref: '#/components/schemas/NetConfig' rng: $ref: '#/components/schemas/RngConfig' + balloon: + $ref: '#/components/schemas/BalloonConfig' fs: type: array items: @@ -647,6 +649,15 @@ components: type: boolean default: false + BalloonConfig: + required: + - size + type: object + properties: + size: + type: integer + format: int64 + FsConfig: required: - tag diff --git a/vmm/src/config.rs b/vmm/src/config.rs index cf50dc61c..e64a025cc 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -54,6 +54,8 @@ pub enum Error { ParseNetwork(OptionParserError), /// Error parsing RNG options ParseRNG(OptionParserError), + /// Error parsing balloon options + ParseBalloon(OptionParserError), /// Error parsing filesystem parameters ParseFileSystem(OptionParserError), /// Error parsing persistent memory parameters @@ -160,6 +162,7 @@ impl fmt::Display for Error { ParseNetwork(o) => write!(f, "Error parsing --net: {}", o), ParseDisk(o) => write!(f, "Error parsing --disk: {}", o), ParseRNG(o) => write!(f, "Error parsing --rng: {}", o), + ParseBalloon(o) => write!(f, "Error parsing --balloon: {}", o), ParseRestore(o) => write!(f, "Error parsing --restore: {}", o), #[cfg(target_arch = "x86_64")] ParseSgxEpc(o) => write!(f, "Error parsing --sgx-epc: {}", o), @@ -184,6 +187,7 @@ pub struct VmParams<'a> { pub disks: Option>, pub net: Option>, pub rng: &'a str, + pub balloon: Option<&'a str>, pub fs: Option>, pub pmem: Option>, pub serial: &'a str, @@ -212,6 +216,7 @@ impl<'a> VmParams<'a> { let disks: Option> = args.values_of("disk").map(|x| x.collect()); let net: Option> = args.values_of("net").map(|x| x.collect()); let console = args.value_of("console").unwrap(); + let balloon = args.value_of("balloon"); let fs: Option> = args.values_of("fs").map(|x| x.collect()); let pmem: Option> = args.values_of("pmem").map(|x| x.collect()); let devices: Option> = args.values_of("device").map(|x| x.collect()); @@ -231,6 +236,7 @@ impl<'a> VmParams<'a> { disks, net, rng, + balloon, fs, pmem, serial, @@ -920,6 +926,29 @@ impl Default for RngConfig { } } +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct BalloonConfig { + pub size: u64, +} + +impl BalloonConfig { + pub const SYNTAX: &'static str = "Balloon parameters \"size=\""; + + pub fn parse(balloon: &str) -> Result { + let mut parser = OptionParser::new(); + parser.add("size"); + parser.parse(balloon).map_err(Error::ParseBalloon)?; + + let size = parser + .convert::("size") + .map_err(Error::ParseBalloon)? + .map(|v| v.0) + .unwrap_or(0); + + Ok(BalloonConfig { size }) + } +} + #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct FsConfig { pub tag: String, @@ -1391,6 +1420,7 @@ pub struct VmConfig { pub net: Option>, #[serde(default)] pub rng: RngConfig, + pub balloon: Option, pub fs: Option>, pub pmem: Option>, #[serde(default = "ConsoleConfig::default_serial")] @@ -1506,6 +1536,11 @@ impl VmConfig { iommu = true; } + let mut balloon: Option = None; + if let Some(balloon_params) = &vm_params.balloon { + balloon = Some(BalloonConfig::parse(balloon_params)?); + } + let mut fs: Option> = None; if let Some(fs_list) = &vm_params.fs { let mut fs_config_list = Vec::new(); @@ -1603,6 +1638,7 @@ impl VmConfig { disks, net, rng, + balloon, fs, pmem, serial, @@ -2175,6 +2211,7 @@ mod tests { src: PathBuf::from("/dev/urandom"), iommu: false, }, + balloon: None, fs: None, pmem: None, serial: ConsoleConfig {