@@ -42,8 +42,8 @@ const (
42
42
CPUTemplateC3 = models .CPUTemplateC3
43
43
)
44
44
45
- // Firecracker is an interface that can be used to mock
46
- // out an Firecracker agent for testing purposes.
45
+ // Firecracker is an interface that can be used to mock out a Firecracker agent
46
+ // for testing purposes.
47
47
type Firecracker interface {
48
48
PutLogger (ctx context.Context , logger * models.Logger ) (* ops.PutLoggerNoContent , error )
49
49
PutMachineConfiguration (ctx context.Context , cfg * models.MachineConfiguration ) (* ops.PutMachineConfigurationNoContent , error )
@@ -58,26 +58,70 @@ type Firecracker interface {
58
58
59
59
// Config is a collection of user-configurable VMM settings
60
60
type Config struct {
61
+ // SocketPath defines the file path where the Firecracker control socket
62
+ // should be created.
61
63
SocketPath string
62
64
63
- LogFifo string
64
- LogLevel string
65
- MetricsFifo string
66
- KernelImagePath string
67
- KernelArgs string
68
- CPUCount int64
69
- HtEnabled bool
70
- CPUTemplate CPUTemplate
71
- MemInMiB int64
72
- RootDrive BlockDevice
65
+ // LogFifo defines the file path where the Firecracker log named-pipe should
66
+ // be located.
67
+ LogFifo string
68
+
69
+ // LogLevel defines the verbosity of Firecracker logging. Valid values are
70
+ // "Error", "Warning", "Info", and "Debug", and are case-sensitive.
71
+ LogLevel string
72
+
73
+ // MetricsFifo defines the file path where the Firecracker metrics
74
+ // named-pipe should be located.
75
+ MetricsFifo string
76
+
77
+ // KernelImagePath defines the file path where the kernel image is located.
78
+ // The kernel image must be an uncompressed ELF image.
79
+ KernelImagePath string
80
+
81
+ // KernelArgs defines the command-line arguments that should be passed to
82
+ // the kernel.
83
+ KernelArgs string
84
+
85
+ // CPUCount defines the number of CPU threads that should be available to
86
+ // the micro-VM.
87
+ CPUCount int64
88
+
89
+ // HtEnabled defines whether hyper-threading should be enabled for the
90
+ // microVM.
91
+ HtEnabled bool
92
+
93
+ // CPUTemplate defines the Firecracker CPU template to use. Valid values
94
+ // are CPUTemplateT2 and CPUTemplateC3,
95
+ CPUTemplate CPUTemplate
96
+
97
+ // MemInMiB defines the amount of memory that should be made available to
98
+ // the microVM.
99
+ MemInMiB int64
100
+
101
+ // RootDrive specifies the BlockDevice that contains the root filesystem.
102
+ RootDrive BlockDevice
103
+
104
+ // RootPartitionUUID defines the UUID that specifies the root partition.
73
105
RootPartitionUUID string
74
- AdditionalDrives []BlockDevice
106
+
107
+ // AdditionalDrives specifies additional BlockDevices that should be made
108
+ // available to the microVM.
109
+ AdditionalDrives []BlockDevice
110
+
111
+ // NetworkInterfaces specifies the tap devices that should be made available
112
+ // to the microVM.
75
113
NetworkInterfaces []NetworkInterface
76
- VsockDevices []VsockDevice
77
- Debug bool
78
- machineCfg models.MachineConfiguration
79
114
80
- // Allows for easier mock testing
115
+ // VsockDevices specifies the vsock devices that should be made available to
116
+ // the microVM.
117
+ VsockDevices []VsockDevice
118
+
119
+ // Debug enables debug-level logging for the SDK.
120
+ Debug bool
121
+ machineCfg models.MachineConfiguration
122
+
123
+ // DisableValidation allows for easier mock testing by disabling the
124
+ // validation of configuration performed by the SDK.
81
125
DisableValidation bool
82
126
}
83
127
@@ -89,21 +133,21 @@ func (cfg *Config) Validate() error {
89
133
}
90
134
91
135
if _ , err := os .Stat (cfg .KernelImagePath ); err != nil {
92
- return fmt .Errorf ("Failed to stat kernal image path, %q: %v" , cfg .KernelImagePath , err )
136
+ return fmt .Errorf ("failed to stat kernal image path, %q: %v" , cfg .KernelImagePath , err )
93
137
}
94
138
if _ , err := os .Stat (cfg .RootDrive .HostPath ); err != nil {
95
- return fmt .Errorf ("Failed to stat host path, %q: %v" , cfg .RootDrive .HostPath , err )
139
+ return fmt .Errorf ("failed to stat host path, %q: %v" , cfg .RootDrive .HostPath , err )
96
140
}
97
141
98
142
// Check the non-existence of some files:
99
143
if _ , err := os .Stat (cfg .SocketPath ); err == nil {
100
- return fmt .Errorf ("Socket %s already exists" , cfg .SocketPath )
144
+ return fmt .Errorf ("socket %s already exists" , cfg .SocketPath )
101
145
}
102
146
103
147
return nil
104
148
}
105
149
106
- // Machine is the main object for manipulating firecracker VMs
150
+ // Machine is the main object for manipulating Firecracker microVMs
107
151
type Machine struct {
108
152
cfg Config
109
153
client Firecracker
@@ -114,32 +158,41 @@ type Machine struct {
114
158
115
159
// Logger returns a logrus logger appropriate for logging hypervisor messages
116
160
func (m * Machine ) Logger () * log.Entry {
117
- // return m.logger.WithField("subsystem", "firecracker-go-sdk")
118
- return m .logger
161
+ return m .logger .WithField ("subsystem" , userAgent )
119
162
}
120
163
121
- // NetworkInterface represents a Firecracker VMs network interface.
164
+ // NetworkInterface represents a Firecracker microVM's network interface.
122
165
type NetworkInterface struct {
123
- MacAddress string
166
+ // MacAddress defines the MAC address that should be assigned to the network
167
+ // interface inside the microVM.
168
+ MacAddress string
169
+ // HostDevName defines the file path of the tap device on the host.
124
170
HostDevName string
125
- AllowMDDS bool
171
+ // AllowMMDS makes the Firecracker MMDS available on this network interface.
172
+ AllowMDDS bool
126
173
}
127
174
128
- // BlockDevice represents a host block device mapped to the firecracker VM.
129
- // mode is either "ro" or "rw"
175
+ // BlockDevice represents a host block device mapped to the Firecracker microVM.
130
176
type BlockDevice struct {
177
+ // HostPath defines the filesystem path of the block device on the host.
131
178
HostPath string
132
- Mode string
179
+ // Mode defines whether the device is writable. Valid values are "ro" and
180
+ // "rw".
181
+ Mode string
133
182
}
134
183
135
- // VsockDevice represents a vsock connection between the
136
- // host and the guest VM .
184
+ // VsockDevice represents a vsock connection between the host and the guest
185
+ // microVM .
137
186
type VsockDevice struct {
187
+ // Path defines the filesystem path of the vsock device on the host.
138
188
Path string
139
- CID uint32
189
+ // CID defines the 32-bit Context Identifier for the vsock device. See
190
+ // the vsock(7) manual page for more information.
191
+ CID uint32
140
192
}
141
193
142
- // SocketPath returns the filesystem path to the socket used for VMM communication
194
+ // SocketPath returns the filesystem path to the socket used for VMM
195
+ // communication
143
196
func (m Machine ) socketPath () string {
144
197
return m .cfg .SocketPath
145
198
}
@@ -154,7 +207,8 @@ func (m Machine) LogLevel() string {
154
207
return m .cfg .LogLevel
155
208
}
156
209
157
- // NewMachine initializes a new Machine instance
210
+ // NewMachine initializes a new Machine instance and performs validation of the
211
+ // provided Config.
158
212
func NewMachine (cfg Config , opts ... Opt ) (* Machine , error ) {
159
213
if err := cfg .Validate (); err != nil {
160
214
return nil , err
@@ -287,7 +341,7 @@ func (m *Machine) startVMM(ctx context.Context) (<-chan error, error) {
287
341
exitCh <- err
288
342
}()
289
343
290
- // Set up a signal hander and pass INT, QUIT, and TERM through to firecracker
344
+ // Set up a signal handler and pass INT, QUIT, and TERM through to firecracker
291
345
vmchan := make (chan error )
292
346
sigchan := make (chan os.Signal )
293
347
signal .Notify (sigchan , os .Interrupt ,
@@ -334,7 +388,7 @@ func (m *Machine) stopVMM() error {
334
388
return nil
335
389
}
336
390
337
- // createFifos sets up the firecracker logging and metrics fifos
391
+ // createFifos sets up the firecracker logging and metrics FIFOs
338
392
func createFifos (logFifo , metricsFifo string ) error {
339
393
log .Debugf ("Creating FIFO %s" , logFifo )
340
394
err := syscall .Mkfifo (logFifo , 0700 )
@@ -488,7 +542,7 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
488
542
return nil
489
543
}
490
544
491
- // StartInstance starts the firecracker VM
545
+ // StartInstance starts the Firecracker microVM
492
546
func (m * Machine ) StartInstance (ctx context.Context ) error {
493
547
return m .startInstance (ctx )
494
548
}
0 commit comments