5
5
// Use of this source code is governed by a BSD-style license that can be
6
6
// found in the THIRD-PARTY file.
7
7
8
- use std:: fmt:: Formatter ;
9
- use std:: { fmt, result} ;
8
+ use std:: result;
10
9
11
10
#[ cfg( target_arch = "x86_64" ) ]
12
11
use kvm_bindings:: {
@@ -26,43 +25,59 @@ use crate::arch::aarch64::gic::GICDevice;
26
25
use crate :: arch:: aarch64:: gic:: GicState ;
27
26
28
27
/// Errors associated with the wrappers over KVM ioctls.
29
- #[ derive( Debug ) ]
28
+ #[ derive( Debug , thiserror :: Error ) ]
30
29
pub enum Error {
31
30
#[ cfg( target_arch = "x86_64" ) ]
32
31
/// Retrieving supported guest MSRs fails.
32
+ #[ error( "Retrieving supported guest MSRs fails: {0:?}" ) ]
33
33
GuestMsrs ( crate :: arch:: x86_64:: msr:: Error ) ,
34
34
/// The number of configured slots is bigger than the maximum reported by KVM.
35
+ #[ error( "The number of configured slots is bigger than the maximum reported by KVM" ) ]
35
36
NotEnoughMemorySlots ,
36
37
/// Cannot set the memory regions.
38
+ #[ error( "Cannot set the memory regions: {0}" ) ]
37
39
SetUserMemoryRegion ( kvm_ioctls:: Error ) ,
38
40
#[ cfg( target_arch = "aarch64" ) ]
39
- /// Cannot create the global interrupt controller..
41
+ /// Cannot create the global interrupt controller.
42
+ #[ error( "Error creating the global interrupt controller: {0:?}" ) ]
40
43
VmCreateGIC ( crate :: arch:: aarch64:: gic:: Error ) ,
41
44
/// Cannot open the VM file descriptor.
45
+ #[ error( "Cannot open the VM file descriptor: {0}" ) ]
42
46
VmFd ( kvm_ioctls:: Error ) ,
43
47
#[ cfg( target_arch = "x86_64" ) ]
44
48
/// Failed to get KVM vm pit state.
49
+ #[ error( "Failed to get KVM vm pit state: {0}" ) ]
45
50
VmGetPit2 ( kvm_ioctls:: Error ) ,
46
51
#[ cfg( target_arch = "x86_64" ) ]
47
52
/// Failed to get KVM vm clock.
53
+ #[ error( "Failed to get KVM vm clock: {0}" ) ]
48
54
VmGetClock ( kvm_ioctls:: Error ) ,
49
55
#[ cfg( target_arch = "x86_64" ) ]
50
56
/// Failed to get KVM vm irqchip.
57
+ #[ error( "Failed to get KVM vm irqchip: {0}" ) ]
51
58
VmGetIrqChip ( kvm_ioctls:: Error ) ,
52
59
#[ cfg( target_arch = "x86_64" ) ]
53
60
/// Failed to set KVM vm pit state.
61
+ #[ error( "Failed to set KVM vm pit state: {0}" ) ]
54
62
VmSetPit2 ( kvm_ioctls:: Error ) ,
55
63
#[ cfg( target_arch = "x86_64" ) ]
56
64
/// Failed to set KVM vm clock.
65
+ #[ error( "Failed to set KVM vm clock: {0}" ) ]
57
66
VmSetClock ( kvm_ioctls:: Error ) ,
58
67
#[ cfg( target_arch = "x86_64" ) ]
59
68
/// Failed to set KVM vm irqchip.
69
+ #[ error( "Failed to set KVM vm irqchip: {0}" ) ]
60
70
VmSetIrqChip ( kvm_ioctls:: Error ) ,
61
71
/// Cannot configure the microvm.
72
+ #[ error( "Cannot configure the microvm: {0}" ) ]
62
73
VmSetup ( kvm_ioctls:: Error ) ,
63
74
#[ cfg( target_arch = "aarch64" ) ]
75
+ /// Failed to save the VM's GIC state.
76
+ #[ error( "Failed to save the VM's GIC state: {0:?}" ) ]
64
77
SaveGic ( crate :: arch:: aarch64:: gic:: Error ) ,
65
78
#[ cfg( target_arch = "aarch64" ) ]
79
+ /// Failed to restore the VM's GIC state.
80
+ #[ error( "Failed to restore the VM's GIC state: {0:?}" ) ]
66
81
RestoreGic ( crate :: arch:: aarch64:: gic:: Error ) ,
67
82
}
68
83
@@ -87,54 +102,14 @@ pub enum RestoreStateError {
87
102
#[ derive( Debug , derive_more:: From ) ]
88
103
pub struct RestoreStateError ( crate :: arch:: aarch64:: gic:: Error ) ;
89
104
#[ cfg( target_arch = "aarch64" ) ]
90
- impl fmt:: Display for RestoreStateError {
91
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
105
+ impl std :: fmt:: Display for RestoreStateError {
106
+ fn fmt ( & self , f : & mut std :: fmt:: Formatter ) -> std :: fmt:: Result {
92
107
write ! ( f, "{}" , self . 0 )
93
108
}
94
109
}
95
110
#[ cfg( target_arch = "aarch64" ) ]
96
111
impl std:: error:: Error for RestoreStateError { }
97
112
98
- impl fmt:: Display for Error {
99
- fn fmt ( & self , f : & mut Formatter ) -> std:: fmt:: Result {
100
- use self :: Error :: * ;
101
-
102
- match self {
103
- #[ cfg( target_arch = "x86_64" ) ]
104
- GuestMsrs ( err) => write ! ( f, "Retrieving supported guest MSRs fails: {:?}" , err) ,
105
- #[ cfg( target_arch = "aarch64" ) ]
106
- VmCreateGIC ( err) => write ! (
107
- f,
108
- "Error creating the global interrupt controller: {:?}" ,
109
- err
110
- ) ,
111
- VmFd ( err) => write ! ( f, "Cannot open the VM file descriptor: {}" , err) ,
112
- VmSetup ( err) => write ! ( f, "Cannot configure the microvm: {}" , err) ,
113
- NotEnoughMemorySlots => write ! (
114
- f,
115
- "The number of configured slots is bigger than the maximum reported by KVM"
116
- ) ,
117
- SetUserMemoryRegion ( err) => write ! ( f, "Cannot set the memory regions: {}" , err) ,
118
- #[ cfg( target_arch = "x86_64" ) ]
119
- VmGetPit2 ( err) => write ! ( f, "Failed to get KVM vm pit state: {}" , err) ,
120
- #[ cfg( target_arch = "x86_64" ) ]
121
- VmGetClock ( err) => write ! ( f, "Failed to get KVM vm clock: {}" , err) ,
122
- #[ cfg( target_arch = "x86_64" ) ]
123
- VmGetIrqChip ( err) => write ! ( f, "Failed to get KVM vm irqchip: {}" , err) ,
124
- #[ cfg( target_arch = "x86_64" ) ]
125
- VmSetPit2 ( err) => write ! ( f, "Failed to set KVM vm pit state: {}" , err) ,
126
- #[ cfg( target_arch = "x86_64" ) ]
127
- VmSetClock ( err) => write ! ( f, "Failed to set KVM vm clock: {}" , err) ,
128
- #[ cfg( target_arch = "x86_64" ) ]
129
- VmSetIrqChip ( err) => write ! ( f, "Failed to set KVM vm irqchip: {}" , err) ,
130
- #[ cfg( target_arch = "aarch64" ) ]
131
- SaveGic ( err) => write ! ( f, "Failed to save the VM's GIC state: {:?}" , err) ,
132
- #[ cfg( target_arch = "aarch64" ) ]
133
- RestoreGic ( err) => write ! ( f, "Failed to restore the VM's GIC state: {:?}" , err) ,
134
- }
135
- }
136
- }
137
-
138
113
pub type Result < T > = result:: Result < T , Error > ;
139
114
140
115
/// A wrapper around creating and using a VM.
0 commit comments