Expand description

Library for implementing vhost-user device executables.

This crate provides

  • VhostUserDevice trait, which is a collection of methods to handle vhost-user requests, and
  • DeviceRequestHandler struct, which makes a connection to a VMM and starts an event loop.

They are expected to be used as follows:

  1. Define a struct and implement VhostUserDevice for it.
  2. Create a DeviceRequestHandler with the backend struct.
  3. Drive the DeviceRequestHandler::run async fn with an executor.
struct MyBackend {
  /* fields */
}

impl VhostUserDevice for MyBackend {
  /* implement methods */
}

fn main() -> Result<(), Box<dyn Error>> {
  let backend = MyBackend { /* initialize fields */ };
  let handler = DeviceRequestHandler::new(backend);
  let socket = std::path::Path("/path/to/socket");
  let ex = cros_async::Executor::new()?;

  if let Err(e) = ex.run_until(handler.run(socket, &ex)) {
    eprintln!("error happened: {}", e);
  }
  Ok(())
}

Modules§

Structs§

Enums§

Traits§

  • Trait for vhost-user devices. Analogous to the VirtioDevice trait.

Functions§