dragonball: support vhost-user-fs in device manager

This patch implements the virtio-fs device used for filesystem sharing
and heavily based on the vhost-user protocol.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
Signed-off-by: Huang Jianan <jnhuang@linux.alibaba.com>
Signed-off-by: Qinqi Qu <quqinqi@linux.alibaba.com>
This commit is contained in:
Huang Jianan 2023-04-21 15:07:03 +08:00 committed by Qinqi Qu
parent 2a1fc29e84
commit 5629b7454f
5 changed files with 46 additions and 13 deletions

View File

@ -64,3 +64,4 @@ virtio-fs = ["dbs-virtio-devices/virtio-fs-pro", "virtio-queue", "atomic-guest-m
virtio-mem = ["dbs-virtio-devices/virtio-mem", "virtio-queue", "atomic-guest-memory"]
virtio-balloon = ["dbs-virtio-devices/virtio-balloon", "virtio-queue"]
vhost-net = ["dbs-virtio-devices/vhost-net"]
vhost-user-fs = ["dbs-virtio-devices/vhost-user-fs"]

View File

@ -30,7 +30,7 @@ pub use crate::device_manager::balloon_dev_mgr::{BalloonDeviceConfigInfo, Balloo
pub use crate::device_manager::blk_dev_mgr::{
BlockDeviceConfigInfo, BlockDeviceConfigUpdateInfo, BlockDeviceError, BlockDeviceMgr,
};
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
pub use crate::device_manager::fs_dev_mgr::{
FsDeviceConfigInfo, FsDeviceConfigUpdateInfo, FsDeviceError, FsDeviceMgr, FsMountConfigInfo,
};
@ -110,7 +110,7 @@ pub enum VmmActionError {
/// Vhost-net device relared errors.
VhostNet(#[source] VhostNetDeviceError),
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
/// The action `InsertFsDevice` failed either because of bad user input or an internal error.
#[error("virtio-fs device error: {0}")]
FsDevice(#[source] FsDeviceError),
@ -204,7 +204,7 @@ pub enum VmmAction {
/// https://github.com/kata-containers/kata-containers/issues/8327
UpdateNetworkInterface(VirtioNetDeviceConfigUpdateInfo),
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
/// Add a new shared fs device or update one that already exists using the
/// `FsDeviceConfig` as input. This action can only be called before the microVM has
/// booted.
@ -331,14 +331,14 @@ impl VmmService {
VmmAction::UpdateNetworkInterface(netif_update) => {
self.update_net_rate_limiters(vmm, netif_update)
}
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
VmmAction::InsertFsDevice(fs_cfg) => self.add_fs_device(vmm, fs_cfg),
#[cfg(feature = "virtio-fs")]
VmmAction::ManipulateFsBackendFs(fs_mount_cfg) => {
self.manipulate_fs_backend_fs(vmm, fs_mount_cfg)
}
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
VmmAction::UpdateFsDevice(fs_update_cfg) => {
self.update_fs_rate_limiters(vmm, fs_update_cfg)
}
@ -712,7 +712,7 @@ impl VmmService {
.map_err(VmmActionError::VhostNet)
}
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
#[instrument(skip(self))]
fn add_fs_device(&mut self, vmm: &mut Vmm, config: FsDeviceConfigInfo) -> VmmRequestResult {
let vm = vmm.get_vm_mut().ok_or(VmmActionError::InvalidVMID)?;

View File

@ -360,6 +360,8 @@ impl FsDeviceMgr {
) -> std::result::Result<DbsVirtioDevice, FsDeviceError> {
match &config.mode as &str {
VIRTIO_FS_MODE => Self::attach_virtio_fs_devices(config, ctx, epoll_mgr),
#[cfg(feature = "vhost-user-fs")]
VHOSTUSER_FS_MODE => Self::attach_vhostuser_fs_devices(config, ctx, epoll_mgr),
_ => Err(FsDeviceError::CreateFsDevice(virtio::Error::InvalidInput)),
}
}
@ -427,6 +429,36 @@ impl FsDeviceMgr {
Ok(device)
}
#[cfg(feature = "vhost-user-fs")]
fn attach_vhostuser_fs_devices(
config: &FsDeviceConfigInfo,
ctx: &mut DeviceOpContext,
epoll_mgr: EpollManager,
) -> std::result::Result<DbsVirtioDevice, FsDeviceError> {
slog::info!(
ctx.logger(),
"attach vhost-fs device";
"subsystem" => "vhost-fs",
"tag" => &config.tag,
"dax_window_size" => &config.cache_size,
"sock_path" => &config.sock_path,
);
let device = Box::new(
virtio::vhost::vhost_user::fs::VhostUserFs::new(
config.sock_path.clone(),
config.tag.clone(),
config.num_queues,
config.queue_size,
config.cache_size,
epoll_mgr,
)
.map_err(FsDeviceError::CreateFsDevice)?,
);
Ok(device)
}
/// Attach a backend fs to a VirtioFs device or detach a backend
/// fs from a Virtiofs device
pub fn manipulate_backend_fs(

View File

@ -80,10 +80,10 @@ pub mod virtio_net_dev_mgr;
#[cfg(feature = "virtio-net")]
use self::virtio_net_dev_mgr::VirtioNetDeviceMgr;
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
/// virtio-block device manager
pub mod fs_dev_mgr;
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
use self::fs_dev_mgr::FsDeviceMgr;
#[cfg(feature = "virtio-fs")]
mod memory_region_handler;
@ -535,7 +535,7 @@ pub struct DeviceManager {
#[cfg(feature = "virtio-net")]
pub(crate) virtio_net_manager: VirtioNetDeviceMgr,
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
fs_manager: Arc<Mutex<FsDeviceMgr>>,
#[cfg(feature = "virtio-mem")]
@ -576,7 +576,7 @@ impl DeviceManager {
block_manager: BlockDeviceMgr::default(),
#[cfg(feature = "virtio-net")]
virtio_net_manager: VirtioNetDeviceMgr::default(),
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
fs_manager: Arc::new(Mutex::new(FsDeviceMgr::default())),
#[cfg(feature = "virtio-mem")]
mem_manager: MemDeviceMgr::default(),
@ -733,7 +733,7 @@ impl DeviceManager {
.attach_devices(&mut ctx)
.map_err(StartMicroVmError::BlockDeviceError)?;
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
{
let mut fs_manager = self.fs_manager.lock().unwrap();
fs_manager
@ -1154,7 +1154,7 @@ mod tests {
legacy_manager: None,
#[cfg(feature = "virtio-blk")]
block_manager: BlockDeviceMgr::default(),
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
fs_manager: Arc::new(Mutex::new(FsDeviceMgr::default())),
#[cfg(feature = "virtio-net")]
virtio_net_manager: VirtioNetDeviceMgr::default(),

View File

@ -184,7 +184,7 @@ pub enum StartMicroVmError {
#[error("virtio-net errors: {0}")]
VirtioNetDeviceError(#[source] device_manager::virtio_net_dev_mgr::VirtioNetDeviceError),
#[cfg(feature = "virtio-fs")]
#[cfg(any(feature = "virtio-fs", feature = "vhost-user-fs"))]
/// Virtio-fs errors.
#[error("virtio-fs errors: {0}")]
FsDeviceError(#[source] device_manager::fs_dev_mgr::FsDeviceError),