diff --git a/src/backend.rs b/src/backend.rs index a2b7d23..f7dddcc 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -18,9 +18,8 @@ //! [VhostUserBackend]: trait.VhostUserBackend.html //! [VhostUserBackendMut]: trait.VhostUserBackendMut.html -use std::io; +use std::io::Result; use std::ops::Deref; -use std::result; use std::sync::{Arc, Mutex, RwLock}; use vhost::vhost_user::message::VhostUserProtocolFeatures; @@ -71,12 +70,12 @@ where /// /// A default implementation is provided as we cannot expect all backends to implement this /// function. - fn set_config(&self, _offset: u32, _buf: &[u8]) -> result::Result<(), io::Error> { + fn set_config(&self, _offset: u32, _buf: &[u8]) -> Result<()> { Ok(()) } /// Update guest memory regions. - fn update_memory(&self, mem: GM) -> result::Result<(), io::Error>; + fn update_memory(&self, mem: GM) -> Result<()>; /// Set handler for communicating with the master by the slave communication channel. /// @@ -115,7 +114,7 @@ where evset: EventSet, vrings: &[V], thread_id: usize, - ) -> result::Result; + ) -> Result; } /// Trait without interior mutability for vhost user backend servers to implement concrete services. @@ -154,12 +153,12 @@ where /// /// 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> { + fn set_config(&mut self, _offset: u32, _buf: &[u8]) -> Result<()> { Ok(()) } /// Update guest memory regions. - fn update_memory(&mut self, mem: GM) -> result::Result<(), io::Error>; + fn update_memory(&mut self, mem: GM) -> Result<()>; /// Set handler for communicating with the master by the slave communication channel. /// @@ -198,7 +197,7 @@ where evset: EventSet, vrings: &[V], thread_id: usize, - ) -> result::Result; + ) -> Result; } impl, V, B> VhostUserBackend for Arc @@ -234,11 +233,11 @@ where self.deref().get_config(offset, size) } - fn set_config(&self, offset: u32, buf: &[u8]) -> Result<(), io::Error> { + fn set_config(&self, offset: u32, buf: &[u8]) -> Result<()> { self.deref().set_config(offset, buf) } - fn update_memory(&self, mem: GM) -> Result<(), io::Error> { + fn update_memory(&self, mem: GM) -> Result<()> { self.deref().update_memory(mem) } @@ -260,7 +259,7 @@ where evset: EventSet, vrings: &[V], thread_id: usize, - ) -> Result { + ) -> Result { self.deref() .handle_event(device_event, evset, vrings, thread_id) } @@ -299,11 +298,11 @@ where self.lock().unwrap().get_config(offset, size) } - fn set_config(&self, offset: u32, buf: &[u8]) -> Result<(), io::Error> { + fn set_config(&self, offset: u32, buf: &[u8]) -> Result<()> { self.lock().unwrap().set_config(offset, buf) } - fn update_memory(&self, mem: GM) -> Result<(), io::Error> { + fn update_memory(&self, mem: GM) -> Result<()> { self.lock().unwrap().update_memory(mem) } @@ -325,7 +324,7 @@ where evset: EventSet, vrings: &[V], thread_id: usize, - ) -> Result { + ) -> Result { self.lock() .unwrap() .handle_event(device_event, evset, vrings, thread_id) @@ -365,11 +364,11 @@ where self.read().unwrap().get_config(offset, size) } - fn set_config(&self, offset: u32, buf: &[u8]) -> Result<(), io::Error> { + fn set_config(&self, offset: u32, buf: &[u8]) -> Result<()> { self.write().unwrap().set_config(offset, buf) } - fn update_memory(&self, mem: GM) -> Result<(), io::Error> { + fn update_memory(&self, mem: GM) -> Result<()> { self.write().unwrap().update_memory(mem) } @@ -391,7 +390,7 @@ where evset: EventSet, vrings: &[V], thread_id: usize, - ) -> Result { + ) -> Result { self.write() .unwrap() .handle_event(device_event, evset, vrings, thread_id) @@ -402,7 +401,6 @@ where pub mod tests { use super::*; use crate::VringRwLock; - use std::io::Error; use std::sync::Mutex; use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap}; @@ -454,7 +452,7 @@ pub mod tests { vec![0xa5u8; 8] } - fn set_config(&mut self, offset: u32, buf: &[u8]) -> Result<(), Error> { + fn set_config(&mut self, offset: u32, buf: &[u8]) -> Result<()> { assert_eq!(offset, 0x200); assert_eq!(buf.len(), 8); assert_eq!(buf, &[0xa5u8; 8]); @@ -462,10 +460,7 @@ pub mod tests { Ok(()) } - fn update_memory( - &mut self, - _atomic_mem: GuestMemoryAtomic, - ) -> Result<(), Error> { + fn update_memory(&mut self, _atomic_mem: GuestMemoryAtomic) -> Result<()> { Ok(()) } @@ -487,7 +482,7 @@ pub mod tests { _evset: EventSet, _vrings: &[VringRwLock], _thread_id: usize, - ) -> Result { + ) -> Result { self.events += 1; Ok(false) diff --git a/src/event_loop.rs b/src/event_loop.rs index 63e7883..d680e8f 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -4,10 +4,9 @@ // SPDX-License-Identifier: Apache-2.0 use std::fmt::{Display, Formatter}; -use std::io; +use std::io::{self, Result}; use std::marker::PhantomData; use std::os::unix::io::{AsRawFd, RawFd}; -use std::result; use vm_memory::bitmap::Bitmap; use vmm_sys_util::epoll::{ControlOperation, Epoll, EpollEvent, EventSet}; @@ -127,12 +126,7 @@ where /// /// When this event is later triggered, the backend implementation of `handle_event` will be /// called. - pub fn register_listener( - &self, - fd: RawFd, - ev_type: EventSet, - data: u64, - ) -> result::Result<(), io::Error> { + pub fn register_listener(&self, fd: RawFd, ev_type: EventSet, data: u64) -> Result<()> { // `data` range [0...num_queues] is reserved for queues and exit event. if data <= self.backend.num_queues() as u64 { Err(io::Error::from_raw_os_error(libc::EINVAL)) @@ -145,12 +139,7 @@ where /// /// If the event is triggered after this function has been called, the event will be silently /// dropped. - pub fn unregister_listener( - &self, - fd: RawFd, - ev_type: EventSet, - data: u64, - ) -> result::Result<(), io::Error> { + pub fn unregister_listener(&self, fd: RawFd, ev_type: EventSet, data: u64) -> Result<()> { // `data` range [0...num_queues] is reserved for queues and exit event. if data <= self.backend.num_queues() as u64 { Err(io::Error::from_raw_os_error(libc::EINVAL)) @@ -159,22 +148,12 @@ where } } - pub(crate) fn register_event( - &self, - fd: RawFd, - ev_type: EventSet, - data: u64, - ) -> result::Result<(), io::Error> { + pub(crate) fn register_event(&self, fd: RawFd, ev_type: EventSet, data: u64) -> Result<()> { self.epoll .ctl(ControlOperation::Add, fd, EpollEvent::new(ev_type, data)) } - pub(crate) fn unregister_event( - &self, - fd: RawFd, - ev_type: EventSet, - data: u64, - ) -> result::Result<(), io::Error> { + pub(crate) fn unregister_event(&self, fd: RawFd, ev_type: EventSet, data: u64) -> Result<()> { self.epoll .ctl(ControlOperation::Delete, fd, EpollEvent::new(ev_type, data)) } diff --git a/src/lib.rs b/src/lib.rs index 403efcc..2fd80af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,6 @@ extern crate log; use std::fmt::{Display, Formatter}; -use std::io; -use std::result; use std::sync::{Arc, Mutex}; use std::thread; @@ -48,7 +46,7 @@ pub enum Error { /// Failed creating vhost-user slave handler. CreateSlaveReqHandler(VhostUserError), /// Failed starting daemon thread. - StartDaemon(io::Error), + StartDaemon(std::io::Error), /// Failed waiting for daemon thread. WaitDaemon(std::boxed::Box), /// Failed handling a vhost-user request. @@ -69,7 +67,7 @@ impl Display for Error { } /// Result of vhost-user daemon operations. -pub type Result = result::Result; +pub type Result = std::result::Result; /// Implement a simple framework to run a vhost-user service daemon. ///