mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-07-10 07:05:51 +00:00
debug: do-not-merge: add logs
Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com>
This commit is contained in:
@@ -18,6 +18,16 @@ use crate::validate::valid_env;
|
||||
|
||||
const DEFAULT_HOOK_TIMEOUT_SEC: i32 = 10;
|
||||
|
||||
// DEBUG: mirror hook execution details to /dev/kmsg so they surface on the guest
|
||||
// console (the only log channel that survives the createContainer fork, where the
|
||||
// slog async drain is dead). Remove once the composable CDI-hook issue is root-caused.
|
||||
fn kmsg_debug(msg: &str) {
|
||||
use std::io::Write;
|
||||
if let Ok(mut f) = std::fs::OpenOptions::new().write(true).open("/dev/kmsg") {
|
||||
let _ = writeln!(f, "KATA-HOOK-DEBUG: {msg}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A simple wrapper over `oci::Hook` to provide `Hash, Eq`.
|
||||
///
|
||||
/// The `oci::Hook` is auto-generated from protobuf source file, which doesn't implement `Hash, Eq`.
|
||||
@@ -127,11 +137,30 @@ impl HookStates {
|
||||
Err(std::io::Error::other("execute hook fail point injection"))
|
||||
});
|
||||
info!(sl!(), "execute hook {:?}", hook);
|
||||
kmsg_debug(&format!(
|
||||
"run path={} args={:?} state.pid={:?} state.bundle={:?}",
|
||||
hook.path().display(),
|
||||
hook.args(),
|
||||
state.as_ref().map(|s| s.pid),
|
||||
state.as_ref().map(|s| s.bundle.clone()),
|
||||
));
|
||||
|
||||
self.states.insert(hook.into(), HookState::Pending);
|
||||
|
||||
let executor = HookExecutor::new(hook)?;
|
||||
let mut job = executor.spawn(state.as_ref())?;
|
||||
let executor = match HookExecutor::new(hook) {
|
||||
Ok(e) => e,
|
||||
Err(e) => {
|
||||
kmsg_debug(&format!("new() failed for {}: {e}", hook.path().display()));
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
let mut job = match executor.spawn(state.as_ref()) {
|
||||
Ok(j) => j,
|
||||
Err(e) => {
|
||||
kmsg_debug(&format!("spawn failed for {}: {e}", hook.path().display()));
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
let communicate_result = job
|
||||
.communicate()?
|
||||
@@ -153,14 +182,20 @@ impl HookStates {
|
||||
Ok((ref stdout, ref stderr)) => {
|
||||
if !stderr.is_empty() {
|
||||
error!(sl!(), "hook {} stderr: {}", hook.path().display(), stderr);
|
||||
kmsg_debug(&format!("{} stderr: {}", hook.path().display(), stderr));
|
||||
}
|
||||
if !stdout.is_empty() {
|
||||
info!(sl!(), "hook {} stdout: {}", hook.path().display(), stdout);
|
||||
kmsg_debug(&format!("{} stdout: {}", hook.path().display(), stdout));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
executor.wait_and_check(&mut job)?;
|
||||
if let Err(e) = executor.wait_and_check(&mut job) {
|
||||
kmsg_debug(&format!("exit-check failed for {}: {e}", hook.path().display()));
|
||||
return Err(e);
|
||||
}
|
||||
kmsg_debug(&format!("{} finished OK", hook.path().display()));
|
||||
info!(sl!(), "hook {} finished", hook.path().display());
|
||||
self.states.insert(hook.into(), HookState::Done);
|
||||
|
||||
@@ -185,6 +220,7 @@ impl HookStates {
|
||||
if let Err(e) = self.execute_hook(hook, state.clone()) {
|
||||
// Ignore error and try next hook, the caller should retry.
|
||||
error!(sl!(), "hook {} failed: {}", hook.path().display(), e);
|
||||
kmsg_debug(&format!("hook {} failed: {e}", hook.path().display()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user