@@ -20,7 +20,7 @@ use super::{
20
20
} ;
21
21
use crate :: builder:: StartMicrovmError ;
22
22
use crate :: cpu_config:: templates:: { CustomCpuTemplate , GuestConfigError } ;
23
- use crate :: logger:: { error , info, warn, LoggerConfig , * } ;
23
+ use crate :: logger:: { info, warn, LoggerConfig , * } ;
24
24
use crate :: mmds:: data_store:: { self , Mmds } ;
25
25
use crate :: persist:: { CreateSnapshotError , RestoreFromSnapshotError , VmInfo } ;
26
26
use crate :: resources:: VmmConfig ;
@@ -42,7 +42,7 @@ use crate::vmm_config::net::{
42
42
use crate :: vmm_config:: snapshot:: { CreateSnapshotParams , LoadSnapshotParams , SnapshotType } ;
43
43
use crate :: vmm_config:: vsock:: { VsockConfigError , VsockDeviceConfig } ;
44
44
use crate :: vmm_config:: { self , RateLimiterUpdate } ;
45
- use crate :: { EventManager , FcExitCode } ;
45
+ use crate :: EventManager ;
46
46
47
47
/// This enum represents the public interface of the VMM. Each action contains various
48
48
/// bits of information (ids, paths, etc.).
@@ -247,7 +247,7 @@ pub struct PrebootApiController<'a> {
247
247
boot_path : bool ,
248
248
// Some PrebootApiRequest errors are irrecoverable and Firecracker
249
249
// should cleanly teardown if they occur.
250
- fatal_error : Option < FcExitCode > ,
250
+ fatal_error : Option < BuildMicrovmFromRequestsError > ,
251
251
}
252
252
253
253
// TODO Remove when `EventManager` implements `std::fmt::Debug`.
@@ -287,6 +287,17 @@ pub type ApiRequest = Box<VmmAction>;
287
287
/// Shorthand type for a response containing a boxed Result.
288
288
pub type ApiResponse = Box < std:: result:: Result < VmmData , VmmActionError > > ;
289
289
290
+ /// Error type for `PrebootApiController::build_microvm_from_requests`.
291
+ #[ derive( Debug , thiserror:: Error , displaydoc:: Display , derive_more:: From ) ]
292
+ pub enum BuildMicrovmFromRequestsError {
293
+ /// Populating MMDS from file failed: {0}.
294
+ Mmds ( data_store:: Error ) ,
295
+ /// Loading snapshot failed.
296
+ Restore ,
297
+ /// Resuming MicroVM after loading snapshot failed.
298
+ Resume ,
299
+ }
300
+
290
301
impl < ' a > PrebootApiController < ' a > {
291
302
/// Constructor for the PrebootApiController.
292
303
pub fn new (
@@ -320,7 +331,7 @@ impl<'a> PrebootApiController<'a> {
320
331
boot_timer_enabled : bool ,
321
332
mmds_size_limit : usize ,
322
333
metadata_json : Option < & str > ,
323
- ) -> Result < ( VmResources , Arc < Mutex < Vmm > > ) , FcExitCode > {
334
+ ) -> Result < ( VmResources , Arc < Mutex < Vmm > > ) , BuildMicrovmFromRequestsError > {
324
335
let mut vm_resources = VmResources :: default ( ) ;
325
336
// Silence false clippy warning. Clippy suggests using
326
337
// VmResources { boot_timer: boot_timer_enabled, ..Default::default() }; but this will
@@ -333,16 +344,9 @@ impl<'a> PrebootApiController<'a> {
333
344
334
345
// Init the data store from file, if present.
335
346
if let Some ( data) = metadata_json {
336
- vm_resources
337
- . locked_mmds_or_default ( )
338
- . put_data (
339
- serde_json:: from_str ( data)
340
- . expect ( "MMDS error: metadata provided not valid json" ) ,
341
- )
342
- . map_err ( |err| {
343
- error ! ( "Populating MMDS from file failed: {:?}" , err) ;
344
- crate :: FcExitCode :: GenericError
345
- } ) ?;
347
+ vm_resources. locked_mmds_or_default ( ) . put_data (
348
+ serde_json:: from_str ( data) . expect ( "MMDS error: metadata provided not valid json" ) ,
349
+ ) ?;
346
350
347
351
info ! ( "Successfully added metadata to mmds from file" ) ;
348
352
}
@@ -376,8 +380,8 @@ impl<'a> PrebootApiController<'a> {
376
380
to_api. send ( Box :: new ( res) ) . expect ( "one-shot channel closed" ) ;
377
381
378
382
// If any fatal errors were encountered, break the loop.
379
- if let Some ( exit_code ) = preboot_controller. fatal_error {
380
- return Err ( exit_code ) ;
383
+ if let Some ( preboot_error ) = preboot_controller. fatal_error {
384
+ return Err ( preboot_error ) ;
381
385
}
382
386
}
383
387
@@ -577,7 +581,7 @@ impl<'a> PrebootApiController<'a> {
577
581
)
578
582
. map_err ( |err| {
579
583
// If restore fails, we consider the process is too dirty to recover.
580
- self . fatal_error = Some ( FcExitCode :: BadConfiguration ) ;
584
+ self . fatal_error = Some ( BuildMicrovmFromRequestsError :: Restore ) ;
581
585
err
582
586
} ) ?;
583
587
// Resume VM
@@ -587,7 +591,7 @@ impl<'a> PrebootApiController<'a> {
587
591
. resume_vm ( )
588
592
. map_err ( |err| {
589
593
// If resume fails, we consider the process is too dirty to recover.
590
- self . fatal_error = Some ( FcExitCode :: BadConfiguration ) ;
594
+ self . fatal_error = Some ( BuildMicrovmFromRequestsError :: Resume ) ;
591
595
err
592
596
} ) ?;
593
597
}
0 commit comments