Skip to content

Commit

Permalink
[virtual machine] added the respective handling of checking state on …
Browse files Browse the repository at this point in the history
…suspended vm based on shutdown policy.
  • Loading branch information
georgeliao committed Sep 2, 2024
1 parent 1addda1 commit 988ce23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3084,14 +3084,8 @@ bool mp::Daemon::delete_vm(InstanceTable::iterator vm_it, bool purge, DeleteRepl

mounts[name].clear();

// Temporary solution to make multipass delete behave right.
// TODO, move this check into check_state_for_shutdown
if (!(instance->current_state() == VirtualMachine::State::suspended) || purge)
{
instance->shutdown(purge == true ? VirtualMachine::ShutdownPolicy::Poweroff
: VirtualMachine::ShutdownPolicy::Halt);
}

instance->shutdown(purge == true ? VirtualMachine::ShutdownPolicy::Poweroff
: VirtualMachine::ShutdownPolicy::Halt);
if (!purge)
{
vm_instance_specs[name].deleted = true;
Expand Down
16 changes: 11 additions & 5 deletions src/platform/backends/shared/base_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,21 @@ void mp::BaseVirtualMachine::check_state_for_shutdown(ShutdownPolicy shutdown_po
return;
}

if (state == State::suspending)
if (state == State::suspended)
{
throw VMStateInvalidException{fmt::format("Cannot shut down instance {} while suspending.", vm_name)};
if (shutdown_policy == ShutdownPolicy::Halt)
{
throw VMStateIdempotentException{"Ignoring shutdown since instance is already suspended."};
}
else // else only can be ShutdownPolicy::Powerdown since ShutdownPolicy::Poweroff check was preemptively done.
{
throw VMStateInvalidException{fmt::format("Cannot shut down suspended instance {}.", vm_name)};
}
}

// add branching here for the halt shutdown policy
if (state == State::suspended)
if (state == State::suspending)
{
throw VMStateInvalidException{fmt::format("Cannot shut down suspended instance {}.", vm_name)};
throw VMStateInvalidException{fmt::format("Cannot shut down instance {} while suspending.", vm_name)};
}

if (state == State::starting || state == State::restarting)
Expand Down

0 comments on commit 988ce23

Please sign in to comment.