mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-01 11:05:46 +00:00
vm-virtio: pmem: Expect an identifier upon device creation
This identifier is chosen from the DeviceManager so that it will manage all identifiers across the VM, which will ensure uniqueness. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
2e91b73881
commit
1592a9292f
@ -337,6 +337,7 @@ impl PmemEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Pmem {
|
pub struct Pmem {
|
||||||
|
id: String,
|
||||||
kill_evt: Option<EventFd>,
|
kill_evt: Option<EventFd>,
|
||||||
pause_evt: Option<EventFd>,
|
pause_evt: Option<EventFd>,
|
||||||
disk: Option<File>,
|
disk: Option<File>,
|
||||||
@ -363,6 +364,7 @@ pub struct PmemState {
|
|||||||
|
|
||||||
impl Pmem {
|
impl Pmem {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
id: String,
|
||||||
disk: File,
|
disk: File,
|
||||||
addr: GuestAddress,
|
addr: GuestAddress,
|
||||||
mapping: UserspaceMapping,
|
mapping: UserspaceMapping,
|
||||||
@ -381,6 +383,7 @@ impl Pmem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(Pmem {
|
Ok(Pmem {
|
||||||
|
id,
|
||||||
kill_evt: None,
|
kill_evt: None,
|
||||||
pause_evt: None,
|
pause_evt: None,
|
||||||
disk: Some(disk),
|
disk: Some(disk),
|
||||||
@ -571,19 +574,18 @@ impl VirtioDevice for Pmem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtio_pausable!(Pmem);
|
virtio_pausable!(Pmem);
|
||||||
const PMEM_SNAPSHOT_ID: &str = "virtio-pmem";
|
|
||||||
impl Snapshottable for Pmem {
|
impl Snapshottable for Pmem {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
PMEM_SNAPSHOT_ID.to_string()
|
self.id.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
let snapshot =
|
let snapshot =
|
||||||
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;
|
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;
|
||||||
|
|
||||||
let mut pmem_snapshot = Snapshot::new(PMEM_SNAPSHOT_ID);
|
let mut pmem_snapshot = Snapshot::new(self.id.as_str());
|
||||||
pmem_snapshot.add_data_section(SnapshotDataSection {
|
pmem_snapshot.add_data_section(SnapshotDataSection {
|
||||||
id: format!("{}-section", PMEM_SNAPSHOT_ID),
|
id: format!("{}-section", self.id),
|
||||||
snapshot,
|
snapshot,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -591,10 +593,7 @@ impl Snapshottable for Pmem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
|
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
|
||||||
if let Some(pmem_section) = snapshot
|
if let Some(pmem_section) = snapshot.snapshot_data.get(&format!("{}-section", self.id)) {
|
||||||
.snapshot_data
|
|
||||||
.get(&format!("{}-section", PMEM_SNAPSHOT_ID))
|
|
||||||
{
|
|
||||||
let pmem_state = match serde_json::from_slice(&pmem_section.snapshot) {
|
let pmem_state = match serde_json::from_slice(&pmem_section.snapshot) {
|
||||||
Ok(state) => state,
|
Ok(state) => state,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
@ -1560,9 +1560,13 @@ impl DeviceManager {
|
|||||||
&mut self,
|
&mut self,
|
||||||
pmem_cfg: &mut PmemConfig,
|
pmem_cfg: &mut PmemConfig,
|
||||||
) -> DeviceManagerResult<(VirtioDeviceArc, bool, Option<String>)> {
|
) -> DeviceManagerResult<(VirtioDeviceArc, bool, Option<String>)> {
|
||||||
if pmem_cfg.id.is_none() {
|
let id = if let Some(id) = &pmem_cfg.id {
|
||||||
pmem_cfg.id = Some(self.next_device_name(PMEM_DEVICE_NAME_PREFIX)?);
|
id.clone()
|
||||||
}
|
} else {
|
||||||
|
let id = self.next_device_name(PMEM_DEVICE_NAME_PREFIX)?;
|
||||||
|
pmem_cfg.id = Some(id.clone());
|
||||||
|
id
|
||||||
|
};
|
||||||
|
|
||||||
let (custom_flags, set_len) = if pmem_cfg.file.is_dir() {
|
let (custom_flags, set_len) = if pmem_cfg.file.is_dir() {
|
||||||
if pmem_cfg.size.is_none() {
|
if pmem_cfg.size.is_none() {
|
||||||
@ -1646,13 +1650,18 @@ impl DeviceManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let virtio_pmem_device = Arc::new(Mutex::new(
|
let virtio_pmem_device = Arc::new(Mutex::new(
|
||||||
vm_virtio::Pmem::new(file, pmem_guest_addr, mapping, mmap_region, pmem_cfg.iommu)
|
vm_virtio::Pmem::new(
|
||||||
.map_err(DeviceManagerError::CreateVirtioPmem)?,
|
id,
|
||||||
|
file,
|
||||||
|
pmem_guest_addr,
|
||||||
|
mapping,
|
||||||
|
mmap_region,
|
||||||
|
pmem_cfg.iommu,
|
||||||
|
)
|
||||||
|
.map_err(DeviceManagerError::CreateVirtioPmem)?,
|
||||||
));
|
));
|
||||||
|
|
||||||
let migratable = Arc::clone(&virtio_pmem_device) as Arc<Mutex<dyn Migratable>>;
|
self.add_migratable_device(Arc::clone(&virtio_pmem_device) as Arc<Mutex<dyn Migratable>>);
|
||||||
let id = migratable.lock().unwrap().id();
|
|
||||||
self.migratable_devices.push((id, migratable));
|
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Arc::clone(&virtio_pmem_device) as VirtioDeviceArc,
|
Arc::clone(&virtio_pmem_device) as VirtioDeviceArc,
|
||||||
|
Loading…
Reference in New Issue
Block a user