Skip to content

Commit 2dc6caa

Browse files
committed
Make mmap_unix.rs and mmap_xen.rs not mutually exclusive
Now that all tension between these two modules is resolves (e.g. no more code depends on exactly one of these being defined, and tests can support iterating over multiple supported backends), drop all the `cfg(not(feature = "xen"))` from across the code base. Signed-off-by: Patrick Roy <[email protected]>
1 parent 5ded635 commit 2dc6caa

File tree

10 files changed

+46
-41
lines changed

10 files changed

+46
-41
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
Change return type of `GuestRegionMmap::new` from `Result` to `Option`.
2525
- \[#324](https:////github.com/rust-vmm/vm-memory/pull/324)\] `GuestMemoryRegion::bitmap()` now returns a `BitmapSlice`. Accessing the full bitmap is now possible only if the type of the memory region is know, for example with `MmapRegion::bitmap()`.
2626
- \[[#339](https://github.com/rust-vmm/vm-memory/pull/339)\] Implement `Bytes::load()` and `Bytes::store()` with `get_slices()` instead of `to_region_addr()`
27+
- \[[#317](https://github.com/rust-vmm/vm-memory/pull/317)\]: Make `xen` feature additive, meaning enabling it
28+
no longer disables the `mmap_unix` module at compile time. For this, various Xen-related structs had to be
29+
renamed due to naming conflicts.
2730

2831
### Removed
2932

benches/guest_memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2020 Alibaba Cloud Computing. All rights reserved.
22
//
33
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
4-
#![cfg(all(feature = "backend-mmap", not(feature = "xen")))]
4+
#![cfg(feature = "backend-mmap")]
55

66
use core::hint::black_box;
77
pub use criterion::Criterion;

benches/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
extern crate criterion;
66

77
pub use criterion::{criterion_group, criterion_main, Criterion};
8-
#[cfg(all(feature = "backend-mmap", not(feature = "xen")))]
8+
#[cfg(feature = "backend-mmap")]
99
use vm_memory::{GuestAddress, GuestMemoryMmap};
1010

1111
mod guest_memory;
@@ -14,7 +14,7 @@ mod volatile;
1414

1515
use volatile::benchmark_for_volatile;
1616

17-
#[cfg(all(feature = "backend-mmap", not(feature = "xen")))]
17+
#[cfg(feature = "backend-mmap")]
1818
// Use this function with caution. It does not check against overflows
1919
// and `GuestMemoryMmap::from_ranges` errors.
2020
fn create_guest_memory_mmap(size: usize, count: u64) -> GuestMemoryMmap<()> {
@@ -27,12 +27,12 @@ fn create_guest_memory_mmap(size: usize, count: u64) -> GuestMemoryMmap<()> {
2727
}
2828

2929
pub fn criterion_benchmark(_c: &mut Criterion) {
30-
#[cfg(all(feature = "backend-mmap", not(feature = "xen")))]
30+
#[cfg(feature = "backend-mmap")]
3131
mmap::benchmark_for_mmap(_c);
3232
}
3333

3434
pub fn benchmark_guest_memory(_c: &mut Criterion) {
35-
#[cfg(all(feature = "backend-mmap", not(feature = "xen")))]
35+
#[cfg(feature = "backend-mmap")]
3636
guest_memory::benchmark_for_guest_memory(_c)
3737
}
3838

benches/mmap/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
//
33
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
4-
#![cfg(all(feature = "backend-mmap", not(feature = "xen")))]
4+
#![cfg(feature = "backend-mmap")]
55
#![allow(clippy::undocumented_unsafe_blocks)]
66

77
extern crate criterion;

src/bitmap/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub(crate) mod tests {
125125
use std::sync::atomic::Ordering;
126126

127127
use crate::{Bytes, VolatileMemory};
128-
#[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
128+
#[cfg(all(feature = "backend-mmap", target_family = "unix"))]
129129
use crate::{GuestAddress, MemoryRegionAddress};
130130

131131
// Helper method to check whether a specified range is clean.
@@ -219,7 +219,7 @@ pub(crate) mod tests {
219219
// them to test the mmap-based backend implementations for now. Going forward, the generic
220220
// test functions defined here can be placed in a separate module (i.e. `test_utilities`)
221221
// which is gated by a feature and can be used for testing purposes by other crates as well.
222-
#[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
222+
#[cfg(all(feature = "backend-mmap", target_family = "unix"))]
223223
fn test_guest_memory_region<R: GuestMemoryRegion>(region: &R) {
224224
let dirty_addr = MemoryRegionAddress(0x0);
225225
let val = 123u64;
@@ -253,7 +253,7 @@ pub(crate) mod tests {
253253
);
254254
}
255255

256-
#[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
256+
#[cfg(all(feature = "backend-mmap", target_family = "unix"))]
257257
// Assumptions about M generated by f ...
258258
pub fn test_guest_memory_and_region<M, F>(f: F)
259259
where

src/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub trait Bytes<A> {
331331
/// * Read bytes from /dev/urandom (uses the `backend-mmap` feature)
332332
///
333333
/// ```
334-
/// # #[cfg(all(feature = "backend-mmap", feature = "rawfd", target_family = "unix", not(feature = "xen")))]
334+
/// # #[cfg(all(feature = "backend-mmap", feature = "rawfd", target_family = "unix"))]
335335
/// # {
336336
/// # use vm_memory::{Address, GuestMemory, Bytes, GuestAddress, GuestMemoryMmap};
337337
/// # use std::fs::File;

src/guest_memory.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl FileOffset {
176176
/// # Examples (uses the `backend-mmap` and `backend-atomic` features)
177177
///
178178
/// ```
179-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
179+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
180180
/// # {
181181
/// # use std::sync::Arc;
182182
/// # use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryMmap};
@@ -294,7 +294,7 @@ pub trait GuestMemory {
294294
/// `backend-mmap` feature)
295295
///
296296
/// ```
297-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
297+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
298298
/// # {
299299
/// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryRegion, GuestMemoryMmap};
300300
/// #
@@ -318,7 +318,7 @@ pub trait GuestMemory {
318318
/// # Examples (uses the `backend-mmap` feature)
319319
///
320320
/// ```
321-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
321+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
322322
/// # {
323323
/// # use vm_memory::{Address, GuestAddress, GuestMemory, GuestMemoryMmap};
324324
/// #
@@ -433,7 +433,7 @@ pub trait GuestMemory {
433433
/// # Examples (uses the `backend-mmap` feature)
434434
///
435435
/// ```
436-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
436+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
437437
/// # {
438438
/// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap};
439439
/// #
@@ -592,9 +592,9 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
592592
/// * Write a slice at guestaddress 0x1000. (uses the `backend-mmap` feature)
593593
///
594594
/// ```
595-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
595+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
596596
/// # {
597-
/// # use vm_memory::{Bytes, GuestAddress, mmap::GuestMemoryMmap};
597+
/// # use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
598598
/// #
599599
/// # let start_addr = GuestAddress(0x1000);
600600
/// # let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])
@@ -620,9 +620,9 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
620620
/// * Read a slice of length 16 at guestaddress 0x1000. (uses the `backend-mmap` feature)
621621
///
622622
/// ```
623-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
623+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
624624
/// # {
625-
/// # use vm_memory::{Bytes, GuestAddress, mmap::GuestMemoryMmap};
625+
/// # use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
626626
/// #
627627
/// let start_addr = GuestAddress(0x1000);
628628
/// let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])

src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ pub use io::{ReadVolatile, WriteVolatile};
6767
#[cfg(feature = "backend-mmap")]
6868
pub mod mmap;
6969

70-
#[cfg(all(feature = "backend-mmap", feature = "xen", target_family = "unix"))]
71-
pub use mmap::{MmapRange, MmapXenFlags};
72-
7370
#[cfg(all(feature = "xen", target_family = "unix"))]
74-
pub use mmap::xen::{GuestMemoryXen, MmapRegion as MmapRegionXen};
71+
pub use mmap::xen::{GuestMemoryXen, MmapRange, MmapRegion as MmapRegionXen, MmapXenFlags};
7572

76-
#[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
77-
pub use mmap::unix::{Error as MmapRegionError, GuestMemoryMmap, GuestRegionMmap, MmapRegion};
73+
#[cfg(all(feature = "backend-mmap", target_family = "unix"))]
74+
pub use mmap::unix::{
75+
Error as MmapRegionError, GuestMemoryMmap, GuestRegionMmap, MmapRegion, MmapRegionBuilder,
76+
};
7877

7978
#[cfg(windows)]
8079
pub use crate::mmap::windows::{

src/mmap/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// re-export for backward compat, as the trait used to be defined in mmap.rs
1616
pub use crate::bitmap::NewBitmap;
1717

18-
#[cfg(all(not(feature = "xen"), target_family = "unix"))]
18+
#[cfg(target_family = "unix")]
1919
pub(super) mod unix;
2020

2121
#[cfg(all(feature = "xen", target_family = "unix"))]
@@ -40,13 +40,11 @@ pub(crate) mod tests {
4040
#![allow(clippy::undocumented_unsafe_blocks)]
4141
extern crate vmm_sys_util;
4242

43-
use super::*;
44-
4543
use crate::bitmap::BS;
4644
use crate::{
4745
guest_memory, Address, Bytes, FileOffset, GuestAddress, GuestMemory, GuestMemoryError,
48-
GuestMemoryRegion, GuestMemoryRegionBytes, GuestUsize, MemoryRegionAddress, VolatileMemory,
49-
VolatileSlice,
46+
GuestMemoryRegion, GuestMemoryRegionBytes, GuestUsize, MemoryRegionAddress, MmapRegion,
47+
VolatileMemory, VolatileSlice,
5048
};
5149

5250
use std::io::Write;
@@ -111,7 +109,7 @@ pub(crate) mod tests {
111109
any_backend! {
112110
#[cfg(all(windows, feature = "backend-mmap"))]
113111
Windows[crate::mmap::windows::GuestRegionWindows<()>],
114-
#[cfg(all(unix, feature = "backend-mmap", not(feature = "xen")))]
112+
#[cfg(all(unix, feature = "backend-mmap"))]
115113
Mmap[crate::mmap::unix::GuestRegionMmap<()>],
116114
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
117115
Xen[crate::mmap::xen::MmapRegion]
@@ -130,7 +128,7 @@ pub(crate) mod tests {
130128
)
131129
.unwrap(),
132130
));
133-
#[cfg(all(unix, feature = "backend-mmap", not(feature = "xen")))]
131+
#[cfg(all(unix, feature = "backend-mmap"))]
134132
regions.push(AnyRegion::Mmap(
135133
crate::mmap::unix::GuestRegionMmap::new(
136134
MmapRegion::from_file(f_off.clone(), size).unwrap(),
@@ -140,8 +138,12 @@ pub(crate) mod tests {
140138
));
141139
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
142140
regions.push(AnyRegion::Xen(
143-
MmapRegion::from_range(MmapRange::new_unix(size, Some(f_off.clone()), addr))
144-
.unwrap(),
141+
crate::MmapRegionXen::from_range(crate::MmapRange::new_unix(
142+
size,
143+
Some(f_off.clone()),
144+
addr,
145+
))
146+
.unwrap(),
145147
));
146148
regions
147149
}
@@ -160,14 +162,15 @@ pub(crate) mod tests {
160162
)
161163
.unwrap(),
162164
));
163-
#[cfg(all(unix, feature = "backend-mmap", not(feature = "xen")))]
165+
#[cfg(all(unix, feature = "backend-mmap"))]
164166
regions.push(AnyRegion::Mmap(
165167
crate::mmap::unix::GuestRegionMmap::new(MmapRegion::new(size).unwrap(), addr)
166168
.unwrap(),
167169
));
168170
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
169171
regions.push(AnyRegion::Xen(
170-
MmapRegion::from_range(MmapRange::new_unix(size, None, addr)).unwrap(),
172+
crate::MmapRegionXen::from_range(crate::MmapRange::new_unix(size, None, addr))
173+
.unwrap(),
171174
));
172175
regions
173176
}

src/region.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub trait GuestMemoryRegion: Bytes<MemoryRegionAddress, E = GuestMemoryError> {
124124
/// # Examples (uses the `backend-mmap` feature)
125125
///
126126
/// ```
127-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
127+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
128128
/// # {
129129
/// # use vm_memory::{GuestAddress, MmapRegion, GuestRegionMmap, GuestMemoryRegion};
130130
/// # use vm_memory::volatile_memory::{VolatileMemory, VolatileSlice, VolatileRef};
@@ -154,7 +154,7 @@ pub trait GuestMemoryRegion: Bytes<MemoryRegionAddress, E = GuestMemoryError> {
154154
/// # Examples (uses the `backend-mmap` feature)
155155
///
156156
/// ```
157-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
157+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
158158
/// # {
159159
/// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap, GuestRegionMmap};
160160
/// let addr = GuestAddress(0x1000);
@@ -335,10 +335,10 @@ impl<R: GuestMemoryRegionBytes> Bytes<MemoryRegionAddress> for R {
335335
/// * Write a slice at guest address 0x1200.
336336
///
337337
/// ```
338-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
338+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
339339
/// # use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
340340
/// #
341-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
341+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
342342
/// # {
343343
/// # let start_addr = GuestAddress(0x1000);
344344
/// # let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])
@@ -361,10 +361,10 @@ impl<R: GuestMemoryRegionBytes> Bytes<MemoryRegionAddress> for R {
361361
/// * Read a slice of length 16 at guestaddress 0x1200.
362362
///
363363
/// ```
364-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
364+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
365365
/// # use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
366366
/// #
367-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
367+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
368368
/// # {
369369
/// # let start_addr = GuestAddress(0x1000);
370370
/// # let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])

0 commit comments

Comments
 (0)