Skip to content

Commit 395144c

Browse files
fogtijounathaen
authored andcommitted
refactor(vm): Improve condition check for SerialPortBase derivation
1 parent a487aeb commit 395144c

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/vm.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,24 +289,23 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
289289
.collect();
290290

291291
let freq = vcpus[0].get_cpu_frequency();
292+
292293
// Kernels with different Uhyve interface versions may have differing addresses for the
293294
// serial port. As we begun embedding the uhyve-interface version in unikernel images
294295
// much later than v1, but before v2, we assume that all images that don't have a version
295296
// embedded must be v1.
296-
297-
let uhyve_interface_version = object.uhyve_interface_version();
298-
let serial_port = SerialPortBase::new(match uhyve_interface_version {
299-
#[cfg(target_arch = "aarch64")]
300-
None | Some(UhyveIfVersion(1)) => uhyve_interface::v1::HypercallAddress::Uart as u64,
301-
#[cfg(target_arch = "x86_64")]
302-
None | Some(UhyveIfVersion(1)) => uhyve_interface::v1::HypercallAddress::Uart as u16,
303-
// FIXME: improve condition
304-
#[cfg(target_arch = "aarch64")]
305-
Some(UhyveIfVersion(2)) => uhyve_interface::v2::HypercallAddress::SerialWriteBuffer as u64,
306-
#[cfg(target_arch = "x86_64")]
307-
Some(UhyveIfVersion(2)) => uhyve_interface::v2::HypercallAddress::SerialWriteBuffer as u16,
308-
_ => {
309-
unimplemented!("Kernel uses unsupported uhyve-interface version. Is Uhyve too old?")
297+
let uhyve_interface_version = object
298+
.uhyve_interface_version()
299+
.unwrap_or(UhyveIfVersion(1));
300+
301+
let serial_port = SerialPortBase::new(match uhyve_interface_version.0 {
302+
1 => uhyve_interface::v1::HypercallAddress::Uart as _,
303+
2 => uhyve_interface::v2::HypercallAddress::SerialWriteBuffer as _,
304+
uhifv => {
305+
unimplemented!(
306+
"Kernel uses unsupported uhyve-interface version {}. Is Uhyve too old?",
307+
uhifv
308+
)
310309
}
311310
});
312311

0 commit comments

Comments
 (0)