Skip to content
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
18 changes: 18 additions & 0 deletions src/vm/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,35 @@ pub(crate) struct VmDataInner {
pub name: String,
pub machine: RwLock<VmMachineState>,
pub status: AtomicState,
pub memory_size: usize,
pub vcpu_num: usize,
error: RwLock<Option<RunError>>,
}

impl VmDataInner {
pub fn new(config: AxVMConfig) -> Self {
// Calculate total memory size
let memory_size = config
.memory_regions
.iter()
.map(|region| match region {
crate::config::MemoryKind::Identical { size } => *size,
crate::config::MemoryKind::Reserved { size, .. } => *size,
crate::config::MemoryKind::Vmem { size, .. } => *size,
})
.sum();

// Get vCPU count
let vcpu_num = config.cpu_num.num();

Self {
id: config.id.into(),
name: config.name.clone(),
machine: RwLock::new(VmMachineState::Uninit(VmMachineUninit::new(config))),
status: AtomicState::new(VMStatus::Uninit),
error: RwLock::new(None),
memory_size,
vcpu_num,
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod machine;

pub(crate) use addrspace::*;
pub use define::*;
pub(crate) use machine::*;
pub use machine::*;

pub struct Vm {
data: VmData,
Expand Down Expand Up @@ -44,4 +44,14 @@ impl Vm {
pub fn wait(&self) -> anyhow::Result<()> {
self.data.wait()
}

/// Get total memory size in bytes.
pub fn memory_size(&self) -> usize {
self.data.memory_size
}

/// Get vCPU count.
pub fn vcpu_num(&self) -> usize {
self.data.vcpu_num
}
}
Loading