11// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4+ use std:: ops:: Deref ;
45use std:: sync:: Arc ;
56use std:: time:: Duration ;
67
@@ -26,7 +27,7 @@ use super::{
2627use crate :: devices:: virtio:: balloon:: BalloonError ;
2728use crate :: devices:: virtio:: device:: ActiveState ;
2829use 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 } ;
3031use crate :: logger:: IncMetric ;
3132use crate :: utils:: u64_to_usize;
3233use crate :: vstate:: memory:: { Address , ByteValued , Bytes , GuestAddress , GuestMemoryMmap } ;
@@ -340,7 +341,7 @@ impl Balloon {
340341 }
341342
342343 if needs_interrupt {
343- self . signal_used_queue ( ) ?;
344+ self . signal_used_queue ( INFLATE_INDEX ) ?;
344345 }
345346
346347 Ok ( ( ) )
@@ -358,7 +359,7 @@ impl Balloon {
358359 }
359360
360361 if needs_interrupt {
361- self . signal_used_queue ( )
362+ self . signal_used_queue ( DEFLATE_INDEX )
362363 } else {
363364 Ok ( ( ) )
364365 }
@@ -402,9 +403,12 @@ impl Balloon {
402403 Ok ( ( ) )
403404 }
404405
405- pub ( crate ) fn signal_used_queue ( & self ) -> Result < ( ) , BalloonError > {
406+ pub ( crate ) fn signal_used_queue ( & self , qidx : usize ) -> Result < ( ) , BalloonError > {
406407 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+ ) )
408412 . map_err ( |err| {
409413 METRICS . event_fails . inc ( ) ;
410414 BalloonError :: InterruptError ( err)
@@ -429,7 +433,7 @@ impl Balloon {
429433 self . queues [ STATS_INDEX ]
430434 . add_used ( index, 0 )
431435 . map_err ( BalloonError :: Queue ) ?;
432- self . signal_used_queue ( )
436+ self . signal_used_queue ( STATS_INDEX )
433437 } else {
434438 error ! ( "Failed to update balloon stats, missing descriptor." ) ;
435439 Ok ( ( ) )
@@ -441,7 +445,7 @@ impl Balloon {
441445 if self . is_activated ( ) {
442446 self . config_space . num_pages = mib_to_pages ( amount_mib) ?;
443447 self . interrupt_trigger ( )
444- . trigger_irq ( IrqType :: Config )
448+ . trigger ( VirtioInterruptType :: Config )
445449 . map_err ( BalloonError :: InterruptError )
446450 } else {
447451 Err ( BalloonError :: DeviceNotActive )
@@ -552,12 +556,12 @@ impl VirtioDevice for Balloon {
552556 & self . queue_evts
553557 }
554558
555- fn interrupt_trigger ( & self ) -> & IrqTrigger {
556- & self
557- . device_state
559+ fn interrupt_trigger ( & self ) -> & dyn VirtioInterrupt {
560+ self . device_state
558561 . active_state ( )
559562 . expect ( "Device is not activated" )
560563 . interrupt
564+ . deref ( )
561565 }
562566
563567 fn read_config ( & self , offset : u64 , data : & mut [ u8 ] ) {
@@ -587,7 +591,7 @@ impl VirtioDevice for Balloon {
587591 fn activate (
588592 & mut self ,
589593 mem : GuestMemoryMmap ,
590- interrupt : Arc < IrqTrigger > ,
594+ interrupt : Arc < dyn VirtioInterrupt > ,
591595 ) -> Result < ( ) , ActivateError > {
592596 for q in self . queues . iter_mut ( ) {
593597 q. initialize ( & mem)
@@ -1059,7 +1063,9 @@ pub(crate) mod tests {
10591063 assert!( balloon. stats_desc_index. is_some( ) ) ;
10601064 balloon. process_stats_timer_event( ) . unwrap( ) ;
10611065 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+ ) ) ;
10631069 } ) ;
10641070 }
10651071 }
0 commit comments