Skip to content

Commit

Permalink
machine: revert the machine inspection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu committed May 11, 2024
1 parent 01ffcb4 commit fdeb4d6
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ fn execute_poweroff(ns_name: &str) -> Result<()> {
}
}

fn wait_for_poweroff(proxy: &MachineProxyBlocking) -> Result<()> {
fn wait_for_poweroff(proxy: &ManagerProxyBlocking, ns_name: &str) -> Result<()> {
for _ in 0..10 {
if proxy.get_uidshift().is_err() {
if proxy.get_machine(ns_name).is_err() {
// machine object no longer exists
return Ok(());
}
Expand Down Expand Up @@ -261,12 +261,15 @@ fn is_booted(proxy: &MachineProxyBlocking) -> Result<bool> {
Ok(false)
}

fn terminate_container(proxy: &MachineProxyBlocking) -> Result<()> {
let ns_name = proxy.name()?;
let _ = proxy.receive_state_changed();
fn terminate_container(
proxy: &ManagerProxyBlocking,
machine_proxy: &MachineProxyBlocking,
ns_name: &str,
) -> Result<()> {
let _ = machine_proxy.receive_state_changed();
if execute_poweroff(&ns_name).is_ok() {
// Successfully passed poweroff command to the container, wait for it
if wait_for_poweroff(proxy).is_ok() {
if wait_for_poweroff(proxy, ns_name).is_ok() {
return Ok(());
}
// still did not poweroff?
Expand All @@ -276,10 +279,10 @@ fn terminate_container(proxy: &MachineProxyBlocking) -> Result<()> {
}

// violently kill everything inside the container
kill_container(proxy)?;
proxy.terminate().ok();
kill_container(machine_proxy)?;
machine_proxy.terminate().ok();
// status re-check, in the event of I/O problems, the container may still be running (stuck)
if wait_for_poweroff(proxy).is_ok() {
if wait_for_poweroff(proxy, ns_name).is_ok() {
return Ok(());
}

Expand All @@ -291,9 +294,9 @@ pub fn terminate_container_by_name(ns_name: &str) -> Result<()> {
let conn = Connection::system()?;
let proxy = ManagerProxyBlocking::new(&conn)?;
let path = proxy.get_machine(ns_name)?;
let proxy = MachineProxyBlocking::builder(&conn).path(&path)?.build()?;
let machine_proxy = MachineProxyBlocking::builder(&conn).path(&path)?.build()?;

terminate_container(&proxy)
terminate_container(&proxy, &machine_proxy, ns_name)
}

/// Mount the filesystem layers using the specified layer manager and the instance name
Expand Down

0 comments on commit fdeb4d6

Please sign in to comment.