build: Upgrade vm-memory crates and its consumers

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen
2023-11-07 11:37:23 -08:00
committed by Rob Bradford
parent d4a163dd39
commit 4d7a4c598a
25 changed files with 179 additions and 188 deletions

View File

@@ -23,7 +23,7 @@ use vhost::vhost_user::message::{
VhostUserConfigFlags, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
VHOST_USER_CONFIG_OFFSET,
};
use vhost::vhost_user::{MasterReqHandler, VhostUserMaster, VhostUserMasterReqHandler};
use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler};
use virtio_bindings::virtio_blk::{
VIRTIO_BLK_F_BLK_SIZE, VIRTIO_BLK_F_CONFIG_WCE, VIRTIO_BLK_F_DISCARD, VIRTIO_BLK_F_FLUSH,
VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_MQ, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_SEG_MAX,
@@ -50,8 +50,8 @@ pub struct State {
impl VersionMapped for State {}
struct SlaveReqHandler {}
impl VhostUserMasterReqHandler for SlaveReqHandler {}
struct BackendReqHandler {}
impl VhostUserFrontendReqHandler for BackendReqHandler {}
pub struct Blk {
common: VirtioCommon,
@@ -294,7 +294,7 @@ impl VirtioDevice for Blk {
self.common.activate(&queues, &interrupt_cb)?;
self.guest_memory = Some(mem.clone());
let slave_req_handler: Option<MasterReqHandler<SlaveReqHandler>> = None;
let backend_req_handler: Option<FrontendReqHandler<BackendReqHandler>> = None;
// Run a dedicated thread for handling potential reconnections with
// the backend.
@@ -305,7 +305,7 @@ impl VirtioDevice for Blk {
queues,
interrupt_cb,
self.common.acked_features,
slave_req_handler,
backend_req_handler,
kill_evt,
pause_evt,
)?;

View File

@@ -22,11 +22,11 @@ use std::thread;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vhost::vhost_user::message::{
VhostUserFSSlaveMsg, VhostUserFSSlaveMsgFlags, VhostUserProtocolFeatures,
VhostUserVirtioFeatures, VHOST_USER_FS_SLAVE_ENTRIES,
VhostUserFSBackendMsg, VhostUserFSBackendMsgFlags, VhostUserProtocolFeatures,
VhostUserVirtioFeatures, VHOST_USER_FS_BACKEND_ENTRIES,
};
use vhost::vhost_user::{
HandlerResult, MasterReqHandler, VhostUserMaster, VhostUserMasterReqHandler,
FrontendReqHandler, HandlerResult, VhostUserFrontend, VhostUserFrontendReqHandler,
};
use virtio_queue::Queue;
use vm_memory::{
@@ -48,19 +48,19 @@ pub struct State {
pub config: VirtioFsConfig,
pub acked_protocol_features: u64,
pub vu_num_queues: usize,
pub slave_req_support: bool,
pub backend_req_support: bool,
}
impl VersionMapped for State {}
struct SlaveReqHandler {
struct BackendReqHandler {
cache_offset: GuestAddress,
cache_size: u64,
mmap_cache_addr: u64,
mem: GuestMemoryAtomic<GuestMemoryMmap>,
}
impl SlaveReqHandler {
impl BackendReqHandler {
// Make sure request is within cache range
fn is_req_valid(&self, offset: u64, len: u64) -> bool {
let end = match offset.checked_add(len) {
@@ -72,16 +72,16 @@ impl SlaveReqHandler {
}
}
impl VhostUserMasterReqHandler for SlaveReqHandler {
impl VhostUserFrontendReqHandler for BackendReqHandler {
fn handle_config_change(&self) -> HandlerResult<u64> {
debug!("handle_config_change");
Ok(0)
}
fn fs_slave_map(&self, fs: &VhostUserFSSlaveMsg, fd: &dyn AsRawFd) -> HandlerResult<u64> {
debug!("fs_slave_map");
fn fs_backend_map(&self, fs: &VhostUserFSBackendMsg, fd: &dyn AsRawFd) -> HandlerResult<u64> {
debug!("fs_backend_map");
for i in 0..VHOST_USER_FS_SLAVE_ENTRIES {
for i in 0..VHOST_USER_FS_BACKEND_ENTRIES {
let offset = fs.cache_offset[i];
let len = fs.len[i];
@@ -115,10 +115,10 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
Ok(0)
}
fn fs_slave_unmap(&self, fs: &VhostUserFSSlaveMsg) -> HandlerResult<u64> {
debug!("fs_slave_unmap");
fn fs_backend_unmap(&self, fs: &VhostUserFSBackendMsg) -> HandlerResult<u64> {
debug!("fs_backend_unmap");
for i in 0..VHOST_USER_FS_SLAVE_ENTRIES {
for i in 0..VHOST_USER_FS_BACKEND_ENTRIES {
let mut len = fs.len[i];
// Ignore if the length is 0.
@@ -126,7 +126,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
continue;
}
// Need to handle a special case where the slave ask for the unmapping
// Need to handle a special case where the backend ask for the unmapping
// of the entire mapping.
let offset = if len == 0xffff_ffff_ffff_ffff {
len = self.cache_size;
@@ -159,10 +159,10 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
Ok(0)
}
fn fs_slave_sync(&self, fs: &VhostUserFSSlaveMsg) -> HandlerResult<u64> {
debug!("fs_slave_sync");
fn fs_backend_sync(&self, fs: &VhostUserFSBackendMsg) -> HandlerResult<u64> {
debug!("fs_backend_sync");
for i in 0..VHOST_USER_FS_SLAVE_ENTRIES {
for i in 0..VHOST_USER_FS_BACKEND_ENTRIES {
let offset = fs.cache_offset[i];
let len = fs.len[i];
@@ -187,11 +187,11 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
Ok(0)
}
fn fs_slave_io(&self, fs: &VhostUserFSSlaveMsg, fd: &dyn AsRawFd) -> HandlerResult<u64> {
debug!("fs_slave_io");
fn fs_backend_io(&self, fs: &VhostUserFSBackendMsg, fd: &dyn AsRawFd) -> HandlerResult<u64> {
debug!("fs_backend_io");
let mut done: u64 = 0;
for i in 0..VHOST_USER_FS_SLAVE_ENTRIES {
for i in 0..VHOST_USER_FS_BACKEND_ENTRIES {
// Ignore if the length is 0.
if fs.len[i] == 0 {
continue;
@@ -230,8 +230,8 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
};
while len > 0 {
let ret = if (fs.flags[i] & VhostUserFSSlaveMsgFlags::MAP_W)
== VhostUserFSSlaveMsgFlags::MAP_W
let ret = if (fs.flags[i] & VhostUserFSBackendMsgFlags::MAP_W)
== VhostUserFSBackendMsgFlags::MAP_W
{
debug!("write: foffset={}, len={}", foffset, len);
// SAFETY: FFI call with valid arguments
@@ -298,7 +298,7 @@ pub struct Fs {
// Hold ownership of the memory that is allocated for the device
// which will be automatically dropped when the device is dropped
cache: Option<(VirtioSharedMemoryList, MmapRegion)>,
slave_req_support: bool,
backend_req_support: bool,
seccomp_action: SeccompAction,
guest_memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>,
epoll_thread: Option<thread::JoinHandle<()>>,
@@ -321,7 +321,7 @@ impl Fs {
iommu: bool,
state: Option<State>,
) -> Result<Fs> {
let mut slave_req_support = false;
let mut backend_req_support = false;
// Calculate the actual number of queues needed.
let num_queues = NUM_QUEUE_OFFSET + req_num_queues;
@@ -335,7 +335,7 @@ impl Fs {
acked_protocol_features,
vu_num_queues,
config,
slave_req_support,
backend_req_support,
paused,
) = if let Some(state) = state {
info!("Restoring vhost-user-fs {}", id);
@@ -351,7 +351,7 @@ impl Fs {
state.acked_protocol_features,
state.vu_num_queues,
state.config,
state.slave_req_support,
state.backend_req_support,
true,
)
} else {
@@ -363,10 +363,10 @@ impl Fs {
| VhostUserProtocolFeatures::REPLY_ACK
| VhostUserProtocolFeatures::INFLIGHT_SHMFD
| VhostUserProtocolFeatures::LOG_SHMFD;
let slave_protocol_features =
VhostUserProtocolFeatures::SLAVE_REQ | VhostUserProtocolFeatures::SLAVE_SEND_FD;
let backend_protocol_features =
VhostUserProtocolFeatures::BACKEND_REQ | VhostUserProtocolFeatures::BACKEND_SEND_FD;
if cache.is_some() {
avail_protocol_features |= slave_protocol_features;
avail_protocol_features |= backend_protocol_features;
}
let (acked_features, acked_protocol_features) =
@@ -389,10 +389,10 @@ impl Fs {
return Err(Error::BadQueueNum);
}
if acked_protocol_features & slave_protocol_features.bits()
== slave_protocol_features.bits()
if acked_protocol_features & backend_protocol_features.bits()
== backend_protocol_features.bits()
{
slave_req_support = true;
backend_req_support = true;
}
// Create virtio-fs device configuration.
@@ -411,7 +411,7 @@ impl Fs {
acked_protocol_features,
num_queues,
config,
slave_req_support,
backend_req_support,
false,
)
};
@@ -437,7 +437,7 @@ impl Fs {
id,
config,
cache,
slave_req_support,
backend_req_support,
seccomp_action,
guest_memory: None,
epoll_thread: None,
@@ -453,7 +453,7 @@ impl Fs {
config: self.config,
acked_protocol_features: self.vu_common.acked_protocol_features,
vu_num_queues: self.vu_common.vu_num_queues,
slave_req_support: self.slave_req_support,
backend_req_support: self.backend_req_support,
}
}
}
@@ -507,10 +507,10 @@ impl VirtioDevice for Fs {
self.common.activate(&queues, &interrupt_cb)?;
self.guest_memory = Some(mem.clone());
// Initialize slave communication.
let slave_req_handler = if self.slave_req_support {
// Initialize backend communication.
let backend_req_handler = if self.backend_req_support {
if let Some(cache) = self.cache.as_ref() {
let vu_master_req_handler = Arc::new(SlaveReqHandler {
let vu_frontend_req_handler = Arc::new(BackendReqHandler {
cache_offset: cache.0.addr,
cache_size: cache.0.len,
mmap_cache_addr: cache.0.host_addr,
@@ -518,8 +518,8 @@ impl VirtioDevice for Fs {
});
let mut req_handler =
MasterReqHandler::new(vu_master_req_handler).map_err(|e| {
ActivateError::VhostUserFsSetup(Error::MasterReqHandlerCreation(e))
FrontendReqHandler::new(vu_frontend_req_handler).map_err(|e| {
ActivateError::VhostUserFsSetup(Error::FrontendReqHandlerCreation(e))
})?;
if self.vu_common.acked_protocol_features
@@ -546,7 +546,7 @@ impl VirtioDevice for Fs {
queues,
interrupt_cb,
self.common.acked_features,
slave_req_handler,
backend_req_handler,
kill_evt,
pause_evt,
)?;

View File

@@ -17,7 +17,7 @@ use versionize::Versionize;
use vhost::vhost_user::message::{
VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
};
use vhost::vhost_user::{MasterReqHandler, VhostUserMasterReqHandler};
use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontendReqHandler};
use vhost::Error as VhostError;
use virtio_queue::Error as QueueError;
use virtio_queue::Queue;
@@ -61,8 +61,8 @@ pub enum Error {
MemoryRegions(MmapError),
#[error("Failed removing socket path: {0}")]
RemoveSocketPath(io::Error),
#[error("Failed to create master: {0}")]
VhostUserCreateMaster(VhostError),
#[error("Failed to create frontend: {0}")]
VhostUserCreateFrontend(VhostError),
#[error("Failed to open vhost device: {0}")]
VhostUserOpen(VhostError),
#[error("Connection to socket failed")]
@@ -105,10 +105,10 @@ pub enum Error {
VhostIrqRead(io::Error),
#[error("Failed to read vhost eventfd: {0}")]
VhostUserMemoryRegion(MmapError),
#[error("Failed to create the master request handler from slave: {0}")]
MasterReqHandlerCreation(vhost::vhost_user::Error),
#[error("Set slave request fd failed: {0}")]
VhostUserSetSlaveRequestFd(vhost::Error),
#[error("Failed to create the frontend request handler from backend: {0}")]
FrontendReqHandlerCreation(vhost::vhost_user::Error),
#[error("Set backend request fd failed: {0}")]
VhostUserSetBackendRequestFd(vhost::Error),
#[error("Add memory region failed: {0}")]
VhostUserAddMemReg(VhostError),
#[error("Failed getting the configuration: {0}")]
@@ -155,7 +155,7 @@ pub const DEFAULT_VIRTIO_FEATURES: u64 = 1 << VIRTIO_F_RING_INDIRECT_DESC
| VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits();
const HUP_CONNECTION_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 1;
const SLAVE_REQ_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 2;
const BACKEND_REQ_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 2;
#[derive(Default)]
pub struct Inflight {
@@ -163,7 +163,7 @@ pub struct Inflight {
pub fd: Option<std::fs::File>,
}
pub struct VhostUserEpollHandler<S: VhostUserMasterReqHandler> {
pub struct VhostUserEpollHandler<S: VhostUserFrontendReqHandler> {
pub vu: Arc<Mutex<VhostUserHandle>>,
pub mem: GuestMemoryAtomic<GuestMemoryMmap>,
pub kill_evt: EventFd,
@@ -174,11 +174,11 @@ pub struct VhostUserEpollHandler<S: VhostUserMasterReqHandler> {
pub acked_protocol_features: u64,
pub socket_path: String,
pub server: bool,
pub slave_req_handler: Option<MasterReqHandler<S>>,
pub backend_req_handler: Option<FrontendReqHandler<S>>,
pub inflight: Option<Inflight>,
}
impl<S: VhostUserMasterReqHandler> VhostUserEpollHandler<S> {
impl<S: VhostUserFrontendReqHandler> VhostUserEpollHandler<S> {
pub fn run(
&mut self,
paused: Arc<AtomicBool>,
@@ -191,8 +191,8 @@ impl<S: VhostUserMasterReqHandler> VhostUserEpollHandler<S> {
epoll::Events::EPOLLHUP,
)?;
if let Some(slave_req_handler) = &self.slave_req_handler {
helper.add_event(slave_req_handler.as_raw_fd(), SLAVE_REQ_EVENT)?;
if let Some(backend_req_handler) = &self.backend_req_handler {
helper.add_event(backend_req_handler.as_raw_fd(), BACKEND_REQ_EVENT)?;
}
helper.run(paused, paused_sync, self)?;
@@ -231,7 +231,7 @@ impl<S: VhostUserMasterReqHandler> VhostUserEpollHandler<S> {
&self.virtio_interrupt,
self.acked_features,
self.acked_protocol_features,
&self.slave_req_handler,
&self.backend_req_handler,
self.inflight.as_mut(),
)
.map_err(|e| {
@@ -255,7 +255,7 @@ impl<S: VhostUserMasterReqHandler> VhostUserEpollHandler<S> {
}
}
impl<S: VhostUserMasterReqHandler> EpollHelperHandler for VhostUserEpollHandler<S> {
impl<S: VhostUserFrontendReqHandler> EpollHelperHandler for VhostUserEpollHandler<S> {
fn handle_event(
&mut self,
helper: &mut EpollHelper,
@@ -271,9 +271,9 @@ impl<S: VhostUserMasterReqHandler> EpollHelperHandler for VhostUserEpollHandler<
))
})?;
}
SLAVE_REQ_EVENT => {
if let Some(slave_req_handler) = self.slave_req_handler.as_mut() {
slave_req_handler.handle_request().map_err(|e| {
BACKEND_REQ_EVENT => {
if let Some(backend_req_handler) = self.backend_req_handler.as_mut() {
backend_req_handler.handle_request().map_err(|e| {
EpollHelperError::HandleEvent(anyhow!(
"Failed to handle request from vhost-user backend: {:?}",
e
@@ -304,13 +304,13 @@ pub struct VhostUserCommon {
impl VhostUserCommon {
#[allow(clippy::too_many_arguments)]
pub fn activate<T: VhostUserMasterReqHandler>(
pub fn activate<T: VhostUserFrontendReqHandler>(
&mut self,
mem: GuestMemoryAtomic<GuestMemoryMmap>,
queues: Vec<(usize, Queue, EventFd)>,
interrupt_cb: Arc<dyn VirtioInterrupt>,
acked_features: u64,
slave_req_handler: Option<MasterReqHandler<T>>,
backend_req_handler: Option<FrontendReqHandler<T>>,
kill_evt: EventFd,
pause_evt: EventFd,
) -> std::result::Result<VhostUserEpollHandler<T>, ActivateError> {
@@ -337,7 +337,7 @@ impl VhostUserCommon {
.collect(),
&interrupt_cb,
acked_features,
&slave_req_handler,
&backend_req_handler,
inflight.as_mut(),
)
.map_err(ActivateError::VhostUserSetup)?;
@@ -353,7 +353,7 @@ impl VhostUserCommon {
acked_protocol_features: self.acked_protocol_features,
socket_path: self.socket_path.clone(),
server: self.server,
slave_req_handler,
backend_req_handler,
inflight,
})
}

View File

@@ -20,7 +20,7 @@ use std::vec::Vec;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures};
use vhost::vhost_user::{MasterReqHandler, VhostUserMaster, VhostUserMasterReqHandler};
use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler};
use virtio_bindings::virtio_net::{
VIRTIO_NET_F_CSUM, VIRTIO_NET_F_CTRL_VQ, VIRTIO_NET_F_GUEST_CSUM, VIRTIO_NET_F_GUEST_ECN,
VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, VIRTIO_NET_F_GUEST_UFO,
@@ -49,8 +49,8 @@ pub struct State {
impl VersionMapped for State {}
struct SlaveReqHandler {}
impl VhostUserMasterReqHandler for SlaveReqHandler {}
struct BackendReqHandler {}
impl VhostUserFrontendReqHandler for BackendReqHandler {}
pub struct Net {
common: VirtioCommon,
@@ -342,7 +342,7 @@ impl VirtioDevice for Net {
self.ctrl_queue_epoll_thread = Some(epoll_threads.remove(0));
}
let slave_req_handler: Option<MasterReqHandler<SlaveReqHandler>> = None;
let backend_req_handler: Option<FrontendReqHandler<BackendReqHandler>> = None;
// The backend acknowledged features must not contain VIRTIO_NET_F_MAC
// since we don't expect the backend to handle it.
@@ -357,7 +357,7 @@ impl VirtioDevice for Net {
queues,
interrupt_cb,
backend_acked_features,
slave_req_handler,
backend_req_handler,
kill_evt,
pause_evt,
)?;

View File

@@ -20,7 +20,9 @@ use vhost::vhost_kern::vhost_binding::{VHOST_F_LOG_ALL, VHOST_VRING_F_LOG};
use vhost::vhost_user::message::{
VhostUserHeaderFlag, VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
};
use vhost::vhost_user::{Master, MasterReqHandler, VhostUserMaster, VhostUserMasterReqHandler};
use vhost::vhost_user::{
Frontend, FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler,
};
use vhost::{VhostBackend, VhostUserDirtyLogRegion, VhostUserMemoryRegionInfo, VringConfigData};
use virtio_queue::{Descriptor, Queue, QueueT};
use vm_memory::{
@@ -47,7 +49,7 @@ struct VringInfo {
#[derive(Clone)]
pub struct VhostUserHandle {
vu: Master,
vu: Frontend,
ready: bool,
supports_migration: bool,
shm_log: Option<Arc<MmapRegion>>,
@@ -148,13 +150,13 @@ impl VhostUserHandle {
}
#[allow(clippy::too_many_arguments)]
pub fn setup_vhost_user<S: VhostUserMasterReqHandler>(
pub fn setup_vhost_user<S: VhostUserFrontendReqHandler>(
&mut self,
mem: &GuestMemoryMmap,
queues: Vec<(usize, Queue, EventFd)>,
virtio_interrupt: &Arc<dyn VirtioInterrupt>,
acked_features: u64,
slave_req_handler: &Option<MasterReqHandler<S>>,
backend_req_handler: &Option<FrontendReqHandler<S>>,
inflight: Option<&mut Inflight>,
) -> Result<()> {
self.vu
@@ -266,10 +268,10 @@ impl VhostUserHandle {
self.enable_vhost_user_vrings(self.queue_indexes.clone(), true)?;
if let Some(slave_req_handler) = slave_req_handler {
if let Some(backend_req_handler) = backend_req_handler {
self.vu
.set_slave_request_fd(&slave_req_handler.get_tx_raw_fd())
.map_err(Error::VhostUserSetSlaveRequestFd)?;
.set_backend_request_fd(&backend_req_handler.get_tx_raw_fd())
.map_err(Error::VhostUserSetBackendRequestFd)?;
}
self.vrings_info = Some(vrings_info);
@@ -333,14 +335,14 @@ impl VhostUserHandle {
}
#[allow(clippy::too_many_arguments)]
pub fn reinitialize_vhost_user<S: VhostUserMasterReqHandler>(
pub fn reinitialize_vhost_user<S: VhostUserFrontendReqHandler>(
&mut self,
mem: &GuestMemoryMmap,
queues: Vec<(usize, Queue, EventFd)>,
virtio_interrupt: &Arc<dyn VirtioInterrupt>,
acked_features: u64,
acked_protocol_features: u64,
slave_req_handler: &Option<MasterReqHandler<S>>,
backend_req_handler: &Option<FrontendReqHandler<S>>,
inflight: Option<&mut Inflight>,
) -> Result<()> {
self.set_protocol_features_vhost_user(acked_features, acked_protocol_features)?;
@@ -350,7 +352,7 @@ impl VhostUserHandle {
queues,
virtio_interrupt,
acked_features,
slave_req_handler,
backend_req_handler,
inflight,
)
}
@@ -372,7 +374,7 @@ impl VhostUserHandle {
let (stream, _) = listener.accept().map_err(Error::AcceptConnection)?;
Ok(VhostUserHandle {
vu: Master::from_stream(stream, num_queues),
vu: Frontend::from_stream(stream, num_queues),
ready: false,
supports_migration: false,
shm_log: None,
@@ -385,7 +387,7 @@ impl VhostUserHandle {
// Retry connecting for a full minute
let err = loop {
let err = match Master::connect(socket_path, num_queues) {
let err = match Frontend::connect(socket_path, num_queues) {
Ok(m) => {
return Ok(VhostUserHandle {
vu: m,
@@ -414,7 +416,7 @@ impl VhostUserHandle {
}
}
pub fn socket_handle(&mut self) -> &mut Master {
pub fn socket_handle(&mut self) -> &mut Frontend {
&mut self.vu
}