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( 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,15 +75,15 @@ impl<M: GuestMemory> GuestMemoryAtomic<M> {
75
75
}
76
76
}
77
77
78
- impl < M : GuestMemory > Clone for GuestMemoryAtomic < M > {
78
+ impl < M : IoMemory > Clone for GuestMemoryAtomic < M > {
79
79
fn clone ( & self ) -> Self {
80
80
Self {
81
81
inner : self . inner . clone ( ) ,
82
82
}
83
83
}
84
84
}
85
85
86
- impl < M : GuestMemory > GuestAddressSpace for GuestMemoryAtomic < M > {
86
+ impl < M : IoMemory > GuestAddressSpace for GuestMemoryAtomic < M > {
87
87
type T = GuestMemoryLoadGuard < M > ;
88
88
type M = M ;
89
89
@@ -94,14 +94,14 @@ impl<M: GuestMemory> GuestAddressSpace for GuestMemoryAtomic<M> {
94
94
95
95
/// A guard that provides temporary access to a `GuestMemoryAtomic`. This
96
96
/// object is returned from the `memory()` method. It dereference to
97
- /// a snapshot of the `GuestMemory `, so it can be used transparently to
97
+ /// a snapshot of the `IoMemory `, so it can be used transparently to
98
98
/// access memory.
99
99
#[ derive( Debug ) ]
100
- pub struct GuestMemoryLoadGuard < M : GuestMemory > {
100
+ pub struct GuestMemoryLoadGuard < M : IoMemory > {
101
101
guard : Guard < Arc < M > > ,
102
102
}
103
103
104
- impl < M : GuestMemory > GuestMemoryLoadGuard < M > {
104
+ impl < M : IoMemory > GuestMemoryLoadGuard < M > {
105
105
/// Make a clone of the held pointer and returns it. This is more
106
106
/// expensive than just using the snapshot, but it allows to hold on
107
107
/// to the snapshot outside the scope of the guard. It also allows
@@ -112,15 +112,15 @@ impl<M: GuestMemory> GuestMemoryLoadGuard<M> {
112
112
}
113
113
}
114
114
115
- impl < M : GuestMemory > Clone for GuestMemoryLoadGuard < M > {
115
+ impl < M : IoMemory > Clone for GuestMemoryLoadGuard < M > {
116
116
fn clone ( & self ) -> Self {
117
117
GuestMemoryLoadGuard {
118
118
guard : Guard :: from_inner ( Arc :: clone ( & * self . guard ) ) ,
119
119
}
120
120
}
121
121
}
122
122
123
- impl < M : GuestMemory > Deref for GuestMemoryLoadGuard < M > {
123
+ impl < M : IoMemory > Deref for GuestMemoryLoadGuard < M > {
124
124
type Target = M ;
125
125
126
126
fn deref ( & self ) -> & Self :: Target {
@@ -133,12 +133,12 @@ impl<M: GuestMemory> Deref for GuestMemoryLoadGuard<M> {
133
133
/// possibly after updating the memory map represented by the
134
134
/// `GuestMemoryAtomic` that created the guard.
135
135
#[ derive( Debug ) ]
136
- pub struct GuestMemoryExclusiveGuard < ' a , M : GuestMemory > {
136
+ pub struct GuestMemoryExclusiveGuard < ' a , M : IoMemory > {
137
137
parent : & ' a GuestMemoryAtomic < M > ,
138
138
_guard : MutexGuard < ' a , ( ) > ,
139
139
}
140
140
141
- impl < M : GuestMemory > GuestMemoryExclusiveGuard < ' _ , M > {
141
+ impl < M : IoMemory > GuestMemoryExclusiveGuard < ' _ , M > {
142
142
/// Replace the memory map in the `GuestMemoryAtomic` that created the guard
143
143
/// with the new memory map, `map`. The lock is then dropped since this
144
144
/// method consumes the guard.
0 commit comments