Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove some getters and setters for boot_source #4917

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ pub fn build_microvm_for_boot(
let request_ts = TimestampUs::default();

let boot_config = vm_resources
.boot_source_builder()
.boot_source
.builder
.as_ref()
.ok_or(MissingKernelConfig)?;

let guest_memory = vm_resources
Expand Down Expand Up @@ -508,7 +510,7 @@ pub fn build_microvm_from_snapshot(
vmm.vm.restore_state(&microvm_state.vm_state)?;

// Restore the boot source config paths.
vm_resources.set_boot_source_config(microvm_state.vm_info.boot_source);
vm_resources.boot_source.config = microvm_state.vm_info.boot_source;

// Restore devices states.
let mmio_ctor_args = MMIODevManagerConstructorArgs {
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl From<&VmResources> for VmInfo {
mem_size_mib: value.vm_config.mem_size_mib as u64,
smt: value.vm_config.smt,
cpu_template: StaticCpuTemplate::from(&value.vm_config.cpu_template),
boot_source: value.boot_source_config().clone(),
boot_source: value.boot_source.config.clone(),
huge_pages: value.vm_config.huge_pages,
}
}
Expand Down
37 changes: 8 additions & 29 deletions src/vmm/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,6 @@ impl VmResources {
mmds_config
}

/// Gets a reference to the boot source configuration.
pub fn boot_source_config(&self) -> &BootSourceConfig {
&self.boot_source.config
}

/// Gets a reference to the boot source builder.
pub fn boot_source_builder(&self) -> Option<&BootConfig> {
self.boot_source.builder.as_ref()
}

/// Sets a balloon device to be attached when the VM starts.
pub fn set_balloon_device(
&mut self,
Expand Down Expand Up @@ -354,14 +344,12 @@ impl VmResources {
return Err(BootSourceConfigError::HugePagesAndInitRd);
}

self.set_boot_source_config(boot_source_cfg);
self.boot_source.builder = Some(BootConfig::new(self.boot_source_config())?);
Ok(())
}
self.boot_source = BootSource {
builder: Some(BootConfig::new(&boot_source_cfg)?),
config: boot_source_cfg,
};

/// Set the boot source configuration (contains raw kernel config details).
pub fn set_boot_source_config(&mut self, boot_source_cfg: BootSourceConfig) {
self.boot_source.config = boot_source_cfg;
Ok(())
}

/// Inserts a block to be attached when the VM starts.
Expand Down Expand Up @@ -512,7 +500,7 @@ impl From<&VmResources> for VmmConfig {
VmmConfig {
balloon_device: resources.balloon.get_config().ok(),
block_devices: resources.block.configs(),
boot_source: resources.boot_source_config().clone(),
boot_source: resources.boot_source.config.clone(),
cpu_config: None,
logger: None,
machine_config: Some(MachineConfig::from(&resources.vm_config)),
Expand Down Expand Up @@ -1521,15 +1509,6 @@ mod tests {
assert_eq!(actual_entropy_cfg, entropy_device_cfg);
}

#[test]
fn test_boot_config() {
let vm_resources = default_vm_resources();
let expected_boot_cfg = vm_resources.boot_source.builder.as_ref().unwrap();
let actual_boot_cfg = vm_resources.boot_source_builder().unwrap();

assert!(actual_boot_cfg == expected_boot_cfg);
}

#[test]
fn test_set_boot_source() {
let tmp_file = TempFile::new().unwrap();
Expand All @@ -1541,7 +1520,7 @@ mod tests {
};

let mut vm_resources = default_vm_resources();
let boot_builder = vm_resources.boot_source_builder().unwrap();
let boot_builder = vm_resources.boot_source.builder.as_ref().unwrap();
let tmp_ino = tmp_file.as_file().metadata().unwrap().st_ino();

assert_ne!(
Expand All @@ -1568,7 +1547,7 @@ mod tests {
);

vm_resources.build_boot_source(expected_boot_cfg).unwrap();
let boot_source_builder = vm_resources.boot_source_builder().unwrap();
let boot_source_builder = vm_resources.boot_source.builder.unwrap();
assert_eq!(
boot_source_builder
.cmdline
Expand Down
Loading