pub struct VsockConnection {
pub id: VsockConnectionId,
pub internal_fd: OwnedFd,
pub injected_notify: Option<Sender<()>>,
pub guest_cid: u64,
pub connect: bool,
pub rx_queue: RxOps,
pub fwd_cnt: Wrapping<u32>,
pub peer_buf_alloc: u32,
pub peer_fwd_cnt: Wrapping<u32>,
pub rx_cnt: Wrapping<u32>,
/* private fields */
}Expand description
A single host↔guest vsock connection.
Owns the internal end of the socketpair. When this entry is removed from
the manager (or the manager is dropped), OwnedFd::drop closes the fd.
The state machine is implicit:
connect == false: handshake in progressconnect == true: data transfer enabledrx_queuecontainsRxOps::RESET: connection is being torn down
Fields§
§id: VsockConnectionId§internal_fd: OwnedFd§injected_notify: Option<Sender<()>>Fired by vCPU thread’s poll_vsock_rx after OP_REQUEST is written to guest memory. The daemon blocks on this before returning the fd — guarantees the guest will see the OP_REQUEST and respond (RST or RESPONSE) so the daemon’s read won’t hang indefinitely.
guest_cid: u64§connect: boolWhether the connection handshake is complete.
rx_queue: RxOpsPer-connection pending RX operations (bitmask priority queue).
fwd_cnt: Wrapping<u32>Total bytes forwarded from host tx_buf to the actual host stream. Sent to guest in every packet so it knows how much host buffer is free.
peer_buf_alloc: u32Guest’s advertised buffer allocation (extracted from every incoming pkt).
peer_fwd_cnt: Wrapping<u32>Guest’s forwarded count (extracted from every incoming packet).
rx_cnt: Wrapping<u32>Total bytes sent TO the guest via RX virtqueue.
Implementations§
Source§impl VsockConnection
impl VsockConnection
Sourcepub fn new_local_init(
id: VsockConnectionId,
guest_cid: u64,
fd: OwnedFd,
injected_notify: Sender<()>,
) -> VsockConnection
pub fn new_local_init( id: VsockConnectionId, guest_cid: u64, fd: OwnedFd, injected_notify: Sender<()>, ) -> VsockConnection
Creates a new connection for a host-initiated connect (OP_REQUEST).
Sourcepub fn peer_avail_credit(&self) -> usize
pub fn peer_avail_credit(&self) -> usize
Returns the number of bytes the guest can still receive.
peer_buf_alloc - (rx_cnt - peer_fwd_cnt) = total guest buffer minus
bytes currently in-flight (sent but not yet consumed by the guest).
Sourcepub fn update_peer_credit(&mut self, buf_alloc: u32, fwd_cnt: u32)
pub fn update_peer_credit(&mut self, buf_alloc: u32, fwd_cnt: u32)
Updates peer credit state from an incoming guest packet. Also clears
any in-flight CREDIT_REQUEST marker: the peer has just told us the
fresh state, so whatever we asked about is answered.
Sourcepub fn maybe_request_credit(&mut self)
pub fn maybe_request_credit(&mut self)
Enqueues a CREDIT_REQUEST op if peer credit has fallen below half
the peer’s advertised buffer and no request is already in flight.
Call from the RX path after sending data the peer now has to process.
Sending the request proactively — rather than only when credit hits
zero — means we refresh our (possibly stale) view of peer_fwd_cnt
before we actually deplete our window, avoiding a full TX stall.
Sourcepub fn note_credit_request_sent(&mut self)
pub fn note_credit_request_sent(&mut self)
Marks a CREDIT_REQUEST as in-flight without going through the
RxOps queue. Used when the caller emits the request packet directly
in the RW-with-zero-credit fallback path — we still want the pending
flag set so maybe_request_credit doesn’t duplicate us.
Sourcepub fn credit_request_pending(&self) -> bool
pub fn credit_request_pending(&self) -> bool
True iff we’re waiting on the peer for a credit update.
Sourcepub fn mark_peer_no_recv(&mut self)
pub fn mark_peer_no_recv(&mut self)
Peer sent OP_SHUTDOWN with F_RECEIVE. Record the half-close so the
RX injection path stops trying to deliver more RW packets.
Sourcepub const fn peer_no_recv(&self) -> bool
pub const fn peer_no_recv(&self) -> bool
True iff the peer has half-closed its receive side.
Sourcepub const fn accepts_data(&self) -> bool
pub const fn accepts_data(&self) -> bool
Whether we may send more data to the peer. False once the handshake hasn’t completed or the peer has told us it won’t accept more.
Sourcepub fn advance_fwd_cnt(&mut self, bytes: u32)
pub fn advance_fwd_cnt(&mut self, bytes: u32)
Called after data is written to the host stream (from guest OP_RW).
Advances fwd_cnt and enqueues a CreditUpdate if buffer is getting low.
Sourcepub fn record_rx(&mut self, bytes: u32)
pub fn record_rx(&mut self, bytes: u32)
Records bytes sent to the guest and returns the new rx_cnt.
Sourcepub fn mark_credit_sent(&mut self)
pub fn mark_credit_sent(&mut self)
Marks that a CreditUpdate was sent to the guest (syncs last_fwd_cnt).
Auto Trait Implementations§
impl Freeze for VsockConnection
impl RefUnwindSafe for VsockConnection
impl Send for VsockConnection
impl Sync for VsockConnection
impl Unpin for VsockConnection
impl UnsafeUnpin for VsockConnection
impl UnwindSafe for VsockConnection
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