MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / handle_event

Method handle_event

virtio-devices/src/vsock/device.rs:230–342  ·  view source on GitHub ↗
(
        &mut self,
        _helper: &mut EpollHelper,
        event: &epoll::Event,
    )

Source from the content-addressed store, hash-verified

228 B: VsockBackend,
229{
230 fn handle_event(
231 &mut self,
232 _helper: &mut EpollHelper,
233 event: &epoll::Event,
234 ) -> result::Result<(), EpollHelperError> {
235 let evset = match epoll::Events::from_bits(event.events) {
236 Some(evset) => evset,
237 None => {
238 let evbits = event.events;
239 warn!("epoll: ignoring unknown event set: 0x{evbits:x}");
240 return Ok(());
241 }
242 };
243
244 let ev_type = event.data as u16;
245 match ev_type {
246 RX_QUEUE_EVENT => {
247 debug!("vsock: RX queue event");
248 self.queue_evts[0].read().map_err(|e| {
249 EpollHelperError::HandleEvent(anyhow!("Failed to get RX queue event: {e:?}"))
250 })?;
251 if self.backend.read().unwrap().has_pending_rx() {
252 let needs_notification = self.process_rx().map_err(|e| {
253 EpollHelperError::HandleEvent(anyhow!("Failed to process RX queue: {e:?}"))
254 })?;
255 if needs_notification {
256 self.signal_used_queue(0).map_err(|e| {
257 EpollHelperError::HandleEvent(anyhow!(
258 "Failed to signal used RX queue: {e:?}"
259 ))
260 })?;
261 }
262 }
263 }
264 TX_QUEUE_EVENT => {
265 debug!("vsock: TX queue event");
266 self.queue_evts[1].read().map_err(|e| {
267 EpollHelperError::HandleEvent(anyhow!("Failed to get TX queue event: {e:?}"))
268 })?;
269
270 let needs_notification = self.process_tx().map_err(|e| {
271 EpollHelperError::HandleEvent(anyhow!("Failed to process TX queue: {e:?}"))
272 })?;
273 if needs_notification {
274 self.signal_used_queue(1).map_err(|e| {
275 EpollHelperError::HandleEvent(anyhow!(
276 "Failed to signal used TX queue: {e:?}"
277 ))
278 })?;
279 }
280
281 // The backend may have queued up responses to the packets we sent during TX queue
282 // processing. If that happened, we need to fetch those responses and place them
283 // into RX buffers.
284 if self.backend.read().unwrap().has_pending_rx() {
285 let needs_notification = self.process_rx().map_err(|e| {
286 EpollHelperError::HandleEvent(anyhow!("Failed to process RX queue: {e:?}"))
287 })?;

Callers 7

test_txq_eventFunction · 0.45
test_rxq_eventFunction · 0.45
test_evq_eventFunction · 0.45
test_backend_eventFunction · 0.45
test_unknown_eventFunction · 0.45
signal_txq_eventMethod · 0.45
signal_rxq_eventMethod · 0.45

Calls 7

readMethod · 0.45
has_pending_rxMethod · 0.45
process_rxMethod · 0.45
signal_used_queueMethod · 0.45
process_txMethod · 0.45
notifyMethod · 0.45
writeMethod · 0.45

Tested by 5

test_txq_eventFunction · 0.36
test_rxq_eventFunction · 0.36
test_evq_eventFunction · 0.36
test_backend_eventFunction · 0.36
test_unknown_eventFunction · 0.36