@@ -46,75 +46,80 @@ where
4646 const PROCESS_EVQ : u32 = 3 ;
4747 const PROCESS_NOTIFY_BACKEND : u32 = 4 ;
4848
49- pub fn handle_rxq_event ( & mut self , evset : EventSet ) -> bool {
49+ pub fn handle_rxq_event ( & mut self , evset : EventSet ) {
5050 if evset != EventSet :: IN {
5151 warn ! ( "vsock: rxq unexpected event {:?}" , evset) ;
5252 METRICS . rx_queue_event_fails . inc ( ) ;
53- return false ;
53+ return ;
5454 }
5555
56- let mut raise_irq = false ;
5756 if let Err ( err) = self . queue_events [ RXQ_INDEX ] . read ( ) {
5857 error ! ( "Failed to get vsock rx queue event: {:?}" , err) ;
5958 METRICS . rx_queue_event_fails . inc ( ) ;
6059 } else if self . backend . has_pending_rx ( ) {
61- raise_irq |= self . process_rx ( ) ;
60+ if self . process_rx ( ) {
61+ self . signal_used_queue ( RXQ_INDEX )
62+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
63+ }
6264 METRICS . rx_queue_event_count . inc ( ) ;
6365 }
64- raise_irq
6566 }
6667
67- pub fn handle_txq_event ( & mut self , evset : EventSet ) -> bool {
68+ pub fn handle_txq_event ( & mut self , evset : EventSet ) {
6869 if evset != EventSet :: IN {
6970 warn ! ( "vsock: txq unexpected event {:?}" , evset) ;
7071 METRICS . tx_queue_event_fails . inc ( ) ;
71- return false ;
72+ return ;
7273 }
7374
74- let mut raise_irq = false ;
7575 if let Err ( err) = self . queue_events [ TXQ_INDEX ] . read ( ) {
7676 error ! ( "Failed to get vsock tx queue event: {:?}" , err) ;
7777 METRICS . tx_queue_event_fails . inc ( ) ;
7878 } else {
79- raise_irq |= self . process_tx ( ) ;
79+ if self . process_tx ( ) {
80+ self . signal_used_queue ( TXQ_INDEX )
81+ . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
82+ }
8083 METRICS . tx_queue_event_count . inc ( ) ;
8184 // The backend may have queued up responses to the packets we sent during
8285 // TX queue processing. If that happened, we need to fetch those responses
8386 // and place them into RX buffers.
84- if self . backend . has_pending_rx ( ) {
85- raise_irq |= self . process_rx ( ) ;
87+ if self . backend . has_pending_rx ( ) && self . process_rx ( ) {
88+ self . signal_used_queue ( RXQ_INDEX )
89+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
8690 }
8791 }
88- raise_irq
8992 }
9093
91- pub fn handle_evq_event ( & mut self , evset : EventSet ) -> bool {
94+ pub fn handle_evq_event ( & mut self , evset : EventSet ) {
9295 if evset != EventSet :: IN {
9396 warn ! ( "vsock: evq unexpected event {:?}" , evset) ;
9497 METRICS . ev_queue_event_fails . inc ( ) ;
95- return false ;
98+ return ;
9699 }
97100
98101 if let Err ( err) = self . queue_events [ EVQ_INDEX ] . read ( ) {
99102 error ! ( "Failed to consume vsock evq event: {:?}" , err) ;
100103 METRICS . ev_queue_event_fails . inc ( ) ;
101104 }
102- false
103105 }
104106
105107 /// Notify backend of new events.
106- pub fn notify_backend ( & mut self , evset : EventSet ) -> bool {
108+ pub fn notify_backend ( & mut self , evset : EventSet ) {
107109 self . backend . notify ( evset) ;
108110 // After the backend has been kicked, it might've freed up some resources, so we
109111 // can attempt to send it more data to process.
110112 // In particular, if `self.backend.send_pkt()` halted the TX queue processing (by
111113 // returning an error) at some point in the past, now is the time to try walking the
112114 // TX queue again.
113- let mut raise_irq = self . process_tx ( ) ;
114- if self . backend . has_pending_rx ( ) {
115- raise_irq |= self . process_rx ( ) ;
115+ if self . process_tx ( ) {
116+ self . signal_used_queue ( TXQ_INDEX )
117+ . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
118+ }
119+ if self . backend . has_pending_rx ( ) && self . process_rx ( ) {
120+ self . signal_used_queue ( RXQ_INDEX )
121+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
116122 }
117- raise_irq
118123 }
119124
120125 fn register_runtime_events ( & self , ops : & mut EventOps ) {
@@ -182,19 +187,14 @@ where
182187 let evset = event. event_set ( ) ;
183188
184189 if self . is_activated ( ) {
185- let mut raise_irq = false ;
186190 match source {
187191 Self :: PROCESS_ACTIVATE => self . handle_activate_event ( ops) ,
188- Self :: PROCESS_RXQ => raise_irq = self . handle_rxq_event ( evset) ,
189- Self :: PROCESS_TXQ => raise_irq = self . handle_txq_event ( evset) ,
190- Self :: PROCESS_EVQ => raise_irq = self . handle_evq_event ( evset) ,
191- Self :: PROCESS_NOTIFY_BACKEND => raise_irq = self . notify_backend ( evset) ,
192+ Self :: PROCESS_RXQ => self . handle_rxq_event ( evset) ,
193+ Self :: PROCESS_TXQ => self . handle_txq_event ( evset) ,
194+ Self :: PROCESS_EVQ => self . handle_evq_event ( evset) ,
195+ Self :: PROCESS_NOTIFY_BACKEND => self . notify_backend ( evset) ,
192196 _ => warn ! ( "Unexpected vsock event received: {:?}" , source) ,
193197 } ;
194- if raise_irq {
195- self . signal_used_queue ( source as usize )
196- . expect ( "vsock: Could not trigger device interrupt" ) ;
197- }
198198 } else {
199199 warn ! (
200200 "Vsock: The device is not yet activated. Spurious event received: {:?}" ,
@@ -302,7 +302,9 @@ mod tests {
302302 let mut ctx = test_ctx. create_event_handler_context ( ) ;
303303 ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
304304
305- assert ! ( !ctx. device. handle_txq_event( EventSet :: IN ) ) ;
305+ let metric_before = METRICS . tx_queue_event_fails . count ( ) ;
306+ ctx. device . handle_txq_event ( EventSet :: IN ) ;
307+ assert_eq ! ( metric_before + 1 , METRICS . tx_queue_event_fails. count( ) ) ;
306308 }
307309 }
308310
@@ -363,7 +365,9 @@ mod tests {
363365 let mut ctx = test_ctx. create_event_handler_context ( ) ;
364366 ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
365367 ctx. device . backend . set_pending_rx ( false ) ;
366- assert ! ( !ctx. device. handle_rxq_event( EventSet :: IN ) ) ;
368+ let metric_before = METRICS . rx_queue_event_fails . count ( ) ;
369+ ctx. device . handle_rxq_event ( EventSet :: IN ) ;
370+ assert_eq ! ( metric_before + 1 , METRICS . rx_queue_event_fails. count( ) ) ;
367371 }
368372 }
369373
@@ -374,7 +378,9 @@ mod tests {
374378 let test_ctx = TestContext :: new ( ) ;
375379 let mut ctx = test_ctx. create_event_handler_context ( ) ;
376380 ctx. device . backend . set_pending_rx ( false ) ;
377- assert ! ( !ctx. device. handle_evq_event( EventSet :: IN ) ) ;
381+ let metric_before = METRICS . ev_queue_event_fails . count ( ) ;
382+ ctx. device . handle_evq_event ( EventSet :: IN ) ;
383+ assert_eq ! ( metric_before + 1 , METRICS . ev_queue_event_fails. count( ) ) ;
378384 }
379385 }
380386
0 commit comments