vmm, virtio: fs: Move freeing of mappped region into device

Move the release of the managed memory region from the DeviceManager to
the vhost-user-fs device. This ensures that the memory will be freed when
the device is unplugged which will lead to it being Drop()ed.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2020-04-14 15:47:11 +01:00
parent 0c6706a510
commit 70ecd6bab4
2 changed files with 10 additions and 8 deletions

View File

@@ -28,6 +28,7 @@ use vhost_rs::vhost_user::{
use vhost_rs::VhostBackend;
use vm_memory::{
Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap,
MmapRegion,
};
use vm_migration::{Migratable, MigratableError, Pausable, Snapshottable, Transportable};
use vmm_sys_util::eventfd::EventFd;
@@ -258,7 +259,9 @@ pub struct Fs {
config: VirtioFsConfig,
kill_evt: Option<EventFd>,
pause_evt: Option<EventFd>,
cache: Option<(VirtioSharedMemoryList, u64)>,
// Hold ownership of the memory that is allocated for the device
// which will be automatically dropped when the device is dropped
cache: Option<(VirtioSharedMemoryList, u64, MmapRegion)>,
slave_req_support: bool,
queue_evts: Option<Vec<EventFd>>,
interrupt_cb: Option<Arc<dyn VirtioInterrupt>>,
@@ -273,7 +276,7 @@ impl Fs {
tag: &str,
req_num_queues: usize,
queue_size: u16,
cache: Option<(VirtioSharedMemoryList, u64)>,
cache: Option<(VirtioSharedMemoryList, u64, MmapRegion)>,
) -> Result<Fs> {
let mut slave_req_support = false;
@@ -471,7 +474,7 @@ impl VirtioDevice for Fs {
// Initialize slave communication.
let slave_req_handler = if self.slave_req_support {
if let Some(cache) = self.cache.clone() {
if let Some(cache) = self.cache.as_ref() {
let vu_master_req_handler = Arc::new(Mutex::new(SlaveReqHandler {
cache_offset: cache.0.addr,
cache_size: cache.0.len,
@@ -542,8 +545,8 @@ impl VirtioDevice for Fs {
}
fn get_shm_regions(&self) -> Option<VirtioSharedMemoryList> {
if let Some(cache) = self.cache.clone() {
Some(cache.0)
if let Some(cache) = self.cache.as_ref() {
Some(cache.0.clone())
} else {
None
}