diff --git a/src/libs/kata-types/src/annotations/mod.rs b/src/libs/kata-types/src/annotations/mod.rs index ea4e5c03a0..d06a67d430 100644 --- a/src/libs/kata-types/src/annotations/mod.rs +++ b/src/libs/kata-types/src/annotations/mod.rs @@ -7,6 +7,7 @@ use std::collections::HashMap; use std::fs::File; use std::io::{self, BufReader, Result}; +use std::result::{self}; use std::u32; use serde::Deserialize; @@ -330,74 +331,24 @@ impl Annotation { &mut self.annotations } + /// Get the value of annotation with `key` + pub fn get_value( + &self, + key: &str, + ) -> result::Result, ::Err> + where + T: std::str::FromStr, + { + if let Some(value) = self.get(key) { + return value.parse::().map(Some); + } + Ok(None) + } + /// Get the value of annotation with `key` as string. pub fn get(&self, key: &str) -> Option { self.annotations.get(key).map(|v| String::from(v.trim())) } - - /// Get the value of annotation with `key` as bool. - pub fn get_bool(&self, key: &str) -> Result> { - if let Some(value) = self.get(key) { - return value - .parse::() - .map_err(|_| { - io::Error::new( - io::ErrorKind::InvalidData, - format!("Invalid input {} for bool", key), - ) - }) - .map(Some); - } - Ok(None) - } - - /// Get the value of annotation with `key` as u32. - pub fn get_u32(&self, key: &str) -> Result> { - if let Some(value) = self.get(key) { - return value - .parse::() - .map_err(|_| { - io::Error::new( - io::ErrorKind::InvalidData, - format!("Invalid input {} for u32", key), - ) - }) - .map(Some); - } - Ok(None) - } - - /// Get the value of annotation with `key` as i32. - pub fn get_i32(&self, key: &str) -> Result> { - if let Some(value) = self.get(key) { - return value - .parse::() - .map_err(|_| { - io::Error::new( - io::ErrorKind::InvalidData, - format!("Invalid input {} for i32", key), - ) - }) - .map(Some); - } - Ok(None) - } - - /// Get the value of annotation with `key` as u64. - pub fn get_u64(&self, key: &str) -> Result> { - if let Some(value) = self.get(key) { - return value - .parse::() - .map_err(|_| { - io::Error::new( - io::ErrorKind::InvalidData, - format!("Invalid input {} for u64", key), - ) - }) - .map(Some); - } - Ok(None) - } } // Miscellaneous annotations. @@ -419,7 +370,7 @@ impl Annotation { /// Get the annotation to specify the Resources.Memory.Swappiness. pub fn get_container_resource_swappiness(&self) -> Result> { - match self.get_u32(KATA_ANNO_CONTAINER_RES_SWAPPINESS) { + match self.get_value::(KATA_ANNO_CONTAINER_RES_SWAPPINESS) { Ok(r) => { if r.unwrap_or_default() > 100 { return Err(io::Error::new( @@ -430,7 +381,10 @@ impl Annotation { Ok(r) } } - Err(e) => Err(e), + Err(_e) => Err(io::Error::new( + io::ErrorKind::InvalidData, + "parse u32 error".to_string(), + )), } } @@ -461,6 +415,11 @@ impl Annotation { format!("agent {} not found", agent_name), )); } + let bool_err = io::Error::new(io::ErrorKind::InvalidData, "parse bool error".to_string()); + 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 mut hv = config.hypervisor.get_mut(hypervisor_name).unwrap(); let mut ag = config.agent.get_mut(agent_name).unwrap(); for (key, value) in &self.annotations { @@ -481,74 +440,87 @@ impl Annotation { hv.validate_jailer_path(value)?; hv.jailer_path = value.to_string(); } - KATA_ANNO_CFG_HYPERVISOR_ENABLE_IO_THREADS => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_ENABLE_IO_THREADS => match self.get_value::(key) + { Ok(r) => { hv.enable_iothreads = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, // Hypervisor Block Device related annotations KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_DRIVER => { hv.blockdev_info.block_device_driver = value.to_string(); } - KATA_ANNO_CFG_HYPERVISOR_DISABLE_BLOCK_DEV_USE => match self.get_bool(key) { - Ok(r) => { - hv.blockdev_info.disable_block_device_use = r.unwrap_or_default(); + KATA_ANNO_CFG_HYPERVISOR_DISABLE_BLOCK_DEV_USE => { + match self.get_value::(key) { + Ok(r) => { + hv.blockdev_info.disable_block_device_use = r.unwrap_or_default(); + } + Err(_e) => { + return Err(bool_err); + } } - Err(e) => { - return Err(e); + } + KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_CACHE_SET => { + match self.get_value::(key) { + Ok(r) => { + hv.blockdev_info.block_device_cache_set = r.unwrap_or_default(); + } + Err(_e) => { + return Err(bool_err); + } } - }, - KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_CACHE_SET => match self.get_bool(key) { - Ok(r) => { - hv.blockdev_info.block_device_cache_set = r.unwrap_or_default(); + } + KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_CACHE_DIRECT => { + match self.get_value::(key) { + Ok(r) => { + hv.blockdev_info.block_device_cache_direct = r.unwrap_or_default(); + } + Err(_e) => { + return Err(bool_err); + } } - Err(e) => { - return Err(e); + } + KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_CACHE_NOFLUSH => { + match self.get_value::(key) { + Ok(r) => { + hv.blockdev_info.block_device_cache_noflush = r.unwrap_or_default(); + } + Err(_e) => { + return Err(bool_err); + } } - }, - KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_CACHE_DIRECT => match self.get_bool(key) { - Ok(r) => { - hv.blockdev_info.block_device_cache_direct = r.unwrap_or_default(); + } + KATA_ANNO_CFG_HYPERVISOR_DISABLE_IMAGE_NVDIMM => { + match self.get_value::(key) { + Ok(r) => { + hv.blockdev_info.disable_image_nvdimm = r.unwrap_or_default(); + } + Err(_e) => { + return Err(bool_err); + } } - Err(e) => { - return Err(e); - } - }, - KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_CACHE_NOFLUSH => match self.get_bool(key) { - Ok(r) => { - hv.blockdev_info.block_device_cache_noflush = r.unwrap_or_default(); - } - Err(e) => { - return Err(e); - } - }, - KATA_ANNO_CFG_HYPERVISOR_DISABLE_IMAGE_NVDIMM => match self.get_bool(key) { - Ok(r) => { - hv.blockdev_info.disable_image_nvdimm = r.unwrap_or_default(); - } - Err(e) => { - return Err(e); - } - }, - KATA_ANNO_CFG_HYPERVISOR_MEMORY_OFFSET => match self.get_u64(key) { + } + KATA_ANNO_CFG_HYPERVISOR_MEMORY_OFFSET => match self.get_value::(key) { Ok(r) => { hv.blockdev_info.memory_offset = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(u64_err); } }, - KATA_ANNO_CFG_HYPERVISOR_ENABLE_VHOSTUSER_STORE => match self.get_bool(key) { - Ok(r) => { - hv.blockdev_info.enable_vhost_user_store = r.unwrap_or_default(); + KATA_ANNO_CFG_HYPERVISOR_ENABLE_VHOSTUSER_STORE => { + match self.get_value::(key) { + Ok(r) => { + hv.blockdev_info.enable_vhost_user_store = r.unwrap_or_default(); + } + Err(_e) => { + return Err(bool_err); + } } - Err(e) => { - return Err(e); - } - }, + } KATA_ANNO_CFG_HYPERVISOR_VHOSTUSER_STORE_PATH => { hv.blockdev_info.validate_vhost_user_store_path(value)?; hv.blockdev_info.vhost_user_store_path = value.to_string(); @@ -577,7 +549,7 @@ impl Annotation { KATA_ANNO_CFG_HYPERVISOR_CPU_FEATURES => { hv.cpu_info.cpu_features = value.to_string(); } - KATA_ANNO_CFG_HYPERVISOR_DEFAULT_VCPUS => match self.get_i32(key) { + KATA_ANNO_CFG_HYPERVISOR_DEFAULT_VCPUS => match self.get_value::(key) { Ok(num_cpus) => { let num_cpus = num_cpus.unwrap_or_default(); if num_cpus @@ -599,49 +571,53 @@ impl Annotation { hv.cpu_info.default_vcpus = num_cpus; } } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(i32_err); } }, - KATA_ANNO_CFG_HYPERVISOR_DEFAULT_MAX_VCPUS => match self.get_u32(key) { - Ok(r) => { - hv.cpu_info.default_maxvcpus = r.unwrap_or_default(); + KATA_ANNO_CFG_HYPERVISOR_DEFAULT_MAX_VCPUS => { + match self.get_value::(key) { + Ok(r) => { + hv.cpu_info.default_maxvcpus = r.unwrap_or_default(); + } + Err(_e) => { + return Err(u32_err); + } } - Err(e) => { - return Err(e); - } - }, + } // Hypervisor Device related annotations - KATA_ANNO_CFG_HYPERVISOR_HOTPLUG_VFIO_ON_ROOT_BUS => match self.get_bool(key) { - Ok(r) => { - hv.device_info.hotplug_vfio_on_root_bus = r.unwrap_or_default(); + KATA_ANNO_CFG_HYPERVISOR_HOTPLUG_VFIO_ON_ROOT_BUS => { + match self.get_value::(key) { + Ok(r) => { + hv.device_info.hotplug_vfio_on_root_bus = r.unwrap_or_default(); + } + Err(_e) => { + return Err(bool_err); + } } - Err(e) => { - return Err(e); - } - }, - KATA_ANNO_CFG_HYPERVISOR_PCIE_ROOT_PORT => match self.get_u32(key) { + } + KATA_ANNO_CFG_HYPERVISOR_PCIE_ROOT_PORT => match self.get_value::(key) { Ok(r) => { hv.device_info.pcie_root_port = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(u32_err); } }, - KATA_ANNO_CFG_HYPERVISOR_IOMMU => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_IOMMU => match self.get_value::(key) { Ok(r) => { hv.device_info.enable_iommu = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_HYPERVISOR_IOMMU_PLATFORM => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_IOMMU_PLATFORM => match self.get_value::(key) { Ok(r) => { hv.device_info.enable_iommu_platform = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, // Hypervisor Machine related annotations @@ -656,7 +632,7 @@ impl Annotation { hv.machine_info.entropy_source = value.to_string(); } // Hypervisor Memory related annotations - KATA_ANNO_CFG_HYPERVISOR_DEFAULT_MEMORY => match self.get_u32(key) { + KATA_ANNO_CFG_HYPERVISOR_DEFAULT_MEMORY => match self.get_value::(key) { Ok(r) => { let mem = r.unwrap_or_default(); if mem @@ -678,100 +654,106 @@ impl Annotation { hv.memory_info.default_memory = mem; } } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(u32_err); } }, - KATA_ANNO_CFG_HYPERVISOR_MEMORY_SLOTS => match self.get_u32(key) { + KATA_ANNO_CFG_HYPERVISOR_MEMORY_SLOTS => match self.get_value::(key) { Ok(v) => { hv.memory_info.memory_slots = v.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(u32_err); } }, - KATA_ANNO_CFG_HYPERVISOR_MEMORY_PREALLOC => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_MEMORY_PREALLOC => match self.get_value::(key) { Ok(r) => { hv.memory_info.enable_mem_prealloc = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_HYPERVISOR_HUGE_PAGES => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_HUGE_PAGES => match self.get_value::(key) { Ok(r) => { hv.memory_info.enable_hugepages = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, KATA_ANNO_CFG_HYPERVISOR_FILE_BACKED_MEM_ROOT_DIR => { hv.memory_info.validate_memory_backend_path(value)?; hv.memory_info.file_mem_backend = value.to_string(); } - KATA_ANNO_CFG_HYPERVISOR_VIRTIO_MEM => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_VIRTIO_MEM => match self.get_value::(key) { Ok(r) => { hv.memory_info.enable_virtio_mem = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_HYPERVISOR_ENABLE_SWAP => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_ENABLE_SWAP => match self.get_value::(key) { Ok(r) => { hv.memory_info.enable_swap = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_HYPERVISOR_ENABLE_GUEST_SWAP => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_ENABLE_GUEST_SWAP => match self.get_value::(key) + { Ok(r) => { hv.memory_info.enable_guest_swap = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, // Hypervisor Network related annotations - KATA_ANNO_CFG_HYPERVISOR_DISABLE_VHOST_NET => match self.get_bool(key) { + KATA_ANNO_CFG_HYPERVISOR_DISABLE_VHOST_NET => match self.get_value::(key) + { Ok(r) => { hv.network_info.disable_vhost_net = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_HYPERVISOR_RX_RATE_LIMITER_MAX_RATE => match self.get_u64(key) { - Ok(r) => { - hv.network_info.rx_rate_limiter_max_rate = r.unwrap_or_default(); + KATA_ANNO_CFG_HYPERVISOR_RX_RATE_LIMITER_MAX_RATE => { + match self.get_value::(key) { + Ok(r) => { + hv.network_info.rx_rate_limiter_max_rate = r.unwrap_or_default(); + } + Err(_e) => { + return Err(u64_err); + } } - Err(e) => { - return Err(e); + } + KATA_ANNO_CFG_HYPERVISOR_TX_RATE_LIMITER_MAX_RATE => { + match self.get_value::(key) { + Ok(r) => { + hv.network_info.tx_rate_limiter_max_rate = r.unwrap_or_default(); + } + Err(_e) => { + return Err(u64_err); + } } - }, - KATA_ANNO_CFG_HYPERVISOR_TX_RATE_LIMITER_MAX_RATE => match self.get_u64(key) { - Ok(r) => { - hv.network_info.tx_rate_limiter_max_rate = r.unwrap_or_default(); - } - Err(e) => { - return Err(e); - } - }, + } // Hypervisor Security related annotations KATA_ANNO_CFG_HYPERVISOR_GUEST_HOOK_PATH => { hv.security_info.validate_path(value)?; hv.security_info.guest_hook_path = value.to_string(); } KATA_ANNO_CFG_HYPERVISOR_ENABLE_ROOTLESS_HYPERVISOR => { - match self.get_bool(key) { + match self.get_value::(key) { Ok(r) => { hv.security_info.rootless = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } } } @@ -788,14 +770,16 @@ impl Annotation { KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_CACHE => { hv.shared_fs.virtio_fs_cache = value.to_string(); } - KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_CACHE_SIZE => match self.get_u32(key) { - Ok(r) => { - hv.shared_fs.virtio_fs_cache_size = r.unwrap_or_default(); + KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_CACHE_SIZE => { + match self.get_value::(key) { + Ok(r) => { + hv.shared_fs.virtio_fs_cache_size = r.unwrap_or_default(); + } + Err(_e) => { + return Err(u32_err); + } } - Err(e) => { - return Err(e); - } - }, + } KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_EXTRA_ARGS => { let args: Vec = value.to_string().split(',').map(str::to_string).collect(); @@ -803,12 +787,12 @@ impl Annotation { hv.shared_fs.virtio_fs_extra_args.push(arg.to_string()); } } - KATA_ANNO_CFG_HYPERVISOR_MSIZE_9P => match self.get_u32(key) { + KATA_ANNO_CFG_HYPERVISOR_MSIZE_9P => match self.get_value::(key) { Ok(v) => { hv.shared_fs.msize_9p = v.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(u32_err); } }, @@ -829,37 +813,37 @@ impl Annotation { ag.kernel_modules.push(modules.to_string()); } } - KATA_ANNO_CFG_AGENT_TRACE => match self.get_bool(key) { + KATA_ANNO_CFG_AGENT_TRACE => match self.get_value::(key) { Ok(r) => { ag.enable_tracing = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_AGENT_CONTAINER_PIPE_SIZE => match self.get_u32(key) { + KATA_ANNO_CFG_AGENT_CONTAINER_PIPE_SIZE => match self.get_value::(key) { Ok(v) => { ag.container_pipe_size = v.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(u32_err); } }, //update runtume config - KATA_ANNO_CFG_DISABLE_GUEST_SECCOMP => match self.get_bool(key) { + KATA_ANNO_CFG_DISABLE_GUEST_SECCOMP => match self.get_value::(key) { Ok(r) => { config.runtime.disable_guest_seccomp = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_ENABLE_PPROF => match self.get_bool(key) { + KATA_ANNO_CFG_ENABLE_PPROF => match self.get_value::(key) { Ok(r) => { config.runtime.enable_pprof = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, KATA_ANNO_CFG_EXPERIMENTAL => { @@ -872,20 +856,20 @@ impl Annotation { KATA_ANNO_CFG_INTER_NETWORK_MODEL => { config.runtime.internetworking_model = value.to_string(); } - KATA_ANNO_CFG_SANDBOX_CGROUP_ONLY => match self.get_bool(key) { + KATA_ANNO_CFG_SANDBOX_CGROUP_ONLY => match self.get_value::(key) { Ok(r) => { config.runtime.sandbox_cgroup_only = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, - KATA_ANNO_CFG_DISABLE_NEW_NETNS => match self.get_bool(key) { + KATA_ANNO_CFG_DISABLE_NEW_NETNS => match self.get_value::(key) { Ok(r) => { config.runtime.disable_new_netns = r.unwrap_or_default(); } - Err(e) => { - return Err(e); + Err(_e) => { + return Err(bool_err); } }, KATA_ANNO_CFG_VFIO_MODE => { diff --git a/src/libs/kata-types/src/annotations/thirdparty.rs b/src/libs/kata-types/src/annotations/thirdparty.rs index 28a522d7c6..e8f2a71683 100644 --- a/src/libs/kata-types/src/annotations/thirdparty.rs +++ b/src/libs/kata-types/src/annotations/thirdparty.rs @@ -9,4 +9,4 @@ /// Annotation to enable SGX. /// /// Hardware-based isolation and memory encryption. -pub const SGXEPC: &str = "sgx.intel.com/epc"; +pub const SGX_EPC: &str = "sgx.intel.com/epc"; diff --git a/src/libs/kata-types/src/config/default.rs b/src/libs/kata-types/src/config/default.rs index fd40e748be..6b047ba8ed 100644 --- a/src/libs/kata-types/src/config/default.rs +++ b/src/libs/kata-types/src/config/default.rs @@ -15,7 +15,7 @@ lazy_static! { "/usr/share/defaults/kata-containers/configuration.toml", ]; } -pub const DEFAULT_AGENT_NAME: &str = "kata"; +pub const DEFAULT_AGENT_NAME: &str = "kata-agent"; pub const DEFAULT_INTERNETWORKING_MODEL: &str = "tcfilter"; @@ -35,13 +35,13 @@ pub const DEFAULT_GUEST_HOOK_PATH: &str = "/opt"; pub const DEFAULT_GUEST_VCPUS: u32 = 1; // Default configuration for Dragonball -pub const DEFAULT_DB_GUEST_KERNEL_IMAGE: &str = "vmlinuz"; -pub const DEFAULT_DB_GUEST_KERNEL_PARAMS: &str = ""; -pub const DEFAULT_DB_ENTROPY_SOURCE: &str = "/dev/urandom"; -pub const DEFAULT_DB_MEMORY_SIZE: u32 = 128; -pub const DEFAULT_DB_MEMORY_SLOTS: u32 = 128; -pub const MAX_DB_VCPUS: u32 = 256; -pub const MIN_DB_MEMORY_SIZE: u32 = 64; +pub const DEFAULT_DRAGONBALL_GUEST_KERNEL_IMAGE: &str = "vmlinuz"; +pub const DEFAULT_DRAGONBALL_GUEST_KERNEL_PARAMS: &str = ""; +pub const DEFAULT_DRAGONBALL_ENTROPY_SOURCE: &str = "/dev/urandom"; +pub const DEFAULT_DRAGONBALL_MEMORY_SIZE: u32 = 128; +pub const DEFAULT_DRAGONBALL_MEMORY_SLOTS: u32 = 128; +pub const MAX_DRAGONBALL_VCPUS: u32 = 256; +pub const MIN_DRAGONBALL_MEMORY_SIZE: u32 = 64; // Default configuration for qemu pub const DEFAULT_QEMU_BINARY_PATH: &str = "qemu"; pub const DEFAULT_QEMU_CONTROL_PATH: &str = ""; diff --git a/src/libs/kata-types/src/config/hypervisor/dragonball.rs b/src/libs/kata-types/src/config/hypervisor/dragonball.rs index 95158019fb..bcb43eaba3 100644 --- a/src/libs/kata-types/src/config/hypervisor/dragonball.rs +++ b/src/libs/kata-types/src/config/hypervisor/dragonball.rs @@ -9,8 +9,8 @@ use std::sync::Arc; use std::u32; use super::{default, register_hypervisor_plugin}; -use crate::config::default::MAX_DB_VCPUS; -use crate::config::default::MIN_DB_MEMORY_SIZE; +use crate::config::default::MAX_DRAGONBALL_VCPUS; +use crate::config::default::MIN_DRAGONBALL_MEMORY_SIZE; use crate::config::hypervisor::{ VIRTIO_BLK, VIRTIO_BLK_MMIO, VIRTIO_FS, VIRTIO_FS_INLINE, VIRTIO_PMEM, }; @@ -39,10 +39,10 @@ impl DragonballConfig { impl ConfigPlugin for DragonballConfig { fn get_max_cpus(&self) -> u32 { - MAX_DB_VCPUS + MAX_DRAGONBALL_VCPUS } fn get_min_memory(&self) -> u32 { - MIN_DB_MEMORY_SIZE + MIN_DRAGONBALL_MEMORY_SIZE } fn name(&self) -> &str { HYPERVISOR_NAME_DRAGONBALL @@ -54,25 +54,27 @@ impl ConfigPlugin for DragonballConfig { resolve_path!(db.jailer_path, "Dragonball jailer path {} is invalid: {}")?; if db.boot_info.kernel.is_empty() { - db.boot_info.kernel = default::DEFAULT_DB_GUEST_KERNEL_IMAGE.to_string(); + db.boot_info.kernel = default::DEFAULT_DRAGONBALL_GUEST_KERNEL_IMAGE.to_string(); } if db.boot_info.kernel_params.is_empty() { - db.boot_info.kernel_params = default::DEFAULT_DB_GUEST_KERNEL_PARAMS.to_string(); + db.boot_info.kernel_params = + default::DEFAULT_DRAGONBALL_GUEST_KERNEL_PARAMS.to_string(); } - if db.cpu_info.default_maxvcpus > default::MAX_DB_VCPUS { - db.cpu_info.default_maxvcpus = default::MAX_DB_VCPUS; + if db.cpu_info.default_maxvcpus > default::MAX_DRAGONBALL_VCPUS { + db.cpu_info.default_maxvcpus = default::MAX_DRAGONBALL_VCPUS; } if db.machine_info.entropy_source.is_empty() { - db.machine_info.entropy_source = default::DEFAULT_DB_ENTROPY_SOURCE.to_string(); + db.machine_info.entropy_source = + default::DEFAULT_DRAGONBALL_ENTROPY_SOURCE.to_string(); } if db.memory_info.default_memory == 0 { - db.memory_info.default_memory = default::DEFAULT_DB_MEMORY_SIZE; + db.memory_info.default_memory = default::DEFAULT_DRAGONBALL_MEMORY_SIZE; } if db.memory_info.memory_slots == 0 { - db.memory_info.memory_slots = default::DEFAULT_DB_MEMORY_SLOTS; + db.memory_info.memory_slots = default::DEFAULT_DRAGONBALL_MEMORY_SLOTS; } } Ok(()) @@ -131,8 +133,8 @@ impl ConfigPlugin for DragonballConfig { } if (db.cpu_info.default_vcpus > 0 - && db.cpu_info.default_vcpus as u32 > default::MAX_DB_VCPUS) - || db.cpu_info.default_maxvcpus > default::MAX_DB_VCPUS + && db.cpu_info.default_vcpus as u32 > default::MAX_DRAGONBALL_VCPUS) + || db.cpu_info.default_maxvcpus > default::MAX_DRAGONBALL_VCPUS { return Err(eother!( "Dragonball hypervisor can not support {} vCPUs", diff --git a/src/libs/kata-types/src/config/runtime_vendor.rs b/src/libs/kata-types/src/config/runtime_vendor.rs index a0529f5ea3..67fafe21d7 100644 --- a/src/libs/kata-types/src/config/runtime_vendor.rs +++ b/src/libs/kata-types/src/config/runtime_vendor.rs @@ -6,7 +6,6 @@ //! A sample for vendor to customize the runtime implementation. use super::*; -use crate::{eother, sl}; use slog::Level; /// Vendor customization runtime configuration. #[derive(Debug, Default, Deserialize, Serialize)] diff --git a/src/libs/kata-types/tests/test_config.rs b/src/libs/kata-types/tests/test_config.rs index 6d4cc65ea9..ad66892049 100644 --- a/src/libs/kata-types/tests/test_config.rs +++ b/src/libs/kata-types/tests/test_config.rs @@ -30,7 +30,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); std::process::Command::new("mkdir") @@ -167,7 +167,7 @@ mod tests { anno_hash.insert(KATA_ANNO_CFG_EXPERIMENTAL.to_string(), "c,d,e".to_string()); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0") @@ -281,7 +281,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let mut anno_hash = HashMap::new(); @@ -290,7 +290,7 @@ mod tests { "fvfvfvfvf".to_string(), ); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0") @@ -304,7 +304,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let mut anno_hash = HashMap::new(); @@ -313,7 +313,7 @@ mod tests { "false".to_string(), ); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0") @@ -327,7 +327,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let mut anno_hash = HashMap::new(); @@ -374,7 +374,7 @@ mod tests { #[test] fn test_fail_to_change_memory_slots_because_of_less_than_zero() { let content = include_str!("texture/configuration-anno-0.toml"); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let qemu = QemuConfig::new(); @@ -386,7 +386,7 @@ mod tests { "-1".to_string(), ); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0") @@ -400,7 +400,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let mut anno_hash = HashMap::new(); @@ -409,7 +409,7 @@ mod tests { "10".to_string(), ); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0") @@ -423,7 +423,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let mut anno_hash = HashMap::new(); @@ -432,7 +432,7 @@ mod tests { "400".to_string(), ); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0") @@ -446,7 +446,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let mut anno_hash = HashMap::new(); @@ -455,7 +455,7 @@ mod tests { "false1".to_string(), ); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0") @@ -469,7 +469,7 @@ mod tests { let qemu = QemuConfig::new(); qemu.register(); - let config = TomlConfig::load(&content).unwrap(); + let config = TomlConfig::load(content).unwrap(); KataConfig::set_active_config(Some(config), "qemu", "agent0"); let mut anno_hash = HashMap::new(); @@ -478,7 +478,7 @@ mod tests { "ddc".to_string(), ); let anno = Annotation::new(anno_hash); - let mut config = TomlConfig::load(&content).unwrap(); + let mut config = TomlConfig::load(content).unwrap(); assert!(anno .update_config_by_annotation(&mut config, "qemu", "agent0")