Skip to content

Commit

Permalink
[qemu] Implement forced stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
luis4a0 committed Aug 16, 2022
1 parent ff358dd commit 5b4d0db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
28 changes: 25 additions & 3 deletions src/platform/backends/qemu/qemu_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,35 @@ void mp::QemuVirtualMachine::start()
vm_process->write(qmp_execute_json("qmp_capabilities"));
}

void mp::QemuVirtualMachine::stop()
void mp::QemuVirtualMachine::stop(bool force)
{
shutdown();
shutdown(force);
}

void mp::QemuVirtualMachine::shutdown()
void mp::QemuVirtualMachine::shutdown(bool force)
{
if (force)
{
state = State::off;
mpl::log(mpl::Level::info, vm_name, "Forced shutdown");

if (vm_process)
{
mpl::log(mpl::Level::info, vm_name, "Killing process");
try
{
vm_process->kill();
}
catch (std::exception&)
{
}
}
else
mpl::log(mpl::Level::info, vm_name, "No process to kill");

return;
}

if (state == State::suspended)
{
mpl::log(mpl::Level::info, vm_name, fmt::format("Ignoring shutdown issued while suspended"));
Expand Down
4 changes: 2 additions & 2 deletions src/platform/backends/qemu/qemu_virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class QemuVirtualMachine final : public QObject, public BaseVirtualMachine
~QemuVirtualMachine();

void start() override;
void stop() override;
void shutdown() override;
void stop(bool force = false) override;
void shutdown(bool force = false) override;
void suspend() override;
State current_state() override;
int ssh_port() override;
Expand Down

0 comments on commit 5b4d0db

Please sign in to comment.