Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate GuestMemory stopgap "iterator" methods #144

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
## [Unreleased]

### Deprecated

- [[#133]](https://github.com/rust-vmm/vm-memory/issues/8): Deprecate `GuestMemory::with_regions()`,
`GuestMemory::with_regions_mut()`, `GuestMemory::map_and_fold()`

## [v0.5.0]

Expand Down
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 85.6,
"coverage_score": 85.4,
"exclude_path": "mmap_windows.rs",
"crate_features": "backend-mmap,backend-atomic"
}
33 changes: 11 additions & 22 deletions src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ impl<M: GuestMemory> GuestMemoryExclusiveGuard<'_, M> {
mod tests {
use super::*;
use crate::{
GuestAddress, GuestMemory, GuestMemoryMmap, GuestMemoryRegion, GuestMemoryResult,
GuestRegionMmap, GuestUsize, MmapRegion,
GuestAddress, GuestMemory, GuestMemoryMmap, GuestMemoryRegion, GuestRegionMmap, GuestUsize,
MmapRegion,
};

type GuestMemoryMmapAtomic = GuestMemoryAtomic<GuestMemoryMmap>;
Expand All @@ -161,16 +161,13 @@ mod tests {
let gm = GuestMemoryMmapAtomic::new(gmm);
let mem = gm.memory();

let res: GuestMemoryResult<()> = mem.with_regions(|_, region| {
for region in mem.iter() {
assert_eq!(region.len(), region_size as GuestUsize);
Ok(())
});
assert!(res.is_ok());
let res: GuestMemoryResult<()> = mem.with_regions_mut(|_, region| {
}

for region in mem.iter() {
iterated_regions.push((region.start_addr(), region.len() as usize));
Ok(())
});
assert!(res.is_ok());
}
assert_eq!(regions, iterated_regions);
assert_eq!(mem.num_regions(), 2);
assert!(mem.find_region(GuestAddress(0x1000)).is_some());
Expand All @@ -182,13 +179,9 @@ mod tests {
.eq(iterated_regions.iter().copied()));

let mem2 = mem.into_inner();
let res: GuestMemoryResult<()> = mem2.with_regions(|_, region| {
for region in mem2.iter() {
assert_eq!(region.len(), region_size as GuestUsize);
Ok(())
});
assert!(res.is_ok());
let res: GuestMemoryResult<()> = mem2.with_regions_mut(|_, _| Ok(()));
assert!(res.is_ok());
}
assert_eq!(mem2.num_regions(), 2);
assert!(mem2.find_region(GuestAddress(0x1000)).is_some());
assert!(mem2.find_region(GuestAddress(0x10000)).is_none());
Expand All @@ -199,13 +192,9 @@ mod tests {
.eq(iterated_regions.iter().copied()));

let mem3 = mem2.memory();
let res: GuestMemoryResult<()> = mem3.with_regions(|_, region| {
for region in mem3.iter() {
assert_eq!(region.len(), region_size as GuestUsize);
Ok(())
});
assert!(res.is_ok());
let res: GuestMemoryResult<()> = mem3.with_regions_mut(|_, _| Ok(()));
assert!(res.is_ok());
}
assert_eq!(mem3.num_regions(), 2);
assert!(mem3.find_region(GuestAddress(0x1000)).is_some());
assert!(mem3.find_region(GuestAddress(0x10000)).is_none());
Expand Down
3 changes: 3 additions & 0 deletions src/guest_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ pub trait GuestMemory {
/// Perform the specified action on each region.
///
/// It only walks children of current region and does not step into sub regions.
#[deprecated(since = "0.6.0", note = "Use `.iter()` instead")]
fn with_regions<F, E>(&self, cb: F) -> std::result::Result<(), E>
where
F: Fn(usize, &Self::R) -> std::result::Result<(), E>,
Expand All @@ -486,6 +487,7 @@ pub trait GuestMemory {
/// Perform the specified action on each region mutably.
///
/// It only walks children of current region and does not step into sub regions.
#[deprecated(since = "0.6.0", note = "Use `.iter()` instead")]
fn with_regions_mut<F, E>(&self, mut cb: F) -> std::result::Result<(), E>
where
F: FnMut(usize, &Self::R) -> std::result::Result<(), E>,
Expand Down Expand Up @@ -554,6 +556,7 @@ pub trait GuestMemory {
/// assert_eq!(3, total_size)
/// # }
/// ```
#[deprecated(since = "0.6.0", note = "Use `.iter()` instead")]
fn map_and_fold<F, G, T>(&self, init: T, mapf: F, foldf: G) -> T
where
F: Fn((usize, &Self::R)) -> T,
Expand Down
27 changes: 11 additions & 16 deletions src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,16 +1196,14 @@ mod tests {
];
let mut iterated_regions = Vec::new();
let gm = GuestMemoryMmap::from_ranges(&regions).unwrap();
let res: guest_memory::Result<()> = gm.with_regions(|_, region| {
defunctio marked this conversation as resolved.
Show resolved Hide resolved

for region in gm.iter() {
assert_eq!(region.len(), region_size as GuestUsize);
Ok(())
});
assert!(res.is_ok());
let res: guest_memory::Result<()> = gm.with_regions_mut(|_, region| {
}

for region in gm.iter() {
iterated_regions.push((region.start_addr(), region.len() as usize));
Ok(())
});
assert!(res.is_ok());
}
assert_eq!(regions, iterated_regions);

assert!(regions
Expand All @@ -1228,16 +1226,13 @@ mod tests {
let gm = Arc::new(GuestMemoryMmap::from_ranges(&regions).unwrap());
let mem = gm.memory();

let res: guest_memory::Result<()> = mem.with_regions(|_, region| {
for region in mem.iter() {
assert_eq!(region.len(), region_size as GuestUsize);
Ok(())
});
assert!(res.is_ok());
let res: guest_memory::Result<()> = mem.with_regions_mut(|_, region| {
}

for region in mem.iter() {
iterated_regions.push((region.start_addr(), region.len() as usize));
Ok(())
});
assert!(res.is_ok());
}
assert_eq!(regions, iterated_regions);

assert!(regions
Expand Down