mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 19:32:20 +00:00
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:
parent
b9c260c0de
commit
271e17bd79
@ -1144,18 +1144,13 @@ impl MemoryManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
fn open_memory_file(
|
||||||
fn create_ram_region(
|
|
||||||
backing_file: &Option<PathBuf>,
|
backing_file: &Option<PathBuf>,
|
||||||
file_offset: u64,
|
file_offset: u64,
|
||||||
start_addr: GuestAddress,
|
|
||||||
size: usize,
|
size: usize,
|
||||||
prefault: bool,
|
|
||||||
shared: bool,
|
|
||||||
hugepages: bool,
|
hugepages: bool,
|
||||||
hugepage_size: Option<u64>,
|
hugepage_size: Option<u64>,
|
||||||
host_numa_node: Option<u32>,
|
) -> Result<(File, u64), Error> {
|
||||||
) -> Result<Arc<GuestRegionMmap>, Error> {
|
|
||||||
let (f, f_off) = match backing_file {
|
let (f, f_off) = match backing_file {
|
||||||
Some(ref file) => {
|
Some(ref file) => {
|
||||||
if file.is_dir() {
|
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
|
let mut mmap_flags = libc::MAP_NORESERVE
|
||||||
| if shared {
|
| if shared {
|
||||||
libc::MAP_SHARED
|
libc::MAP_SHARED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user