Skip to content

Commit

Permalink
[vsock] try epoll_modify before epoll_register in recv_pkt
Browse files Browse the repository at this point in the history
in this context, epoll listener can be already registered via other TX
event, so let it try epoll_modify first to avoid 'silent' failure which
possibly drops packets.

Signed-off-by: Jeongik Cha <jeongik@google.com>
  • Loading branch information
ikicha committed Oct 27, 2023
1 parent 09e9da3 commit 13940d4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions vhost-device-vsock/src/vsock_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,21 @@ impl<S: AsRawFd + Read + Write> VsockConnection<S> {
pkt.set_op(VSOCK_OP_RW).set_len(read_cnt as u32);

// Re-register the stream file descriptor for read and write events
VhostUserVsockThread::epoll_register(
if VhostUserVsockThread::epoll_modify(
self.epoll_fd,
self.stream.as_raw_fd(),
epoll::Events::EPOLLIN | epoll::Events::EPOLLOUT,
)?;
)
.is_err()
{
if let Err(e) = VhostUserVsockThread::epoll_register(
self.epoll_fd,
self.stream.as_raw_fd(),
epoll::Events::EPOLLIN | epoll::Events::EPOLLOUT,
) {
info!("epoll_register failed: {:?}, but proceed further.", e);
}
};
}

// Update the rx_cnt with the amount of data in the vsock packet.
Expand Down Expand Up @@ -683,8 +693,7 @@ mod tests {
conn_local.stream.write_all(b"hello").unwrap();
conn_local.rx_queue.enqueue(RxOps::Rw);
let op_zero_read = conn_local.recv_pkt(&mut pkt);
// below error due to epoll add
assert!(op_zero_read.is_err());
assert!(op_zero_read.is_ok());
assert_eq!(pkt.op(), VSOCK_OP_RW);
assert!(!conn_local.rx_queue.pending_rx());
assert_eq!(pkt.len(), 5);
Expand Down

0 comments on commit 13940d4

Please sign in to comment.