From a8a458664dc6ee116c0092658f90e906cff50781 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 2 Dec 2025 17:13:26 +0800 Subject: [PATCH] kata-types: Allow dynamic queue config via Pod annotations This commit introduces the capability to dynamically configure `queue_size` and `num_queues` parameters via Pod annotations. Currently, `kata-runtime` allows for static configuration of `queue_size` and `num_queues` for block devices through its config file. However, a critical issue arises when a Pod is allocated fewer CPU cores than the statically configured `num_queues` value. In such scenarios, the Pod fails to start, leading to operational instability and limiting flexibility in resource allocation. To address this, this feature enables users to override the default queue_size and num_queues parameters by specifying them in Pod annotations.This allows for fine-grained control and dynamic adjustment of these parameters based on the specific resource allocation of a Pod. Signed-off-by: Alex Lyn --- src/libs/kata-types/src/annotations/mod.rs | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libs/kata-types/src/annotations/mod.rs b/src/libs/kata-types/src/annotations/mod.rs index 0ae1492a0a..ec82107d9c 100644 --- a/src/libs/kata-types/src/annotations/mod.rs +++ b/src/libs/kata-types/src/annotations/mod.rs @@ -283,6 +283,13 @@ pub const KATA_ANNO_CFG_HYPERVISOR_DEFAULT_GPUS: &str = pub const KATA_ANNO_CFG_HYPERVISOR_DEFAULT_GPU_MODEL: &str = "io.katacontainers.config.hypervisor.default_gpu_model"; +/// Block device specific annotation for num_queues +pub const KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_NUM_QUEUES: &str = + "io.katacontainers.config.hypervisor.block_device_num_queues"; +/// Block device specific annotation for queue_size +pub const KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_QUEUE_SIZE: &str = + "io.katacontainers.config.hypervisor.block_device_queue_size"; + // Runtime related annotations /// Prefix for Runtime configurations. pub const KATA_ANNO_CFG_RUNTIME_PREFIX: &str = "io.katacontainers.config.runtime."; @@ -503,6 +510,7 @@ impl Annotation { let u32_err = io::Error::new(io::ErrorKind::InvalidData, "parse u32 error".to_string()); let u64_err = io::Error::new(io::ErrorKind::InvalidData, "parse u64 error".to_string()); let i32_err = io::Error::new(io::ErrorKind::InvalidData, "parse i32 error".to_string()); + let usize_err = io::Error::new(io::ErrorKind::InvalidData, "parse usize error".to_string()); let hv = config.hypervisor.get_mut(hypervisor_name).ok_or_else(|| { io::Error::new( io::ErrorKind::InvalidData, @@ -960,7 +968,26 @@ impl Annotation { return Err(u32_err); } }, - + KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_NUM_QUEUES => { + match self.get_value::(key) { + Ok(v) => { + hv.blockdev_info.num_queues = v.unwrap_or_default(); + } + Err(_e) => { + return Err(usize_err); + } + } + } + KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_QUEUE_SIZE => { + match self.get_value::(key) { + Ok(v) => { + hv.blockdev_info.queue_size = v.unwrap_or_default(); + } + Err(_e) => { + return Err(u32_err); + } + } + } _ => { return Err(io::Error::new( io::ErrorKind::InvalidInput,