From 1c2587f8cbd5f97c6bb0ebc9edc426d7b101bbb6 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 10 Dec 2019 17:09:28 +0100 Subject: [PATCH] vmm: api: Match VhostUserNetConfig defaults between CLI and HTTP API In order to let the CLI and the HTTP API behave the same regarding the VhostUserNetConfig structure, this patch defines some default values for num_queues, queue_size and mac. num_queues is 2 since that's a pair of TX/RX queues, queue_size is 256 and mac is a randomly generated value. Signed-off-by: Sebastien Boeuf --- vmm/src/api/openapi/cloud-hypervisor.yaml | 5 ++--- vmm/src/config.rs | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index e99ae1569..5c97b6304 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -375,17 +375,16 @@ components: VhostUserNetConfig: required: - sock - - num_queues - - queue_size - - mac type: object properties: sock: type: string num_queues: type: integer + default: 2 queue_size: type: integer + default: 256 mac: type: string diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 4be606a6c..1a0a3e5b2 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -15,6 +15,8 @@ use std::result; pub const DEFAULT_VCPUS: u8 = 1; pub const DEFAULT_MEMORY_MB: u64 = 512; pub const DEFAULT_RNG_SOURCE: &str = "/dev/urandom"; +pub const DEFAULT_NUM_QUEUES_VUNET: usize = 2; +pub const DEFAULT_QUEUE_SIZE_VUNET: u16 = 256; /// Errors associated with VM configuration parameters. #[derive(Debug)] @@ -696,11 +698,26 @@ impl DeviceConfig { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct VhostUserNetConfig { pub sock: String, + #[serde(default = "default_vunetconfig_num_queues")] pub num_queues: usize, + #[serde(default = "default_vunetconfig_queue_size")] pub queue_size: u16, + #[serde(default = "default_vunetconfig_mac")] pub mac: MacAddr, } +fn default_vunetconfig_num_queues() -> usize { + DEFAULT_NUM_QUEUES_VUNET +} + +fn default_vunetconfig_queue_size() -> u16 { + DEFAULT_QUEUE_SIZE_VUNET +} + +fn default_vunetconfig_mac() -> MacAddr { + MacAddr::local_random() +} + impl VhostUserNetConfig { pub fn parse(vhost_user_net: &str) -> Result { // Split the parameters based on the comma delimiter @@ -723,9 +740,9 @@ impl VhostUserNetConfig { } } - let mut mac: MacAddr = MacAddr::local_random(); - let mut num_queues: usize = 2; - let mut queue_size: u16 = 256; + let mut mac: MacAddr = default_vunetconfig_mac(); + let mut num_queues: usize = default_vunetconfig_num_queues(); + let mut queue_size: u16 = default_vunetconfig_queue_size(); if !mac_str.is_empty() { mac = MacAddr::parse_str(mac_str).map_err(Error::ParseVuNetMacParam)?;