@@ -47,81 +47,82 @@ where
4747 const PROCESS_EVQ : u32 = 3 ;
4848 const PROCESS_NOTIFY_BACKEND : u32 = 4 ;
4949
50- pub fn handle_rxq_event ( & mut self , evset : EventSet ) -> bool {
50+ pub fn handle_rxq_event ( & mut self , evset : EventSet ) {
5151 if evset != EventSet :: IN {
5252 warn ! ( "vsock: rxq unexpected event {:?}" , evset) ;
5353 METRICS . rx_queue_event_fails . inc ( ) ;
54- return false ;
54+ return ;
5555 }
5656
57- let mut raise_irq = false ;
5857 if let Err ( err) = self . queue_events [ RXQ_INDEX ] . read ( ) {
5958 error ! ( "Failed to get vsock rx queue event: {:?}" , err) ;
6059 METRICS . rx_queue_event_fails . inc ( ) ;
6160 } else if self . backend . has_pending_rx ( ) {
62- // OK to unwrap: Only QueueError::InvalidAvailIdx is returned, and we explicitly
63- // want to panic on that one.
64- raise_irq |= self . process_rx ( ) . unwrap ( ) ;
61+ if self . process_rx ( ) . unwrap ( ) {
62+ self . signal_used_queue ( RXQ_INDEX )
63+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
64+ }
6565 METRICS . rx_queue_event_count . inc ( ) ;
6666 }
67- raise_irq
6867 }
6968
70- pub fn handle_txq_event ( & mut self , evset : EventSet ) -> bool {
69+ pub fn handle_txq_event ( & mut self , evset : EventSet ) {
7170 if evset != EventSet :: IN {
7271 warn ! ( "vsock: txq unexpected event {:?}" , evset) ;
7372 METRICS . tx_queue_event_fails . inc ( ) ;
74- return false ;
73+ return ;
7574 }
7675
77- let mut raise_irq = false ;
7876 if let Err ( err) = self . queue_events [ TXQ_INDEX ] . read ( ) {
7977 error ! ( "Failed to get vsock tx queue event: {:?}" , err) ;
8078 METRICS . tx_queue_event_fails . inc ( ) ;
8179 } else {
82- // OK to unwrap: Only QueueError::InvalidAvailIdx is returned, and we explicitly
83- // want to panic on that one.
84- raise_irq |= self . process_tx ( ) . unwrap ( ) ;
80+ if self . process_tx ( ) . unwrap ( ) {
81+ self . signal_used_queue ( TXQ_INDEX )
82+ . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
83+ }
8584 METRICS . tx_queue_event_count . inc ( ) ;
8685 // The backend may have queued up responses to the packets we sent during
8786 // TX queue processing. If that happened, we need to fetch those responses
8887 // and place them into RX buffers.
89- if self . backend . has_pending_rx ( ) {
90- raise_irq |= self . process_rx ( ) . unwrap ( ) ;
88+ if self . backend . has_pending_rx ( ) && self . process_rx ( ) . unwrap ( ) {
89+ self . signal_used_queue ( RXQ_INDEX )
90+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
9191 }
9292 }
93- raise_irq
9493 }
9594
96- pub fn handle_evq_event ( & mut self , evset : EventSet ) -> bool {
95+ pub fn handle_evq_event ( & mut self , evset : EventSet ) {
9796 if evset != EventSet :: IN {
9897 warn ! ( "vsock: evq unexpected event {:?}" , evset) ;
9998 METRICS . ev_queue_event_fails . inc ( ) ;
100- return false ;
99+ return ;
101100 }
102101
103102 if let Err ( err) = self . queue_events [ EVQ_INDEX ] . read ( ) {
104103 error ! ( "Failed to consume vsock evq event: {:?}" , err) ;
105104 METRICS . ev_queue_event_fails . inc ( ) ;
106105 }
107- false
108106 }
109107
110108 /// Notify backend of new events.
111- pub fn notify_backend ( & mut self , evset : EventSet ) -> Result < bool , InvalidAvailIdx > {
109+ pub fn notify_backend ( & mut self , evset : EventSet ) -> Result < ( ) , InvalidAvailIdx > {
112110 self . backend . notify ( evset) ;
113111 // After the backend has been kicked, it might've freed up some resources, so we
114112 // can attempt to send it more data to process.
115113 // In particular, if `self.backend.send_pkt()` halted the TX queue processing (by
116114 // returning an error) at some point in the past, now is the time to try walking the
117115 // TX queue again.
118- // OK to unwrap: Only QueueError::InvalidAvailIdx is returned, and we explicitly
119- // want to panic on that one.
120- let mut raise_irq = self . process_tx ( ) ?;
121- if self . backend . has_pending_rx ( ) {
122- raise_irq |= self . process_rx ( ) ?;
116+ if self . process_tx ( ) ? {
117+ self . signal_used_queue ( TXQ_INDEX )
118+ . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
119+ }
120+ if self . backend . has_pending_rx ( ) && self . process_rx ( ) ? {
121+ self . signal_used_queue ( RXQ_INDEX )
122+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
123123 }
124- Ok ( raise_irq)
124+
125+ Ok ( ( ) )
125126 }
126127
127128 fn register_runtime_events ( & self , ops : & mut EventOps ) {
@@ -189,19 +190,14 @@ where
189190 let evset = event. event_set ( ) ;
190191
191192 if self . is_activated ( ) {
192- let mut raise_irq = false ;
193193 match source {
194194 Self :: PROCESS_ACTIVATE => self . handle_activate_event ( ops) ,
195- Self :: PROCESS_RXQ => raise_irq = self . handle_rxq_event ( evset) ,
196- Self :: PROCESS_TXQ => raise_irq = self . handle_txq_event ( evset) ,
197- Self :: PROCESS_EVQ => raise_irq = self . handle_evq_event ( evset) ,
198- Self :: PROCESS_NOTIFY_BACKEND => raise_irq = self . notify_backend ( evset) . unwrap ( ) ,
195+ Self :: PROCESS_RXQ => self . handle_rxq_event ( evset) ,
196+ Self :: PROCESS_TXQ => self . handle_txq_event ( evset) ,
197+ Self :: PROCESS_EVQ => self . handle_evq_event ( evset) ,
198+ Self :: PROCESS_NOTIFY_BACKEND => self . notify_backend ( evset) . unwrap ( ) ,
199199 _ => warn ! ( "Unexpected vsock event received: {:?}" , source) ,
200200 } ;
201- if raise_irq {
202- self . signal_used_queue ( source as usize )
203- . expect ( "vsock: Could not trigger device interrupt" ) ;
204- }
205201 } else {
206202 warn ! (
207203 "Vsock: The device is not yet activated. Spurious event received: {:?}" ,
@@ -309,7 +305,9 @@ mod tests {
309305 let mut ctx = test_ctx. create_event_handler_context ( ) ;
310306 ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
311307
312- assert ! ( !ctx. device. handle_txq_event( EventSet :: IN ) ) ;
308+ let metric_before = METRICS . tx_queue_event_fails . count ( ) ;
309+ ctx. device . handle_txq_event ( EventSet :: IN ) ;
310+ assert_eq ! ( metric_before + 1 , METRICS . tx_queue_event_fails. count( ) ) ;
313311 }
314312 }
315313
@@ -370,7 +368,9 @@ mod tests {
370368 let mut ctx = test_ctx. create_event_handler_context ( ) ;
371369 ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
372370 ctx. device . backend . set_pending_rx ( false ) ;
373- assert ! ( !ctx. device. handle_rxq_event( EventSet :: IN ) ) ;
371+ let metric_before = METRICS . rx_queue_event_fails . count ( ) ;
372+ ctx. device . handle_rxq_event ( EventSet :: IN ) ;
373+ assert_eq ! ( metric_before + 1 , METRICS . rx_queue_event_fails. count( ) ) ;
374374 }
375375 }
376376
@@ -381,7 +381,9 @@ mod tests {
381381 let test_ctx = TestContext :: new ( ) ;
382382 let mut ctx = test_ctx. create_event_handler_context ( ) ;
383383 ctx. device . backend . set_pending_rx ( false ) ;
384- assert ! ( !ctx. device. handle_evq_event( EventSet :: IN ) ) ;
384+ let metric_before = METRICS . ev_queue_event_fails . count ( ) ;
385+ ctx. device . handle_evq_event ( EventSet :: IN ) ;
386+ assert_eq ! ( metric_before + 1 , METRICS . ev_queue_event_fails. count( ) ) ;
385387 }
386388 }
387389
0 commit comments