@@ -621,68 +621,75 @@ impl VhostUserVsockThread {
621
621
None => return Err ( Error :: NoMemoryConfigured ) ,
622
622
} ;
623
623
624
- while let Some ( mut avail_desc) = vring
625
- . get_mut ( )
626
- . get_queue_mut ( )
627
- . iter ( atomic_mem. memory ( ) )
628
- . map_err ( |_| Error :: IterateQueue ) ?
629
- . next ( )
630
- {
631
- used_any = true ;
632
- let mem = atomic_mem. clone ( ) . memory ( ) ;
633
-
634
- let head_idx = avail_desc. head_index ( ) ;
635
- let pkt = match VsockPacket :: from_tx_virtq_chain (
636
- mem. deref ( ) ,
637
- & mut avail_desc,
638
- self . tx_buffer_size ,
639
- ) {
640
- Ok ( pkt) => pkt,
641
- Err ( e) => {
642
- dbg ! ( "vsock: error reading TX packet: {:?}" , e) ;
643
- continue ;
644
- }
645
- } ;
646
-
647
- if self . thread_backend . send_pkt ( & pkt) . is_err ( ) {
648
- vring
649
- . get_mut ( )
650
- . get_queue_mut ( )
651
- . iter ( mem)
652
- . unwrap ( )
653
- . go_to_previous_position ( ) ;
654
- break ;
655
- }
624
+ let mut vring_mut = vring. get_mut ( ) ;
625
+
626
+ let queue = vring_mut. get_queue_mut ( ) ;
656
627
657
- // TODO: Check if the protocol requires read length to be correct
658
- let used_len = 0 ;
628
+ let mut iter_has_elemnt = true ;
629
+ while iter_has_elemnt {
630
+ let queue_iter = queue
631
+ . iter ( atomic_mem. memory ( ) )
632
+ . map_err ( |_| Error :: IterateQueue ) ?;
659
633
660
- let vring = vring. clone ( ) ;
661
- let event_idx = self . event_idx ;
634
+ iter_has_elemnt = false ;
635
+ for mut avail_desc in queue_iter {
636
+ iter_has_elemnt = true ;
637
+ used_any = true ;
638
+ let mem = atomic_mem. clone ( ) . memory ( ) ;
662
639
663
- self . pool . spawn_ok ( async move {
664
- if event_idx {
665
- if vring. add_used ( head_idx, used_len as u32 ) . is_err ( ) {
666
- warn ! ( "Could not return used descriptors to ring" ) ;
640
+ let head_idx = avail_desc. head_index ( ) ;
641
+ let pkt = match VsockPacket :: from_tx_virtq_chain (
642
+ mem. deref ( ) ,
643
+ & mut avail_desc,
644
+ self . tx_buffer_size ,
645
+ ) {
646
+ Ok ( pkt) => pkt,
647
+ Err ( e) => {
648
+ dbg ! ( "vsock: error reading TX packet: {:?}" , e) ;
649
+ continue ;
667
650
}
668
- match vring. needs_notification ( ) {
669
- Err ( _) => {
670
- warn ! ( "Could not check if queue needs to be notified" ) ;
671
- vring. signal_used_queue ( ) . unwrap ( ) ;
651
+ } ;
652
+
653
+ if self . thread_backend . send_pkt ( & pkt) . is_err ( ) {
654
+ vring
655
+ . get_mut ( )
656
+ . get_queue_mut ( )
657
+ . iter ( mem)
658
+ . unwrap ( )
659
+ . go_to_previous_position ( ) ;
660
+ break ;
661
+ }
662
+
663
+ // TODO: Check if the protocol requires read length to be correct
664
+ let used_len = 0 ;
665
+
666
+ let vring = vring. clone ( ) ;
667
+ let event_idx = self . event_idx ;
668
+
669
+ self . pool . spawn_ok ( async move {
670
+ if event_idx {
671
+ if vring. add_used ( head_idx, used_len as u32 ) . is_err ( ) {
672
+ warn ! ( "Could not return used descriptors to ring" ) ;
672
673
}
673
- Ok ( needs_notification) => {
674
- if needs_notification {
674
+ match vring. needs_notification ( ) {
675
+ Err ( _) => {
676
+ warn ! ( "Could not check if queue needs to be notified" ) ;
675
677
vring. signal_used_queue ( ) . unwrap ( ) ;
676
678
}
679
+ Ok ( needs_notification) => {
680
+ if needs_notification {
681
+ vring. signal_used_queue ( ) . unwrap ( ) ;
682
+ }
683
+ }
677
684
}
685
+ } else {
686
+ if vring. add_used ( head_idx, used_len as u32 ) . is_err ( ) {
687
+ warn ! ( "Could not return used descriptors to ring" ) ;
688
+ }
689
+ vring. signal_used_queue ( ) . unwrap ( ) ;
678
690
}
679
- } else {
680
- if vring. add_used ( head_idx, used_len as u32 ) . is_err ( ) {
681
- warn ! ( "Could not return used descriptors to ring" ) ;
682
- }
683
- vring. signal_used_queue ( ) . unwrap ( ) ;
684
- }
685
- } ) ;
691
+ } ) ;
692
+ }
686
693
}
687
694
688
695
Ok ( used_any)
0 commit comments