Skip to content

Commit b982e78

Browse files
merge spec-smbios-type1-fix (#1200) into zl/multicast
2 parents 3c07d60 + 19e2250 commit b982e78

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

bin/propolis-server/src/lib/spec/api_spec_latest.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ pub(crate) fn latest_to_spec_builder(
3838
value: latest::instance_spec::InstanceSpec,
3939
) -> Result<SpecBuilder, ApiSpecError> {
4040
let mut builder = SpecBuilder::with_instance_spec_board(value.board)?;
41+
42+
if let Some(smbios) = value.smbios {
43+
builder.set_smbios_type1_input(smbios);
44+
}
45+
4146
let mut devices: Vec<(SpecKey, latest::instance_spec::Component)> = vec![];
4247
let mut boot_settings = None;
4348
let mut storage_backends: BTreeMap<SpecKey, StorageBackend> =
@@ -216,3 +221,49 @@ pub(crate) fn latest_to_spec_builder(
216221

217222
Ok(builder)
218223
}
224+
225+
#[cfg(test)]
226+
mod test {
227+
use super::*;
228+
use latest::components::board::{
229+
Board, Chipset, Cpuid, GuestHypervisorInterface, I440Fx,
230+
};
231+
use latest::instance_spec::{CpuidVendor, SmbiosType1Input};
232+
233+
// Regression test: the SMBIOS type 1 input must survive conversion
234+
// from the API instance spec to the internal spec. The conversion rework in
235+
// #1178 dropped it, leaving guests with default type 1 contents.
236+
#[test]
237+
fn smbios_type1_input_preserved() {
238+
let api_spec = latest::instance_spec::InstanceSpec {
239+
board: Board {
240+
cpus: 4,
241+
memory_mb: 512,
242+
chipset: Chipset::I440Fx(I440Fx { enable_pcie: false }),
243+
guest_hv_interface: GuestHypervisorInterface::Bhyve,
244+
// Explicit values keep the builder from querying bhyve for
245+
// its default guest CPUID set, which needs VMM device access
246+
// the test runner may lack.
247+
cpuid: Some(Cpuid {
248+
entries: vec![],
249+
vendor: CpuidVendor::Amd,
250+
}),
251+
},
252+
components: Default::default(),
253+
smbios: Some(SmbiosType1Input {
254+
manufacturer: "a4x2".to_string(),
255+
product_name: "913-0000019".to_string(),
256+
serial_number: "2FAKE000".to_string(),
257+
version: 2,
258+
}),
259+
};
260+
261+
let spec = latest_to_spec_builder(api_spec).unwrap().finish();
262+
let smbios =
263+
spec.smbios_type1_input.expect("SMBIOS type 1 input preserved");
264+
assert_eq!(smbios.manufacturer, "a4x2");
265+
assert_eq!(smbios.product_name, "913-0000019");
266+
assert_eq!(smbios.serial_number, "2FAKE000");
267+
assert_eq!(smbios.version, 2);
268+
}
269+
}

bin/propolis-server/src/lib/spec/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use propolis_api_types::instance_spec::{
1111
board::Board as InstanceSpecBoard,
1212
devices::{PciPciBridge, SerialPortNumber},
1313
},
14-
PciPath, SpecKey,
14+
PciPath, SmbiosType1Input, SpecKey,
1515
};
1616
use thiserror::Error;
1717

@@ -391,6 +391,11 @@ impl SpecBuilder {
391391
Ok(self)
392392
}
393393

394+
/// Sets the SMBIOS type 1 table contents to expose to the guest.
395+
pub fn set_smbios_type1_input(&mut self, input: SmbiosType1Input) {
396+
self.spec.smbios_type1_input = Some(input);
397+
}
398+
394399
/// Yields the completed spec, consuming the builder.
395400
pub fn finish(self) -> super::Spec {
396401
self.spec

0 commit comments

Comments
 (0)