diff options
author | Keiichi Watanabe <keiichiw@chromium.org> | 2021-07-06 00:59:35 +0900 |
---|---|---|
committer | Sergio Lopez <slp@sinrega.org> | 2021-07-07 17:27:32 +0200 |
commit | 12fa07029bb4dd2293900c080d741f33b26b8698 (patch) | |
tree | 5169fc85ea0959585fa52c0b29ed1076d1794271 | |
parent | 4c8a94065c5e4e379a808bbc732b0c39e9175e63 (diff) | |
download | vmm_vhost-12fa07029bb4dd2293900c080d741f33b26b8698.tar.gz |
vhost_user: Move utility function to mod.rs
Move take_single_file() to mod.rs as it is used in both master feature
and slave feature so that we can build the master feature without the
slave feature.
Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
-rw-r--r-- | src/vhost_user/master.rs | 3 | ||||
-rw-r--r-- | src/vhost_user/mod.rs | 11 | ||||
-rw-r--r-- | src/vhost_user/slave_req_handler.rs | 12 |
3 files changed, 13 insertions, 13 deletions
diff --git a/src/vhost_user/master.rs b/src/vhost_user/master.rs index 7933f4d..ff0454a 100644 --- a/src/vhost_user/master.rs +++ b/src/vhost_user/master.rs @@ -14,8 +14,7 @@ use vmm_sys_util::eventfd::EventFd; use super::connection::Endpoint; use super::message::*; -use super::slave_req_handler::take_single_file; -use super::{Error as VhostUserError, Result as VhostUserResult}; +use super::{take_single_file, Error as VhostUserError, Result as VhostUserResult}; use crate::backend::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData}; use crate::{Error, Result}; diff --git a/src/vhost_user/mod.rs b/src/vhost_user/mod.rs index 3467c25..99d6f80 100644 --- a/src/vhost_user/mod.rs +++ b/src/vhost_user/mod.rs @@ -18,6 +18,7 @@ //! Most messages that can be sent via the Unix domain socket implementing vhost-user have an //! equivalent ioctl to the kernel implementation. +use std::fs::File; use std::io::Error as IOError; pub mod message; @@ -175,6 +176,16 @@ pub type Result<T> = std::result::Result<T, Error>; /// Result of request handler. pub type HandlerResult<T> = std::result::Result<T, IOError>; +/// Utility function to take the first element from option of a vector of files. +/// Returns `None` if the vector contains no file or more than one file. +pub(crate) fn take_single_file(files: Option<Vec<File>>) -> Option<File> { + let mut files = files?; + if files.len() != 1 { + return None; + } + Some(files.swap_remove(0)) +} + #[cfg(all(test, feature = "vhost-user-slave"))] mod dummy_slave; diff --git a/src/vhost_user/slave_req_handler.rs b/src/vhost_user/slave_req_handler.rs index 7c3de7d..bbc935e 100644 --- a/src/vhost_user/slave_req_handler.rs +++ b/src/vhost_user/slave_req_handler.rs @@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex}; use super::connection::Endpoint; use super::message::*; use super::slave_fs_cache::SlaveFsCacheReq; -use super::{Error, Result}; +use super::{take_single_file, Error, Result}; /// Services provided to the master by the slave with interior mutability. /// @@ -803,16 +803,6 @@ impl<S: VhostUserSlaveReqHandler> SlaveReqHandler<S> { } } -/// Utility function to take the first element from option of a vector of files. -/// Returns `None` if the vector contains no file or more than one file. -pub(crate) fn take_single_file(files: Option<Vec<File>>) -> Option<File> { - let mut files = files?; - if files.len() != 1 { - return None; - } - Some(files.swap_remove(0)) -} - impl<S: VhostUserSlaveReqHandler> AsRawFd for SlaveReqHandler<S> { fn as_raw_fd(&self) -> RawFd { self.main_sock.as_raw_fd() |