@@ -35,7 +35,7 @@ use crate::devices::virtio::generated::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
3535use crate :: devices:: virtio:: queue:: { InvalidAvailIdx , Queue } ;
3636use crate :: devices:: virtio:: transport:: { VirtioInterrupt , VirtioInterruptType } ;
3737use crate :: impl_device_type;
38- use crate :: logger:: { IncMetric , error, warn} ;
38+ use crate :: logger:: { IncMetric , debug , error, warn} ;
3939use crate :: rate_limiter:: { BucketUpdate , RateLimiter } ;
4040use crate :: utils:: u64_to_usize;
4141use 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}
0 commit comments