virtio: vhost: user: remove Error type parameter for VhostUserBackend

This type is never set to anything else than `anyhow::Error` and makes
it harder to work with VhostUserBackends as trait objects.

BUG=b:217480043
TEST=cargo build

Change-Id: Iae0be59f9b2bcec1e3fe9b22cbec2f9b99a59020
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3702776
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Morg <morg@chromium.org>
This commit is contained in:
Alexandre Courbot 2022-06-13 14:04:39 +09:00 committed by Chromeos LUCI
parent c12ea3dc0b
commit 2ac78210ef
8 changed files with 7 additions and 30 deletions

View file

@ -130,8 +130,6 @@ impl VhostUserBackend for BlockBackend {
const MAX_QUEUE_NUM: usize = NUM_QUEUES as usize;
const MAX_VRING_LEN: u16 = QUEUE_SIZE;
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.avail_features
}

View file

@ -237,8 +237,6 @@ impl VhostUserBackend for ConsoleBackend {
const MAX_QUEUE_NUM: usize = 2; /* transmit and receive queues */
const MAX_VRING_LEN: u16 = 256;
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.device.avail_features
}

View file

@ -91,8 +91,6 @@ impl VhostUserBackend for CrasSndBackend {
const MAX_QUEUE_NUM: usize = MAX_QUEUE_NUM;
const MAX_VRING_LEN: u16 = MAX_VRING_LEN;
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.avail_features
}

View file

@ -104,8 +104,6 @@ impl VhostUserBackend for FsBackend {
const MAX_QUEUE_NUM: usize = 2; /* worker queue and high priority queue */
const MAX_VRING_LEN: u16 = 1024;
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.avail_features
}

View file

@ -151,8 +151,6 @@ impl VhostUserBackend for GpuBackend {
const MAX_QUEUE_NUM: usize = gpu::QUEUE_SIZES.len();
const MAX_VRING_LEN: u16 = gpu::QUEUE_SIZES[0];
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.gpu.borrow().features() | VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits()
}

View file

@ -155,19 +155,15 @@ pub fn create_guest_memory(
pub trait VhostUserBackend
where
Self: Sized,
Self::Error: std::fmt::Display,
{
const MAX_QUEUE_NUM: usize;
const MAX_VRING_LEN: u16;
/// Error type specific to this backend.
type Error;
/// The set of feature bits that this backend supports.
fn features(&self) -> u64;
/// Acknowledges that this set of features should be enabled.
fn ack_features(&mut self, value: u64) -> std::result::Result<(), Self::Error>;
fn ack_features(&mut self, value: u64) -> anyhow::Result<()>;
/// Returns the set of enabled features.
fn acked_features(&self) -> u64;
@ -176,7 +172,7 @@ where
fn protocol_features(&self) -> VhostUserProtocolFeatures;
/// Acknowledges that this set of protocol features should be enabled.
fn ack_protocol_features(&mut self, _value: u64) -> std::result::Result<(), Self::Error>;
fn ack_protocol_features(&mut self, _value: u64) -> anyhow::Result<()>;
/// Returns the set of enabled protocol features.
fn acked_protocol_features(&self) -> u64;
@ -188,10 +184,7 @@ where
fn write_config(&self, _offset: u64, _data: &[u8]) {}
/// Sets the channel for device-specific communication.
fn set_device_request_channel(
&mut self,
_channel: File,
) -> std::result::Result<(), Self::Error> {
fn set_device_request_channel(&mut self, _channel: File) -> anyhow::Result<()> {
Ok(())
}
@ -205,7 +198,7 @@ where
mem: GuestMemory,
doorbell: Arc<Mutex<Doorbell>>,
kick_evt: Event,
) -> std::result::Result<(), Self::Error>;
) -> anyhow::Result<()>;
/// Indicates that the backend should stop processing requests for virtio queue number `idx`.
fn stop_queue(&mut self, idx: usize);
@ -697,13 +690,11 @@ mod tests {
const MAX_QUEUE_NUM: usize = 16;
const MAX_VRING_LEN: u16 = 256;
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.avail_features
}
fn ack_features(&mut self, value: u64) -> std::result::Result<(), Self::Error> {
fn ack_features(&mut self, value: u64) -> anyhow::Result<()> {
let unrequested_features = value & !self.avail_features;
if unrequested_features != 0 {
bail!(
@ -723,7 +714,7 @@ mod tests {
VhostUserProtocolFeatures::CONFIG
}
fn ack_protocol_features(&mut self, features: u64) -> std::result::Result<(), Self::Error> {
fn ack_protocol_features(&mut self, features: u64) -> anyhow::Result<()> {
let features = VhostUserProtocolFeatures::from_bits(features).ok_or(anyhow!(
"invalid protocol features are given: 0x{:x}",
features
@ -750,7 +741,7 @@ mod tests {
_mem: GuestMemory,
_doorbell: Arc<Mutex<Doorbell>>,
_kick_evt: Event,
) -> std::result::Result<(), Self::Error> {
) -> anyhow::Result<()> {
Ok(())
}

View file

@ -105,8 +105,6 @@ where
const MAX_QUEUE_NUM: usize = MAX_QUEUE_NUM; /* rx, tx, ctrl */
const MAX_VRING_LEN: u16 = MAX_VRING_LEN;
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.avail_features
}

View file

@ -116,8 +116,6 @@ impl VhostUserBackend for WlBackend {
const MAX_QUEUE_NUM: usize = wl::QUEUE_SIZES.len();
const MAX_VRING_LEN: u16 = wl::QUEUE_SIZE;
type Error = anyhow::Error;
fn features(&self) -> u64 {
self.features
}