Skip to content

Commit 662c4af

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 31b28b0 commit 662c4af

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
@@ -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

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)