diff --git a/Cargo.lock b/Cargo.lock index 9833afbee..b300f8cd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1157,7 +1157,7 @@ dependencies = [ [[package]] name = "vm-memory" version = "0.1.0" -source = "git+https://github.com/rust-vmm/vm-memory#4237db35e821fd67a4b8f52934adcd58f8679421" +source = "git+https://github.com/rust-vmm/vm-memory#f3d1c2775ccf619d7a7330ddfc4954a784b45751" dependencies = [ "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index 223d742a7..a6f274718 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -226,7 +226,7 @@ mod tests { #[test] fn test_system_configuration() { let no_vcpus = 4; - let gm = GuestMemoryMmap::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); + let gm = GuestMemoryMmap::from_ranges(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let config_err = configure_system(&gm, GuestAddress(0), 0, 1, None, None); assert!(config_err.is_err()); @@ -238,7 +238,7 @@ mod tests { .filter(|r| r.2 == RegionType::Ram) .map(|r| (r.0, r.1)) .collect(); - let gm = GuestMemoryMmap::new(&ram_regions).unwrap(); + let gm = GuestMemoryMmap::from_ranges(&ram_regions).unwrap(); configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap(); // Now assigning some memory that is equal to the start of the 32bit memory hole. @@ -249,7 +249,7 @@ mod tests { .filter(|r| r.2 == RegionType::Ram) .map(|r| (r.0, r.1)) .collect(); - let gm = GuestMemoryMmap::new(&ram_regions).unwrap(); + let gm = GuestMemoryMmap::from_ranges(&ram_regions).unwrap(); configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap(); // Now assigning some memory that falls after the 32bit memory hole. @@ -260,7 +260,7 @@ mod tests { .filter(|r| r.2 == RegionType::Ram) .map(|r| (r.0, r.1)) .collect(); - let gm = GuestMemoryMmap::new(&ram_regions).unwrap(); + let gm = GuestMemoryMmap::from_ranges(&ram_regions).unwrap(); configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap(); } diff --git a/arch/src/x86_64/mptable.rs b/arch/src/x86_64/mptable.rs index 11d83d71c..aaa44109c 100644 --- a/arch/src/x86_64/mptable.rs +++ b/arch/src/x86_64/mptable.rs @@ -296,7 +296,8 @@ mod tests { #[test] fn bounds_check() { let num_cpus = 4; - let mem = GuestMemoryMmap::new(&[(MPTABLE_START, compute_mp_size(num_cpus))]).unwrap(); + let mem = + GuestMemoryMmap::from_ranges(&[(MPTABLE_START, compute_mp_size(num_cpus))]).unwrap(); setup_mptable(&mem, num_cpus).unwrap(); } @@ -304,7 +305,8 @@ mod tests { #[test] fn bounds_check_fails() { let num_cpus = 4; - let mem = GuestMemoryMmap::new(&[(MPTABLE_START, compute_mp_size(num_cpus) - 1)]).unwrap(); + let mem = GuestMemoryMmap::from_ranges(&[(MPTABLE_START, compute_mp_size(num_cpus) - 1)]) + .unwrap(); assert!(setup_mptable(&mem, num_cpus).is_err()); } @@ -312,7 +314,8 @@ mod tests { #[test] fn mpf_intel_checksum() { let num_cpus = 1; - let mem = GuestMemoryMmap::new(&[(MPTABLE_START, compute_mp_size(num_cpus))]).unwrap(); + let mem = + GuestMemoryMmap::from_ranges(&[(MPTABLE_START, compute_mp_size(num_cpus))]).unwrap(); setup_mptable(&mem, num_cpus).unwrap(); @@ -327,7 +330,8 @@ mod tests { #[test] fn mpc_table_checksum() { let num_cpus = 4; - let mem = GuestMemoryMmap::new(&[(MPTABLE_START, compute_mp_size(num_cpus))]).unwrap(); + let mem = + GuestMemoryMmap::from_ranges(&[(MPTABLE_START, compute_mp_size(num_cpus))]).unwrap(); setup_mptable(&mem, num_cpus).unwrap(); @@ -356,9 +360,11 @@ mod tests { #[test] fn cpu_entry_count() { - let mem = - GuestMemoryMmap::new(&[(MPTABLE_START, compute_mp_size(MAX_SUPPORTED_CPUS as u8))]) - .unwrap(); + let mem = GuestMemoryMmap::from_ranges(&[( + MPTABLE_START, + compute_mp_size(MAX_SUPPORTED_CPUS as u8), + )]) + .unwrap(); for i in 0..MAX_SUPPORTED_CPUS as u8 { setup_mptable(&mem, i).unwrap(); @@ -391,7 +397,8 @@ mod tests { #[test] fn cpu_entry_count_max() { let cpus = MAX_SUPPORTED_CPUS + 1; - let mem = GuestMemoryMmap::new(&[(MPTABLE_START, compute_mp_size(cpus as u8))]).unwrap(); + let mem = + GuestMemoryMmap::from_ranges(&[(MPTABLE_START, compute_mp_size(cpus as u8))]).unwrap(); let result = setup_mptable(&mem, cpus as u8); assert!(result.is_err()); diff --git a/arch/src/x86_64/regs.rs b/arch/src/x86_64/regs.rs index e0cc9b2da..c963f7533 100644 --- a/arch/src/x86_64/regs.rs +++ b/arch/src/x86_64/regs.rs @@ -269,7 +269,7 @@ mod tests { use vm_memory::{GuestAddress, GuestMemoryMmap}; fn create_guest_mem() -> GuestMemoryMmap { - GuestMemoryMmap::new(&vec![(GuestAddress(0), 0x10000)]).unwrap() + GuestMemoryMmap::from_ranges(&vec![(GuestAddress(0), 0x10000)]).unwrap() } fn read_u64(gm: &GuestMemoryMmap, offset: GuestAddress) -> u64 { diff --git a/vhost_user_backend/src/lib.rs b/vhost_user_backend/src/lib.rs index e5db87ad4..f9f96ba37 100644 --- a/vhost_user_backend/src/lib.rs +++ b/vhost_user_backend/src/lib.rs @@ -536,7 +536,7 @@ impl VhostUserSlaveReqHandler for VhostUserHandler { }); } - let mem = GuestMemoryMmap::with_files(regions).map_err(|e| { + let mem = GuestMemoryMmap::from_ranges_with_files(regions).map_err(|e| { VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e)) })?; self.backend diff --git a/vhost_user_fs/src/descriptor_utils.rs b/vhost_user_fs/src/descriptor_utils.rs index 4db6a5ae1..d0d26802d 100644 --- a/vhost_user_fs/src/descriptor_utils.rs +++ b/vhost_user_fs/src/descriptor_utils.rs @@ -546,7 +546,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -587,7 +587,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -628,7 +628,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -653,7 +653,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -678,7 +678,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -726,7 +726,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let secret: Le32 = 0x12345678.into(); @@ -765,7 +765,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -795,7 +795,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -824,7 +824,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -853,7 +853,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -882,7 +882,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -911,7 +911,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -940,7 +940,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, @@ -964,7 +964,7 @@ mod tests { use DescriptorType::*; let memory_start_addr = GuestAddress(0x0); - let memory = GuestMemoryMmap::new(&vec![(memory_start_addr, 0x10000)]).unwrap(); + let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap(); let chain = create_descriptor_chain( &memory, diff --git a/vm-device/src/lib.rs b/vm-device/src/lib.rs index 5be910637..bd5b01e57 100644 --- a/vm-device/src/lib.rs +++ b/vm-device/src/lib.rs @@ -89,7 +89,7 @@ mod tests { let start_addr1 = GuestAddress(0x0); let start_addr2 = GuestAddress(0x1000); let guest_mem = - GuestMemoryMmap::new(&[(start_addr1, 0x400), (start_addr2, 0x400)]).unwrap(); + GuestMemoryMmap::from_ranges(&[(start_addr1, 0x400), (start_addr2, 0x400)]).unwrap(); assert!(get_host_address_range(&guest_mem, GuestAddress(0x600), 0x100).is_none()); diff --git a/vm-virtio/src/queue.rs b/vm-virtio/src/queue.rs index 2a46ce94e..137167f67 100644 --- a/vm-virtio/src/queue.rs +++ b/vm-virtio/src/queue.rs @@ -731,7 +731,7 @@ pub(crate) mod tests { #[test] fn test_checked_new_descriptor_chain() { - let m = &GuestMemoryMmap::new(&[(GuestAddress(0), 0x10000)]).unwrap(); + let m = &GuestMemoryMmap::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap(); let vq = VirtQueue::new(GuestAddress(0), m, 16); assert!(vq.end().0 < 0x1000); @@ -792,7 +792,7 @@ pub(crate) mod tests { #[test] fn test_queue_and_iterator() { - let m = &GuestMemoryMmap::new(&[(GuestAddress(0), 0x10000)]).unwrap(); + let m = &GuestMemoryMmap::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap(); let vq = VirtQueue::new(GuestAddress(0), m, 16); let mut q = vq.create_queue(); @@ -897,7 +897,7 @@ pub(crate) mod tests { #[test] fn test_add_used() { - let m = &GuestMemoryMmap::new(&[(GuestAddress(0), 0x10000)]).unwrap(); + let m = &GuestMemoryMmap::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap(); let vq = VirtQueue::new(GuestAddress(0), m, 16); let mut q = vq.create_queue(); diff --git a/vm-virtio/src/vsock/mod.rs b/vm-virtio/src/vsock/mod.rs index 3feb2bff9..e47628ce7 100644 --- a/vm-virtio/src/vsock/mod.rs +++ b/vm-virtio/src/vsock/mod.rs @@ -264,7 +264,7 @@ mod tests { const MEM_SIZE: usize = 1024 * 1024 * 128; Self { cid: CID, - mem: GuestMemoryMmap::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap(), + mem: GuestMemoryMmap::from_ranges(&[(GuestAddress(0), MEM_SIZE)]).unwrap(), mem_size: MEM_SIZE, device: Vsock::new(CID, TestBackend::new(), false).unwrap(), } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index c23f52743..192d6efdd 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -749,7 +749,7 @@ pub fn test_vm() { let mem_size = 0x1000; let load_addr = GuestAddress(0x1000); - let mem = GuestMemoryMmap::new(&[(load_addr, mem_size)]).unwrap(); + let mem = GuestMemoryMmap::from_ranges(&[(load_addr, mem_size)]).unwrap(); let kvm = Kvm::new().expect("new KVM instance creation failed"); let vm_fd = kvm.create_vm().expect("new VM fd creation failed");