mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-09-12 10:04:51 +00:00
vhost_user_fs: Add Server structure to consume FileSystem implementation
Add a Server type that links the FUSE protocol with the virtio transport. It parses messages sent on the virtio queue and then calls the appropriate method of the Filesystem trait. This code has been ported over from crosvm commit 961461350c0b6824e5f20655031bf6c6bf6b7c30. One small modification has been applied to the original code. Because cloud-hypervisor didn't have the macro used by crosvm, the match statement in the function handle_message() has been updated. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
e1fccc3615
commit
5c128023da
@ -11,3 +11,47 @@ pub mod filesystem;
|
|||||||
pub mod fuse;
|
pub mod fuse;
|
||||||
pub mod multikey;
|
pub mod multikey;
|
||||||
pub mod passthrough;
|
pub mod passthrough;
|
||||||
|
pub mod server;
|
||||||
|
|
||||||
|
use std::ffi::FromBytesWithNulError;
|
||||||
|
use std::{error, fmt, io};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
/// Failed to decode protocol messages.
|
||||||
|
DecodeMessage(io::Error),
|
||||||
|
/// Failed to encode protocol messages.
|
||||||
|
EncodeMessage(io::Error),
|
||||||
|
/// One or more parameters are missing.
|
||||||
|
MissingParameter,
|
||||||
|
/// A C string parameter is invalid.
|
||||||
|
InvalidCString(FromBytesWithNulError),
|
||||||
|
/// The `len` field of the header is too small.
|
||||||
|
InvalidHeaderLength,
|
||||||
|
/// The `size` field of the `SetxattrIn` message does not match the length
|
||||||
|
/// of the decoded value.
|
||||||
|
InvalidXattrSize((u32, usize)),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl error::Error for Error {}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
match self {
|
||||||
|
DecodeMessage(err) => write!(f, "failed to decode fuse message: {}", err),
|
||||||
|
EncodeMessage(err) => write!(f, "failed to encode fuse message: {}", err),
|
||||||
|
MissingParameter => write!(f, "one or more parameters are missing"),
|
||||||
|
InvalidHeaderLength => write!(f, "the `len` field of the header is too small"),
|
||||||
|
InvalidCString(err) => write!(f, "a c string parameter is invalid: {}", err),
|
||||||
|
InvalidXattrSize((size, len)) => write!(
|
||||||
|
f,
|
||||||
|
"The `size` field of the `SetxattrIn` message does not match the length of the\
|
||||||
|
decoded value: size = {}, value.len() = {}",
|
||||||
|
size, len
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||||
|
1269
vhost_user_fs/src/server.rs
Normal file
1269
vhost_user_fs/src/server.rs
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user