From 4bfd51cc42e362a7a1e89c0e9b1b127664bd0bcb Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 10 Dec 2019 17:15:43 +0100 Subject: [PATCH] vmm: api: Match VhostUserBlkConfig defaults between CLI and HTTP API In order to let the CLI and the HTTP API behave the same regarding the VhostUserBlkConfig structure, this patch defines some default values for num_queues, queue_size and wce. num_queues is 1, queue_size is 128 and wce is true. Signed-off-by: Sebastien Boeuf --- vmm/src/api/openapi/cloud-hypervisor.yaml | 6 +++--- vmm/src/config.rs | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index 5c97b6304..d00873f56 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -391,19 +391,19 @@ components: VhostUserBlkConfig: required: - sock - - num_queues - - queue_size - - wce type: object properties: sock: type: string num_queues: type: integer + default: 1 queue_size: type: integer + default: 128 wce: type: boolean + default: true VsockConfig: required: diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 1a0a3e5b2..eeba43102 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -17,6 +17,8 @@ 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; +pub const DEFAULT_NUM_QUEUES_VUBLK: usize = 1; +pub const DEFAULT_QUEUE_SIZE_VUBLK: u16 = 128; /// Errors associated with VM configuration parameters. #[derive(Debug)] @@ -812,11 +814,26 @@ impl VsockConfig { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct VhostUserBlkConfig { pub sock: String, + #[serde(default = "default_vublkconfig_num_queues")] pub num_queues: usize, + #[serde(default = "default_vublkconfig_queue_size")] pub queue_size: u16, + #[serde(default = "default_vublkconfig_wce")] pub wce: bool, } +fn default_vublkconfig_num_queues() -> usize { + DEFAULT_NUM_QUEUES_VUBLK +} + +fn default_vublkconfig_queue_size() -> u16 { + DEFAULT_QUEUE_SIZE_VUBLK +} + +fn default_vublkconfig_wce() -> bool { + true +} + impl VhostUserBlkConfig { pub fn parse(vhost_user_blk: &str) -> Result { // Split the parameters based on the comma delimiter @@ -839,9 +856,9 @@ impl VhostUserBlkConfig { } } - let mut num_queues: usize = 1; - let mut queue_size: u16 = 128; - let mut wce: bool = true; + let mut num_queues: usize = default_vublkconfig_num_queues(); + let mut queue_size: u16 = default_vublkconfig_queue_size(); + let mut wce: bool = default_vublkconfig_wce(); if !num_queues_str.is_empty() { num_queues = num_queues_str