mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 23:38:31 +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 MAX_BRIDGE_SIZE: u32 = 5;
|
||||
|
||||
const KERNEL_PARAM_DELIMITER: &str = " ";
|
||||
|
||||
lazy_static! {
|
||||
static ref HYPERVISOR_PLUGINS: Mutex<HashMap<String, Arc<dyn ConfigPlugin>>> =
|
||||
Mutex::new(HashMap::new());
|
||||
@ -237,6 +239,14 @@ impl BootInfo {
|
||||
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
|
||||
pub fn validate_boot_path(&self, path: &str) -> Result<()> {
|
||||
validate_path!(path, "path {} is invalid{}")?;
|
||||
|
@ -151,7 +151,29 @@ impl TomlConfig {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Probe configuration file according to the default configuration file list.
|
||||
/// 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.
|
||||
fn get_default_config_file() -> Result<PathBuf> {
|
||||
for f in default::DEFAULT_RUNTIME_CONFIGURATIONS.iter() {
|
||||
if let Ok(path) = fs::canonicalize(f) {
|
||||
|
@ -91,6 +91,7 @@ impl DragonballInner {
|
||||
kernel_params.append(&mut KernelParams::from_string(
|
||||
&self.config.boot_info.kernel_params,
|
||||
));
|
||||
info!(sl!(), "prepared kernel_params={:?}", kernel_params);
|
||||
|
||||
// set boot source
|
||||
let kernel_path = self.config.boot_info.kernel.clone();
|
||||
|
@ -28,6 +28,18 @@ impl Param {
|
||||
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)]
|
||||
@ -129,18 +141,7 @@ impl KernelParams {
|
||||
let mut parameters: Vec<String> = Vec::new();
|
||||
|
||||
for param in &self.params {
|
||||
if param.key.is_empty() && param.value.is_empty() {
|
||||
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
|
||||
));
|
||||
}
|
||||
parameters.push(param.to_string()?);
|
||||
}
|
||||
|
||||
Ok(parameters.join(KERNEL_PARAM_DELIMITER))
|
||||
@ -153,6 +154,20 @@ mod tests {
|
||||
|
||||
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]
|
||||
fn test_kernel_params() -> Result<()> {
|
||||
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"}
|
||||
oci = { path = "../../../libs/oci" }
|
||||
persist = { path = "../persist" }
|
||||
hypervisor = { path = "../hypervisor" }
|
||||
# runtime handler
|
||||
linux_container = { path = "./linux_container", optional = true }
|
||||
virt_container = { path = "./virt_container", optional = true }
|
||||
|
@ -14,6 +14,7 @@ use common::{
|
||||
types::{Request, Response},
|
||||
RuntimeHandler, RuntimeInstance, Sandbox,
|
||||
};
|
||||
use hypervisor::Param;
|
||||
use kata_types::{annotations::Annotation, config::TomlConfig};
|
||||
#[cfg(feature = "linux")]
|
||||
use linux_container::LinuxContainer;
|
||||
@ -323,6 +324,7 @@ fn load_config(spec: &oci::Spec) -> Result<TomlConfig> {
|
||||
let (mut toml_config, _) =
|
||||
TomlConfig::load_from_file(&config_path).context("load toml config")?;
|
||||
annotation.update_config_by_annotation(&mut toml_config)?;
|
||||
update_agent_kparams(&mut toml_config)?;
|
||||
|
||||
// validate configuration and return the error
|
||||
toml_config.validate()?;
|
||||
@ -346,3 +348,20 @@ fn load_config(spec: &oci::Spec) -> Result<TomlConfig> {
|
||||
info!(sl!(), "get config content {:?}", &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