@@ -12,7 +12,9 @@ use utils::net::ipv4addr::is_link_local_valid;
1212
1313use crate :: device_manager:: persist:: SharedDeviceType ;
1414use 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+ } ;
1618use crate :: vmm_config:: drive:: * ;
1719use crate :: vmm_config:: instance_info:: InstanceInfo ;
1820use crate :: vmm_config:: logger:: { init_logger, LoggerConfig , LoggerConfigError } ;
@@ -99,8 +101,8 @@ pub struct VmmConfig {
99101pub struct VmResources {
100102 /// The vCpu and memory configuration for this microVM.
101103 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 ,
104106 /// The block devices.
105107 pub block : BlockBuilder ,
106108 /// The vsock device.
@@ -146,7 +148,7 @@ impl VmResources {
146148 resources. update_vm_config ( & machine_config) ?;
147149 }
148150
149- resources. set_boot_source ( vmm_config. boot_source ) ?;
151+ resources. build_boot_source ( vmm_config. boot_source ) ?;
150152
151153 for drive_config in vmm_config. block_devices . into_iter ( ) {
152154 resources. set_block_device ( drive_config) ?;
@@ -340,8 +342,13 @@ impl VmResources {
340342 }
341343
342344 /// 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 ( )
345352 }
346353
347354 /// Sets a balloon device to be attached when the VM starts.
@@ -358,15 +365,21 @@ impl VmResources {
358365 self . balloon . set ( config)
359366 }
360367
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 (
363370 & mut self ,
364371 boot_source_cfg : BootSourceConfig ,
365372 ) -> 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 ( ) ) ?) ;
367375 Ok ( ( ) )
368376 }
369377
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+
370383 /// Inserts a block to be attached when the VM starts.
371384 // Only call this function as part of user configuration.
372385 // If the drive_id does not exist, a new Block Device Config is added to the list.
@@ -465,16 +478,10 @@ impl VmResources {
465478
466479impl From < & VmResources > for VmmConfig {
467480 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-
474481 VmmConfig {
475482 balloon_device : resources. balloon . get_config ( ) . ok ( ) ,
476483 block_devices : resources. block . configs ( ) ,
477- boot_source,
484+ boot_source : resources . boot_source_config ( ) . clone ( ) ,
478485 logger : None ,
479486 machine_config : Some ( resources. vm_config . clone ( ) ) ,
480487 metrics : None ,
0 commit comments