@@ -97,10 +97,7 @@ impl MmioTransport {
97
97
}
98
98
99
99
fn are_queues_valid ( & self ) -> bool {
100
- self . locked_device ( )
101
- . queues ( )
102
- . iter ( )
103
- . all ( |q| q. is_valid ( & self . mem ) )
100
+ self . locked_device ( ) . queues ( ) . all ( |q| q. is_valid ( & self . mem ) )
104
101
}
105
102
106
103
fn with_queue < U , F > ( & self , d : U , f : F ) -> U
@@ -111,7 +108,7 @@ impl MmioTransport {
111
108
match self
112
109
. locked_device ( )
113
110
. queues ( )
114
- . get ( self . queue_select as usize )
111
+ . nth ( self . queue_select as usize )
115
112
{
116
113
Some ( queue) => f ( queue) ,
117
114
None => d,
@@ -122,7 +119,7 @@ impl MmioTransport {
122
119
if let Some ( queue) = self
123
120
. locked_device ( )
124
121
. queues_mut ( )
125
- . get_mut ( self . queue_select as usize )
122
+ . nth ( self . queue_select as usize )
126
123
{
127
124
f ( queue) ;
128
125
true
@@ -363,6 +360,7 @@ pub(crate) mod tests {
363
360
use utils:: u64_to_usize;
364
361
365
362
use super :: * ;
363
+ use crate :: devices:: virtio:: queue:: { Queue , QueueIter , QueueIterMut } ;
366
364
use crate :: devices:: virtio:: ActivateError ;
367
365
use crate :: vstate:: memory:: { GuestMemoryExtension , GuestMemoryMmap } ;
368
366
@@ -417,12 +415,12 @@ pub(crate) mod tests {
417
415
123
418
416
}
419
417
420
- fn queues ( & self ) -> & [ Queue ] {
421
- & self . queues
418
+ fn queues ( & self ) -> QueueIter {
419
+ self . queues . iter ( )
422
420
}
423
421
424
- fn queues_mut ( & mut self ) -> & mut [ Queue ] {
425
- & mut self . queues
422
+ fn queues_mut ( & mut self ) -> QueueIterMut {
423
+ self . queues . iter_mut ( )
426
424
}
427
425
428
426
fn queue_events ( & self ) -> & [ EventFd ] {
@@ -482,15 +480,23 @@ pub(crate) mod tests {
482
480
assert_eq ! ( d. with_queue( 0 , |q| q. max_size( ) ) , 16 ) ;
483
481
assert ! ( d. with_queue_mut( |q| q. set_size( 16 ) ) ) ;
484
482
assert_eq ! (
485
- d. locked_device( ) . queues( ) [ d. queue_select as usize ] . size( ) ,
483
+ d. locked_device( )
484
+ . queues( )
485
+ . nth( d. queue_select as usize )
486
+ . unwrap( )
487
+ . size( ) ,
486
488
16
487
489
) ;
488
490
489
491
d. queue_select = 1 ;
490
492
assert_eq ! ( d. with_queue( 0 , |q| q. max_size( ) ) , 32 ) ;
491
493
assert ! ( d. with_queue_mut( |q| q. set_size( 16 ) ) ) ;
492
494
assert_eq ! (
493
- d. locked_device( ) . queues( ) [ d. queue_select as usize ] . size( ) ,
495
+ d. locked_device( )
496
+ . queues( )
497
+ . nth( d. queue_select as usize )
498
+ . unwrap( )
499
+ . size( ) ,
494
500
16
495
501
) ;
496
502
@@ -673,43 +679,52 @@ pub(crate) mod tests {
673
679
assert_eq ! ( d. queue_select, 3 ) ;
674
680
675
681
d. queue_select = 0 ;
676
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . size( ) , 0 ) ;
682
+ assert_eq ! ( d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . size( ) , 0 ) ;
677
683
write_le_u32 ( & mut buf[ ..] , 16 ) ;
678
684
d. bus_write ( 0x38 , & buf[ ..] ) ;
679
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . size( ) , 16 ) ;
685
+ assert_eq ! ( d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . size( ) , 16 ) ;
680
686
681
- assert ! ( !d. locked_device( ) . queues( ) [ 0 ] . ready( ) ) ;
687
+ assert ! ( !d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . ready( ) ) ;
682
688
write_le_u32 ( & mut buf[ ..] , 1 ) ;
683
689
d. bus_write ( 0x44 , & buf[ ..] ) ;
684
- assert ! ( d. locked_device( ) . queues( ) [ 0 ] . ready( ) ) ;
690
+ assert ! ( d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . ready( ) ) ;
685
691
686
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . desc_table( ) . 0 , 0 ) ;
692
+ assert_eq ! ( d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . desc_table( ) . 0 , 0 ) ;
687
693
write_le_u32 ( & mut buf[ ..] , 123 ) ;
688
694
d. bus_write ( 0x80 , & buf[ ..] ) ;
689
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . desc_table( ) . 0 , 123 ) ;
695
+ assert_eq ! (
696
+ d. locked_device( ) . queues( ) . nth( 0 ) . unwrap( ) . desc_table( ) . 0 ,
697
+ 123
698
+ ) ;
690
699
d. bus_write ( 0x84 , & buf[ ..] ) ;
691
700
assert_eq ! (
692
- d. locked_device( ) . queues( ) [ 0 ] . desc_table( ) . 0 ,
701
+ d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . desc_table( ) . 0 ,
693
702
123 + ( 123 << 32 )
694
703
) ;
695
704
696
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . avail_ring( ) . 0 , 0 ) ;
705
+ assert_eq ! ( d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . avail_ring( ) . 0 , 0 ) ;
697
706
write_le_u32 ( & mut buf[ ..] , 124 ) ;
698
707
d. bus_write ( 0x90 , & buf[ ..] ) ;
699
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . avail_ring( ) . 0 , 124 ) ;
708
+ assert_eq ! (
709
+ d. locked_device( ) . queues( ) . nth( 0 ) . unwrap( ) . avail_ring( ) . 0 ,
710
+ 124
711
+ ) ;
700
712
d. bus_write ( 0x94 , & buf[ ..] ) ;
701
713
assert_eq ! (
702
- d. locked_device( ) . queues( ) [ 0 ] . avail_ring( ) . 0 ,
714
+ d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . avail_ring( ) . 0 ,
703
715
124 + ( 124 << 32 )
704
716
) ;
705
717
706
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . used_ring( ) . 0 , 0 ) ;
718
+ assert_eq ! ( d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . used_ring( ) . 0 , 0 ) ;
707
719
write_le_u32 ( & mut buf[ ..] , 125 ) ;
708
720
d. bus_write ( 0xa0 , & buf[ ..] ) ;
709
- assert_eq ! ( d. locked_device( ) . queues( ) [ 0 ] . used_ring( ) . 0 , 125 ) ;
721
+ assert_eq ! (
722
+ d. locked_device( ) . queues( ) . nth( 0 ) . unwrap( ) . used_ring( ) . 0 ,
723
+ 125
724
+ ) ;
710
725
d. bus_write ( 0xa4 , & buf[ ..] ) ;
711
726
assert_eq ! (
712
- d. locked_device( ) . queues( ) [ 0 ] . used_ring( ) . 0 ,
727
+ d. locked_device( ) . queues( ) . nth ( 0 ) . unwrap ( ) . used_ring( ) . 0 ,
713
728
125 + ( 125 << 32 )
714
729
) ;
715
730
0 commit comments