@@ -9,22 +9,24 @@ use chrono::Utc;
9
9
use illumos_utils:: dladm:: EtherstubVnic ;
10
10
use illumos_utils:: running_zone:: RunCommandError ;
11
11
use illumos_utils:: zpool:: PathInPool ;
12
- use illumos_utils:: zpool:: ZpoolName ;
13
12
use key_manager:: StorageKeyRequester ;
14
13
use nexus_sled_agent_shared:: inventory:: OmicronSledConfig ;
15
14
use sled_agent_types:: time_sync:: TimeSync ;
16
15
use slog:: Logger ;
17
- use std:: collections:: BTreeSet ;
18
16
use std:: sync:: Arc ;
19
17
use std:: time:: Duration ;
20
18
use std:: time:: Instant ;
21
19
use tokio:: sync:: watch;
22
- use tokio:: sync:: watch:: error:: RecvError ;
23
20
24
21
use crate :: TimeSyncConfig ;
25
22
use crate :: ledger:: CurrentSledConfig ;
26
23
use crate :: sled_agent_facilities:: SledAgentFacilities ;
27
24
25
+ mod external_disks;
26
+
27
+ pub use self :: external_disks:: CurrentlyManagedZpools ;
28
+ pub use self :: external_disks:: CurrentlyManagedZpoolsReceiver ;
29
+
28
30
#[ allow( clippy:: too_many_arguments) ]
29
31
pub ( crate ) fn spawn < T : SledAgentFacilities > (
30
32
key_requester : StorageKeyRequester ,
@@ -133,114 +135,6 @@ pub enum TimeSyncError {
133
135
FailedToParse { reason : & ' static str , stdout : String } ,
134
136
}
135
137
136
- #[ derive( Debug , Clone ) ]
137
- pub struct CurrentlyManagedZpoolsReceiver {
138
- inner : CurrentlyManagedZpoolsReceiverInner ,
139
- }
140
-
141
- #[ derive( Debug , Clone ) ]
142
- enum CurrentlyManagedZpoolsReceiverInner {
143
- Real ( watch:: Receiver < Arc < CurrentlyManagedZpools > > ) ,
144
- #[ cfg( any( test, feature = "testing" ) ) ]
145
- FakeDynamic ( watch:: Receiver < BTreeSet < ZpoolName > > ) ,
146
- #[ cfg( any( test, feature = "testing" ) ) ]
147
- FakeStatic ( BTreeSet < ZpoolName > ) ,
148
- }
149
-
150
- impl CurrentlyManagedZpoolsReceiver {
151
- #[ cfg( any( test, feature = "testing" ) ) ]
152
- pub fn fake_dynamic ( rx : watch:: Receiver < BTreeSet < ZpoolName > > ) -> Self {
153
- Self { inner : CurrentlyManagedZpoolsReceiverInner :: FakeDynamic ( rx) }
154
- }
155
-
156
- #[ cfg( any( test, feature = "testing" ) ) ]
157
- pub fn fake_static ( zpools : impl Iterator < Item = ZpoolName > ) -> Self {
158
- Self {
159
- inner : CurrentlyManagedZpoolsReceiverInner :: FakeStatic (
160
- zpools. collect ( ) ,
161
- ) ,
162
- }
163
- }
164
-
165
- pub ( crate ) fn new (
166
- rx : watch:: Receiver < Arc < CurrentlyManagedZpools > > ,
167
- ) -> Self {
168
- Self { inner : CurrentlyManagedZpoolsReceiverInner :: Real ( rx) }
169
- }
170
-
171
- pub fn current ( & self ) -> Arc < CurrentlyManagedZpools > {
172
- match & self . inner {
173
- CurrentlyManagedZpoolsReceiverInner :: Real ( rx) => {
174
- Arc :: clone ( & * rx. borrow ( ) )
175
- }
176
- #[ cfg( any( test, feature = "testing" ) ) ]
177
- CurrentlyManagedZpoolsReceiverInner :: FakeDynamic ( rx) => {
178
- Arc :: new ( CurrentlyManagedZpools ( rx. borrow ( ) . clone ( ) ) )
179
- }
180
- #[ cfg( any( test, feature = "testing" ) ) ]
181
- CurrentlyManagedZpoolsReceiverInner :: FakeStatic ( zpools) => {
182
- Arc :: new ( CurrentlyManagedZpools ( zpools. clone ( ) ) )
183
- }
184
- }
185
- }
186
-
187
- pub fn current_and_update ( & mut self ) -> Arc < CurrentlyManagedZpools > {
188
- match & mut self . inner {
189
- CurrentlyManagedZpoolsReceiverInner :: Real ( rx) => {
190
- Arc :: clone ( & * rx. borrow_and_update ( ) )
191
- }
192
- #[ cfg( any( test, feature = "testing" ) ) ]
193
- CurrentlyManagedZpoolsReceiverInner :: FakeDynamic ( rx) => {
194
- Arc :: new ( CurrentlyManagedZpools ( rx. borrow_and_update ( ) . clone ( ) ) )
195
- }
196
- #[ cfg( any( test, feature = "testing" ) ) ]
197
- CurrentlyManagedZpoolsReceiverInner :: FakeStatic ( zpools) => {
198
- Arc :: new ( CurrentlyManagedZpools ( zpools. clone ( ) ) )
199
- }
200
- }
201
- }
202
-
203
- /// Wait for changes in the underlying watch channel.
204
- ///
205
- /// Cancel-safe.
206
- pub async fn changed ( & mut self ) -> Result < ( ) , RecvError > {
207
- match & mut self . inner {
208
- CurrentlyManagedZpoolsReceiverInner :: Real ( rx) => rx. changed ( ) . await ,
209
- #[ cfg( any( test, feature = "testing" ) ) ]
210
- CurrentlyManagedZpoolsReceiverInner :: FakeDynamic ( rx) => {
211
- rx. changed ( ) . await
212
- }
213
- #[ cfg( any( test, feature = "testing" ) ) ]
214
- CurrentlyManagedZpoolsReceiverInner :: FakeStatic ( _) => {
215
- // Static set of zpools never changes
216
- std:: future:: pending ( ) . await
217
- }
218
- }
219
- }
220
- }
221
-
222
- /// Set of currently managed zpools.
223
- ///
224
- /// This handle should only be used to decide to _stop_ using a zpool (e.g., if
225
- /// a previously-launched zone is on a zpool that is no longer managed). It does
226
- /// not expose a means to list or choose from the currently-managed pools;
227
- /// instead, consumers should choose mounted datasets.
228
- ///
229
- /// This level of abstraction even for "when to stop using a zpool" is probably
230
- /// wrong: if we choose a dataset on which to place a zone's root, we should
231
- /// shut that zone down if the _dataset_ goes away, not the zpool. For now we
232
- /// live with "assume the dataset bases we choose stick around as long as their
233
- /// parent zpool does".
234
- #[ derive( Default , Debug , Clone ) ]
235
- pub struct CurrentlyManagedZpools ( BTreeSet < ZpoolName > ) ;
236
-
237
- impl CurrentlyManagedZpools {
238
- /// Returns true if `zpool` is currently managed.
239
- pub fn contains ( & self , zpool : & ZpoolName ) -> bool {
240
- self . 0 . contains ( zpool)
241
- }
242
- }
243
-
244
138
#[ derive( Debug ) ]
245
139
struct LatestReconcilerTaskResultInner {
246
140
sled_config : OmicronSledConfig ,
0 commit comments