@@ -142,18 +142,9 @@ pub trait GuestMemoryRegion: Bytes<MemoryRegionAddress, E = GuestMemoryError> {
142142 }
143143}
144144
145- /// Errors that can occur when dealing with [`GuestRegion `]s, or collections thereof
145+ /// Errors that can occur when dealing with [`GuestRegionCollection `]s
146146#[ derive( Debug , thiserror:: Error ) ]
147- pub enum GuestRegionError {
148- /// Adding the guest base address to the length of the underlying mapping resulted
149- /// in an overflow.
150- #[ error( "Adding the guest base address to the length of the underlying mapping resulted in an overflow" ) ]
151- #[ cfg( feature = "backend-mmap" ) ]
152- InvalidGuestRegion ,
153- /// Error creating a `MmapRegion` object.
154- #[ error( "{0}" ) ]
155- #[ cfg( feature = "backend-mmap" ) ]
156- MmapRegion ( crate :: mmap:: MmapRegionError ) ,
147+ pub enum GuestRegionCollectionError {
157148 /// No memory region found.
158149 #[ error( "No memory region found" ) ]
159150 NoMemoryRegion ,
@@ -203,7 +194,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
203194 /// * `regions` - The vector of regions.
204195 /// The regions shouldn't overlap, and they should be sorted
205196 /// by the starting address.
206- pub fn from_regions ( mut regions : Vec < R > ) -> std:: result:: Result < Self , GuestRegionError > {
197+ pub fn from_regions ( mut regions : Vec < R > ) -> std:: result:: Result < Self , GuestRegionCollectionError > {
207198 Self :: from_arc_regions ( regions. drain ( ..) . map ( Arc :: new) . collect ( ) )
208199 }
209200
@@ -219,21 +210,21 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
219210 /// * `regions` - The vector of `Arc` regions.
220211 /// The regions shouldn't overlap and they should be sorted
221212 /// by the starting address.
222- pub fn from_arc_regions ( regions : Vec < Arc < R > > ) -> std:: result:: Result < Self , GuestRegionError > {
213+ pub fn from_arc_regions ( regions : Vec < Arc < R > > ) -> std:: result:: Result < Self , GuestRegionCollectionError > {
223214 if regions. is_empty ( ) {
224- return Err ( GuestRegionError :: NoMemoryRegion ) ;
215+ return Err ( GuestRegionCollectionError :: NoMemoryRegion ) ;
225216 }
226217
227218 for window in regions. windows ( 2 ) {
228219 let prev = & window[ 0 ] ;
229220 let next = & window[ 1 ] ;
230221
231222 if prev. start_addr ( ) > next. start_addr ( ) {
232- return Err ( GuestRegionError :: UnsortedMemoryRegions ) ;
223+ return Err ( GuestRegionCollectionError :: UnsortedMemoryRegions ) ;
233224 }
234225
235226 if prev. last_addr ( ) >= next. start_addr ( ) {
236- return Err ( GuestRegionError :: MemoryRegionOverlap ) ;
227+ return Err ( GuestRegionCollectionError :: MemoryRegionOverlap ) ;
237228 }
238229 }
239230
@@ -247,7 +238,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
247238 pub fn insert_region (
248239 & self ,
249240 region : Arc < R > ,
250- ) -> std:: result:: Result < GuestRegionCollection < R > , GuestRegionError > {
241+ ) -> std:: result:: Result < GuestRegionCollection < R > , GuestRegionCollectionError > {
251242 let mut regions = self . regions . clone ( ) ;
252243 regions. push ( region) ;
253244 regions. sort_by_key ( |x| x. start_addr ( ) ) ;
@@ -265,7 +256,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
265256 & self ,
266257 base : GuestAddress ,
267258 size : GuestUsize ,
268- ) -> std:: result:: Result < ( GuestRegionCollection < R > , Arc < R > ) , GuestRegionError > {
259+ ) -> std:: result:: Result < ( GuestRegionCollection < R > , Arc < R > ) , GuestRegionCollectionError > {
269260 if let Ok ( region_index) = self . regions . binary_search_by_key ( & base, |x| x. start_addr ( ) ) {
270261 if self . regions . get ( region_index) . unwrap ( ) . len ( ) == size {
271262 let mut regions = self . regions . clone ( ) ;
@@ -274,7 +265,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
274265 }
275266 }
276267
277- Err ( GuestRegionError :: NoMemoryRegion )
268+ Err ( GuestRegionCollectionError :: NoMemoryRegion )
278269 }
279270}
280271
@@ -452,7 +443,7 @@ impl<R: GuestMemoryRegionBytes> Bytes<MemoryRegionAddress> for R {
452443
453444#[ cfg( test) ]
454445pub ( crate ) mod tests {
455- use crate :: region:: { GuestMemoryRegionBytes , GuestRegionError } ;
446+ use crate :: region:: { GuestMemoryRegionBytes , GuestRegionCollectionError } ;
456447 use crate :: {
457448 Address , GuestAddress , GuestMemory , GuestMemoryRegion , GuestRegionCollection , GuestUsize ,
458449 } ;
@@ -483,7 +474,7 @@ pub(crate) mod tests {
483474 pub ( crate ) type Collection = GuestRegionCollection < MockRegion > ;
484475
485476 fn check_guest_memory_mmap (
486- maybe_guest_mem : Result < Collection , GuestRegionError > ,
477+ maybe_guest_mem : Result < Collection , GuestRegionCollectionError > ,
487478 expected_regions_summary : & [ ( GuestAddress , u64 ) ] ,
488479 ) {
489480 assert ! ( maybe_guest_mem. is_ok( ) ) ;
@@ -510,7 +501,7 @@ pub(crate) mod tests {
510501
511502 pub ( crate ) fn new_guest_memory_collection_from_regions (
512503 regions_summary : & [ ( GuestAddress , u64 ) ] ,
513- ) -> Result < Collection , GuestRegionError > {
504+ ) -> Result < Collection , GuestRegionCollectionError > {
514505 Collection :: from_regions (
515506 regions_summary
516507 . iter ( )
@@ -521,7 +512,7 @@ pub(crate) mod tests {
521512
522513 fn new_guest_memory_collection_from_arc_regions (
523514 regions_summary : & [ ( GuestAddress , u64 ) ] ,
524- ) -> Result < Collection , GuestRegionError > {
515+ ) -> Result < Collection , GuestRegionCollectionError > {
525516 Collection :: from_arc_regions (
526517 regions_summary
527518 . iter ( )
@@ -536,11 +527,11 @@ pub(crate) mod tests {
536527
537528 assert ! ( matches!(
538529 new_guest_memory_collection_from_regions( & regions_summary) . unwrap_err( ) ,
539- GuestRegionError :: NoMemoryRegion
530+ GuestRegionCollectionError :: NoMemoryRegion
540531 ) ) ;
541532 assert ! ( matches!(
542533 new_guest_memory_collection_from_arc_regions( & regions_summary) . unwrap_err( ) ,
543- GuestRegionError :: NoMemoryRegion
534+ GuestRegionCollectionError :: NoMemoryRegion
544535 ) ) ;
545536 }
546537
@@ -550,11 +541,11 @@ pub(crate) mod tests {
550541
551542 assert ! ( matches!(
552543 new_guest_memory_collection_from_regions( & regions_summary) . unwrap_err( ) ,
553- GuestRegionError :: MemoryRegionOverlap
544+ GuestRegionCollectionError :: MemoryRegionOverlap
554545 ) ) ;
555546 assert ! ( matches!(
556547 new_guest_memory_collection_from_arc_regions( & regions_summary) . unwrap_err( ) ,
557- GuestRegionError :: MemoryRegionOverlap
548+ GuestRegionCollectionError :: MemoryRegionOverlap
558549 ) ) ;
559550 }
560551
@@ -564,11 +555,11 @@ pub(crate) mod tests {
564555
565556 assert ! ( matches!(
566557 new_guest_memory_collection_from_regions( & regions_summary) . unwrap_err( ) ,
567- GuestRegionError :: UnsortedMemoryRegions
558+ GuestRegionCollectionError :: UnsortedMemoryRegions
568559 ) ) ;
569560 assert ! ( matches!(
570561 new_guest_memory_collection_from_arc_regions( & regions_summary) . unwrap_err( ) ,
571- GuestRegionError :: UnsortedMemoryRegions
562+ GuestRegionCollectionError :: UnsortedMemoryRegions
572563 ) ) ;
573564 }
574565
0 commit comments