Skip to main content

VsockConnectionManager

Struct VsockConnectionManager 

Source
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_rxrecv_pkt.

Implementations§

Source§

impl VsockConnectionManager

Source

pub fn new() -> VsockConnectionManager

Creates a new empty connection manager.

Source

pub fn set_doorbell(&mut self, doorbell: Arc<dyn Fn() + Send + Sync>)

Installs the doorbell rung when new host→guest RX work appears.

Source

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.

Source

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.

Source

pub fn get_mut( &mut self, id: &VsockConnectionId, ) -> Option<&mut VsockConnection>

Returns a mutable reference to a connection.

Source

pub fn get(&self, id: &VsockConnectionId) -> Option<&VsockConnection>

Returns a reference to a connection.

Source

pub fn enqueue_rw(&mut self, id: VsockConnectionId)

Enqueues a data-available RX op for a connected stream.

Source

pub fn enqueue_reset(&mut self, id: VsockConnectionId)

Enqueues a reset for a connection (e.g., when host stream closes).

Source

pub fn remove(&mut self, id: &VsockConnectionId)

Removes a connection and closes its fd.

Source

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

Source§

fn default() -> VsockConnectionManager

Returns the “default value” for a type. Read more
Source§

impl VsockHostConnections for VsockConnectionManager

Source§

fn fd_for(&self, guest_port: u32, host_port: u32) -> Option<i32>

Returns the host fd for a connection identified by (guest_port, host_port).
Source§

fn mark_connected(&mut self, guest_port: u32, host_port: u32)

Marks a connection as established (called when OP_RESPONSE is received).
Source§

fn remove_connection(&mut self, guest_port: u32, host_port: u32)

Removes a connection and closes the associated fd (called on OP_RST).
Source§

fn update_peer_credit( &mut self, guest_port: u32, host_port: u32, buf_alloc: u32, fwd_cnt: u32, )

Updates peer credit state from an incoming guest packet. Called for every TX packet to keep credit info in sync.
Source§

fn advance_fwd_cnt( &mut self, guest_port: u32, host_port: u32, bytes: u32, ) -> bool

Advances 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)

Enqueues a CreditUpdate to be sent on the next RX fill.
Source§

fn handle_shutdown(&mut self, guest_port: u32, host_port: u32, flags: u32)

Handles a guest-originated OP_SHUTDOWN with its flags bitmask. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more