mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Stop using deprecated functions from vm-memory crate
See: https://github.com/rust-vmm/vm-memory/pull/247 Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
@@ -51,6 +51,7 @@ use std::{result, thread};
|
||||
use thiserror::Error;
|
||||
use tracer::trace_scoped;
|
||||
use vm_memory::bitmap::AtomicBitmap;
|
||||
use vm_memory::{ReadVolatile, WriteVolatile};
|
||||
use vm_migration::{protocol::*, Migratable};
|
||||
use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
@@ -1449,7 +1450,7 @@ impl Vmm {
|
||||
memory_manager: &mut MemoryManager,
|
||||
) -> std::result::Result<(), MigratableError>
|
||||
where
|
||||
T: Read + Write,
|
||||
T: Read + ReadVolatile + Write,
|
||||
{
|
||||
// Read table
|
||||
let table = MemoryRangeTable::read_from(socket, req.length())?;
|
||||
@@ -1608,7 +1609,7 @@ impl Vmm {
|
||||
socket: &mut T,
|
||||
) -> result::Result<bool, MigratableError>
|
||||
where
|
||||
T: Read + Write,
|
||||
T: Read + Write + WriteVolatile,
|
||||
{
|
||||
// Send (dirty) memory table
|
||||
let table = vm.dirty_log()?;
|
||||
|
||||
@@ -30,8 +30,10 @@ use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::ffi;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, Read};
|
||||
use std::io::{self};
|
||||
use std::ops::{BitAnd, Deref, Not, Sub};
|
||||
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
|
||||
use std::os::fd::AsFd;
|
||||
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
|
||||
use std::path::PathBuf;
|
||||
use std::result;
|
||||
@@ -47,8 +49,9 @@ use vm_device::BusDevice;
|
||||
use vm_memory::bitmap::AtomicBitmap;
|
||||
use vm_memory::guest_memory::FileOffset;
|
||||
use vm_memory::{
|
||||
mmap::MmapRegionError, Address, Bytes, Error as MmapError, GuestAddress, GuestAddressSpace,
|
||||
mmap::MmapRegionError, Address, Error as MmapError, GuestAddress, GuestAddressSpace,
|
||||
GuestMemory, GuestMemoryAtomic, GuestMemoryError, GuestMemoryRegion, GuestUsize, MmapRegion,
|
||||
ReadVolatile,
|
||||
};
|
||||
use vm_migration::{
|
||||
protocol::MemoryRange, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable,
|
||||
@@ -728,7 +731,7 @@ impl MemoryManager {
|
||||
// see: https://github.com/rust-vmm/vm-memory/issues/174
|
||||
loop {
|
||||
let bytes_read = guest_memory
|
||||
.read_from(
|
||||
.read_volatile_from(
|
||||
GuestAddress(range.gpa + offset),
|
||||
&mut memory_file,
|
||||
(range.length - offset) as usize,
|
||||
@@ -2084,7 +2087,7 @@ impl MemoryManager {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut coredump_file = dump_state.file.as_ref().unwrap();
|
||||
let coredump_file = dump_state.file.as_ref().unwrap();
|
||||
|
||||
let guest_memory = self.guest_memory.memory();
|
||||
let mut total_bytes: u64 = 0;
|
||||
@@ -2093,9 +2096,9 @@ impl MemoryManager {
|
||||
let mut offset: u64 = 0;
|
||||
loop {
|
||||
let bytes_written = guest_memory
|
||||
.write_to(
|
||||
.write_volatile_to(
|
||||
GuestAddress(range.gpa + offset),
|
||||
&mut coredump_file,
|
||||
&mut coredump_file.as_fd(),
|
||||
(range.length - offset) as usize,
|
||||
)
|
||||
.map_err(|e| GuestDebuggableError::Coredump(e.into()))?;
|
||||
@@ -2118,7 +2121,7 @@ impl MemoryManager {
|
||||
fd: &mut F,
|
||||
) -> std::result::Result<(), MigratableError>
|
||||
where
|
||||
F: Read,
|
||||
F: ReadVolatile,
|
||||
{
|
||||
let guest_memory = self.guest_memory();
|
||||
let mem = guest_memory.memory();
|
||||
@@ -2132,7 +2135,7 @@ impl MemoryManager {
|
||||
// see: https://github.com/rust-vmm/vm-memory/issues/174
|
||||
loop {
|
||||
let bytes_read = mem
|
||||
.read_from(
|
||||
.read_volatile_from(
|
||||
GuestAddress(range.gpa + offset),
|
||||
fd,
|
||||
(range.length - offset) as usize,
|
||||
@@ -2600,7 +2603,7 @@ impl Transportable for MemoryManager {
|
||||
// see: https://github.com/rust-vmm/vm-memory/issues/174
|
||||
loop {
|
||||
let bytes_written = guest_memory
|
||||
.write_to(
|
||||
.write_volatile_to(
|
||||
GuestAddress(range.gpa + offset),
|
||||
&mut memory_file,
|
||||
(range.length - offset) as usize,
|
||||
|
||||
@@ -72,8 +72,6 @@ use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, Seek, SeekFrom, Write};
|
||||
#[cfg(feature = "tdx")]
|
||||
use std::mem;
|
||||
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
|
||||
use std::mem::size_of;
|
||||
use std::num::Wrapping;
|
||||
@@ -86,8 +84,10 @@ use thiserror::Error;
|
||||
use tracer::trace_scoped;
|
||||
use vm_device::Bus;
|
||||
#[cfg(feature = "tdx")]
|
||||
use vm_memory::{Address, ByteValued, GuestMemory, GuestMemoryRegion};
|
||||
use vm_memory::{Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic};
|
||||
use vm_memory::{Address, ByteValued, GuestMemoryRegion, ReadVolatile};
|
||||
use vm_memory::{
|
||||
Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, WriteVolatile,
|
||||
};
|
||||
use vm_migration::protocol::{Request, Response, Status};
|
||||
use vm_migration::{
|
||||
protocol::MemoryRangeTable, snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot,
|
||||
@@ -884,7 +884,7 @@ impl Vm {
|
||||
}
|
||||
|
||||
fn load_initramfs(&mut self, guest_mem: &GuestMemoryMmap) -> Result<arch::InitramfsConfig> {
|
||||
let mut initramfs = self.initramfs.as_ref().unwrap();
|
||||
let initramfs = self.initramfs.as_mut().unwrap();
|
||||
let size: usize = initramfs
|
||||
.seek(SeekFrom::End(0))
|
||||
.map_err(|_| Error::InitramfsLoad)?
|
||||
@@ -897,7 +897,7 @@ impl Vm {
|
||||
let address = GuestAddress(address);
|
||||
|
||||
guest_mem
|
||||
.read_from(address, &mut initramfs, size)
|
||||
.read_volatile_from(address, initramfs, size)
|
||||
.map_err(|_| Error::InitramfsLoad)?;
|
||||
|
||||
info!("Initramfs loaded: address = 0x{:x}", address.0);
|
||||
@@ -1744,7 +1744,7 @@ impl Vm {
|
||||
firmware_file
|
||||
.seek(SeekFrom::Start(section.data_offset as u64))
|
||||
.map_err(Error::LoadTdvf)?;
|
||||
mem.read_from(
|
||||
mem.read_volatile_from(
|
||||
GuestAddress(section.address),
|
||||
&mut firmware_file,
|
||||
section.data_size as usize,
|
||||
@@ -1766,13 +1766,8 @@ impl Vm {
|
||||
.map_err(Error::LoadPayload)?;
|
||||
|
||||
let mut payload_header = linux_loader::bootparam::setup_header::default();
|
||||
payload_header
|
||||
.as_bytes()
|
||||
.read_from(
|
||||
0,
|
||||
payload_file,
|
||||
mem::size_of::<linux_loader::bootparam::setup_header>(),
|
||||
)
|
||||
payload_file
|
||||
.read_volatile(&mut payload_header.as_bytes())
|
||||
.unwrap();
|
||||
|
||||
if payload_header.header != 0x5372_6448 {
|
||||
@@ -1786,7 +1781,7 @@ impl Vm {
|
||||
}
|
||||
|
||||
payload_file.rewind().map_err(Error::LoadPayload)?;
|
||||
mem.read_from(
|
||||
mem.read_volatile_from(
|
||||
GuestAddress(section.address),
|
||||
payload_file,
|
||||
payload_size as usize,
|
||||
@@ -2129,7 +2124,7 @@ impl Vm {
|
||||
fd: &mut F,
|
||||
) -> std::result::Result<(), MigratableError>
|
||||
where
|
||||
F: Write,
|
||||
F: WriteVolatile,
|
||||
{
|
||||
let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory();
|
||||
let mem = guest_memory.memory();
|
||||
@@ -2143,7 +2138,7 @@ impl Vm {
|
||||
// see: https://github.com/rust-vmm/vm-memory/issues/174
|
||||
loop {
|
||||
let bytes_written = mem
|
||||
.write_to(
|
||||
.write_volatile_to(
|
||||
GuestAddress(range.gpa + offset),
|
||||
fd,
|
||||
(range.length - offset) as usize,
|
||||
|
||||
Reference in New Issue
Block a user