pub struct BackendClient {
    connection: Connection<FrontendReq>,
    virtio_features: u64,
    acked_virtio_features: u64,
    acked_protocol_features: u64,
}
Expand description

Client for a vhost-user device. The API is a thin abstraction over the vhost-user protocol.

Fields§

§connection: Connection<FrontendReq>§virtio_features: u64§acked_virtio_features: u64§acked_protocol_features: u64

Implementations§

source§

impl BackendClient

source

pub fn from_stream(sock: SystemStream) -> Self

Create a new instance from a Unix stream socket.

source

fn new(connection: Connection<FrontendReq>) -> Self

Create a new instance.

source

pub fn connect<P: AsRef<Path>>(path: P) -> Result<Self>

Create a new instance.

Will retry as the backend may not be ready to accept the connection.

Arguments
  • path - path of Unix domain socket listener to connect to
source

pub fn get_features(&mut self) -> Result<u64>

Get a bitmask of supported virtio/vhost features.

source

pub fn set_features(&mut self, features: u64) -> Result<()>

Inform the vhost subsystem which features to enable. This should be a subset of supported features from get_features().

source

pub fn set_owner(&self) -> Result<()>

Set the current process as the owner of the vhost backend. This must be run before any other vhost commands.

source

pub fn reset_owner(&self) -> Result<()>

Used to be sent to request disabling all rings This is no longer used.

source

pub fn set_mem_table(&self, regions: &[VhostUserMemoryRegionInfo]) -> Result<()>

Set the memory map regions on the backend so it can translate the vring addresses. In the ancillary data there is an array of file descriptors

source

pub fn set_log_base(&self, base: u64, fd: Option<RawDescriptor>) -> Result<()>

Set base address for page modification logging.

source

pub fn set_log_fd(&self, fd: RawDescriptor) -> Result<()>

Specify an event file descriptor to signal on log write.

source

pub fn set_vring_num(&self, queue_index: usize, num: u16) -> Result<()>

Set the number of descriptors in the vring.

source

pub fn set_vring_addr( &self, queue_index: usize, config_data: &VringConfigData ) -> Result<()>

Set the addresses for a given vring.

source

pub fn set_vring_base(&self, queue_index: usize, base: u16) -> Result<()>

Set the first index to look for available descriptors.

source

pub fn get_vring_base(&self, queue_index: usize) -> Result<u32>

Get the available vring base offset.

source

pub fn set_vring_call(&self, queue_index: usize, event: &Event) -> Result<()>

Set the event to trigger when buffers have been used by the host.

Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling will be used instead of waiting for the call.

source

pub fn set_vring_kick(&self, queue_index: usize, event: &Event) -> Result<()>

Set the event that will be signaled by the guest when buffers are available for the host to process.

Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling should be used instead of waiting for a kick.

source

pub fn set_vring_err(&self, queue_index: usize, event: &Event) -> Result<()>

Set the event that will be signaled by the guest when error happens.

Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data.

source

pub fn sleep(&self) -> Result<()>

Put the device to sleep.

source

pub fn wake(&self) -> Result<()>

Wake the device up.

source

pub fn snapshot(&self) -> Result<Vec<u8>>

Snapshot the device and receive serialized state of the device.

source

pub fn restore( &mut self, data_bytes: &[u8], queue_evts: Option<Vec<Event>> ) -> Result<()>

Restore the device.

source

pub fn get_protocol_features(&self) -> Result<VhostUserProtocolFeatures>

Get the protocol feature bitmask from the underlying vhost implementation.

source

pub fn set_protocol_features( &mut self, features: VhostUserProtocolFeatures ) -> Result<()>

Enable protocol features in the underlying vhost implementation.

source

pub fn get_queue_num(&self) -> Result<u64>

Query how many queues the backend supports.

source

pub fn set_vring_enable(&self, queue_index: usize, enable: bool) -> Result<()>

Signal backend to enable or disable corresponding vring.

Backend must not pass data to/from the ring until ring is enabled by VHOST_USER_SET_VRING_ENABLE with parameter 1, or after it has been disabled by VHOST_USER_SET_VRING_ENABLE with parameter 0.

source

pub fn get_config( &self, offset: u32, size: u32, flags: VhostUserConfigFlags, buf: &[u8] ) -> Result<(VhostUserConfig, VhostUserConfigPayload)>

Fetch the contents of the virtio device configuration space.

source

pub fn set_config( &self, offset: u32, flags: VhostUserConfigFlags, buf: &[u8] ) -> Result<()>

Change the virtio device configuration space. It also can be used for live migration on the destination host to set readonly configuration space fields.

source

pub fn set_backend_req_fd(&self, fd: &dyn AsRawDescriptor) -> Result<()>

Setup backend communication channel.

source

pub fn get_inflight_fd( &self, inflight: &VhostUserInflight ) -> Result<(VhostUserInflight, File)>

Retrieve shared buffer for inflight I/O tracking.

source

pub fn set_inflight_fd( &self, inflight: &VhostUserInflight, fd: RawDescriptor ) -> Result<()>

Set shared buffer for inflight I/O tracking.

source

pub fn get_max_mem_slots(&self) -> Result<u64>

Query the maximum amount of memory slots supported by the backend.

source

pub fn add_mem_region(&self, region: &VhostUserMemoryRegionInfo) -> Result<()>

Add a new guest memory mapping for vhost to use.

source

pub fn remove_mem_region( &self, region: &VhostUserMemoryRegionInfo ) -> Result<()>

Remove a guest memory mapping from vhost.

source

pub fn get_shared_memory_regions(&self) -> Result<Vec<VhostSharedMemoryRegion>>

Gets the shared memory regions used by the device.

source

fn send_request_header( &self, code: FrontendReq, fds: Option<&[RawDescriptor]> ) -> VhostUserResult<VhostUserMsgHeader<FrontendReq>>

source

fn send_request_with_body<T: Sized + AsBytes>( &self, code: FrontendReq, msg: &T, fds: Option<&[RawDescriptor]> ) -> VhostUserResult<VhostUserMsgHeader<FrontendReq>>

source

fn send_request_with_payload<T: Sized + AsBytes>( &self, code: FrontendReq, msg: &T, payload: &[u8], fds: Option<&[RawDescriptor]> ) -> VhostUserResult<VhostUserMsgHeader<FrontendReq>>

source

fn send_fd_for_vring( &self, code: FrontendReq, queue_index: usize, fd: RawDescriptor ) -> VhostUserResult<VhostUserMsgHeader<FrontendReq>>

source

fn recv_reply<T: Sized + FromBytes + AsBytes + Default + VhostUserMsgValidator>( &self, hdr: &VhostUserMsgHeader<FrontendReq> ) -> VhostUserResult<T>

source

fn recv_reply_with_files<T: Sized + AsBytes + FromBytes + Default + VhostUserMsgValidator>( &self, hdr: &VhostUserMsgHeader<FrontendReq> ) -> VhostUserResult<(T, Vec<File>)>

source

fn recv_reply_with_payload<T: Sized + AsBytes + FromBytes + Default + VhostUserMsgValidator>( &self, hdr: &VhostUserMsgHeader<FrontendReq> ) -> VhostUserResult<(T, Vec<u8>, Vec<File>)>

source

fn wait_for_ack( &self, hdr: &VhostUserMsgHeader<FrontendReq> ) -> VhostUserResult<()>

source

fn is_feature_mq_available(&self) -> bool

source

fn new_request_header( &self, request: FrontendReq, size: u32 ) -> VhostUserMsgHeader<FrontendReq>

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.