Skip to content

Commit c158651

Browse files
committed
feat: 更新 VmMachineRunning 和 VmStatusStopping 结构,增强 VM 停止逻辑
1 parent 2c2cf9e commit c158651

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/arch/aarch64/vm/running.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ impl VmMachineRunningOps for VmMachineRunning {
1818
type Stopping = VmStatusStopping;
1919

2020
fn stop(self) -> Self::Stopping {
21-
Self::Stopping {}
21+
Self::Stopping {
22+
vmspace: self.common.vmspace,
23+
}
2224
}
2325
}
2426

25-
pub struct VmStatusStopping {}
27+
pub struct VmStatusStopping {
28+
vmspace: VmAddrSpace,
29+
}
2630

2731
impl VmMachineStoppingOps for VmStatusStopping {}

src/vm/data.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl VmDataInner {
4141
VmMachineState::Running(running) => {
4242
let stopping = running.stop();
4343
*status_guard = VmMachineState::Stopping(stopping);
44+
self.status.store(VMStatus::Stopping);
4445
Ok(())
4546
}
4647
other => {
@@ -51,7 +52,7 @@ impl VmDataInner {
5152
}
5253

5354
pub fn wait(&self) -> anyhow::Result<()> {
54-
while self.is_active() {
55+
while !matches!(self.status(), VMStatus::Stopped) {
5556
std::thread::sleep(std::time::Duration::from_millis(50));
5657
}
5758
self.run_result()

src/vm/machine/running.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl VmMachineRunningCommon {
6767
}
6868
waiter.running_cpu_count.fetch_sub(1, Ordering::SeqCst);
6969
if waiter.running_cpu_count.load(Ordering::SeqCst) == 0 {
70+
info!("All vCPUs have exited, VM set stopped.");
7071
waiter.vm.set_stopped();
7172
}
7273
})

0 commit comments

Comments
 (0)