@@ -12,7 +12,9 @@ use utils::net::ipv4addr::is_link_local_valid;
12
12
13
13
use crate :: device_manager:: persist:: SharedDeviceType ;
14
14
use crate :: vmm_config:: balloon:: * ;
15
- use crate :: vmm_config:: boot_source:: { BootConfig , BootSourceConfig , BootSourceConfigError } ;
15
+ use crate :: vmm_config:: boot_source:: {
16
+ BootConfig , BootSource , BootSourceConfig , BootSourceConfigError ,
17
+ } ;
16
18
use crate :: vmm_config:: drive:: * ;
17
19
use crate :: vmm_config:: instance_info:: InstanceInfo ;
18
20
use crate :: vmm_config:: logger:: { init_logger, LoggerConfig , LoggerConfigError } ;
@@ -99,8 +101,8 @@ pub struct VmmConfig {
99
101
pub struct VmResources {
100
102
/// The vCpu and memory configuration for this microVM.
101
103
vm_config : VmConfig ,
102
- /// The boot configuration for this microVM.
103
- boot_config : Option < BootConfig > ,
104
+ /// The boot source spec (contains both config and builder) for this microVM.
105
+ boot_source : BootSource ,
104
106
/// The block devices.
105
107
pub block : BlockBuilder ,
106
108
/// The vsock device.
@@ -146,7 +148,7 @@ impl VmResources {
146
148
resources. update_vm_config ( & machine_config) ?;
147
149
}
148
150
149
- resources. set_boot_source ( vmm_config. boot_source ) ?;
151
+ resources. build_boot_source ( vmm_config. boot_source ) ?;
150
152
151
153
for drive_config in vmm_config. block_devices . into_iter ( ) {
152
154
resources. set_block_device ( drive_config) ?;
@@ -340,8 +342,13 @@ impl VmResources {
340
342
}
341
343
342
344
/// Gets a reference to the boot source configuration.
343
- pub fn boot_source ( & self ) -> Option < & BootConfig > {
344
- self . boot_config . as_ref ( )
345
+ pub fn boot_source_config ( & self ) -> & BootSourceConfig {
346
+ & self . boot_source . config
347
+ }
348
+
349
+ /// Gets a reference to the boot source builder.
350
+ pub fn boot_source_builder ( & self ) -> Option < & BootConfig > {
351
+ self . boot_source . builder . as_ref ( )
345
352
}
346
353
347
354
/// Sets a balloon device to be attached when the VM starts.
@@ -358,15 +365,21 @@ impl VmResources {
358
365
self . balloon . set ( config)
359
366
}
360
367
361
- /// Set the guest boot source configuration .
362
- pub fn set_boot_source (
368
+ /// Obtains the boot source hooks (kernel fd, commandline creation and validation) .
369
+ pub fn build_boot_source (
363
370
& mut self ,
364
371
boot_source_cfg : BootSourceConfig ,
365
372
) -> Result < BootSourceConfigError > {
366
- self . boot_config = Some ( BootConfig :: new ( boot_source_cfg) ?) ;
373
+ self . set_boot_source_config ( boot_source_cfg) ;
374
+ self . boot_source . builder = Some ( BootConfig :: new ( & self . boot_source_config ( ) ) ?) ;
367
375
Ok ( ( ) )
368
376
}
369
377
378
+ /// Set the boot source configuration (contains raw kernel config details).
379
+ pub fn set_boot_source_config ( & mut self , boot_source_cfg : BootSourceConfig ) {
380
+ self . boot_source . config = boot_source_cfg;
381
+ }
382
+
370
383
/// Inserts a block to be attached when the VM starts.
371
384
// Only call this function as part of user configuration.
372
385
// If the drive_id does not exist, a new Block Device Config is added to the list.
@@ -465,16 +478,10 @@ impl VmResources {
465
478
466
479
impl From < & VmResources > for VmmConfig {
467
480
fn from ( resources : & VmResources ) -> Self {
468
- let boot_source = resources
469
- . boot_config
470
- . as_ref ( )
471
- . map ( BootSourceConfig :: from)
472
- . unwrap_or_default ( ) ;
473
-
474
481
VmmConfig {
475
482
balloon_device : resources. balloon . get_config ( ) . ok ( ) ,
476
483
block_devices : resources. block . configs ( ) ,
477
- boot_source,
484
+ boot_source : resources . boot_source_config ( ) . clone ( ) ,
478
485
logger : None ,
479
486
machine_config : Some ( resources. vm_config . clone ( ) ) ,
480
487
metrics : None ,
0 commit comments