Skip to content

Commit 8ffa614

Browse files
committed
add debug messages
1 parent 0ca53bf commit 8ffa614

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/vmm/src/devices/virtio/block/virtio/device.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::devices::virtio::generated::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
3535
use crate::devices::virtio::queue::{InvalidAvailIdx, Queue};
3636
use crate::devices::virtio::transport::{VirtioInterrupt, VirtioInterruptType};
3737
use crate::impl_device_type;
38-
use crate::logger::{IncMetric, error, warn};
38+
use crate::logger::{IncMetric, debug, error, warn};
3939
use crate::rate_limiter::{BucketUpdate, RateLimiter};
4040
use crate::utils::u64_to_usize;
4141
use crate::vmm_config::RateLimiterConfig;
@@ -474,6 +474,7 @@ impl VirtioBlock {
474474
// This is safe since we checked in the event handler that the device is activated.
475475
let active_state = self.device_state.active_state().unwrap();
476476
let queue = &mut self.queues[0];
477+
let mut processed = 0_u32;
477478

478479
loop {
479480
match engine.pop(&active_state.mem) {
@@ -504,6 +505,7 @@ impl VirtioBlock {
504505
finished.desc_idx, err
505506
)
506507
});
508+
processed = processed.saturating_add(1);
507509
}
508510
}
509511
}
@@ -517,6 +519,10 @@ impl VirtioBlock {
517519
self.metrics.event_fails.inc();
518520
});
519521
}
522+
debug!(
523+
"virtio-block '{}' processed {} io_uring completions",
524+
self.id, processed
525+
);
520526
}
521527

522528
pub fn process_async_completion_event(&mut self) {
@@ -573,21 +579,37 @@ impl VirtioBlock {
573579
/// Prepare device for being snapshotted.
574580
pub fn prepare_save(&mut self) -> Result<(), VirtioBlockError> {
575581
if !self.is_activated() {
582+
debug!(
583+
"virtio-block '{}' prepare_save skipped (device inactive)",
584+
self.id
585+
);
576586
return Ok(());
577587
}
578588

589+
debug!(
590+
"virtio-block '{}' draining outstanding IO before snapshot",
591+
self.id
592+
);
579593
self.drain_and_flush(false)?;
580594
let is_async = matches!(self.disk.file_engine, FileEngine::Async(_));
581595
if is_async {
582596
self.process_async_completion_queue();
583597
if let FileEngine::Async(ref engine) = self.disk.file_engine {
584598
let pending = engine.pending_ops();
599+
debug!(
600+
"virtio-block '{}' prepare_save async pending_ops after drain: {}",
601+
self.id, pending
602+
);
585603
if pending != 0 {
586604
return Err(VirtioBlockError::PendingAsyncOperations(pending));
587605
}
588606
}
589607
}
590608

609+
debug!(
610+
"virtio-block '{}' prepare_save finished; async backend drained",
611+
self.id
612+
);
591613
Ok(())
592614
}
593615
}

src/vmm/src/devices/virtio/block/virtio/io/async_io.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::devices::virtio::block::virtio::{IO_URING_NUM_ENTRIES, PendingRequest
1414
use crate::io_uring::operation::{Cqe, OpCode, Operation};
1515
use crate::io_uring::restriction::Restriction;
1616
use crate::io_uring::{IoUring, IoUringError};
17-
use crate::logger::log_dev_preview_warning;
17+
use crate::logger::{debug, log_dev_preview_warning};
1818
use crate::vstate::memory::{GuestAddress, GuestMemory, GuestMemoryExtension, GuestMemoryMmap};
1919

2020
#[derive(Debug, thiserror::Error, displaydoc::Display)]
@@ -224,12 +224,26 @@ impl AsyncFileEngine {
224224
}
225225

226226
pub fn drain_and_flush(&mut self, discard_cqes: bool) -> Result<(), AsyncIoError> {
227+
let pending_before = self.pending_ops();
228+
debug!(
229+
"AsyncFileEngine draining: pending_ops={} discard_cqes={}",
230+
pending_before, discard_cqes
231+
);
227232
self.drain(discard_cqes)?;
233+
debug!(
234+
"AsyncFileEngine drain complete: pending_ops={} (discard_cqes={})",
235+
self.pending_ops(),
236+
discard_cqes
237+
);
228238

229239
// Sync data out to physical media on host.
230240
// We don't need to call flush first since all the ops are performed through io_uring
231241
// and Rust shouldn't manage any data in its internal buffers.
232242
self.file.sync_all().map_err(AsyncIoError::SyncAll)?;
243+
debug!(
244+
"AsyncFileEngine sync complete: pending_ops={}",
245+
self.pending_ops()
246+
);
233247

234248
Ok(())
235249
}

0 commit comments

Comments
 (0)