vhost_user_backend: Provide some default trait implementations

We cannot expect every backend to support GET_CONFIG and SET_CONFIG
commands. That's why this patch adds some default implementations for
the trait VhostUserBackend regarding both get_config() and set_config()
functions.

Signed-off-by: Cathy Zhang <cathy.zhang@intel.com>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-09-23 11:36:52 -07:00
parent 1aab372a06
commit cfc8c39446

View File

@ -85,10 +85,18 @@ pub trait VhostUserBackend: Send + Sync + 'static {
) -> result::Result<u32, io::Error>;
/// Get virtio device configuration.
fn get_config(&self, offset: u32, size: u32) -> Vec<u8>;
/// A default implementation is provided as we cannot expect all backends
/// to implement this function.
fn get_config(&self, offset: u32, size: u32) -> Vec<u8> {
Vec::new()
}
/// Set virtio device configuration.
fn set_config(&mut self, offset: u32, buf: &[u8]) -> result::Result<(), io::Error>;
/// A default implementation is provided as we cannot expect all backends
/// to implement this function.
fn set_config(&mut self, offset: u32, buf: &[u8]) -> result::Result<(), io::Error> {
Ok(())
}
}
/// This structure is the public API the backend is allowed to interact with