Skip to content

Commit 99b7e2c

Browse files
committed
refactor: impl From<VmmError> for StartMicrovmError
This allows us to eliminate some more .map_err(Internal). Signed-off-by: Patrick Roy <[email protected]>
1 parent 83f77b3 commit 99b7e2c

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/vmm/src/builder.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub enum StartMicrovmError {
104104
/// Cannot load initrd due to an invalid image: {0}
105105
InitrdRead(io::Error),
106106
/// Internal error while starting microVM: {0}
107-
Internal(VmmError),
107+
Internal(#[from] VmmError),
108108
/// Failed to get CPU template: {0}
109109
GetCpuTemplate(#[from] GetCpuTemplateError),
110110
/// Invalid kernel command line: {0}
@@ -258,8 +258,7 @@ pub fn build_microvm_for_boot(
258258
None,
259259
vm_resources.machine_config.vcpu_count,
260260
cpu_template.kvm_capabilities.clone(),
261-
)
262-
.map_err(Internal)?;
261+
)?;
263262

264263
#[cfg(feature = "gdb")]
265264
let (gdb_tx, gdb_rx) = mpsc::channel();
@@ -306,7 +305,7 @@ pub fn build_microvm_for_boot(
306305
}
307306

308307
#[cfg(target_arch = "aarch64")]
309-
attach_legacy_devices_aarch64(event_manager, &mut vmm, &mut boot_cmdline).map_err(Internal)?;
308+
attach_legacy_devices_aarch64(event_manager, &mut vmm, &mut boot_cmdline)?;
310309

311310
attach_vmgenid_device(&mut vmm)?;
312311

@@ -346,8 +345,7 @@ pub fn build_microvm_for_boot(
346345
.ok_or_else(|| MissingSeccompFilters("vcpu".to_string()))?
347346
.clone(),
348347
)
349-
.map_err(VmmError::VcpuStart)
350-
.map_err(Internal)?;
348+
.map_err(VmmError::VcpuStart)?;
351349

352350
// Load seccomp filters for the VMM thread.
353351
// Execution panics if filters cannot be loaded, use --no-seccomp if skipping filters
@@ -358,8 +356,7 @@ pub fn build_microvm_for_boot(
358356
.get("vmm")
359357
.ok_or_else(|| MissingSeccompFilters("vmm".to_string()))?,
360358
)
361-
.map_err(VmmError::SeccompFilters)
362-
.map_err(Internal)?;
359+
.map_err(VmmError::SeccompFilters)?;
363360

364361
event_manager.add_subscriber(vmm.clone());
365362

@@ -384,10 +381,7 @@ pub fn build_and_boot_microvm(
384381
debug!("event_end: build microvm for boot");
385382
// The vcpus start off in the `Paused` state, let them run.
386383
debug!("event_start: boot microvm");
387-
vmm.lock()
388-
.unwrap()
389-
.resume_vm()
390-
.map_err(StartMicrovmError::Internal)?;
384+
vmm.lock().unwrap().resume_vm()?;
391385
debug!("event_end: boot microvm");
392386
Ok(vmm)
393387
}
@@ -559,7 +553,7 @@ fn load_kernel(
559553
let mut kernel_file = boot_config
560554
.kernel_file
561555
.try_clone()
562-
.map_err(|err| StartMicrovmError::Internal(VmmError::KernelFile(err)))?;
556+
.map_err(VmmError::KernelFile)?;
563557

564558
let entry_addr = Loader::load::<std::fs::File, GuestMemoryMmap>(
565559
guest_memory,
@@ -593,7 +587,7 @@ fn load_kernel(
593587
let mut kernel_file = boot_config
594588
.kernel_file
595589
.try_clone()
596-
.map_err(|err| StartMicrovmError::Internal(VmmError::KernelFile(err)))?;
590+
.map_err(VmmError::KernelFile)?;
597591

598592
let entry_addr = Loader::load::<std::fs::File, GuestMemoryMmap>(
599593
guest_memory,
@@ -762,8 +756,7 @@ pub fn configure_system_for_boot(
762756
for vcpu in vcpus.iter_mut() {
763757
vcpu.kvm_vcpu
764758
.init(&cpu_template.vcpu_features)
765-
.map_err(VmmError::VcpuInit)
766-
.map_err(Internal)?;
759+
.map_err(VmmError::VcpuInit)?;
767760
}
768761

769762
let mut regs = Aarch64RegisterVec::default();
@@ -787,8 +780,7 @@ pub fn configure_system_for_boot(
787780
for vcpu in vcpus.iter_mut() {
788781
vcpu.kvm_vcpu
789782
.configure(vmm.guest_memory(), entry_point, &vcpu_config)
790-
.map_err(VmmError::VcpuConfigure)
791-
.map_err(Internal)?;
783+
.map_err(VmmError::VcpuConfigure)?;
792784
}
793785

794786
// Write the kernel command line to guest memory. This is x86_64 specific, since on
@@ -836,8 +828,7 @@ pub fn configure_system_for_boot(
836828
&vcpu_config,
837829
&optional_capabilities,
838830
)
839-
.map_err(VmmError::VcpuConfigure)
840-
.map_err(Internal)?;
831+
.map_err(VmmError::VcpuConfigure)?;
841832
}
842833
let vcpu_mpidr = vcpus
843834
.iter_mut()

0 commit comments

Comments
 (0)