pub struct VsockConnectionManager {
pub backend_rxq: VecDeque<VsockConnectionId>,
/* private fields */
}Expand description
Manages all active host-initiated vsock connections for the HV backend.
Thread-safe: wrapped in Arc<Mutex<>> and shared between the daemon
threads (which call allocate) and vCPU threads (which call poll
methods via VsockHostConnections trait).
Fields§
§backend_rxq: VecDeque<VsockConnectionId>FIFO of connection IDs with pending RX operations.
Consumed by poll_vsock_rx → recv_pkt.
Implementations§
Source§impl VsockConnectionManager
impl VsockConnectionManager
Sourcepub fn new() -> VsockConnectionManager
pub fn new() -> VsockConnectionManager
Creates a new empty connection manager.
Sourcepub fn set_doorbell(&mut self, doorbell: Arc<dyn Fn() + Send + Sync>)
pub fn set_doorbell(&mut self, doorbell: Arc<dyn Fn() + Send + Sync>)
Installs the doorbell rung when new host→guest RX work appears.
Sourcepub fn allocate(
&mut self,
guest_port: u32,
guest_cid: u64,
internal_fd: OwnedFd,
) -> (VsockConnectionId, Receiver<()>)
pub fn allocate( &mut self, guest_port: u32, guest_cid: u64, internal_fd: OwnedFd, ) -> (VsockConnectionId, Receiver<()>)
Allocates a new connection to guest_port, returning a unique ID.
The internal_fd is the internal end of a socketpair; the external
end was returned to the daemon caller. Ownership of internal_fd
transfers to the manager — it will be closed automatically when the
connection is removed.
Enqueues RxOps::REQUEST and pushes to backend_rxq so the next
poll_vsock_rx sends OP_REQUEST to the guest.
Allocates a new connection to guest_port, returning the ID and a
receiver that signals when the connection is established (OP_RESPONSE)
or rejected (OP_RST). The daemon should wait on this receiver before
using the socketpair for data transfer.
Allocates a new connection. Returns the ID and a receiver that fires
when the vCPU thread has injected the OP_REQUEST into guest memory.
The daemon MUST wait on this receiver before using the fd.
Sourcepub fn connected_fds(&self) -> Vec<(VsockConnectionId, i32)>
pub fn connected_fds(&self) -> Vec<(VsockConnectionId, i32)>
Returns a snapshot of all connected (id, raw_fd) pairs for polling.
The caller uses these to libc::read from each fd and, if data is
available, enqueue RxOps::RW and push to backend_rxq.
Sourcepub fn get_mut(
&mut self,
id: &VsockConnectionId,
) -> Option<&mut VsockConnection>
pub fn get_mut( &mut self, id: &VsockConnectionId, ) -> Option<&mut VsockConnection>
Returns a mutable reference to a connection.
Sourcepub fn get(&self, id: &VsockConnectionId) -> Option<&VsockConnection>
pub fn get(&self, id: &VsockConnectionId) -> Option<&VsockConnection>
Returns a reference to a connection.
Sourcepub fn enqueue_rw(&mut self, id: VsockConnectionId)
pub fn enqueue_rw(&mut self, id: VsockConnectionId)
Enqueues a data-available RX op for a connected stream.
Sourcepub fn enqueue_reset(&mut self, id: VsockConnectionId)
pub fn enqueue_reset(&mut self, id: VsockConnectionId)
Enqueues a reset for a connection (e.g., when host stream closes).
Sourcepub fn remove(&mut self, id: &VsockConnectionId)
pub fn remove(&mut self, id: &VsockConnectionId)
Removes a connection and closes its fd.
Sourcepub fn connections_with_pending_rx(&self) -> Vec<VsockConnectionId>
pub fn connections_with_pending_rx(&self) -> Vec<VsockConnectionId>
Returns IDs of connections that have pending RX ops but are NOT
already in the backend_rxq. Used after TX processing to pick up
newly-enqueued ops (e.g., CreditUpdate after guest OP_CREDIT_REQUEST).
Trait Implementations§
Source§impl Default for VsockConnectionManager
impl Default for VsockConnectionManager
Source§fn default() -> VsockConnectionManager
fn default() -> VsockConnectionManager
Source§impl VsockHostConnections for VsockConnectionManager
impl VsockHostConnections for VsockConnectionManager
Source§fn fd_for(&self, guest_port: u32, host_port: u32) -> Option<i32>
fn fd_for(&self, guest_port: u32, host_port: u32) -> Option<i32>
guest_port, host_port).Source§fn mark_connected(&mut self, guest_port: u32, host_port: u32)
fn mark_connected(&mut self, guest_port: u32, host_port: u32)
OP_RESPONSE is received).Source§fn remove_connection(&mut self, guest_port: u32, host_port: u32)
fn remove_connection(&mut self, guest_port: u32, host_port: u32)
OP_RST).Source§fn update_peer_credit(
&mut self,
guest_port: u32,
host_port: u32,
buf_alloc: u32,
fwd_cnt: u32,
)
fn update_peer_credit( &mut self, guest_port: u32, host_port: u32, buf_alloc: u32, fwd_cnt: u32, )
Source§fn advance_fwd_cnt(
&mut self,
guest_port: u32,
host_port: u32,
bytes: u32,
) -> bool
fn advance_fwd_cnt( &mut self, guest_port: u32, host_port: u32, bytes: u32, ) -> bool
fwd_cnt after writing guest data to the host stream.
Returns true if the host has pending RX data as a result (CreditUpdate).Source§fn enqueue_credit_update(&mut self, guest_port: u32, host_port: u32)
fn enqueue_credit_update(&mut self, guest_port: u32, host_port: u32)
CreditUpdate to be sent on the next RX fill.Auto Trait Implementations§
impl !Freeze for VsockConnectionManager
impl !RefUnwindSafe for VsockConnectionManager
impl !UnwindSafe for VsockConnectionManager
impl Send for VsockConnectionManager
impl Sync for VsockConnectionManager
impl Unpin for VsockConnectionManager
impl UnsafeUnpin for VsockConnectionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more