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