Skip to content

Commit

Permalink
vhost_user: Slave requests aren't only FS specific
Browse files Browse the repository at this point in the history
There are a lot of slave requests supported by vhost-user protocol, it
isn't just about FS_MAP and FS_UNMAP. Rename the files and declarations
to slave request specific names.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
  • Loading branch information
vireshk committed Feb 23, 2023
1 parent 9b6c400 commit f5592e5
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 75 deletions.
20 changes: 10 additions & 10 deletions crates/vhost-user-backend/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::ops::Deref;
use std::sync::{Arc, Mutex, RwLock};

use vhost::vhost_user::message::VhostUserProtocolFeatures;
use vhost::vhost_user::SlaveFsCacheReq;
use vhost::vhost_user::Slave;
use vm_memory::bitmap::Bitmap;
use vmm_sys_util::epoll::EventSet;
use vmm_sys_util::eventfd::EventFd;
Expand Down Expand Up @@ -82,7 +82,7 @@ where
/// function.
///
/// TODO: this interface is designed only for vhost-user-fs, it should be refined.
fn set_slave_req_fd(&self, _vu_req: SlaveFsCacheReq) {}
fn set_slave_req_fd(&self, _slave: Slave) {}

/// Get the map to map queue index to worker thread index.
///
Expand Down Expand Up @@ -165,7 +165,7 @@ where
/// function.
///
/// TODO: this interface is designed only for vhost-user-fs, it should be refined.
fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {}
fn set_slave_req_fd(&mut self, _slave: Slave) {}

/// Get the map to map queue index to worker thread index.
///
Expand Down Expand Up @@ -240,8 +240,8 @@ where
self.deref().update_memory(mem)
}

