From cfc8c394468082ebac3cbb436c4b9789a03bdc8d Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 23 Sep 2019 11:36:52 -0700 Subject: [PATCH] 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 Signed-off-by: Sebastien Boeuf --- vhost_user_backend/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vhost_user_backend/src/lib.rs b/vhost_user_backend/src/lib.rs index 716c77f08..5b9a5c6c8 100644 --- a/vhost_user_backend/src/lib.rs +++ b/vhost_user_backend/src/lib.rs @@ -85,10 +85,18 @@ pub trait VhostUserBackend: Send + Sync + 'static { ) -> result::Result; /// Get virtio device configuration. - fn get_config(&self, offset: u32, size: u32) -> Vec; + /// A default implementation is provided as we cannot expect all backends + /// to implement this function. + fn get_config(&self, offset: u32, size: u32) -> Vec { + 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