@@ -25,8 +25,9 @@ use super::{
25
25
VIRTIO_BALLOON_S_SWAP_OUT ,
26
26
} ;
27
27
use crate :: devices:: virtio:: balloon:: BalloonError ;
28
+ use crate :: devices:: virtio:: device:: ActiveState ;
28
29
use crate :: devices:: virtio:: generated:: virtio_config:: VIRTIO_F_VERSION_1 ;
29
- use crate :: devices:: virtio:: transport:: mmio :: { IrqTrigger , IrqType } ;
30
+ use crate :: devices:: virtio:: transport:: { VirtioInterrupt , VirtioInterruptType } ;
30
31
use crate :: logger:: IncMetric ;
31
32
use crate :: utils:: u64_to_usize;
32
33
use crate :: vstate:: memory:: { Address , ByteValued , Bytes , GuestAddress , GuestMemoryMmap } ;
@@ -259,7 +260,7 @@ impl Balloon {
259
260
260
261
pub ( crate ) fn process_inflate ( & mut self ) -> Result < ( ) , BalloonError > {
261
262
// This is safe since we checked in the event handler that the device is activated.
262
- let ( mem, _ ) = self . device_state . active_state ( ) . unwrap ( ) ;
263
+ let mem = & self . device_state . active_state ( ) . unwrap ( ) . mem ;
263
264
METRICS . inflate_count . inc ( ) ;
264
265
265
266
let queue = & mut self . queues [ INFLATE_INDEX ] ;
@@ -340,7 +341,7 @@ impl Balloon {
340
341
}
341
342
342
343
if needs_interrupt {
343
- self . signal_used_queue ( ) ?;
344
+ self . signal_used_queue ( INFLATE_INDEX ) ?;
344
345
}
345
346
346
347
Ok ( ( ) )
@@ -358,15 +359,15 @@ impl Balloon {
358
359
}
359
360
360
361
if needs_interrupt {
361
- self . signal_used_queue ( )
362
+ self . signal_used_queue ( DEFLATE_INDEX )
362
363
} else {
363
364
Ok ( ( ) )
364
365
}
365
366
}
366
367
367
368
pub ( crate ) fn process_stats_queue ( & mut self ) -> Result < ( ) , BalloonError > {
368
369
// This is safe since we checked in the event handler that the device is activated.
369
- let ( mem, _ ) = self . device_state . active_state ( ) . unwrap ( ) ;
370
+ let mem = & self . device_state . active_state ( ) . unwrap ( ) . mem ;
370
371
METRICS . stats_updates_count . inc ( ) ;
371
372
372
373
while let Some ( head) = self . queues [ STATS_INDEX ] . pop ( ) {
@@ -402,9 +403,12 @@ impl Balloon {
402
403
Ok ( ( ) )
403
404
}
404
405
405
- pub ( crate ) fn signal_used_queue ( & self ) -> Result < ( ) , BalloonError > {
406
+ pub ( crate ) fn signal_used_queue ( & self , qidx : usize ) -> Result < ( ) , BalloonError > {
406
407
self . interrupt_trigger ( )
407
- . trigger_irq ( IrqType :: Vring )
408
+ . trigger ( VirtioInterruptType :: Queue (
409
+ qidx. try_into ( )
410
+ . unwrap_or_else ( |_| panic ! ( "balloon: invalid queue id: {qidx}" ) ) ,
411
+ ) )
408
412
. map_err ( |err| {
409
413
METRICS . event_fails . inc ( ) ;
410
414
BalloonError :: InterruptError ( err)
@@ -429,7 +433,7 @@ impl Balloon {
429
433
self . queues [ STATS_INDEX ]
430
434
. add_used ( index, 0 )
431
435
. map_err ( BalloonError :: Queue ) ?;
432
- self . signal_used_queue ( )
436
+ self . signal_used_queue ( STATS_INDEX )
433
437
} else {
434
438
error ! ( "Failed to update balloon stats, missing descriptor." ) ;
435
439
Ok ( ( ) )
@@ -441,7 +445,7 @@ impl Balloon {
441
445
if self . is_activated ( ) {
442
446
self . config_space . num_pages = mib_to_pages ( amount_mib) ?;
443
447
self . interrupt_trigger ( )
444
- . trigger_irq ( IrqType :: Config )
448
+ . trigger ( VirtioInterruptType :: Config )
445
449
. map_err ( BalloonError :: InterruptError )
446
450
} else {
447
451
Err ( BalloonError :: DeviceNotActive )
@@ -552,11 +556,11 @@ impl VirtioDevice for Balloon {
552
556
& self . queue_evts
553
557
}
554
558
555
- fn interrupt_trigger ( & self ) -> & IrqTrigger {
559
+ fn interrupt_trigger ( & self ) -> & dyn VirtioInterrupt {
556
560
self . device_state
557
561
. active_state ( )
558
562
. expect ( "Device is not activated" )
559
- . 1
563
+ . interrupt
560
564
. deref ( )
561
565
}
562
566
@@ -587,14 +591,14 @@ impl VirtioDevice for Balloon {
587
591
fn activate (
588
592
& mut self ,
589
593
mem : GuestMemoryMmap ,
590
- interrupt : Arc < IrqTrigger > ,
594
+ interrupt : Arc < dyn VirtioInterrupt > ,
591
595
) -> Result < ( ) , ActivateError > {
592
596
for q in self . queues . iter_mut ( ) {
593
597
q. initialize ( & mem)
594
598
. map_err ( ActivateError :: QueueMemoryError ) ?;
595
599
}
596
600
597
- self . device_state = DeviceState :: Activated ( ( mem, interrupt) ) ;
601
+ self . device_state = DeviceState :: Activated ( ActiveState { mem, interrupt } ) ;
598
602
if self . activate_evt . write ( 1 ) . is_err ( ) {
599
603
METRICS . activate_fails . inc ( ) ;
600
604
self . device_state = DeviceState :: Inactive ;
@@ -1059,7 +1063,9 @@ pub(crate) mod tests {
1059
1063
assert!( balloon. stats_desc_index. is_some( ) ) ;
1060
1064
balloon. process_stats_timer_event( ) . unwrap( ) ;
1061
1065
assert!( balloon. stats_desc_index. is_none( ) ) ;
1062
- assert!( balloon. interrupt_trigger( ) . has_pending_irq( IrqType :: Vring ) ) ;
1066
+ assert!( balloon. interrupt_trigger( ) . has_pending_interrupt(
1067
+ VirtioInterruptType :: Queue ( STATS_INDEX . try_into( ) . unwrap( ) )
1068
+ ) ) ;
1063
1069
} ) ;
1064
1070
}
1065
1071
}
@@ -1114,8 +1120,10 @@ pub(crate) mod tests {
1114
1120
fn test_num_pages ( ) {
1115
1121
let mut balloon = Balloon :: new ( 0 , true , 0 , false ) . unwrap ( ) ;
1116
1122
// Switch the state to active.
1117
- balloon. device_state =
1118
- DeviceState :: Activated ( ( single_region_mem ( 0x1 ) , default_interrupt ( ) ) ) ;
1123
+ balloon. device_state = DeviceState :: Activated ( ActiveState {
1124
+ mem : single_region_mem ( 0x1 ) ,
1125
+ interrupt : default_interrupt ( ) ,
1126
+ } ) ;
1119
1127
1120
1128
assert_eq ! ( balloon. num_pages( ) , 0 ) ;
1121
1129
assert_eq ! ( balloon. actual_pages( ) , 0 ) ;
0 commit comments