Skip to content

Commit 7f6afef

Browse files
committed
xen: rename MmapRegion to GuestRegionXen
It plays the same role as GuestRegionMmap for unix, so update the name to provide some consistency between the two. Signed-off-by: Patrick Roy <[email protected]>
1 parent 4bb661d commit 7f6afef

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use io::{ReadVolatile, WriteVolatile};
6868
pub mod mmap;
6969

7070
#[cfg(all(feature = "xen", target_family = "unix"))]
71-
pub use mmap::xen::{GuestMemoryXen, MmapRange, MmapRegion as MmapRegionXen, MmapXenFlags};
71+
pub use mmap::xen::{GuestMemoryXen, GuestRegionXen, MmapRange, MmapXenFlags};
7272

7373
#[cfg(all(feature = "backend-mmap", target_family = "unix"))]
7474
pub use mmap::unix::{

src/mmap/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(super) mod windows;
2828
pub use unix::{Error as MmapRegionError, MmapRegion, MmapRegionBuilder};
2929

3030
#[cfg(all(feature = "xen", target_family = "unix"))]
31-
pub use xen::{Error as MmapRegionError, MmapRange, MmapRegion, MmapXenFlags};
31+
pub use xen::{Error as MmapRegionError, GuestRegionXen, MmapRange, MmapXenFlags};
3232

3333
#[cfg(target_family = "windows")]
3434
pub use std::io::Error as MmapRegionError;
@@ -112,7 +112,7 @@ pub(crate) mod tests {
112112
#[cfg(all(unix, feature = "backend-mmap"))]
113113
Mmap[crate::mmap::unix::GuestRegionMmap<()>],
114114
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
115-
Xen[crate::mmap::xen::MmapRegion]
115+
Xen[crate::mmap::xen::GuestRegionXen]
116116
}
117117

118118
// The cfgs make using vec![...] instead more unreadable, so suppress the lint here.
@@ -138,7 +138,7 @@ pub(crate) mod tests {
138138
));
139139
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
140140
regions.push(AnyRegion::Xen(
141-
crate::MmapRegionXen::from_range(crate::MmapRange::new_unix(
141+
crate::GuestRegionXen::from_range(crate::MmapRange::new_unix(
142142
size,
143143
Some(f_off.clone()),
144144
addr,
@@ -169,7 +169,7 @@ pub(crate) mod tests {
169169
));
170170
#[cfg(all(unix, feature = "backend-mmap", feature = "xen"))]
171171
regions.push(AnyRegion::Xen(
172-
crate::MmapRegionXen::from_range(crate::MmapRange::new_unix(size, None, addr))
172+
crate::GuestRegionXen::from_range(crate::MmapRange::new_unix(size, None, addr))
173173
.unwrap(),
174174
));
175175
regions

src/mmap/xen.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl MmapRange {
143143
/// physical memory may be mapped into the current process due to the limited virtual address
144144
/// space size of the process.
145145
#[derive(Debug)]
146-
pub struct MmapRegion<B = ()> {
146+
pub struct GuestRegionXen<B = ()> {
147147
bitmap: B,
148148
size: usize,
149149
prot: i32,
@@ -153,7 +153,7 @@ pub struct MmapRegion<B = ()> {
153153
mmap: MmapXen,
154154
}
155155

156-
impl<B: Bitmap> GuestMemoryRegion for MmapRegion<B> {
156+
impl<B: Bitmap> GuestMemoryRegion for GuestRegionXen<B> {
157157
type B = B;
158158

159159
fn len(&self) -> GuestUsize {
@@ -195,23 +195,23 @@ impl<B: Bitmap> GuestMemoryRegion for MmapRegion<B> {
195195
}
196196
}
197197

198-
impl<B: Bitmap> GuestMemoryRegionBytes for MmapRegion<B> {}
198+
impl<B: Bitmap> GuestMemoryRegionBytes for GuestRegionXen<B> {}
199199

200200
/// A collection of Xen guest memory regions.
201201
///
202202
/// Represents the entire physical memory of the guest by tracking all its memory regions.
203-
/// Each region is an instance of [`MmapRegionXen`].
204-
pub type GuestMemoryXen<B> = GuestRegionCollection<MmapRegion<B>>;
203+
/// Each region is an instance of [`GuestRegionXen`].
204+
pub type GuestMemoryXen<B> = GuestRegionCollection<GuestRegionXen<B>>;
205205

206206
// SAFETY: Send and Sync aren't automatically inherited for the raw address pointer.
207207
// Accessing that pointer is only done through the stateless interface which
208208
// allows the object to be shared by multiple threads without a decrease in
209209
// safety.
210-
unsafe impl<B: Send> Send for MmapRegion<B> {}
210+
unsafe impl<B: Send> Send for GuestRegionXen<B> {}
211211
// SAFETY: See comment above.
212-
unsafe impl<B: Sync> Sync for MmapRegion<B> {}
212+
unsafe impl<B: Sync> Sync for GuestRegionXen<B> {}
213213

214-
impl<B: NewBitmap> MmapRegion<B> {
214+
impl<B: NewBitmap> GuestRegionXen<B> {
215215
/// Creates a shared anonymous mapping of `size` bytes.
216216
///
217217
/// # Arguments
@@ -224,7 +224,7 @@ impl<B: NewBitmap> MmapRegion<B> {
224224
/// use std::fs::File;
225225
/// use std::path::Path;
226226
/// use vm_memory::{
227-
/// Bytes, FileOffset, GuestAddress, GuestMemoryXen, MmapRange, MmapRegionXen, MmapXenFlags,
227+
/// Bytes, FileOffset, GuestAddress, GuestMemoryXen, GuestRegionXen, MmapRange, MmapXenFlags,
228228
/// };
229229
/// # use vmm_sys_util::tempfile::TempFile;
230230
///
@@ -240,7 +240,7 @@ impl<B: NewBitmap> MmapRegion<B> {
240240
/// # // We need a UNIX mapping for tests to succeed.
241241
/// # let range = MmapRange::new_unix(0x400, None, addr);
242242
///
243-
/// let r = MmapRegionXen::<()>::from_range(range).expect("Could not create mmap region");
243+
/// let r = GuestRegionXen::<()>::from_range(range).expect("Could not create mmap region");
244244
///
245245
/// let mut gm = GuestMemoryXen::from_regions(vec![r]).expect("Could not create guest memory");
246246
/// let res = gm
@@ -255,7 +255,7 @@ impl<B: NewBitmap> MmapRegion<B> {
255255
/// use std::fs::File;
256256
/// use std::path::Path;
257257
/// use vm_memory::{
258-
/// Bytes, FileOffset, GuestAddress, GuestMemoryXen, MmapRange, MmapRegionXen, MmapXenFlags,
258+
/// Bytes, FileOffset, GuestAddress, GuestMemoryXen, GuestRegionXen, MmapRange, MmapXenFlags,
259259
/// };
260260
/// # use vmm_sys_util::tempfile::TempFile;
261261
///
@@ -271,7 +271,7 @@ impl<B: NewBitmap> MmapRegion<B> {
271271
/// # // We need a UNIX mapping for tests to succeed.
272272
/// # let range = MmapRange::new_unix(0x400, None, addr);
273273
///
274-
/// let r = MmapRegionXen::<()>::from_range(range).expect("Could not create mmap region");
274+
/// let r = GuestRegionXen::<()>::from_range(range).expect("Could not create mmap region");
275275
///
276276
/// let mut gm = GuestMemoryXen::from_regions(vec![r]).expect("Could not create guest memory");
277277
/// let res = gm
@@ -297,7 +297,7 @@ impl<B: NewBitmap> MmapRegion<B> {
297297

298298
let mmap = MmapXen::new(&range)?;
299299

300-
Ok(MmapRegion {
300+
Ok(GuestRegionXen {
301301
bitmap: B::with_len(range.size),
302302
size: range.size,
303303
prot: range.prot.ok_or(Error::Unexpected)?,
@@ -309,7 +309,7 @@ impl<B: NewBitmap> MmapRegion<B> {
309309
}
310310
}
311311

312-
impl<B: Bitmap> MmapRegion<B> {
312+
impl<B: Bitmap> GuestRegionXen<B> {
313313
/// Returns a pointer to the beginning of the memory region. Mutable accesses performed
314314
/// using the resulting pointer are not automatically accounted for by the dirty bitmap
315315
/// tracking functionality.
@@ -344,7 +344,7 @@ impl<B: Bitmap> MmapRegion<B> {
344344
///
345345
/// This is mostly a sanity check available for convenience, as different file descriptors
346346
/// can alias the same file.
347-
pub fn fds_overlap<T: Bitmap>(&self, other: &MmapRegion<T>) -> bool {
347+
pub fn fds_overlap<T: Bitmap>(&self, other: &GuestRegionXen<T>) -> bool {
348348
if let Some(f_off1) = self.file_offset() {
349349
if let Some(f_off2) = other.file_offset() {
350350
if f_off1.file().as_raw_fd() == f_off2.file().as_raw_fd() {
@@ -390,7 +390,7 @@ impl<B: Bitmap> MmapRegion<B> {
390390
}
391391
}
392392

393-
impl<B: Bitmap> VolatileMemory for MmapRegion<B> {
393+
impl<B: Bitmap> VolatileMemory for GuestRegionXen<B> {
394394
type B = B;
395395

396396
fn len(&self) -> usize {
@@ -1035,6 +1035,7 @@ mod tests {
10351035
#![allow(clippy::undocumented_unsafe_blocks)]
10361036

10371037
use super::*;
1038+
use crate::mmap::GuestRegionXen;
10381039
use matches::assert_matches;
10391040
use vmm_sys_util::tempfile::TempFile;
10401041

@@ -1071,7 +1072,7 @@ mod tests {
10711072
}
10721073
}
10731074

1074-
impl MmapRegion {
1075+
impl GuestRegionXen {
10751076
/// Create an `MmapRegion` with specified `size` at GuestAdress(0)
10761077
pub fn new(size: usize) -> Result<Self> {
10771078
let range = MmapRange::new_unix(size, None, GuestAddress(0));

0 commit comments

Comments
 (0)