@@ -47,81 +47,82 @@ where
47
47
const PROCESS_EVQ : u32 = 3 ;
48
48
const PROCESS_NOTIFY_BACKEND : u32 = 4 ;
49
49
50
- pub fn handle_rxq_event ( & mut self , evset : EventSet ) -> bool {
50
+ pub fn handle_rxq_event ( & mut self , evset : EventSet ) {
51
51
if evset != EventSet :: IN {
52
52
warn ! ( "vsock: rxq unexpected event {:?}" , evset) ;
53
53
METRICS . rx_queue_event_fails . inc ( ) ;
54
- return false ;
54
+ return ;
55
55
}
56
56
57
- let mut raise_irq = false ;
58
57
if let Err ( err) = self . queue_events [ RXQ_INDEX ] . read ( ) {
59
58
error ! ( "Failed to get vsock rx queue event: {:?}" , err) ;
60
59
METRICS . rx_queue_event_fails . inc ( ) ;
61
60
} 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
+ }
65
65
METRICS . rx_queue_event_count . inc ( ) ;
66
66
}
67
- raise_irq
68
67
}
69
68
70
- pub fn handle_txq_event ( & mut self , evset : EventSet ) -> bool {
69
+ pub fn handle_txq_event ( & mut self , evset : EventSet ) {
71
70
if evset != EventSet :: IN {
72
71
warn ! ( "vsock: txq unexpected event {:?}" , evset) ;
73
72
METRICS . tx_queue_event_fails . inc ( ) ;
74
- return false ;
73
+ return ;
75
74
}
76
75
77
- let mut raise_irq = false ;
78
76
if let Err ( err) = self . queue_events [ TXQ_INDEX ] . read ( ) {
79
77
error ! ( "Failed to get vsock tx queue event: {:?}" , err) ;
80
78
METRICS . tx_queue_event_fails . inc ( ) ;
81
79
} 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
+ }
85
84
METRICS . tx_queue_event_count . inc ( ) ;
86
85
// The backend may have queued up responses to the packets we sent during
87
86
// TX queue processing. If that happened, we need to fetch those responses
88
87
// 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" ) ;
91
91
}
92
92
}
93
- raise_irq
94
93
}
95
94
96
- pub fn handle_evq_event ( & mut self , evset : EventSet ) -> bool {
95
+ pub fn handle_evq_event ( & mut self , evset : EventSet ) {
97
96
if evset != EventSet :: IN {
98
97
warn ! ( "vsock: evq unexpected event {:?}" , evset) ;
99
98
METRICS . ev_queue_event_fails . inc ( ) ;
100
- return false ;
99
+ return ;
101
100
}
102
101
103
102
if let Err ( err) = self . queue_events [ EVQ_INDEX ] . read ( ) {
104
103
error ! ( "Failed to consume vsock evq event: {:?}" , err) ;
105
104
METRICS . ev_queue_event_fails . inc ( ) ;
106
105
}
107
- false
108
106
}
109
107
110
108
/// 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 > {
112
110
self . backend . notify ( evset) ;
113
111
// After the backend has been kicked, it might've freed up some resources, so we
114
112
// can attempt to send it more data to process.
115
113
// In particular, if `self.backend.send_pkt()` halted the TX queue processing (by
116
114
// returning an error) at some point in the past, now is the time to try walking the
117
115
// 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" ) ;
123
123
}
124
- Ok ( raise_irq)
124
+
125
+ Ok ( ( ) )
125
126
}
126
127
127
128
fn register_runtime_events ( & self , ops : & mut EventOps ) {
@@ -189,19 +190,14 @@ where
189
190
let evset = event. event_set ( ) ;
190
191
191
192
if self . is_activated ( ) {
192
- let mut raise_irq = false ;
193
193
match source {
194
194
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 ( ) ,
199
199
_ => warn ! ( "Unexpected vsock event received: {:?}" , source) ,
200
200
} ;
201
- if raise_irq {
202
- self . signal_used_queue ( source as usize )
203
- . expect ( "vsock: Could not trigger device interrupt" ) ;
204
- }
205
201
} else {
206
202
warn ! (
207
203
"Vsock: The device is not yet activated. Spurious event received: {:?}" ,
@@ -309,7 +305,9 @@ mod tests {
309
305
let mut ctx = test_ctx. create_event_handler_context ( ) ;
310
306
ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
311
307
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( ) ) ;
313
311
}
314
312
}
315
313
@@ -370,7 +368,9 @@ mod tests {
370
368
let mut ctx = test_ctx. create_event_handler_context ( ) ;
371
369
ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
372
370
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( ) ) ;
374
374
}
375
375
}
376
376
@@ -381,7 +381,9 @@ mod tests {
381
381
let test_ctx = TestContext :: new ( ) ;
382
382
let mut ctx = test_ctx. create_event_handler_context ( ) ;
383
383
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( ) ) ;
385
387
}
386
388
}
387
389
0 commit comments