fn set_slave_req_fd(&self, vu_req: SlaveFsCacheReq) {
self.deref().set_slave_req_fd(vu_req)
fn set_slave_req_fd(&self, slave: Slave) {
self.deref().set_slave_req_fd(slave)
}

fn queues_per_thread(&self) -> Vec<u64> {
Expand Down Expand Up @@ -305,8 +305,8 @@ where
self.lock().unwrap().update_memory(mem)
}

fn set_slave_req_fd(&self, vu_req: SlaveFsCacheReq) {
self.lock().unwrap().set_slave_req_fd(vu_req)
fn set_slave_req_fd(&self, slave: Slave) {
self.lock().unwrap().set_slave_req_fd(slave)
}

fn queues_per_thread(&self) -> Vec<u64> {
Expand Down Expand Up @@ -371,8 +371,8 @@ where
self.write().unwrap().update_memory(mem)
}

fn set_slave_req_fd(&self, vu_req: SlaveFsCacheReq) {
self.write().unwrap().set_slave_req_fd(vu_req)
fn set_slave_req_fd(&self, slave: Slave) {
self.write().unwrap().set_slave_req_fd(slave)
}

fn queues_per_thread(&self) -> Vec<u64> {
Expand Down Expand Up @@ -463,7 +463,7 @@ pub mod tests {
Ok(())
}

fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {}
fn set_slave_req_fd(&mut self, _slave: Slave) {}

fn queues_per_thread(&self) -> Vec<u64> {
vec![1, 1]
Expand Down
9 changes: 4 additions & 5 deletions crates/vhost-user-backend/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use vhost::vhost_user::message::{
VhostUserVringState,
};
use vhost::vhost_user::{
Error as VhostUserError, Result as VhostUserResult, SlaveFsCacheReq,
VhostUserSlaveReqHandlerMut,
Error as VhostUserError, Result as VhostUserResult, Slave, VhostUserSlaveReqHandlerMut,
};
use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use virtio_queue::{Error as VirtQueError, QueueT};
Expand Down Expand Up @@ -499,12 +498,12 @@ where
.map_err(VhostUserError::ReqHandlerError)
}

fn set_slave_req_fd(&mut self, vu_req: SlaveFsCacheReq) {
fn set_slave_req_fd(&mut self, slave: Slave) {
if self.acked_protocol_features & VhostUserProtocolFeatures::REPLY_ACK.bits() != 0 {
vu_req.set_reply_ack_flag(true);
slave.set_reply_ack_flag(true);
}

self.backend.set_slave_req_fd(vu_req);
self.backend.set_slave_req_fd(slave);
}

fn get_inflight_fd(
Expand Down
4 changes: 2 additions & 2 deletions crates/vhost-user-backend/tests/vhost-user-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::thread;
use vhost::vhost_user::message::{
VhostUserConfigFlags, VhostUserHeaderFlag, VhostUserInflight, VhostUserProtocolFeatures,
};
use vhost::vhost_user::{Listener, Master, SlaveFsCacheReq, VhostUserMaster};
use vhost::vhost_user::{Listener, Master, Slave, VhostUserMaster};
use vhost::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData};
use vhost_user_backend::{VhostUserBackendMut, VhostUserDaemon, VringRwLock};
use vm_memory::{
Expand Down Expand Up @@ -81,7 +81,7 @@ impl VhostUserBackendMut<VringRwLock, ()> for MockVhostBackend {
Ok(())
}

fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {}
fn set_slave_req_fd(&mut self, _slave: Slave) {}

fn queues_per_thread(&self) -> Vec<u64> {
vec![1, 1]
Expand Down
2 changes: 1 addition & 1 deletion crates/vhost/docs/vhost_architecture.drawio
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</Array>
</mxGeometry>
</mxCell>
<mxCell id="5" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;SlaveFsCacheReq&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxCell id="5" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;Slave&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxGeometry x="1715" y="767" width="220" height="50" as="geometry"/>
</mxCell>
<mxCell id="7" value="&lt;pre style=&quot;font-size: 16.5pt; font-weight: 700; font-family: &amp;quot;jetbrains mono&amp;quot;, monospace;&quot;&gt;VhostUserMasterReqHandlerMut&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
Expand Down
20 changes: 10 additions & 10 deletions crates/vhost/src/vhost_user/master_req_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::{Error, HandlerResult, Result};
/// request services from masters. The [VhostUserMasterReqHandler] trait defines services provided
/// by masters, and it's used both on the master side and slave side.
/// - on the slave side, a stub forwarder implementing [VhostUserMasterReqHandler] will proxy
/// service requests to masters. The [SlaveFsCacheReq] is an example stub forwarder.
/// service requests to masters. The [Slave] is an example stub forwarder.
/// - on the master side, the [MasterReqHandler] will forward service requests to a handler
/// implementing [VhostUserMasterReqHandler].
///
Expand All @@ -26,7 +26,7 @@ use super::{Error, HandlerResult, Result};
///
/// [VhostUserMasterReqHandler]: trait.VhostUserMasterReqHandler.html
/// [MasterReqHandler]: struct.MasterReqHandler.html
/// [SlaveFsCacheReq]: struct.SlaveFsCacheReq.html
/// [Slave]: struct.Slave.html
pub trait VhostUserMasterReqHandler {
/// Handle device configuration change notifications.
fn handle_config_change(&self) -> HandlerResult<u64> {
Expand Down Expand Up @@ -362,7 +362,7 @@ mod tests {
use super::*;

#[cfg(feature = "vhost-user-slave")]
use crate::vhost_user::SlaveFsCacheReq;
use crate::vhost_user::Slave;
#[cfg(feature = "vhost-user-slave")]
use std::os::unix::io::FromRawFd;

Expand Down Expand Up @@ -410,20 +410,20 @@ mod tests {
panic!("failed to duplicated tx fd!");
}
let stream = unsafe { UnixStream::from_raw_fd(fd) };
let fs_cache = SlaveFsCacheReq::from_stream(stream);
let slave = Slave::from_stream(stream);

std::thread::spawn(move || {
let res = handler.handle_request().unwrap();
assert_eq!(res, 0);
handler.handle_request().unwrap_err();
});

fs_cache
slave
.fs_slave_map(&VhostUserFSSlaveMsg::default(), &fd)
.unwrap();
// When REPLY_ACK has not been negotiated, the master has no way to detect failure from
// slave side.
fs_cache
slave
.fs_slave_unmap(&VhostUserFSSlaveMsg::default())
.unwrap();
}
Expand All @@ -440,19 +440,19 @@ mod tests {
panic!("failed to duplicated tx fd!");
}
let stream = unsafe { UnixStream::from_raw_fd(fd) };
let fs_cache = SlaveFsCacheReq::from_stream(stream);
let slave = Slave::from_stream(stream);

std::thread::spawn(move || {
let res = handler.handle_request().unwrap();
assert_eq!(res, 0);
handler.handle_request().unwrap_err();
});

fs_cache.set_reply_ack_flag(true);
fs_cache
slave.set_reply_ack_flag(true);
slave
.fs_slave_map(&VhostUserFSSlaveMsg::default(), &fd)
.unwrap();
fs_cache
slave
.fs_slave_unmap(&VhostUserFSSlaveMsg::default())
.unwrap_err();
}
Expand Down
4 changes: 2 additions & 2 deletions crates/vhost/src/vhost_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub use self::slave_req_handler::{
SlaveReqHandler, VhostUserSlaveReqHandler, VhostUserSlaveReqHandlerMut,
};
#[cfg(feature = "vhost-user-slave")]
mod slave_fs_cache;
mod slave_req;
#[cfg(feature = "vhost-user-slave")]
pub use self::slave_fs_cache::SlaveFsCacheReq;
pub use self::slave_req::Slave;

/// Errors for vhost-user operations
#[derive(Debug)]
Expand Down
Loading

0 comments on commit f5592e5

Please sign in to comment.