arcbox_hypervisor/
config.rs1use crate::types::{CpuArch, default_vm_cpu_count, default_vm_memory_size};
4
5#[derive(Debug, Clone)]
7pub struct VmConfig {
8 pub vcpu_count: u32,
10 pub memory_size: u64,
12 pub arch: CpuArch,
14 pub kernel_path: Option<String>,
16 pub kernel_cmdline: Option<String>,
18 pub initrd_path: Option<String>,
20 pub enable_rosetta: bool,
22 pub nested_virt: bool,
29}
30
31impl Default for VmConfig {
32 fn default() -> Self {
33 Self {
34 vcpu_count: default_vm_cpu_count(),
35 memory_size: default_vm_memory_size(),
36 arch: CpuArch::native(),
37 kernel_path: None,
38 kernel_cmdline: None,
39 initrd_path: None,
40 enable_rosetta: false,
41 nested_virt: false,
42 }
43 }
44}
45
46impl VmConfig {
47 #[must_use]
49 pub fn builder() -> VmConfigBuilder {
50 VmConfigBuilder::default()
51 }
52}
53
54#[derive(Debug, Default)]
56pub struct VmConfigBuilder {
57 config: VmConfig,
58}
59
60impl VmConfigBuilder {
61 #[must_use]
63 pub const fn vcpu_count(mut self, count: u32) -> Self {
64 self.config.vcpu_count = count;
65 self
66 }
67
68 #[must_use]
70 pub const fn memory_size(mut self, size: u64) -> Self {
71 self.config.memory_size = size;
72 self
73 }
74
75 #[must_use]
77 pub const fn arch(mut self, arch: CpuArch) -> Self {
78 self.config.arch = arch;
79 self
80 }
81
82 #[must_use]
84 pub fn kernel_path(mut self, path: impl Into<String>) -> Self {
85 self.config.kernel_path = Some(path.into());
86 self
87 }
88
89 #[must_use]
91 pub fn kernel_cmdline(mut self, cmdline: impl Into<String>) -> Self {
92 self.config.kernel_cmdline = Some(cmdline.into());
93 self
94 }
95
96 #[must_use]
98 pub fn initrd_path(mut self, path: impl Into<String>) -> Self {
99 self.config.initrd_path = Some(path.into());
100 self
101 }
102
103 #[must_use]
105 pub const fn enable_rosetta(mut self, enable: bool) -> Self {
106 self.config.enable_rosetta = enable;
107 self
108 }
109
110 #[must_use]
112 pub const fn nested_virt(mut self, enable: bool) -> Self {
113 self.config.nested_virt = enable;
114 self
115 }
116
117 #[must_use]
119 pub fn build(self) -> VmConfig {
120 self.config
121 }
122}