vmm: Extract code for opening a file for memory

This function is used to open an FD (wrapped in a File) that points to
guest memory from memfd_create() or backed on the filesystem.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-01-12 10:06:46 +00:00
parent b9c260c0de
commit 271e17bd79

View File

@ -1144,18 +1144,13 @@ impl MemoryManager {
}
}
#[allow(clippy::too_many_arguments)]
fn create_ram_region(
fn open_memory_file(
backing_file: &Option<PathBuf>,
file_offset: u64,
start_addr: GuestAddress,
size: usize,
prefault: bool,
shared: bool,
hugepages: bool,
hugepage_size: Option<u64>,
host_numa_node: Option<u32>,
) -> Result<Arc<GuestRegionMmap>, Error> {
) -> Result<(File, u64), Error> {
let (f, f_off) = match backing_file {
Some(ref file) => {
if file.is_dir() {
@ -1218,6 +1213,24 @@ impl MemoryManager {
}
};
Ok((f, f_off))
}
#[allow(clippy::too_many_arguments)]
fn create_ram_region(
backing_file: &Option<PathBuf>,
file_offset: u64,
start_addr: GuestAddress,
size: usize,
prefault: bool,
shared: bool,
hugepages: bool,
hugepage_size: Option<u64>,
host_numa_node: Option<u32>,
) -> Result<Arc<GuestRegionMmap>, Error> {
let (f, f_off) =
Self::open_memory_file(backing_file, file_offset, size, hugepages, hugepage_size)?;
let mut mmap_flags = libc::MAP_NORESERVE
| if shared {
libc::MAP_SHARED