Skip to content

Commit 22b5a08

Browse files
committed
review feedback:
* a few typos * a few 80col violations * actually enforce that boot devices are on PCI bus 0 * emphasize that propolis-server should never see a Spec with invalid boot disk * vestigial line * phd_skip!() instead of warn!+return Ok
1 parent ba45929 commit 22b5a08

File tree

4 files changed

+58
-39
lines changed

4 files changed

+58
-39
lines changed

bin/propolis-server/src/lib/initializer.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,26 +1041,38 @@ impl<'a> MachineInitializer<'a> {
10411041
match &spec.device_spec {
10421042
StorageDevice::Virtio(disk) => {
10431043
let bdf = parse_bdf(&disk.pci_path)?;
1044-
// TODO: check that bus is 0. only support boot devices
1045-
// directly attached to the root bus for now.
1044+
if bdf.bus.get() != 0 {
1045+
return Err(Error::new(
1046+
ErrorKind::InvalidInput,
1047+
"Boot device currently must be on PCI bus 0",
1048+
));
1049+
}
1050+
10461051
order.add_disk(bdf.location);
10471052
}
10481053
StorageDevice::Nvme(disk) => {
10491054
let bdf = parse_bdf(&disk.pci_path)?;
1050-
// TODO: check that bus is 0. only support boot devices
1051-
// directly attached to the root bus for now.
1052-
//
1055+
if bdf.bus.get() != 0 {
1056+
return Err(Error::new(
1057+
ErrorKind::InvalidInput,
1058+
"Boot device currently must be on PCI bus 0",
1059+
));
1060+
}
1061+
10531062
// TODO: separately, propolis-standalone passes an eui64
10541063
// of 0, so do that here too. is that.. ok?
10551064
order.add_nvme(bdf.location, 0);
10561065
}
10571066
};
10581067
} else {
1068+
// This should be unreachable - we check that the boot disk is
1069+
// valid when constructing the spec we're initializing from.
10591070
let message = format!(
1060-
"Instance spec included boot entry which does not refer to an existing disk: `{}`",
1071+
"Instance spec included boot entry which does not refer \
1072+
to an existing disk: `{}`",
10611073
boot_entry.name.as_str(),
10621074
);
1063-
return Err(Error::new(ErrorKind::Other, message));
1075+
return Err(Error::new(ErrorKind::InvalidInput, message));
10641076
}
10651077
}
10661078

