2
2
// Copyright (C) 2020 Red Hat, Inc. All rights reserved.
3
3
// SPDX-License-Identifier: Apache-2.0
4
4
5
- //! A wrapper over an `ArcSwap<GuestMemory >` struct to support RCU-style mutability.
5
+ //! A wrapper over an `ArcSwap<IoMemory >` struct to support RCU-style mutability.
6
6
//!
7
7
//! With the `backend-atomic` feature enabled, simply replacing `GuestMemoryMmap`
8
8
//! with `GuestMemoryAtomic<GuestMemoryMmap>` will enable support for mutable memory maps.
@@ -15,17 +15,17 @@ use arc_swap::{ArcSwap, Guard};
15
15
use std:: ops:: Deref ;
16
16
use std:: sync:: { Arc , LockResult , Mutex , MutexGuard , PoisonError } ;
17
17
18
- use crate :: { GuestAddressSpace , GuestMemory } ;
18
+ use crate :: { GuestAddressSpace , IoMemory } ;
19
19
20
20
/// A fast implementation of a mutable collection of memory regions.
21
21
///
22
22
/// This implementation uses `ArcSwap` to provide RCU-like snapshotting of the memory map:
23
- /// every update of the memory map creates a completely new `GuestMemory ` object, and
23
+ /// every update of the memory map creates a completely new `IoMemory ` object, and
24
24
/// readers will not be blocked because the copies they retrieved will be collected once
25
25
/// no one can access them anymore. Under the assumption that updates to the memory map
26
26
/// are rare, this allows a very efficient implementation of the `memory()` method.
27
27
#[ derive( Clone , Debug ) ]
28
- pub struct GuestMemoryAtomic < M : GuestMemory > {
28
+ pub struct GuestMemoryAtomic < M : IoMemory > {
29
29
// GuestAddressSpace<M>, which we want to implement, is basically a drop-in
30
30
// replacement for &M. Therefore, we need to pass to devices the `GuestMemoryAtomic`
31
31
// rather than a reference to it. To obtain this effect we wrap the actual fields
@@ -34,9 +34,9 @@ pub struct GuestMemoryAtomic<M: GuestMemory> {
34
34
inner : Arc < ( ArcSwap < M > , Mutex < ( ) > ) > ,
35
35
}
36
36
37
- impl < M : GuestMemory > From < Arc < M > > for GuestMemoryAtomic < M > {
37
+ impl < M : IoMemory > From < Arc < M > > for GuestMemoryAtomic < M > {
38
38
/// create a new `GuestMemoryAtomic` object whose initial contents come from
39
- /// the `map` reference counted `GuestMemory `.
39
+ /// the `map` reference counted `IoMemory `.
40
40
fn from ( map : Arc < M > ) -> Self {
41
41
let inner = ( ArcSwap :: new ( map) , Mutex :: new ( ( ) ) ) ;
42
42
GuestMemoryAtomic {
@@ -45,9 +45,9 @@ impl<M: GuestMemory> From<Arc<M>> for GuestMemoryAtomic<M> {
45
45
}
46
46
}
47
47
48
- impl < M : GuestMemory > GuestMemoryAtomic < M > {
48
+ impl < M : IoMemory > GuestMemoryAtomic < M > {
49
49
/// create a new `GuestMemoryAtomic` object whose initial contents come from
50
- /// the `map` `GuestMemory `.
50
+ /// the `map` `IoMemory `.
51
51
pub fn new ( map : M ) -> Self {
52
52
Arc :: new ( map) . into ( )
53
53
}
@@ -75,7 +75,7 @@ impl<M: GuestMemory> GuestMemoryAtomic<M> {
75
75
}
76
76
}
77
77
78
- impl < M : GuestMemory > GuestAddressSpace for GuestMemoryAtomic < M > {
78
+ impl < M : IoMemory > GuestAddressSpace for GuestMemoryAtomic < M > {
79
79
type T = GuestMemoryLoadGuard < M > ;
80
80
type M = M ;
81
81
@@ -86,14 +86,14 @@ impl<M: GuestMemory> GuestAddressSpace for GuestMemoryAtomic<M> {
86
86
87
87
/// A guard that provides temporary access to a `GuestMemoryAtomic`. This
88
88
/// object is returned from the `memory()` method. It dereference to
89
- /// a snapshot of the `GuestMemory `, so it can be used transparently to
89
+ /// a snapshot of the `IoMemory `, so it can be used transparently to
90
90
/// access memory.
91
91
#[ derive( Debug ) ]
92
- pub struct GuestMemoryLoadGuard < M : GuestMemory > {
92
+ pub struct GuestMemoryLoadGuard < M : IoMemory > {
93
93
guard : Guard < Arc < M > > ,
94
94
}
95
95
96
- impl < M : GuestMemory > GuestMemoryLoadGuard < M > {
96
+ impl < M : IoMemory > GuestMemoryLoadGuard < M > {
97
97
/// Make a clone of the held pointer and returns it. This is more
98
98
/// expensive than just using the snapshot, but it allows to hold on
99
99
/// to the snapshot outside the scope of the guard. It also allows
@@ -104,15 +104,15 @@ impl<M: GuestMemory> GuestMemoryLoadGuard<M> {
104
104
}
105
105
}
106
106
107
- impl < M : GuestMemory > Clone for GuestMemoryLoadGuard < M > {
107
+ impl < M : IoMemory > Clone for GuestMemoryLoadGuard < M > {
108
108
fn clone ( & self ) -> Self {
109
109
GuestMemoryLoadGuard {
110
110
guard : Guard :: from_inner ( Arc :: clone ( & * self . guard ) ) ,
111
111
}
112
112
}
113
113
}
114
114
115
- impl < M : GuestMemory > Deref for GuestMemoryLoadGuard < M > {
115
+ impl < M : IoMemory > Deref for GuestMemoryLoadGuard < M > {
116
116
type Target = M ;
117
117
118
118
fn deref ( & self ) -> & Self :: Target {
@@ -125,12 +125,12 @@ impl<M: GuestMemory> Deref for GuestMemoryLoadGuard<M> {
125
125
/// possibly after updating the memory map represented by the
126
126
/// `GuestMemoryAtomic` that created the guard.
127
127
#[ derive( Debug ) ]
128
- pub struct GuestMemoryExclusiveGuard < ' a , M : GuestMemory > {
128
+ pub struct GuestMemoryExclusiveGuard < ' a , M : IoMemory > {
129
129
parent : & ' a GuestMemoryAtomic < M > ,
130
130
_guard : MutexGuard < ' a , ( ) > ,
131
131
}
132
132
133
- impl < M : GuestMemory > GuestMemoryExclusiveGuard < ' _ , M > {
133
+ impl < M : IoMemory > GuestMemoryExclusiveGuard < ' _ , M > {
134
134
/// Replace the memory map in the `GuestMemoryAtomic` that created the guard
135
135
/// with the new memory map, `map`. The lock is then dropped since this
136
136
/// method consumes the guard.
0 commit comments