diff options
author | Liu Jiang <gerry@linux.alibaba.com> | 2021-02-19 19:21:17 +0800 |
---|---|---|
committer | Sergio Lopez <slp@sinrega.org> | 2021-03-01 12:50:56 +0100 |
commit | 97421f754d8d38508687926b5045c4ed1bd6c107 (patch) | |
tree | 70a5a0dabe8b02522c0d858f2f181a1f5ffd8bd9 | |
parent | a7847dcf7def2b750468297e060d0a55be2a7b62 (diff) | |
download | vmm_vhost-97421f754d8d38508687926b5045c4ed1bd6c107.tar.gz |
Upgrade to rust 2018 edition
Upgrade Cargo.toml to rust edition 2018. Also introduce a helper
feature flag "vhost-user" to simplify code.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
-rw-r--r-- | Cargo.toml | 9 | ||||
-rw-r--r-- | coverage_config_x86_64.json | 2 | ||||
-rw-r--r-- | src/backend.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 62 |
4 files changed, 58 insertions, 17 deletions
@@ -4,13 +4,15 @@ version = "0.1.0" authors = ["Liu Jiang <gerry@linux.alibaba.com>"] repository = "https://github.com/rust-vmm/vhost" license = "Apache-2.0 or BSD-3-Clause" +edition = "2018" [features] default = [] vhost-vsock = [] vhost-kern = ["vm-memory"] -vhost-user-master = [] -vhost-user-slave = [] +vhost-user = [] +vhost-user-master = ["vhost-user"] +vhost-user-slave = ["vhost-user"] [dependencies] bitflags = ">=1.0.1" @@ -18,3 +20,6 @@ libc = ">=0.2.39" vmm-sys-util = ">=0.3.1" vm-memory = { version = "0.2.0", optional = true } + +[dev-dependencies] +vm-memory = { version = "0.2.0", features=["backend-mmap"] } diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index ec91006..e9ac51c 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1 +1 @@ -{"coverage_score": 40.2, "exclude_path": "", "crate_features": "vhost-vsock,vhost-kern,vhost-user-master,vhost-user-slave"} +{"coverage_score": 73.3, "exclude_path": "src/vhost_kern/", "crate_features": ""} diff --git a/src/backend.rs b/src/backend.rs index 9dafef7..89fde50 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -364,7 +364,7 @@ impl<T: VhostBackendMut> VhostBackend for RefCell<T> { } #[cfg(test)] mod tests { - use VringConfigData; + use super::*; struct MockBackend {} @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Alibaba Cloud Computing. All rights reserved. +// Copyright (C) 2019 Alibaba Cloud. All rights reserved. // SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause //! Virtio Vhost Backend Drivers @@ -32,14 +32,8 @@ #![deny(missing_docs)] -#[cfg_attr( - any(feature = "vhost-user-master", feature = "vhost-user-slave"), - macro_use -)] +#[cfg_attr(feature = "vhost-user", macro_use)] extern crate bitflags; -extern crate libc; -#[cfg(feature = "vhost-kern")] -extern crate vm_memory; #[cfg_attr(feature = "vhost-kern", macro_use)] extern crate vmm_sys_util; @@ -48,7 +42,7 @@ pub use backend::*; #[cfg(feature = "vhost-kern")] pub mod vhost_kern; -#[cfg(any(feature = "vhost-user-master", feature = "vhost-user-slave"))] +#[cfg(feature = "vhost-user")] pub mod vhost_user; #[cfg(feature = "vhost-vsock")] pub mod vsock; @@ -80,7 +74,7 @@ pub enum Error { IoctlError(std::io::Error), /// Error from IO subsystem. IOError(std::io::Error), - #[cfg(any(feature = "vhost-user-master", feature = "vhost-user-slave"))] + #[cfg(feature = "vhost-user-master")] /// Error from the vhost-user subsystem. VhostUserProtocol(vhost_user::Error), } @@ -94,20 +88,22 @@ impl std::fmt::Display for Error { Error::InvalidQueue => write!(f, "invalid virtque"), Error::DescriptorTableAddress => write!(f, "invalid virtque descriptor talbe address"), Error::UsedAddress => write!(f, "invalid virtque used talbe address"), - Error::AvailAddress => write!(f, "invalid virtque available talbe address"), + Error::AvailAddress => write!(f, "invalid virtque available table address"), Error::LogAddress => write!(f, "invalid virtque log address"), Error::IOError(e) => write!(f, "IO error: {}", e), #[cfg(feature = "vhost-kern")] Error::VhostOpen(e) => write!(f, "failure in opening vhost file: {}", e), #[cfg(feature = "vhost-kern")] Error::IoctlError(e) => write!(f, "failure in vhost ioctl: {}", e), - #[cfg(any(feature = "vhost-user-master", feature = "vhost-user-slave"))] + #[cfg(feature = "vhost-user-master")] Error::VhostUserProtocol(e) => write!(f, "vhost-user: {}", e), } } } -#[cfg(any(feature = "vhost-user-master", feature = "vhost-user-slave"))] +impl std::error::Error for Error {} + +#[cfg(feature = "vhost-user")] impl std::convert::From<vhost_user::Error> for Error { fn from(err: vhost_user::Error) -> Self { Error::VhostUserProtocol(err) @@ -116,3 +112,43 @@ impl std::convert::From<vhost_user::Error> for Error { /// Result of vhost operations pub type Result<T> = std::result::Result<T, Error>; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_error() { + assert_eq!( + format!("{}", Error::AvailAddress), + "invalid virtque available table address" + ); + assert_eq!( + format!("{}", Error::InvalidOperation), + "invalid vhost operations" + ); + assert_eq!( + format!("{}", Error::InvalidGuestMemory), + "invalid guest memory object" + ); + assert_eq!( + format!("{}", Error::InvalidGuestMemoryRegion), + "invalid guest memory region" + ); + assert_eq!(format!("{}", Error::InvalidQueue), "invalid virtque"); + assert_eq!( + format!("{}", Error::DescriptorTableAddress), + "invalid virtque descriptor talbe address" + ); + assert_eq!( + format!("{}", Error::UsedAddress), + "invalid virtque used talbe address" + ); + assert_eq!( + format!("{}", Error::LogAddress), + "invalid virtque log address" + ); + + assert_eq!(format!("{:?}", Error::AvailAddress), "AvailAddress"); + } +} |