From b0353992d6645b2f1b3ea316dd95619f61ef6462 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 20 Apr 2020 16:12:59 +0200 Subject: [PATCH] vm-virtio: Implement userspace_mappings() for virtio-fs This will help when we will implement the hot-unplug of the virtio-fs device, as we will have to remove correctly the userspace mappings associated with the device. Signed-off-by: Sebastien Boeuf --- vm-virtio/src/vhost_user/fs.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/vm-virtio/src/vhost_user/fs.rs b/vm-virtio/src/vhost_user/fs.rs index 31095859c..14631184a 100644 --- a/vm-virtio/src/vhost_user/fs.rs +++ b/vm-virtio/src/vhost_user/fs.rs @@ -6,8 +6,8 @@ use super::Error as DeviceError; use super::{Error, Result}; use crate::vhost_user::handler::{VhostUserEpollConfig, VhostUserEpollHandler}; use crate::{ - ActivateError, ActivateResult, Queue, VirtioDevice, VirtioDeviceType, VirtioInterrupt, - VirtioSharedMemoryList, VIRTIO_F_VERSION_1, + ActivateError, ActivateResult, Queue, UserspaceMapping, VirtioDevice, VirtioDeviceType, + VirtioInterrupt, VirtioSharedMemoryList, VIRTIO_F_VERSION_1, }; use libc::{self, c_void, off64_t, pread64, pwrite64, EFD_NONBLOCK}; use std::cmp; @@ -567,6 +567,21 @@ impl VirtioDevice for Fs { fn update_memory(&mut self, mem: &GuestMemoryMmap) -> std::result::Result<(), crate::Error> { update_mem_table(&mut self.vu, mem).map_err(crate::Error::VhostUserUpdateMemory) } + + fn userspace_mappings(&self) -> Vec { + let mut mappings = Vec::new(); + if let Some(cache) = self.cache.as_ref() { + mappings.push(UserspaceMapping { + host_addr: cache.0.host_addr, + mem_slot: cache.0.mem_slot, + addr: cache.0.addr, + len: cache.0.len, + mergeable: false, + }) + } + + mappings + } } virtio_pausable!(Fs);