mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 08:17:37 +00:00
runtime-rs: debug console support in runtime
Read debug console configuration in kernel params. Fixes: #5068 Signed-Off-By: Ji-Xinyou <jerryji0414@outlook.com>
This commit is contained in:
parent
e05e42fd3c
commit
87959cb72d
@ -50,6 +50,8 @@ const VIRTIO_FS: &str = "virtio-fs";
|
|||||||
const VIRTIO_FS_INLINE: &str = "inline-virtio-fs";
|
const VIRTIO_FS_INLINE: &str = "inline-virtio-fs";
|
||||||
const MAX_BRIDGE_SIZE: u32 = 5;
|
const MAX_BRIDGE_SIZE: u32 = 5;
|
||||||
|
|
||||||
|
const KERNEL_PARAM_DELIMITER: &str = " ";
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref HYPERVISOR_PLUGINS: Mutex<HashMap<String, Arc<dyn ConfigPlugin>>> =
|
static ref HYPERVISOR_PLUGINS: Mutex<HashMap<String, Arc<dyn ConfigPlugin>>> =
|
||||||
Mutex::new(HashMap::new());
|
Mutex::new(HashMap::new());
|
||||||
@ -237,6 +239,14 @@ impl BootInfo {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add kernel parameters to bootinfo. It is always added before the original
|
||||||
|
/// to let the original one takes priority
|
||||||
|
pub fn add_kparams(&mut self, params: Vec<String>) {
|
||||||
|
let mut p = params;
|
||||||
|
p.push(self.kernel_params.clone()); // [new_params0, new_params1, ..., original_params]
|
||||||
|
self.kernel_params = p.join(KERNEL_PARAM_DELIMITER);
|
||||||
|
}
|
||||||
|
|
||||||
/// Validate guest kernel image annotaion
|
/// Validate guest kernel image annotaion
|
||||||
pub fn validate_boot_path(&self, path: &str) -> Result<()> {
|
pub fn validate_boot_path(&self, path: &str) -> Result<()> {
|
||||||
validate_path!(path, "path {} is invalid{}")?;
|
validate_path!(path, "path {} is invalid{}")?;
|
||||||
|
@ -151,6 +151,28 @@ impl TomlConfig {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get agent-specfic kernel parameters for further Hypervisor config revision
|
||||||
|
pub fn get_agent_kparams(&self) -> Result<HashMap<String, String>> {
|
||||||
|
let mut kv = HashMap::new();
|
||||||
|
if let Some(cfg) = self.agent.get(&self.runtime.agent_name) {
|
||||||
|
if cfg.debug {
|
||||||
|
kv.insert("agent.log".to_string(), "debug".to_string());
|
||||||
|
}
|
||||||
|
if cfg.enable_tracing {
|
||||||
|
kv.insert("agent.trace".to_string(), "true".to_string());
|
||||||
|
}
|
||||||
|
if cfg.container_pipe_size > 0 {
|
||||||
|
let container_pipe_size = cfg.container_pipe_size.to_string();
|
||||||
|
kv.insert("agent.container_pipe_size".to_string(), container_pipe_size);
|
||||||
|
}
|
||||||
|
if cfg.debug_console_enabled {
|
||||||
|
kv.insert("agent.debug_console".to_string(), "".to_string());
|
||||||
|
kv.insert("agent.debug_console_vport".to_string(), "1026".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(kv)
|
||||||
|
}
|
||||||
|
|
||||||
/// Probe configuration file according to the default configuration file list.
|
/// Probe configuration file according to the default configuration file list.
|
||||||
fn get_default_config_file() -> Result<PathBuf> {
|
fn get_default_config_file() -> Result<PathBuf> {
|
||||||
for f in default::DEFAULT_RUNTIME_CONFIGURATIONS.iter() {
|
for f in default::DEFAULT_RUNTIME_CONFIGURATIONS.iter() {
|
||||||
|
@ -91,6 +91,7 @@ impl DragonballInner {
|
|||||||
kernel_params.append(&mut KernelParams::from_string(
|
kernel_params.append(&mut KernelParams::from_string(
|
||||||
&self.config.boot_info.kernel_params,
|
&self.config.boot_info.kernel_params,
|
||||||
));
|
));
|
||||||
|
info!(sl!(), "prepared kernel_params={:?}", kernel_params);
|
||||||
|
|
||||||
// set boot source
|
// set boot source
|
||||||
let kernel_path = self.config.boot_info.kernel.clone();
|
let kernel_path = self.config.boot_info.kernel.clone();
|
||||||
|
@ -28,6 +28,18 @@ impl Param {
|
|||||||
value: value.to_owned(),
|
value: value.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_string(&self) -> Result<String> {
|
||||||
|
if self.key.is_empty() && self.value.is_empty() {
|
||||||
|
Err(anyhow!("Empty key and value"))
|
||||||
|
} else if self.key.is_empty() {
|
||||||
|
Err(anyhow!("Empty key"))
|
||||||
|
} else if self.value.is_empty() {
|
||||||
|
Ok(self.key.to_string())
|
||||||
|
} else {
|
||||||
|
Ok(format!("{}{}{}", self.key, KERNEL_KV_DELIMITER, self.value))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -129,18 +141,7 @@ impl KernelParams {
|
|||||||
let mut parameters: Vec<String> = Vec::new();
|
let mut parameters: Vec<String> = Vec::new();
|
||||||
|
|
||||||
for param in &self.params {
|
for param in &self.params {
|
||||||
if param.key.is_empty() && param.value.is_empty() {
|
parameters.push(param.to_string()?);
|
||||||
return Err(anyhow!("Empty key and value"));
|
|
||||||
} else if param.key.is_empty() {
|
|
||||||
return Err(anyhow!("Empty key"));
|
|
||||||
} else if param.value.is_empty() {
|
|
||||||
parameters.push(param.key.to_string());
|
|
||||||
} else {
|
|
||||||
parameters.push(format!(
|
|
||||||
"{}{}{}",
|
|
||||||
param.key, KERNEL_KV_DELIMITER, param.value
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(parameters.join(KERNEL_PARAM_DELIMITER))
|
Ok(parameters.join(KERNEL_PARAM_DELIMITER))
|
||||||
@ -153,6 +154,20 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_params() {
|
||||||
|
let param1 = Param::new("", "");
|
||||||
|
let param2 = Param::new("", "foo");
|
||||||
|
let param3 = Param::new("foo", "");
|
||||||
|
|
||||||
|
assert!(param1.to_string().is_err());
|
||||||
|
assert!(param2.to_string().is_err());
|
||||||
|
assert_eq!(param3.to_string().unwrap(), String::from("foo"));
|
||||||
|
|
||||||
|
let param4 = Param::new("foo", "bar");
|
||||||
|
assert_eq!(param4.to_string().unwrap(), String::from("foo=bar"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_kernel_params() -> Result<()> {
|
fn test_kernel_params() -> Result<()> {
|
||||||
let expect_params_string = "k1=v1 k2=v2 k3=v3".to_string();
|
let expect_params_string = "k1=v1 k2=v2 k3=v3".to_string();
|
||||||
|
@ -19,6 +19,7 @@ kata-types = { path = "../../../libs/kata-types" }
|
|||||||
logging = { path = "../../../libs/logging"}
|
logging = { path = "../../../libs/logging"}
|
||||||
oci = { path = "../../../libs/oci" }
|
oci = { path = "../../../libs/oci" }
|
||||||
persist = { path = "../persist" }
|
persist = { path = "../persist" }
|
||||||
|
hypervisor = { path = "../hypervisor" }
|
||||||
# runtime handler
|
# runtime handler
|
||||||
linux_container = { path = "./linux_container", optional = true }
|
linux_container = { path = "./linux_container", optional = true }
|
||||||
virt_container = { path = "./virt_container", optional = true }
|
virt_container = { path = "./virt_container", optional = true }
|
||||||
|
@ -14,6 +14,7 @@ use common::{
|
|||||||
types::{Request, Response},
|
types::{Request, Response},
|
||||||
RuntimeHandler, RuntimeInstance, Sandbox,
|
RuntimeHandler, RuntimeInstance, Sandbox,
|
||||||
};
|
};
|
||||||
|
use hypervisor::Param;
|
||||||
use kata_types::{annotations::Annotation, config::TomlConfig};
|
use kata_types::{annotations::Annotation, config::TomlConfig};
|
||||||
#[cfg(feature = "linux")]
|
#[cfg(feature = "linux")]
|
||||||
use linux_container::LinuxContainer;
|
use linux_container::LinuxContainer;
|
||||||
@ -323,6 +324,7 @@ fn load_config(spec: &oci::Spec) -> Result<TomlConfig> {
|
|||||||
let (mut toml_config, _) =
|
let (mut toml_config, _) =
|
||||||
TomlConfig::load_from_file(&config_path).context("load toml config")?;
|
TomlConfig::load_from_file(&config_path).context("load toml config")?;
|
||||||
annotation.update_config_by_annotation(&mut toml_config)?;
|
annotation.update_config_by_annotation(&mut toml_config)?;
|
||||||
|
update_agent_kparams(&mut toml_config)?;
|
||||||
|
|
||||||
// validate configuration and return the error
|
// validate configuration and return the error
|
||||||
toml_config.validate()?;
|
toml_config.validate()?;
|
||||||
@ -346,3 +348,20 @@ fn load_config(spec: &oci::Spec) -> Result<TomlConfig> {
|
|||||||
info!(sl!(), "get config content {:?}", &toml_config);
|
info!(sl!(), "get config content {:?}", &toml_config);
|
||||||
Ok(toml_config)
|
Ok(toml_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this update the agent-specfic kernel parameters into hypervisor's bootinfo
|
||||||
|
// the agent inside the VM will read from file cmdline to get the params and function
|
||||||
|
fn update_agent_kparams(config: &mut TomlConfig) -> Result<()> {
|
||||||
|
let mut params = vec![];
|
||||||
|
if let Ok(kv) = config.get_agent_kparams() {
|
||||||
|
for (k, v) in kv.into_iter() {
|
||||||
|
if let Ok(s) = Param::new(k.as_str(), v.as_str()).to_string() {
|
||||||
|
params.push(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(h) = config.hypervisor.get_mut(&config.runtime.hypervisor_name) {
|
||||||
|
h.boot_info.add_kparams(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user