@@ -25,7 +25,7 @@ use super::{
2525} ; 
2626use  crate :: devices:: virtio:: balloon:: BalloonError ; 
2727use  crate :: devices:: virtio:: generated:: virtio_config:: VIRTIO_F_VERSION_1 ; 
28- use  crate :: devices:: virtio:: transport:: mmio :: { IrqTrigger ,   IrqType } ; 
28+ use  crate :: devices:: virtio:: transport:: { VirtioInterrupt ,   VirtioInterruptType } ; 
2929use  crate :: logger:: IncMetric ; 
3030use  crate :: utils:: u64_to_usize; 
3131use  crate :: vstate:: memory:: { Address ,  ByteValued ,  Bytes ,  GuestAddress ,  GuestMemoryMmap } ; 
@@ -339,7 +339,7 @@ impl Balloon {
339339        } 
340340
341341        if  needs_interrupt { 
342-             self . signal_used_queue ( ) ?; 
342+             self . signal_used_queue ( INFLATE_INDEX ) ?; 
343343        } 
344344
345345        Ok ( ( ) ) 
@@ -357,7 +357,7 @@ impl Balloon {
357357        } 
358358
359359        if  needs_interrupt { 
360-             self . signal_used_queue ( ) 
360+             self . signal_used_queue ( DEFLATE_INDEX ) 
361361        }  else  { 
362362            Ok ( ( ) ) 
363363        } 
@@ -401,9 +401,12 @@ impl Balloon {
401401        Ok ( ( ) ) 
402402    } 
403403
404-     pub ( crate )  fn  signal_used_queue ( & self )  -> Result < ( ) ,  BalloonError >  { 
404+     pub ( crate )  fn  signal_used_queue ( & self ,   qidx :   usize )  -> Result < ( ) ,  BalloonError >  { 
405405        self . interrupt_trigger ( ) 
406-             . trigger_irq ( IrqType :: Vring ) 
406+             . trigger ( VirtioInterruptType :: Queue ( 
407+                 qidx. try_into ( ) 
408+                     . unwrap_or_else ( |_| panic ! ( "balloon: invalid queue id: {qidx}" ) ) , 
409+             ) ) 
407410            . map_err ( |err| { 
408411                METRICS . event_fails . inc ( ) ; 
409412                BalloonError :: InterruptError ( err) 
@@ -428,7 +431,7 @@ impl Balloon {
428431            self . queues [ STATS_INDEX ] 
429432                . add_used ( index,  0 ) 
430433                . map_err ( BalloonError :: Queue ) ?; 
431-             self . signal_used_queue ( ) 
434+             self . signal_used_queue ( STATS_INDEX ) 
432435        }  else  { 
433436            error ! ( "Failed to update balloon stats, missing descriptor." ) ; 
434437            Ok ( ( ) ) 
@@ -440,7 +443,7 @@ impl Balloon {
440443        if  self . is_activated ( )  { 
441444            self . config_space . num_pages  = mib_to_pages ( amount_mib) ?; 
442445            self . interrupt_trigger ( ) 
443-                 . trigger_irq ( IrqType :: Config ) 
446+                 . trigger ( VirtioInterruptType :: Config ) 
444447                . map_err ( BalloonError :: InterruptError ) 
445448        }  else  { 
446449            Err ( BalloonError :: DeviceNotActive ) 
@@ -551,7 +554,7 @@ impl VirtioDevice for Balloon {
551554        & self . queue_evts 
552555    } 
553556
554-     fn  interrupt_trigger ( & self )  -> Arc < IrqTrigger >  { 
557+     fn  interrupt_trigger ( & self )  -> Arc < dyn   VirtioInterrupt >  { 
555558        self . device_state 
556559            . active_state ( ) 
557560            . expect ( "Device is not activated" ) 
@@ -585,7 +588,7 @@ impl VirtioDevice for Balloon {
585588    fn  activate ( 
586589        & mut  self , 
587590        mem :  GuestMemoryMmap , 
588-         interrupt :  Arc < IrqTrigger > , 
591+         interrupt :  Arc < dyn   VirtioInterrupt > , 
589592    )  -> Result < ( ) ,  ActivateError >  { 
590593        for  q in  self . queues . iter_mut ( )  { 
591594            q. initialize ( & mem) 
@@ -621,7 +624,7 @@ pub(crate) mod tests {
621624        check_request_completion,  invoke_handler_for_queue_event,  set_request, 
622625    } ; 
623626    use  crate :: devices:: virtio:: queue:: { VIRTQ_DESC_F_NEXT ,  VIRTQ_DESC_F_WRITE } ; 
624-     use  crate :: devices:: virtio:: test_utils:: { VirtQueue ,  default_mem} ; 
627+     use  crate :: devices:: virtio:: test_utils:: { VirtQueue ,  default_interrupt ,   default_mem} ; 
625628    use  crate :: test_utils:: single_region_mem; 
626629    use  crate :: vstate:: memory:: GuestAddress ; 
627630
@@ -798,11 +801,10 @@ pub(crate) mod tests {
798801    fn  test_invalid_request ( )  { 
799802        let  mut  balloon = Balloon :: new ( 0 ,  true ,  0 ,  false ) . unwrap ( ) ; 
800803        let  mem = default_mem ( ) ; 
801-         let  interrupt = Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ; 
802804        // Only initialize the inflate queue to demonstrate invalid request handling. 
803805        let  infq = VirtQueue :: new ( GuestAddress ( 0 ) ,  & mem,  16 ) ; 
804806        balloon. set_queue ( INFLATE_INDEX ,  infq. create_queue ( ) ) ; 
805-         balloon. activate ( mem. clone ( ) ,  interrupt ) . unwrap ( ) ; 
807+         balloon. activate ( mem. clone ( ) ,  default_interrupt ( ) ) . unwrap ( ) ; 
806808
807809        // Fill the second page with non-zero bytes. 
808810        for  i in  0 ..0x1000  { 
@@ -858,10 +860,9 @@ pub(crate) mod tests {
858860    fn  test_inflate ( )  { 
859861        let  mut  balloon = Balloon :: new ( 0 ,  true ,  0 ,  false ) . unwrap ( ) ; 
860862        let  mem = default_mem ( ) ; 
861-         let  interrupt = Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ; 
862863        let  infq = VirtQueue :: new ( GuestAddress ( 0 ) ,  & mem,  16 ) ; 
863864        balloon. set_queue ( INFLATE_INDEX ,  infq. create_queue ( ) ) ; 
864-         balloon. activate ( mem. clone ( ) ,  interrupt ) . unwrap ( ) ; 
865+         balloon. activate ( mem. clone ( ) ,  default_interrupt ( ) ) . unwrap ( ) ; 
865866
866867        // Fill the third page with non-zero bytes. 
867868        for  i in  0 ..0x1000  { 
@@ -929,10 +930,9 @@ pub(crate) mod tests {
929930    fn  test_deflate ( )  { 
930931        let  mut  balloon = Balloon :: new ( 0 ,  true ,  0 ,  false ) . unwrap ( ) ; 
931932        let  mem = default_mem ( ) ; 
932-         let  interrupt = Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ; 
933933        let  defq = VirtQueue :: new ( GuestAddress ( 0 ) ,  & mem,  16 ) ; 
934934        balloon. set_queue ( DEFLATE_INDEX ,  defq. create_queue ( ) ) ; 
935-         balloon. activate ( mem. clone ( ) ,  interrupt ) . unwrap ( ) ; 
935+         balloon. activate ( mem. clone ( ) ,  default_interrupt ( ) ) . unwrap ( ) ; 
936936
937937        let  page_addr = 0x10 ; 
938938
@@ -978,10 +978,9 @@ pub(crate) mod tests {
978978    fn  test_stats ( )  { 
979979        let  mut  balloon = Balloon :: new ( 0 ,  true ,  1 ,  false ) . unwrap ( ) ; 
980980        let  mem = default_mem ( ) ; 
981-         let  interrupt = Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ; 
982981        let  statsq = VirtQueue :: new ( GuestAddress ( 0 ) ,  & mem,  16 ) ; 
983982        balloon. set_queue ( STATS_INDEX ,  statsq. create_queue ( ) ) ; 
984-         balloon. activate ( mem. clone ( ) ,  interrupt ) . unwrap ( ) ; 
983+         balloon. activate ( mem. clone ( ) ,  default_interrupt ( ) ) . unwrap ( ) ; 
985984
986985        let  page_addr = 0x100 ; 
987986
@@ -1057,7 +1056,11 @@ pub(crate) mod tests {
10571056                assert!( balloon. stats_desc_index. is_some( ) ) ; 
10581057                balloon. process_stats_timer_event( ) . unwrap( ) ; 
10591058                assert!( balloon. stats_desc_index. is_none( ) ) ; 
1060-                 assert!( balloon. interrupt_trigger( ) . has_pending_irq( IrqType :: Vring ) ) ; 
1059+                 assert!( 
1060+                     balloon
1061+                         . interrupt_trigger( ) 
1062+                         . has_pending_interrupt( VirtioInterruptType :: Queue ( STATS_INDEX  as  u16 ) ) 
1063+                 ) ; 
10611064            } ) ; 
10621065        } 
10631066    } 
@@ -1066,23 +1069,21 @@ pub(crate) mod tests {
10661069    fn  test_process_balloon_queues ( )  { 
10671070        let  mut  balloon = Balloon :: new ( 0x10 ,  true ,  0 ,  false ) . unwrap ( ) ; 
10681071        let  mem = default_mem ( ) ; 
1069-         let  interrupt = Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ; 
10701072        let  infq = VirtQueue :: new ( GuestAddress ( 0 ) ,  & mem,  16 ) ; 
10711073        let  defq = VirtQueue :: new ( GuestAddress ( 0 ) ,  & mem,  16 ) ; 
10721074
10731075        balloon. set_queue ( INFLATE_INDEX ,  infq. create_queue ( ) ) ; 
10741076        balloon. set_queue ( DEFLATE_INDEX ,  defq. create_queue ( ) ) ; 
10751077
1076-         balloon. activate ( mem,  interrupt ) . unwrap ( ) ; 
1078+         balloon. activate ( mem,  default_interrupt ( ) ) . unwrap ( ) ; 
10771079        balloon. process_virtio_queues ( ) 
10781080    } 
10791081
10801082    #[ test]  
10811083    fn  test_update_stats_interval ( )  { 
10821084        let  mut  balloon = Balloon :: new ( 0 ,  true ,  0 ,  false ) . unwrap ( ) ; 
10831085        let  mem = default_mem ( ) ; 
1084-         let  interrupt = Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ; 
1085-         balloon. activate ( mem,  interrupt) . unwrap ( ) ; 
1086+         balloon. activate ( mem,  default_interrupt ( ) ) . unwrap ( ) ; 
10861087        assert_eq ! ( 
10871088            format!( "{:?}" ,  balloon. update_stats_polling_interval( 1 ) ) , 
10881089            "Err(StatisticsStateChange)" 
@@ -1091,8 +1092,7 @@ pub(crate) mod tests {
10911092
10921093        let  mut  balloon = Balloon :: new ( 0 ,  true ,  1 ,  false ) . unwrap ( ) ; 
10931094        let  mem = default_mem ( ) ; 
1094-         let  interrupt = Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ; 
1095-         balloon. activate ( mem,  interrupt) . unwrap ( ) ; 
1095+         balloon. activate ( mem,  default_interrupt ( ) ) . unwrap ( ) ; 
10961096        assert_eq ! ( 
10971097            format!( "{:?}" ,  balloon. update_stats_polling_interval( 0 ) ) , 
10981098            "Err(StatisticsStateChange)" 
@@ -1113,7 +1113,7 @@ pub(crate) mod tests {
11131113        let  mut  balloon = Balloon :: new ( 0 ,  true ,  0 ,  false ) . unwrap ( ) ; 
11141114        // Switch the state to active. 
11151115        balloon. device_state  =
1116-             DeviceState :: Activated ( ( single_region_mem ( 0x1 ) ,  Arc :: new ( IrqTrigger :: new ( ) . unwrap ( ) ) ) ) ; 
1116+             DeviceState :: Activated ( ( single_region_mem ( 0x1 ) ,  default_interrupt ( ) ) ) ; 
11171117
11181118        assert_eq ! ( balloon. num_pages( ) ,  0 ) ; 
11191119        assert_eq ! ( balloon. actual_pages( ) ,  0 ) ; 
0 commit comments