mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Automatically pause VM for coredump
If the VMM is not already paused then pause the VM prior to executing the coredump and then resume it after. If the VM is already paused then the original state is maintained. Signed-off-by: Yi Wang <foxywang@tencent.com>
This commit is contained in:
@@ -36,6 +36,8 @@ pub struct DumpState {
|
||||
pub enum GuestDebuggableError {
|
||||
Coredump(anyhow::Error),
|
||||
CoredumpFile(std::io::Error),
|
||||
Pause(vm_migration::MigratableError),
|
||||
Resume(vm_migration::MigratableError),
|
||||
}
|
||||
|
||||
pub trait GuestDebuggable: vm_migration::Pausable {
|
||||
|
||||
@@ -2607,6 +2607,8 @@ impl GuestDebuggable for Vm {
|
||||
fn coredump(&mut self, destination_url: &str) -> std::result::Result<(), GuestDebuggableError> {
|
||||
event!("vm", "coredumping");
|
||||
|
||||
let mut resume = false;
|
||||
|
||||
#[cfg(feature = "tdx")]
|
||||
{
|
||||
if let Some(ref platform) = self.config.lock().unwrap().platform {
|
||||
@@ -2618,11 +2620,17 @@ impl GuestDebuggable for Vm {
|
||||
}
|
||||
}
|
||||
|
||||
let current_state = self.get_state().unwrap();
|
||||
if current_state != VmState::Paused {
|
||||
return Err(GuestDebuggableError::Coredump(anyhow!(
|
||||
"Trying to coredump while VM is running"
|
||||
)));
|
||||
match self.get_state().unwrap() {
|
||||
VmState::Running => {
|
||||
self.pause().map_err(GuestDebuggableError::Pause)?;
|
||||
resume = true;
|
||||
}
|
||||
VmState::Paused => {}
|
||||
_ => {
|
||||
return Err(GuestDebuggableError::Coredump(anyhow!(
|
||||
"Trying to coredump while VM is not running or paused"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
let coredump_state = self.get_dump_state(destination_url)?;
|
||||
@@ -2643,7 +2651,13 @@ impl GuestDebuggable for Vm {
|
||||
self.memory_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.coredump_iterate_save_mem(&coredump_state)
|
||||
.coredump_iterate_save_mem(&coredump_state)?;
|
||||
|
||||
if resume {
|
||||
self.resume().map_err(GuestDebuggableError::Resume)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user