Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/vmm/src/devices/virtio/pmem/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ pub struct Pmem {
pub config: PmemConfig,
}

impl Drop for Pmem {
fn drop(&mut self) {
let mmap_len = align_up(self.file_len, Self::ALIGNMENT);
// SAFETY: `mmap_ptr` is a valid pointer since Pmem can only be created with `new*` methods.
// Mapping size calculation is same for original mmap call.
unsafe {
_ = libc::munmap(self.mmap_ptr as *mut libc::c_void, u64_to_usize(mmap_len));
}
}
}

impl Pmem {
// Pmem devices need to have address and size to be
// a multiple of 2MB
Expand Down Expand Up @@ -130,10 +141,7 @@ impl Pmem {
})
}

pub fn mmap_backing_file(
path: &str,
read_only: bool,
) -> Result<(File, u64, u64, u64), PmemError> {
fn mmap_backing_file(path: &str, read_only: bool) -> Result<(File, u64, u64, u64), PmemError> {
let file = OpenOptions::new()
.read(true)
.write(!read_only)
Expand Down