lib/propolis-client/src/instance_spec.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,16 @@ impl SpecBuilderV0 {
186186

187187
/// Sets a boot order. Names here refer to devices included in this spec.
188188
///
189-
/// Permissible to not this if the implicit boot order is desired, but the implicit boot order
190-
/// may be unstable across device addition and removal.
189+
/// Permissible to not set this if the implicit boot order is desired, but
190+
/// the implicit boot order may be unstable across device addition and
191+
/// removal.
191192
///
192-
/// If any devices named in this order are not actually present in the constructed spec,
193-
/// Propolis will return an error when the spec is provided.
193+
/// If any devices named in this order are not actually present in the
194+
/// constructed spec, Propolis will return an error when the spec is
195+
/// provided.
194196
///
195-
/// XXX: this should certainly return `&mut Self` - all the builders here should. check if any
196-
/// of these are chained..?
197+
/// XXX: this should certainly return `&mut Self` - all the builders here
198+
/// should. check if any of these are chained..?
197199
pub fn set_boot_order(
198200
&mut self,
199201
boot_order: Vec<String>,

phd-tests/framework/src/test_vm/config.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,11 @@ impl<'dr> VmConfig<'dr> {
132132
self
133133
}
134134

135-
/// Add a new disk to the VM config, and add it to the front of the VM's boot order.
135+
/// Add a new disk to the VM config, and add it to the front of the VM's
136+
/// boot order.
136137
///
137-
/// The added disk will have the name `boot-disk`, and replace the previous existing
138-
/// `boot-disk`.
138+
/// The added disk will have the name `boot-disk`, and replace the previous
139+
/// existing `boot-disk`.
139140
pub fn boot_disk(
140141
&mut self,
141142
artifact: &'dr str,
@@ -207,28 +208,37 @@ impl<'dr> VmConfig<'dr> {
207208
})
208209
.context("serializing Propolis server config")?;
209210

210-
// The first disk in the boot list might not be the disk a test *actually* expects to boot.
211+
// The first disk in the boot list might not be the disk a test
212+
// *actually* expects to boot.
211213
//
212-
// If there are multiple bootable disks in the boot order, we'll assume they're all
213-
// the same guest OS kind. So look for `boot-disk` - if there isn't a disk named
214-
// `boot-disk` then fall back to hoping the first disk in the boot order is a bootable
215-
// disk, and if *that* isn't a bootable disk, maybe the first disk is.
214+
// If there are multiple bootable disks in the boot order, we'll assume
215+
// they're all the same guest OS kind. So look for `boot-disk` - if
216+
// there isn't a disk named `boot-disk` then fall back to hoping the
217+
// first disk in the boot order is a bootable disk, and if *that* isn't
218+
// a bootable disk, maybe the first disk is.
216219
//
217-
// TODO: theoretically we might want to accept configuration of a specific guest OS adapter
218-
// and avoid the guessing games. So far the above supports existing tests and makes them
219-
// "Just Work", but a more complicated test may want more control here.
220-
let boot_disk =
221-
self.disks.iter().find(|d| d.name == "boot-disk")
222-
.or_else(|| if let Some(boot_order) = self.boot_order.as_ref() {
223-
boot_order.first().and_then(|name| self.disks.iter().find(|d| &d.name == name))
220+
// TODO: theoretically we might want to accept configuration of a
221+
// specific guest OS adapter and avoid the guessing games. So far the
222+
// above supports existing tests and makes them "Just Work", but a more
223+
// complicated test may want more control here.
224+
let boot_disk = self
225+
.disks
226+
.iter()
227+
.find(|d| d.name == "boot-disk")
228+
.or_else(|| {
229+
if let Some(boot_order) = self.boot_order.as_ref() {
230+
boot_order.first().and_then(|name| {
231+
self.disks.iter().find(|d| &d.name == name)
232+
})
224233
} else {
225234
None
226-
})
227-
.or_else(|| self.disks.first())
228-
.expect("VM config includes at least one disk (and maybe a boot order)?");
235+
}
236+
})
237+
.or_else(|| self.disks.first())
238+
.expect("VM config includes at least one disk");
229239

230-
// XXX: assuming all bootable images are equivalent to the first, or at least the same
231-
// guest OS kind.
240+
// XXX: assuming all bootable images are equivalent to the first, or at
241+
// least the same guest OS kind.
232242
let DiskSource::Artifact(boot_artifact) = boot_disk.source else {
233243
unreachable!("boot disks always use artifacts as sources");
234244
};
@@ -242,7 +252,6 @@ impl<'dr> VmConfig<'dr> {
242252
let mut disk_handles = Vec::new();
243253
for disk in self.disks.iter() {
244254
disk_handles.push(
245-
// format!("data-disk-{}", idx)
246255
make_disk(disk.name.to_owned(), framework, disk)
247256
.await
248257
.context("creating disk")?,

phd-tests/tests/src/boot_order.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,7 @@ async fn guest_can_adjust_boot_order(ctx: &Framework) {
353353
write_efivar(&vm, &bootvar(0xfff0), &boot_option_bytes).await?;
354354
let reread = read_efivar(&vm, &bootvar(0xfff0)).await?;
355355
if reread.is_empty() {
356-
warn!(
357-
"guest environment drops EFI variable writes! \
358-
exiting test WITHOUT VALIDATING ANYTHING"
359-
);
360-
return Ok(());
356+
phd_skip!("Guest environment drops EFI variable writes");
361357
} else {
362358
assert_eq!(
363359
boot_option_bytes,

0 commit comments

Comments
 (0)