Skip to content

Commit 1f04b2f

Browse files
committed
phd: put less Crucible state into the inner struct
1 parent 2907f70 commit 1f04b2f

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

phd-tests/framework/src/disk/crucible.rs

+12-22
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ impl Drop for Downstairs {
6363
#[derive(Debug)]
6464
pub struct CrucibleDisk {
6565
device_name: DeviceName,
66+
disk_id: Uuid,
67+
guest_os: Option<GuestOsKind>,
6668
inner: Mutex<Inner>,
6769
}
6870

@@ -81,22 +83,23 @@ impl CrucibleDisk {
8183
) -> anyhow::Result<Self> {
8284
Ok(Self {
8385
device_name,
86+
disk_id: Uuid::new_v4(),
87+
guest_os,
8488
inner: Mutex::new(Inner::new(
8589
min_disk_size_gib,
8690
block_size,
8791
downstairs_binary_path,
8892
downstairs_ports,
8993
data_dir_root,
9094
read_only_parent,
91-
guest_os,
9295
log_mode,
9396
)?),
9497
})
9598
}
9699

97100
/// Obtains the current volume construction request for this disk.
98101
pub fn vcr(&self) -> VolumeConstructionRequest {
99-
self.inner.lock().unwrap().vcr()
102+
self.inner.lock().unwrap().vcr(self.disk_id)
100103
}
101104

102105
/// Sets the generation number to use in subsequent calls to create a
@@ -112,11 +115,11 @@ impl super::DiskConfig for CrucibleDisk {
112115
}
113116

114117
fn backend_spec(&self) -> ComponentV0 {
115-
self.inner.lock().unwrap().backend_spec()
118+
self.inner.lock().unwrap().backend_spec(self.disk_id)
116119
}
117120

118121
fn guest_os(&self) -> Option<GuestOsKind> {
119-
self.inner.lock().unwrap().guest_os()
122+
self.guest_os
120123
}
121124

122125
fn as_crucible(&self) -> Option<&CrucibleDisk> {
@@ -126,9 +129,6 @@ impl super::DiskConfig for CrucibleDisk {
126129

127130
#[derive(Debug)]
128131
struct Inner {
129-
/// The UUID to insert into this disk's `VolumeConstructionRequest`s.
130-
id: Uuid,
131-
132132
/// The disk's block size.
133133
block_size: BlockSize,
134134

@@ -144,9 +144,6 @@ struct Inner {
144144
/// An optional path to a file to use as a read-only parent for this disk.
145145
read_only_parent: Option<PathBuf>,
146146

147-
/// The kind of guest OS that can be found on this disk, if there is one.
148-
guest_os: Option<GuestOsKind>,
149-
150147
/// The base64-encoded encryption key to use for this disk.
151148
encryption_key: String,
152149

@@ -166,7 +163,6 @@ impl Inner {
166163
downstairs_ports: &[u16],
167164
data_dir_root: &impl AsRef<Path>,
168165
read_only_parent: Option<&impl AsRef<Path>>,
169-
guest_os: Option<GuestOsKind>,
170166
log_mode: ServerLogMode,
171167
) -> anyhow::Result<Self> {
172168
// To create a region, Crucible requires a block size, an extent size
@@ -313,7 +309,6 @@ impl Inner {
313309
}
314310

315311
Ok(Self {
316-
id: disk_uuid,
317312
block_size,
318313
blocks_per_extent,
319314
extent_count: extents_in_disk as u32,
@@ -328,13 +323,12 @@ impl Inner {
328323
bytes
329324
},
330325
),
331-
guest_os,
332326
generation: 1,
333327
})
334328
}
335329

336-
fn backend_spec(&self) -> ComponentV0 {
337-
let vcr = self.vcr();
330+
fn backend_spec(&self, disk_id: Uuid) -> ComponentV0 {
331+
let vcr = self.vcr(disk_id);
338332

339333
ComponentV0::CrucibleStorageBackend(CrucibleStorageBackend {
340334
request_json: serde_json::to_string(&vcr)
@@ -343,19 +337,19 @@ impl Inner {
343337
})
344338
}
345339

346-
fn vcr(&self) -> VolumeConstructionRequest {
340+
fn vcr(&self, disk_id: Uuid) -> VolumeConstructionRequest {
347341
let downstairs_addrs =
348342
self.downstairs_instances.iter().map(|ds| ds.address).collect();
349343

350344
VolumeConstructionRequest::Volume {
351-
id: self.id,
345+
id: disk_id,
352346
block_size: self.block_size.bytes(),
353347
sub_volumes: vec![VolumeConstructionRequest::Region {
354348
block_size: self.block_size.bytes(),
355349
blocks_per_extent: self.blocks_per_extent,
356350
extent_count: self.extent_count,
357351
opts: CrucibleOpts {
358-
id: self.id,
352+
id: disk_id,
359353
target: downstairs_addrs,
360354
lossy: false,
361355
flush_timeout: None,
@@ -377,10 +371,6 @@ impl Inner {
377371
}),
378372
}
379373
}
380-
381-
fn guest_os(&self) -> Option<GuestOsKind> {
382-
self.guest_os
383-
}
384374
}
385375

386376
fn run_crucible_downstairs(

0 commit comments

Comments
 (0)