devices: improve failure logging for snapshotting.

A device failing to wake up is a pretty generic error. This CL adds the
device's debug label so it's easier to understand which device is
failing.

BUG=None
TEST=builds

Change-Id: I35d67cd356b95f3b4875ae1fe3bf358c0cc329fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5271324
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
This commit is contained in:
Noah Gold 2024-02-05 18:21:44 -08:00 committed by crosvm LUCI
parent 94a580d8fb
commit 87cfdaca23
2 changed files with 26 additions and 6 deletions

View file

@ -1132,7 +1132,10 @@ impl Suspendable for VirtioPciDevice {
if let Some(queues) = self.device.virtio_sleep()? {
anyhow::ensure!(
self.device_activated,
"unactivated device returned queues on sleep"
format!(
"unactivated device {} returned queues on sleep",
self.debug_label()
),
);
self.sleep_state = Some(SleepState::Active {
activated_queues: queues,
@ -1140,7 +1143,10 @@ impl Suspendable for VirtioPciDevice {
} else {
anyhow::ensure!(
!self.device_activated,
"activated device didn't return queues on sleep"
format!(
"activated device {} didn't return queues on sleep",
self.debug_label()
),
);
self.sleep_state = Some(SleepState::Inactive);
}
@ -1158,9 +1164,12 @@ impl Suspendable for VirtioPciDevice {
// If the device is already awake, we should not request it to wake again.
}
Some(SleepState::Inactive) => {
self.device
.virtio_wake(None)
.expect("virtio_wake failed, can't recover");
self.device.virtio_wake(None).with_context(|| {
format!(
"virtio_wake failed for {}, can't recover",
self.debug_label(),
)
})?;
}
Some(SleepState::Active { activated_queues }) => {
self.device
@ -1171,7 +1180,12 @@ impl Suspendable for VirtioPciDevice {
.expect("interrupt missing for already active queues"),
activated_queues,
)))
.expect("virtio_wake failed, can't recover");
.with_context(|| {
format!(
"virtio_wake failed for {}, can't recover",
self.debug_label(),
)
})?;
}
};
Ok(())

View file

@ -2039,6 +2039,7 @@ fn do_snapshot(
let snapshot_writer = SnapshotWriter::new(snapshot_path)?;
// Snapshot Vcpus
info!("VCPUs snapshotting...");
let (send_chan, recv_chan) = mpsc::channel();
kick_vcpus(VcpuControl::Snapshot(
snapshot_writer.add_namespace("vcpu")?,
@ -2051,14 +2052,18 @@ fn do_snapshot(
.context("Failed to recv Vcpu snapshot response")?
.context("Failed to snapshot Vcpu")?;
}
info!("VCPUs snapshotted.");
// Snapshot irqchip
info!("Snapshotting irqchip...");
let irqchip_snap = snapshot_irqchip()?;
snapshot_writer
.write_fragment("irqchip", &irqchip_snap)
.context("Failed to write irqchip state")?;
info!("Snapshotted irqchip.");
// Snapshot devices
info!("Devices snapshotting...");
device_control_tube
.send(&DeviceControlCommand::SnapshotDevices { snapshot_writer })
.context("send command to devices control socket")?;
@ -2068,6 +2073,7 @@ fn do_snapshot(
if !matches!(resp, VmResponse::Ok) {
bail!("unexpected SnapshotDevices response: {resp}");
}
info!("Devices snapshotted.");
Ok(())
}