1
1
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
+ use std:: ops:: Deref ;
4
5
use std:: sync:: Arc ;
5
6
use std:: time:: Duration ;
6
7
@@ -26,7 +27,7 @@ use super::{
26
27
use crate :: devices:: virtio:: balloon:: BalloonError ;
27
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 } ;
@@ -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,7 +359,7 @@ 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
}
@@ -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,12 +556,12 @@ impl VirtioDevice for Balloon {
552
556
& self . queue_evts
553
557
}
554
558
555
- fn interrupt_trigger ( & self ) -> & IrqTrigger {
556
- & self
557
- . device_state
559
+ fn interrupt_trigger ( & self ) -> & dyn VirtioInterrupt {
560
+ self . device_state
558
561
. active_state ( )
559
562
. expect ( "Device is not activated" )
560
563
. interrupt
564
+ . deref ( )
561
565
}
562
566
563
567
fn read_config ( & self , offset : u64 , data : & mut [ u8 ] ) {
@@ -587,7 +591,7 @@ 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)
@@ -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
}
0 commit comments