vhost-user: Make number of queues configurable

We need the vhost-user protocol crate to be more generic to allow
communication with a configurable amount of virtqueues.

This is a workaround for the virtio-fs backend. According to the
vhost-user specification, the master should issue get_queue_num()
to get the maximum number of queues supported by the slave. With
current virtio-fs implementations, it needs multiple virtques, but
it doesn't support the get_queue_num() request and not set the MQ
feature bit too. So this is a workaround to hard-code the max_queue_num
on the master side.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-02-19 06:59:58 -08:00 committed by Andreea Florescu
parent 0c1edfc628
commit c3506d3bc0
2 changed files with 14 additions and 11 deletions

View file

@ -62,7 +62,7 @@ pub struct Master {
impl Master {
/// Create a new instance.
fn new(ep: Endpoint<MasterReq>) -> Self {
fn new(ep: Endpoint<MasterReq>, max_queue_num: u64) -> Self {
Master {
node: Arc::new(Mutex::new(MasterInternal {
main_sock: ep,
@ -71,23 +71,26 @@ impl Master {
protocol_features: 0,
acked_protocol_features: 0,
protocol_features_ready: false,
max_queue_num: 1,
max_queue_num,
error: None,
})),
}
}
/// Create a new instance from a Unix stream socket.
pub fn from_stream(sock: UnixStream) -> Self {
Self::new(Endpoint::<MasterReq>::from_stream(sock))
pub fn from_stream(sock: UnixStream, max_queue_num: u64) -> Self {
Self::new(Endpoint::<MasterReq>::from_stream(sock), max_queue_num)
}
/// Create a new vhost-user master endpoint.
///
/// # Arguments
/// * `path` - path of Unix domain socket listener to connect to
pub fn connect(path: &str) -> Result<Self> {
Ok(Self::new(Endpoint::<MasterReq>::connect(path)?))
pub fn connect(path: &str, max_queue_num: u64) -> Result<Self> {
Ok(Self::new(
Endpoint::<MasterReq>::connect(path)?,
max_queue_num,
))
}
}
@ -617,7 +620,7 @@ mod tests {
fn create_pair(path: &str) -> (Master, Endpoint<MasterReq>) {
let listener = Listener::new(path, true).unwrap();
listener.set_nonblocking(true).unwrap();
let master = Master::connect(path).unwrap();
let master = Master::connect(path, 2).unwrap();
let slave = listener.accept().unwrap().unwrap();
(master, Endpoint::from_stream(slave))
}
@ -627,7 +630,7 @@ mod tests {
let listener = Listener::new(UNIX_SOCKET_MASTER, true).unwrap();
listener.set_nonblocking(true).unwrap();
let mut master = Master::connect(UNIX_SOCKET_MASTER).unwrap();
let mut master = Master::connect(UNIX_SOCKET_MASTER, 1).unwrap();
let mut slave = Endpoint::<MasterReq>::from_stream(listener.accept().unwrap().unwrap());
// Send two messages continuously
@ -651,13 +654,13 @@ mod tests {
fn test_create_failure() {
let _ = Listener::new(UNIX_SOCKET_MASTER2, true).unwrap();
let _ = Listener::new(UNIX_SOCKET_MASTER2, false).is_err();
assert!(Master::connect(UNIX_SOCKET_MASTER2).is_err());
assert!(Master::connect(UNIX_SOCKET_MASTER2, 1).is_err());
let listener = Listener::new(UNIX_SOCKET_MASTER2, true).unwrap();
assert!(Listener::new(UNIX_SOCKET_MASTER2, false).is_err());
listener.set_nonblocking(true).unwrap();
let _master = Master::connect(UNIX_SOCKET_MASTER2).unwrap();
let _master = Master::connect(UNIX_SOCKET_MASTER2, 1).unwrap();
let _slave = listener.accept().unwrap().unwrap();
}

View file

@ -178,7 +178,7 @@ mod tests {
backend: Arc<Mutex<S>>,
) -> (Master, SlaveReqHandler<S>) {
let mut slave_listener = SlaveListener::new(path, true, backend).unwrap();
let master = Master::connect(path).unwrap();
let master = Master::connect(path, 1).unwrap();
(master, slave_listener.accept().unwrap().unwrap())
}