5
5
6
6
#[ cfg( target_arch = "x86_64" ) ]
7
7
use std:: convert:: TryFrom ;
8
- use std:: fmt:: { Display , Formatter } ;
9
8
use std:: io:: { self , Read , Seek , SeekFrom } ;
10
9
use std:: os:: unix:: io:: { AsRawFd , RawFd } ;
11
10
use std:: sync:: { Arc , Mutex } ;
@@ -55,50 +54,76 @@ use crate::vstate::vm::Vm;
55
54
use crate :: { device_manager, Error , EventManager , RestoreVcpusError , Vmm , VmmEventsObserver } ;
56
55
57
56
/// Errors associated with starting the instance.
58
- #[ derive( Debug ) ]
57
+ #[ derive( Debug , thiserror :: Error ) ]
59
58
pub enum StartMicrovmError {
60
- /// Error using CPU template to configure vCPUs
61
- CreateCpuConfig ( GuestConfigError ) ,
62
59
/// Unable to attach block device to Vmm.
60
+ #[ error( "Unable to attach block device to Vmm: {0}" ) ]
63
61
AttachBlockDevice ( io:: Error ) ,
64
62
/// This error is thrown by the minimal boot loader implementation.
63
+ #[ error( "System configuration error: {0:?}" ) ]
65
64
ConfigureSystem ( crate :: arch:: Error ) ,
65
+ /// Error using CPU template to configure vCPUs
66
+ #[ error( "Unable to successfully create cpu configuration usable for guest vCPUs: {0:?}" ) ]
67
+ CreateCpuConfig ( GuestConfigError ) ,
66
68
/// Internal errors are due to resource exhaustion.
69
+ #[ error( "Cannot create network device. {}" , format!( "{:?}" , . 0 ) . replace( '\"' , "" ) ) ]
67
70
CreateNetDevice ( devices:: virtio:: net:: Error ) ,
68
71
/// Failed to create a `RateLimiter` object.
72
+ #[ error( "Cannot create RateLimiter: {0}" ) ]
69
73
CreateRateLimiter ( io:: Error ) ,
70
74
/// Memory regions are overlapping or mmap fails.
75
+ #[ error( "Invalid Memory Configuration: {}" , format!( "{:?}" , . 0 ) . replace( '\"' , "" ) ) ]
71
76
GuestMemoryMmap ( utils:: vm_memory:: Error ) ,
72
77
/// Cannot load initrd due to an invalid memory configuration.
78
+ #[ error( "Cannot load initrd due to an invalid memory configuration." ) ]
73
79
InitrdLoad ,
74
80
/// Cannot load initrd due to an invalid image.
81
+ #[ error( "Cannot load initrd due to an invalid image: {0}" ) ]
75
82
InitrdRead ( io:: Error ) ,
76
83
/// Internal error encountered while starting a microVM.
84
+ #[ error( "Internal error while starting microVM: {0}" ) ]
77
85
Internal ( Error ) ,
78
86
/// The kernel command line is invalid.
87
+ #[ error( "Invalid kernel command line: {0}" ) ]
79
88
KernelCmdline ( String ) ,
80
89
/// Cannot load kernel due to invalid memory configuration or invalid kernel image.
90
+ #[ error(
91
+ "Cannot load kernel due to invalid memory configuration or invalid kernel image: {}" ,
92
+ format!( "{}" , . 0 ) . replace( '\"' , "" )
93
+ ) ]
81
94
KernelLoader ( linux_loader:: loader:: Error ) ,
82
95
/// Cannot load command line string.
96
+ #[ error( "Cannot load command line string: {}" , format!( "{}" , . 0 ) . replace( '\"' , "" ) ) ]
83
97
LoadCommandline ( linux_loader:: loader:: Error ) ,
84
98
/// Cannot start the VM because the kernel builder was not configured.
99
+ #[ error( "Cannot start microvm without kernel configuration." ) ]
85
100
MissingKernelConfig ,
86
101
/// Cannot start the VM because the size of the guest memory was not specified.
102
+ #[ error( "Cannot start microvm without guest mem_size config." ) ]
87
103
MissingMemSizeConfig ,
88
104
/// The seccomp filter map is missing a key.
105
+ #[ error( "No seccomp filter for thread category: {0}" ) ]
89
106
MissingSeccompFilters ( String ) ,
90
107
/// The net device configuration is missing the tap device.
108
+ #[ error( "The net device configuration is missing the tap device." ) ]
91
109
NetDeviceNotConfigured ,
92
110
/// Cannot open the block device backing file.
111
+ #[ error( "Cannot open the block device backing file: {}" , format!( "{:?}" , . 0 ) . replace( '\"' , "" ) ) ]
93
112
OpenBlockDevice ( io:: Error ) ,
94
113
/// Cannot initialize a MMIO Device or add a device to the MMIO Bus or cmdline.
114
+ #[ error(
115
+ "Cannot initialize a MMIO Device or add a device to the MMIO Bus or cmdline: {}" ,
116
+ format!( "{}" , . 0 ) . replace( '\"' , "" )
117
+ ) ]
95
118
RegisterMmioDevice ( device_manager:: mmio:: Error ) ,
96
119
/// Cannot restore microvm state.
120
+ #[ error( "Cannot restore microvm state: {0}" ) ]
97
121
RestoreMicrovmState ( MicrovmStateError ) ,
98
122
/// Unable to set VmResources.
123
+ #[ error( "Cannot set vm resources: {0}" ) ]
99
124
SetVmResources ( VmConfigError ) ,
100
125
}
101
- impl std :: error :: Error for StartMicrovmError { }
126
+
102
127
/// It's convenient to automatically convert `linux_loader::cmdline::Error`s
103
128
/// to `StartMicrovmError`s.
104
129
impl std:: convert:: From < linux_loader:: cmdline:: Error > for StartMicrovmError {
@@ -107,90 +132,6 @@ impl std::convert::From<linux_loader::cmdline::Error> for StartMicrovmError {
107
132
}
108
133
}
109
134
110
- impl Display for StartMicrovmError {
111
- fn fmt ( & self , f : & mut Formatter ) -> std:: fmt:: Result {
112
- use self :: StartMicrovmError :: * ;
113
- match self {
114
- CreateCpuConfig ( err) => {
115
- write ! (
116
- f,
117
- "Unable to successfully create cpu configuration usable for guest vCPUs: {:?}" ,
118
- err
119
- )
120
- }
121
- AttachBlockDevice ( err) => {
122
- write ! ( f, "Unable to attach block device to Vmm: {}" , err)
123
- }
124
- ConfigureSystem ( err) => write ! ( f, "System configuration error: {:?}" , err) ,
125
- CreateRateLimiter ( err) => write ! ( f, "Cannot create RateLimiter: {}" , err) ,
126
- CreateNetDevice ( err) => {
127
- let mut err_msg = format ! ( "{:?}" , err) ;
128
- err_msg = err_msg. replace ( '\"' , "" ) ;
129
-
130
- write ! ( f, "Cannot create network device. {}" , err_msg)
131
- }
132
- GuestMemoryMmap ( err) => {
133
- // Remove imbricated quotes from error message.
134
- let mut err_msg = format ! ( "{:?}" , err) ;
135
- err_msg = err_msg. replace ( '\"' , "" ) ;
136
- write ! ( f, "Invalid Memory Configuration: {}" , err_msg)
137
- }
138
- InitrdLoad => write ! (
139
- f,
140
- "Cannot load initrd due to an invalid memory configuration."
141
- ) ,
142
- InitrdRead ( err) => write ! ( f, "Cannot load initrd due to an invalid image: {}" , err) ,
143
- Internal ( err) => write ! ( f, "Internal error while starting microVM: {}" , err) ,
144
- KernelCmdline ( err) => write ! ( f, "Invalid kernel command line: {}" , err) ,
145
- KernelLoader ( err) => {
146
- let mut err_msg = format ! ( "{}" , err) ;
147
- err_msg = err_msg. replace ( '\"' , "" ) ;
148
- write ! (
149
- f,
150
- "Cannot load kernel due to invalid memory configuration or invalid kernel \
151
- image. {}",
152
- err_msg
153
- )
154
- }
155
- LoadCommandline ( err) => {
156
- let mut err_msg = format ! ( "{}" , err) ;
157
- err_msg = err_msg. replace ( '\"' , "" ) ;
158
- write ! ( f, "Cannot load command line string. {}" , err_msg)
159
- }
160
- MissingKernelConfig => write ! ( f, "Cannot start microvm without kernel configuration." ) ,
161
- MissingMemSizeConfig => {
162
- write ! ( f, "Cannot start microvm without guest mem_size config." )
163
- }
164
- MissingSeccompFilters ( thread_category) => write ! (
165
- f,
166
- "No seccomp filter for thread category: {}" ,
167
- thread_category
168
- ) ,
169
- NetDeviceNotConfigured => {
170
- write ! ( f, "The net device configuration is missing the tap device." )
171
- }
172
- OpenBlockDevice ( err) => {
173
- let mut err_msg = format ! ( "{:?}" , err) ;
174
- err_msg = err_msg. replace ( '\"' , "" ) ;
175
-
176
- write ! ( f, "Cannot open the block device backing file. {}" , err_msg)
177
- }
178
- RegisterMmioDevice ( err) => {
179
- let mut err_msg = format ! ( "{}" , err) ;
180
- err_msg = err_msg. replace ( '\"' , "" ) ;
181
- write ! (
182
- f,
183
- "Cannot initialize a MMIO Device or add a device to the MMIO Bus or cmdline. \
184
- {}",
185
- err_msg
186
- )
187
- }
188
- RestoreMicrovmState ( err) => write ! ( f, "Cannot restore microvm state. Error: {}" , err) ,
189
- SetVmResources ( err) => write ! ( f, "Cannot set vm resources. Error: {}" , err) ,
190
- }
191
- }
192
- }
193
-
194
135
// Wrapper over io::Stdin that implements `Serial::ReadableFd` and `vmm::VmmEventsObserver`.
195
136
pub ( crate ) struct SerialStdin ( io:: Stdin ) ;
196
137
impl SerialStdin {
0 commit comments