vmm: Propagate the set of memory slots to FDs received in migration

Create the VM using the FDs (wrapped in Files) that have been received
during the migration process.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-01-14 08:19:43 +00:00
parent 735658a49d
commit 1daef5e8c9
2 changed files with 12 additions and 3 deletions

View File

@ -29,6 +29,7 @@ use memory_manager::MemoryManagerSnapshotData;
use pci::PciBdf; use pci::PciBdf;
use seccompiler::{apply_filter, SeccompAction}; use seccompiler::{apply_filter, SeccompAction};
use serde::ser::{Serialize, SerializeStruct, Serializer}; use serde::ser::{Serialize, SerializeStruct, Serializer};
use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::io; use std::io;
use std::io::{Read, Write}; use std::io::{Read, Write};
@ -753,6 +754,7 @@ impl Vmm {
&mut self, &mut self,
req: &Request, req: &Request,
socket: &mut T, socket: &mut T,
existing_memory_files: Option<HashMap<u32, File>>,
) -> std::result::Result<Vm, MigratableError> ) -> std::result::Result<Vm, MigratableError>
where where
T: Read + Write, T: Read + Write,
@ -794,6 +796,7 @@ impl Vmm {
self.hypervisor.clone(), self.hypervisor.clone(),
activate_evt, activate_evt,
&vm_migration_config.memory_manager_data, &vm_migration_config.memory_manager_data,
existing_memory_files,
) )
.map_err(|e| { .map_err(|e| {
MigratableError::MigrateReceive(anyhow!("Error creating VM from snapshot: {:?}", e)) MigratableError::MigrateReceive(anyhow!("Error creating VM from snapshot: {:?}", e))
@ -886,7 +889,7 @@ impl Vmm {
let mut started = false; let mut started = false;
let mut vm: Option<Vm> = None; let mut vm: Option<Vm> = None;
let mut existing_memory_files = None;
loop { loop {
let req = Request::read_from(&mut socket)?; let req = Request::read_from(&mut socket)?;
match req.command() { match req.command() {
@ -905,7 +908,11 @@ impl Vmm {
Response::error().write_to(&mut socket)?; Response::error().write_to(&mut socket)?;
continue; continue;
} }
vm = Some(self.vm_receive_config(&req, &mut socket)?); vm = Some(self.vm_receive_config(
&req,
&mut socket,
existing_memory_files.take(),
)?);
} }
Command::State => { Command::State => {
info!("State Command Received"); info!("State Command Received");

View File

@ -867,6 +867,7 @@ impl Vm {
) )
} }
#[allow(clippy::too_many_arguments)]
pub fn new_from_migration( pub fn new_from_migration(
config: Arc<Mutex<VmConfig>>, config: Arc<Mutex<VmConfig>>,
exit_evt: EventFd, exit_evt: EventFd,
@ -875,6 +876,7 @@ impl Vm {
hypervisor: Arc<dyn hypervisor::Hypervisor>, hypervisor: Arc<dyn hypervisor::Hypervisor>,
activate_evt: EventFd, activate_evt: EventFd,
memory_manager_data: &MemoryManagerSnapshotData, memory_manager_data: &MemoryManagerSnapshotData,
existing_memory_files: Option<HashMap<u32, File>>,
) -> Result<Self> { ) -> Result<Self> {
hypervisor.check_required_extensions().unwrap(); hypervisor.check_required_extensions().unwrap();
let vm = hypervisor.create_vm().unwrap(); let vm = hypervisor.create_vm().unwrap();
@ -897,7 +899,7 @@ impl Vm {
#[cfg(feature = "tdx")] #[cfg(feature = "tdx")]
false, false,
Some(memory_manager_data), Some(memory_manager_data),
None, existing_memory_files,
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
None, None,
) )