@@ -34,6 +34,7 @@ use super::VsockBackend;
34
34
use super :: device:: { EVQ_INDEX , RXQ_INDEX , TXQ_INDEX , Vsock } ;
35
35
use crate :: devices:: virtio:: device:: VirtioDevice ;
36
36
use crate :: devices:: virtio:: queue:: InvalidAvailIdx ;
37
+ use crate :: devices:: virtio:: vsock:: defs:: VSOCK_NUM_QUEUES ;
37
38
use crate :: devices:: virtio:: vsock:: metrics:: METRICS ;
38
39
use crate :: logger:: IncMetric ;
39
40
@@ -47,49 +48,50 @@ where
47
48
const PROCESS_EVQ : u32 = 3 ;
48
49
const PROCESS_NOTIFY_BACKEND : u32 = 4 ;
49
50
50
- pub fn handle_rxq_event ( & mut self , evset : EventSet ) {
51
+ pub fn handle_rxq_event ( & mut self , evset : EventSet ) -> Vec < u16 > {
52
+ let mut used_queues = Vec :: new ( ) ;
51
53
if evset != EventSet :: IN {
52
54
warn ! ( "vsock: rxq unexpected event {:?}" , evset) ;
53
55
METRICS . rx_queue_event_fails . inc ( ) ;
54
- return ;
56
+ return used_queues ;
55
57
}
56
58
57
59
if let Err ( err) = self . queue_events [ RXQ_INDEX ] . read ( ) {
58
60
error ! ( "Failed to get vsock rx queue event: {:?}" , err) ;
59
61
METRICS . rx_queue_event_fails . inc ( ) ;
60
62
} else if self . backend . has_pending_rx ( ) {
61
63
if self . process_rx ( ) . unwrap ( ) {
62
- self . signal_used_queue ( RXQ_INDEX )
63
- . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
64
+ used_queues. push ( RXQ_INDEX . try_into ( ) . unwrap ( ) ) ;
64
65
}
65
66
METRICS . rx_queue_event_count . inc ( ) ;
66
67
}
68
+ used_queues
67
69
}
68
70
69
- pub fn handle_txq_event ( & mut self , evset : EventSet ) {
71
+ pub fn handle_txq_event ( & mut self , evset : EventSet ) -> Vec < u16 > {
72
+ let mut used_queues = Vec :: new ( ) ;
70
73
if evset != EventSet :: IN {
71
74
warn ! ( "vsock: txq unexpected event {:?}" , evset) ;
72
75
METRICS . tx_queue_event_fails . inc ( ) ;
73
- return ;
76
+ return used_queues ;
74
77
}
75
78
76
79
if let Err ( err) = self . queue_events [ TXQ_INDEX ] . read ( ) {
77
80
error ! ( "Failed to get vsock tx queue event: {:?}" , err) ;
78
81
METRICS . tx_queue_event_fails . inc ( ) ;
79
82
} else {
80
83
if self . process_tx ( ) . unwrap ( ) {
81
- self . signal_used_queue ( TXQ_INDEX )
82
- . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
84
+ used_queues. push ( TXQ_INDEX . try_into ( ) . unwrap ( ) ) ;
83
85
}
84
86
METRICS . tx_queue_event_count . inc ( ) ;
85
87
// The backend may have queued up responses to the packets we sent during
86
88
// TX queue processing. If that happened, we need to fetch those responses
87
89
// and place them into RX buffers.
88
90
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
+ used_queues. push ( RXQ_INDEX . try_into ( ) . unwrap ( ) ) ;
91
92
}
92
93
}
94
+ used_queues
93
95
}
94
96
95
97
pub fn handle_evq_event ( & mut self , evset : EventSet ) {
@@ -106,23 +108,22 @@ where
106
108
}
107
109
108
110
/// Notify backend of new events.
109
- pub fn notify_backend ( & mut self , evset : EventSet ) -> Result < ( ) , InvalidAvailIdx > {
111
+ pub fn notify_backend ( & mut self , evset : EventSet ) -> Result < Vec < u16 > , InvalidAvailIdx > {
112
+ let mut used_queues = Vec :: new ( ) ;
110
113
self . backend . notify ( evset) ;
111
114
// After the backend has been kicked, it might've freed up some resources, so we
112
115
// can attempt to send it more data to process.
113
116
// In particular, if `self.backend.send_pkt()` halted the TX queue processing (by
114
117
// returning an error) at some point in the past, now is the time to try walking the
115
118
// TX queue again.
116
119
if self . process_tx ( ) ? {
117
- self . signal_used_queue ( TXQ_INDEX )
118
- . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
120
+ used_queues. push ( TXQ_INDEX . try_into ( ) . unwrap ( ) ) ;
119
121
}
120
122
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
+ used_queues. push ( RXQ_INDEX . try_into ( ) . unwrap ( ) )
123
124
}
124
125
125
- Ok ( ( ) )
126
+ Ok ( used_queues )
126
127
}
127
128
128
129
fn register_runtime_events ( & self , ops : & mut EventOps ) {
@@ -190,14 +191,25 @@ where
190
191
let evset = event. event_set ( ) ;
191
192
192
193
if self . is_activated ( ) {
193
- match source {
194
- Self :: PROCESS_ACTIVATE => self . handle_activate_event ( ops) ,
194
+ let used_queues = match source {
195
+ Self :: PROCESS_ACTIVATE => {
196
+ self . handle_activate_event ( ops) ;
197
+ Vec :: new ( )
198
+ }
195
199
Self :: PROCESS_RXQ => self . handle_rxq_event ( evset) ,
196
200
Self :: PROCESS_TXQ => self . handle_txq_event ( evset) ,
197
- Self :: PROCESS_EVQ => self . handle_evq_event ( evset) ,
201
+ Self :: PROCESS_EVQ => {
202
+ self . handle_evq_event ( evset) ;
203
+ Vec :: new ( )
204
+ }
198
205
Self :: PROCESS_NOTIFY_BACKEND => self . notify_backend ( evset) . unwrap ( ) ,
199
- _ => warn ! ( "Unexpected vsock event received: {:?}" , source) ,
206
+ _ => {
207
+ warn ! ( "Unexpected vsock event received: {:?}" , source) ;
208
+ Vec :: new ( )
209
+ }
200
210
} ;
211
+ self . signal_used_queues ( & used_queues)
212
+ . expect ( "vsock: Could not trigger device interrupt" ) ;
201
213
} else {
202
214
warn ! (
203
215
"Vsock: The device is not yet activated. Spurious event received: {:?}" ,
0 commit comments