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

@@ -1331,7 +1331,7 @@ impl DeviceManager {
if let Some(fs_list_cfg) = &self.config.lock().unwrap().fs {
for fs_cfg in fs_list_cfg.iter() {
if let Some(fs_sock) = fs_cfg.sock.to_str() {
let cache: Option<(VirtioSharedMemoryList, u64)> = if fs_cfg.dax {
let cache = if fs_cfg.dax {
let fs_cache = fs_cfg.cache_size;
// The memory needs to be 2MiB aligned in order to support
// hugepages.
@@ -1356,8 +1356,6 @@ impl DeviceManager {
.map_err(DeviceManagerError::NewMmapRegion)?;
let addr: u64 = mmap_region.as_ptr() as u64;
self._mmap_regions.push(mmap_region);
self.memory_manager
.lock()
.unwrap()
@@ -1383,6 +1381,7 @@ impl DeviceManager {
region_list,
},
addr,
mmap_region,
))
} else {
None