Skip to content

Commit b28125b

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 c94e4e4 commit b28125b

File tree

6 files changed

+37
-32
lines changed

6 files changed

+37
-32
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
and `GuestRegionMmap::from_range` to be separate from the error type returned by `GuestRegionCollection` functions.
2121
Change return type of `GuestRegionMmap::new` from `Result` to `Option`.
2222
- \[#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()`.
23+
- \[[#317](https://github.com/rust-vmm/vm-memory/pull/317)\]: Make `xen` feature additive, meaning enabling it
24+
no longer disables the `mmap_unix` module at compile time. For this, various Xen-related structs had to be
25+
renamed due to naming conflicts.
2326

2427
### Removed
2528

src/bytes.rs

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

src/guest_memory.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl FileOffset {
174174
/// # Examples (uses the `backend-mmap` and `backend-atomic` features)
175175
///
176176
/// ```
177-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
177+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
178178
/// # {
179179
/// # use std::sync::Arc;
180180
/// # use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryMmap};
@@ -292,7 +292,7 @@ pub trait GuestMemory {
292292
/// `backend-mmap` feature)
293293
///
294294
/// ```
295-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
295+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
296296
/// # {
297297
/// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryRegion, GuestMemoryMmap};
298298
/// #
@@ -316,7 +316,7 @@ pub trait GuestMemory {
316316
/// # Examples (uses the `backend-mmap` feature)
317317
///
318318
/// ```
319-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
319+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
320320
/// # {
321321
/// # use vm_memory::{Address, GuestAddress, GuestMemory, GuestMemoryMmap};
322322
/// #
@@ -428,7 +428,7 @@ pub trait GuestMemory {
428428
/// # Examples (uses the `backend-mmap` feature)
429429
///
430430
/// ```
431-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
431+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
432432
/// # {
433433
/// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap};
434434
/// #
@@ -485,9 +485,9 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
485485
/// * Write a slice at guestaddress 0x1000. (uses the `backend-mmap` feature)
486486
///
487487
/// ```
488-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
488+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
489489
/// # {
490-
/// # use vm_memory::{Bytes, GuestAddress, mmap::GuestMemoryMmap};
490+
/// # use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
491491
/// #
492492
/// # let start_addr = GuestAddress(0x1000);
493493
/// # let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])
@@ -513,9 +513,9 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
513513
/// * Read a slice of length 16 at guestaddress 0x1000. (uses the `backend-mmap` feature)
514514
///
515515
/// ```
516-
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
516+
/// # #[cfg(all(feature = "backend-mmap", target_family = "unix"))]
517517
/// # {
518-
/// # use vm_memory::{Bytes, GuestAddress, mmap::GuestMemoryMmap};
518+
/// # use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
519519
/// #
520520
/// let start_addr = GuestAddress(0x1000);
521521
/// 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
@@ -61,14 +61,13 @@ pub use io::{ReadVolatile, WriteVolatile};
6161
#[cfg(feature = "backend-mmap")]
6262
pub mod mmap;
6363

64-
#[cfg(all(feature = "backend-mmap", feature = "xen", target_family = "unix"))]
65-
pub use mmap::{MmapRange, MmapXenFlags};
66-
6764
#[cfg(all(feature = "xen", target_family = "unix"))]
68-
pub use mmap::xen::{GuestMemoryXen, MmapRegion as MmapRegionXen};
65+
pub use mmap::xen::{GuestMemoryXen, MmapRange, MmapRegion as MmapRegionXen, MmapXenFlags};
6966

70-
#[cfg(all(feature = "backend-mmap", target_family = "unix", not(feature = "xen")))]
71-
pub use mmap::unix::{Error as MmapRegionError, GuestMemoryMmap, GuestRegionMmap, MmapRegion};
67+
#[cfg(all(feature = "backend-mmap", target_family = "unix"))]
68+
pub use mmap::unix::{
69+
Error as MmapRegionError, GuestMemoryMmap, GuestRegionMmap, MmapRegion, MmapRegionBuilder,
70+
};
7271

7372
#[cfg(windows)]
7473
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;
@@ -110,7 +108,7 @@ pub(crate) mod tests {
110108
any_backend! {
111109
#[cfg(all(windows, feature = "backend-mmap"))]
112110
Windows[crate::mmap::windows::GuestRegionWindows<()>],
113-
#[cfg(all(unix, feature = "backend-mmap", not(feature = "xen")))]
111+
#[cfg(all(unix, feature = "backend-mmap"))]
114112
Mmap[crate::mmap::unix::GuestRegionMmap<()>],
115113
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
116114
Xen[crate::mmap::xen::MmapRegion]
@@ -129,7 +127,7 @@ pub(crate) mod tests {
129127
)
130128
.unwrap(),
131129
));
132-
#[cfg(all(unix, feature = "backend-mmap", not(feature = "xen")))]
130+
#[cfg(all(unix, feature = "backend-mmap"))]
133131
regions.push(AnyRegion::Mmap(
134132
crate::mmap::unix::GuestRegionMmap::new(
135133
MmapRegion::from_file(f_off.clone(), size).unwrap(),
@@ -139,8 +137,12 @@ pub(crate) mod tests {
139137
));
140138
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
141139
regions.push(AnyRegion::Xen(
142-
MmapRegion::from_range(MmapRange::new_unix(size, Some(f_off.clone()), addr))
143-
.unwrap(),
140+
crate::MmapRegionXen::from_range(crate::MmapRange::new_unix(
141+
size,
142+
Some(f_off.clone()),
143+
addr,
144+
))
145+
.unwrap(),
144146
));
145147
regions
146148
}
@@ -159,14 +161,15 @@ pub(crate) mod tests {
159161
)
160162
.unwrap(),
161163
));
162-
#[cfg(all(unix, feature = "backend-mmap", not(feature = "xen")))]
164+
#[cfg(all(unix, feature = "backend-mmap"))]
163165
regions.push(AnyRegion::Mmap(
164166
crate::mmap::unix::GuestRegionMmap::new(MmapRegion::new(size).unwrap(), addr)
165167
.unwrap(),
166168
));
167169
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
168170
regions.push(AnyRegion::Xen(
169-
MmapRegion::from_range(MmapRange::new_unix(size, None, addr)).unwrap(),
171+
crate::MmapRegionXen::from_range(crate::MmapRange::new_unix(size, None, addr))
172+
.unwrap(),
170173
));
171174
regions
172175
}

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)