summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-09-22 11:27:06 -0700
committerJoel Galenson <jgalenson@google.com>2021-09-22 11:27:06 -0700
commit25c2a16906631c537a1cf398402c430847e6d4b6 (patch)
treed61c753f3a2deb9f1c334c0a593d7a81c76709fa
parent570efe19a5181d0a478be828133716861855054c (diff)
parentd65bd280d9f4e192a884f1761e4b097c11aae6de (diff)
downloadvmm_vhost-25c2a16906631c537a1cf398402c430847e6d4b6.tar.gz
Upgrade rust/vmm_vhost to d65bd280d9f4e192a884f1761e4b097c11aae6de
Test: make Change-Id: I4065eb4385c40bed09ce804ca7343b668f4822e7
-rw-r--r--METADATA6
-rw-r--r--coverage_config_x86_64.json2
-rw-r--r--src/vhost_user/message.rs132
-rw-r--r--src/vhost_user/slave_req_handler.rs13
4 files changed, 80 insertions, 73 deletions
diff --git a/METADATA b/METADATA
index 8d5aa99..f939dcd 100644
--- a/METADATA
+++ b/METADATA
@@ -9,11 +9,11 @@ third_party {
type: GIT
value: "https://chromium.googlesource.com/chromiumos/third_party/rust-vmm/vhost"
}
- version: "fff997dda0625bd6f7c33bc0d79653c91b41b6c7"
+ version: "d65bd280d9f4e192a884f1761e4b097c11aae6de"
license_type: NOTICE
last_upgrade_date {
year: 2021
- month: 8
- day: 9
+ month: 9
+ day: 22
}
}
diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json
index 644f4bc..c3e6939 100644
--- a/coverage_config_x86_64.json
+++ b/coverage_config_x86_64.json
@@ -1 +1 @@
-{"coverage_score": 82.8, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"}
+{"coverage_score": 82.3, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"}
diff --git a/src/vhost_user/message.rs b/src/vhost_user/message.rs
index 76feca2..fc33e1b 100644
--- a/src/vhost_user/message.rs
+++ b/src/vhost_user/message.rs
@@ -223,9 +223,8 @@ bitflags! {
/// Common message header for vhost-user requests and replies.
/// A vhost-user message consists of 3 header fields and an optional payload. All numbers are in the
/// machine native byte order.
-#[allow(safe_packed_borrows)]
#[repr(packed)]
-#[derive(Debug, Clone, Copy, PartialEq)]
+#[derive(Copy)]
pub(super) struct VhostUserMsgHeader<R: Req> {
request: u32,
flags: u32,
@@ -233,6 +232,28 @@ pub(super) struct VhostUserMsgHeader<R: Req> {
_r: PhantomData<R>,
}
+impl<R: Req> Debug for VhostUserMsgHeader<R> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("Point")
+ .field("request", &{ self.request })
+ .field("flags", &{ self.flags })
+ .field("size", &{ self.size })
+ .finish()
+ }
+}
+
+impl<R: Req> Clone for VhostUserMsgHeader<R> {
+ fn clone(&self) -> VhostUserMsgHeader<R> {
+ *self
+ }
+}
+
+impl<R: Req> PartialEq for VhostUserMsgHeader<R> {
+ fn eq(&self, other: &Self) -> bool {
+ self.request == other.request && self.flags == other.flags && self.size == other.size
+ }
+}
+
impl<R: Req> VhostUserMsgHeader<R> {
/// Create a new instance of `VhostUserMsgHeader`.
pub fn new(request: R, flags: u32, size: u32) -> Self {
@@ -249,7 +270,7 @@ impl<R: Req> VhostUserMsgHeader<R> {
/// Get message type.
pub fn get_code(&self) -> R {
// It's safe because R is marked as repr(u32).
- unsafe { std::mem::transmute_copy::<u32, R>(&self.request) }
+ unsafe { std::mem::transmute_copy::<u32, R>(&{ self.request }) }
}
/// Set message type.
@@ -783,49 +804,45 @@ impl VhostUserMsgValidator for VhostUserFSSlaveMsg {
/// Inflight I/O descriptor state for split virtqueues
#[repr(packed)]
-#[derive(Clone, Copy)]
-struct DescStateSplit {
+#[derive(Clone, Copy, Default)]
+pub struct DescStateSplit {
/// Indicate whether this descriptor (only head) is inflight or not.
- inflight: u8,
+ pub inflight: u8,
/// Padding
padding: [u8; 5],
/// List of last batch of used descriptors, only when batching is used for submitting
- next: u16,
+ pub next: u16,
/// Preserve order of fetching available descriptors, only for head descriptor
- counter: u64,
+ pub counter: u64,
}
impl DescStateSplit {
- fn new() -> Self {
- DescStateSplit {
- inflight: 0,
- padding: [0; 5],
- next: 0,
- counter: 0,
- }
+ /// New instance of DescStateSplit struct
+ pub fn new() -> Self {
+ Self::default()
}
}
/// Inflight I/O queue region for split virtqueues
-#[allow(safe_packed_borrows)]
#[repr(packed)]
-struct QueueRegionSplit {
+pub struct QueueRegionSplit {
/// Features flags of this region
- features: u64,
+ pub features: u64,
/// Version of this region
- version: u16,
+ pub version: u16,
/// Number of DescStateSplit entries
- desc_num: u16,
+ pub desc_num: u16,
/// List to track last batch of used descriptors
- last_batch_head: u16,
+ pub last_batch_head: u16,
/// Idx value of used ring
- used_idx: u16,
+ pub used_idx: u16,
/// Pointer to an array of DescStateSplit entries
- desc: u64,
+ pub desc: u64,
}
impl QueueRegionSplit {
- fn new(features: u64, queue_size: u16) -> Self {
+ /// New instance of QueueRegionSplit struct
+ pub fn new(features: u64, queue_size: u16) -> Self {
QueueRegionSplit {
features,
version: 1,
@@ -839,77 +856,67 @@ impl QueueRegionSplit {
/// Inflight I/O descriptor state for packed virtqueues
#[repr(packed)]
-#[derive(Clone, Copy)]
-struct DescStatePacked {
+#[derive(Clone, Copy, Default)]
+pub struct DescStatePacked {
/// Indicate whether this descriptor (only head) is inflight or not.
- inflight: u8,
+ pub inflight: u8,
/// Padding
padding: u8,
/// Link to next free entry
- next: u16,
+ pub next: u16,
/// Link to last entry of descriptor list, only for head
- last: u16,
+ pub last: u16,
/// Length of descriptor list, only for head
- num: u16,
+ pub num: u16,
/// Preserve order of fetching avail descriptors, only for head
- counter: u64,
+ pub counter: u64,
/// Buffer ID
- id: u16,
+ pub id: u16,
/// Descriptor flags
- flags: u16,
+ pub flags: u16,
/// Buffer length
- len: u32,
+ pub len: u32,
/// Buffer address
- addr: u64,
+ pub addr: u64,
}
impl DescStatePacked {
- fn new() -> Self {
- DescStatePacked {
- inflight: 0,
- padding: 0,
- next: 0,
- last: 0,
- num: 0,
- counter: 0,
- id: 0,
- flags: 0,
- len: 0,
- addr: 0,
- }
+ /// New instance of DescStatePacked struct
+ pub fn new() -> Self {
+ Self::default()
}
}
/// Inflight I/O queue region for packed virtqueues
-#[allow(safe_packed_borrows)]
#[repr(packed)]
-struct QueueRegionPacked {
+pub struct QueueRegionPacked {
/// Features flags of this region
- features: u64,
+ pub features: u64,
/// version of this region
- version: u16,
+ pub version: u16,
/// size of descriptor state array
- desc_num: u16,
+ pub desc_num: u16,
/// head of free DescStatePacked entry list
- free_head: u16,
+ pub free_head: u16,
/// old head of free DescStatePacked entry list
- old_free_head: u16,
+ pub old_free_head: u16,
/// used idx of descriptor ring
- used_idx: u16,
+ pub used_idx: u16,
/// old used idx of descriptor ring
- old_used_idx: u16,
+ pub old_used_idx: u16,
/// device ring wrap counter
- used_wrap_counter: u8,
+ pub used_wrap_counter: u8,
/// old device ring wrap counter
- old_used_wrap_counter: u8,
+ pub old_used_wrap_counter: u8,
/// Padding
padding: [u8; 7],
/// Pointer to array tracking state of each descriptor from descriptor ring
- desc: u64,
+ pub desc: u64,
}
impl QueueRegionPacked {
- fn new(features: u64, queue_size: u16) -> Self {
+ /// New instance of QueueRegionPacked struct
+ pub fn new(features: u64, queue_size: u16) -> Self {
QueueRegionPacked {
features,
version: 1,
@@ -1006,7 +1013,10 @@ mod tests {
hdr.set_version(0x1);
assert!(hdr.is_valid());
+ // Test Debug, Clone, PartiaEq trait
assert_eq!(hdr, hdr.clone());
+ assert_eq!(hdr.clone().get_code(), hdr.get_code());
+ assert_eq!(format!("{:?}", hdr.clone()), format!("{:?}", hdr));
}
#[test]
diff --git a/src/vhost_user/slave_req_handler.rs b/src/vhost_user/slave_req_handler.rs
index bbc935e..402030c 100644
--- a/src/vhost_user/slave_req_handler.rs
+++ b/src/vhost_user/slave_req_handler.rs
@@ -3,14 +3,13 @@
use std::fs::File;
use std::mem;
-use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
+use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::net::UnixStream;
use std::slice;
use std::sync::{Arc, Mutex};
use super::connection::Endpoint;
use super::message::*;
-use super::slave_fs_cache::SlaveFsCacheReq;
use super::{take_single_file, Error, Result};
/// Services provided to the master by the slave with interior mutability.
@@ -62,7 +61,7 @@ pub trait VhostUserSlaveReqHandler {
fn set_vring_enable(&self, index: u32, enable: bool) -> Result<()>;
fn get_config(&self, offset: u32, size: u32, flags: VhostUserConfigFlags) -> Result<Vec<u8>>;
fn set_config(&self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>;
- fn set_slave_req_fd(&self, _vu_req: SlaveFsCacheReq) {}
+ fn set_slave_req_fd(&self, _vu_req: File) {}
fn get_inflight_fd(&self, inflight: &VhostUserInflight) -> Result<(VhostUserInflight, File)>;
fn set_inflight_fd(&self, inflight: &VhostUserInflight, file: File) -> Result<()>;
fn get_max_mem_slots(&self) -> Result<u64>;
@@ -107,7 +106,7 @@ pub trait VhostUserSlaveReqHandlerMut {
flags: VhostUserConfigFlags,
) -> Result<Vec<u8>>;
fn set_config(&mut self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>;
- fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {}
+ fn set_slave_req_fd(&mut self, _vu_req: File) {}
fn get_inflight_fd(
&mut self,
inflight: &VhostUserInflight,
@@ -201,7 +200,7 @@ impl<T: VhostUserSlaveReqHandlerMut> VhostUserSlaveReqHandler for Mutex<T> {
self.lock().unwrap().set_config(offset, buf, flags)
}
- fn set_slave_req_fd(&self, vu_req: SlaveFsCacheReq) {
+ fn set_slave_req_fd(&self, vu_req: File) {
self.lock().unwrap().set_slave_req_fd(vu_req)
}
@@ -639,9 +638,7 @@ impl<S: VhostUserSlaveReqHandler> SlaveReqHandler<S> {
fn set_slave_req_fd(&mut self, files: Option<Vec<File>>) -> Result<()> {
let file = take_single_file(files).ok_or(Error::InvalidMessage)?;
- let sock = unsafe { UnixStream::from_raw_fd(file.into_raw_fd()) };
- let vu_req = SlaveFsCacheReq::from_stream(sock);
- self.backend.set_slave_req_fd(vu_req);
+ self.backend.set_slave_req_fd(file);
Ok(())
}