vmm: memory_manager: Replace 'backing_file' variable names

In the context of saving the memory regions content through snapshot,
using the term "backing file" brings confusion with the actual backing
file that might back the memory mapping.

To avoid such conflicting naming, the 'backing_file' field from the
MemoryRegion structure gets replaced with 'content', as this is
designating the potential file containing the memory region data.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-10-23 13:54:29 +02:00
parent 1409b36cad
commit c0e8e5b53f

View File

@ -764,20 +764,20 @@ impl MemoryManager {
} }
}; };
// Here we turn the backing file name into a backing file path as // Here we turn the content file name into a content file path as
// this will be needed when the memory region will be created with // this will be needed to copy the content of the saved memory
// mmap(). // region into the newly created memory region.
// We simply ignore the backing files that are None, as they // We simply ignore the content files that are None, as they
// represent files that have been directly saved by the user, with // represent regions that have been directly saved by the user, with
// no need for saving into a dedicated external file. For these // no need for saving into a dedicated external file. For these
// files, the VmConfig already contains the information on where to // files, the VmConfig already contains the information on where to
// find them. // find them.
let mut ext_regions = mem_snapshot.memory_regions; let mut ext_regions = mem_snapshot.memory_regions;
for region in ext_regions.iter_mut() { for region in ext_regions.iter_mut() {
if let Some(backing_file) = &mut region.backing_file { if let Some(content) = &mut region.content {
let mut memory_region_path = vm_snapshot_path.clone(); let mut memory_region_path = vm_snapshot_path.clone();
memory_region_path.push(backing_file.clone()); memory_region_path.push(content.clone());
*backing_file = memory_region_path; *content = memory_region_path;
} }
} }
@ -844,7 +844,7 @@ impl MemoryManager {
if let Some(ext_regions) = ext_regions { if let Some(ext_regions) = ext_regions {
for ext_region in ext_regions.iter() { for ext_region in ext_regions.iter() {
if ext_region.start_addr == start_addr && ext_region.size as usize == size { if ext_region.start_addr == start_addr && ext_region.size as usize == size {
copy_ext_region_content = ext_region.backing_file.clone(); copy_ext_region_content = ext_region.content.clone();
// No need to iterate further as we found the external // No need to iterate further as we found the external
// region matching the current region. // region matching the current region.
@ -922,11 +922,11 @@ impl MemoryManager {
.map_err(Error::GuestMemory)?; .map_err(Error::GuestMemory)?;
// Copy data to the region if needed // Copy data to the region if needed
if let Some(ext_backing_file) = &copy_ext_region_content { if let Some(ext_region_content) = &copy_ext_region_content {
// Open (read only) the snapshot file for the given region. // Open (read only) the snapshot file for the given region.
let mut memory_region_file = OpenOptions::new() let mut memory_region_file = OpenOptions::new()
.read(true) .read(true)
.open(ext_backing_file) .open(ext_region_content)
.map_err(Error::SnapshotOpen)?; .map_err(Error::SnapshotOpen)?;
// Fill the region with the file content. // Fill the region with the file content.
@ -1748,7 +1748,7 @@ pub struct GuestAddressDef(pub u64);
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Serialize, Deserialize)]
pub struct MemoryRegion { pub struct MemoryRegion {
backing_file: Option<PathBuf>, content: Option<PathBuf>,
#[serde(with = "GuestAddressDef")] #[serde(with = "GuestAddressDef")]
start_addr: GuestAddress, start_addr: GuestAddress,
size: GuestUsize, size: GuestUsize,
@ -1775,7 +1775,7 @@ impl Snapshottable for MemoryManager {
return Err(MigratableError::Snapshot(anyhow!("Zero length region"))); return Err(MigratableError::Snapshot(anyhow!("Zero length region")));
} }
let mut backing_file = Some(PathBuf::from(format!("memory-region-{}", index))); let mut content = Some(PathBuf::from(format!("memory-region-{}", index)));
if let Some(file_offset) = region.file_offset() { if let Some(file_offset) = region.file_offset() {
if (region.flags() & libc::MAP_SHARED == libc::MAP_SHARED) if (region.flags() & libc::MAP_SHARED == libc::MAP_SHARED)
&& Self::is_hardlink(file_offset.file()) && Self::is_hardlink(file_offset.file())
@ -1789,12 +1789,12 @@ impl Snapshottable for MemoryManager {
// the memory content for this specific region, as we can // the memory content for this specific region, as we can
// assume the user will have it saved through the backing // assume the user will have it saved through the backing
// file already. // file already.
backing_file = None; content = None;
} }
} }
memory_regions.push(MemoryRegion { memory_regions.push(MemoryRegion {
backing_file, content,
start_addr: region.start_addr(), start_addr: region.start_addr(),
size: region.len(), size: region.len(),
}); });
@ -1858,9 +1858,9 @@ impl Transportable for MemoryManager {
if let Some(guest_memory) = &*self.snapshot.lock().unwrap() { if let Some(guest_memory) = &*self.snapshot.lock().unwrap() {
for region in self.snapshot_memory_regions.iter() { for region in self.snapshot_memory_regions.iter() {
if let Some(backing_file) = &region.backing_file { if let Some(content) = &region.content {
let mut memory_region_path = vm_memory_snapshot_path.clone(); let mut memory_region_path = vm_memory_snapshot_path.clone();
memory_region_path.push(backing_file); memory_region_path.push(content);
// Create the snapshot file for the region // Create the snapshot file for the region
let mut memory_region_file = OpenOptions::new() let mut memory_region_file = OpenOptions::new()