backup: prepare: factor out getting running status

In preparation to use it to conditionally issue a QMP 'backup-cancel'
should a previous backup still be running.

While at it, avoid using the compat-only check_running() helper.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2024-11-11 14:54:30 +01:00 committed by Thomas Lamprecht
parent 35c93dde5b
commit 67d9ef4c5d

View File

@ -57,6 +57,8 @@ sub vmlist {
sub prepare { sub prepare {
my ($self, $task, $vmid, $mode) = @_; my ($self, $task, $vmid, $mode) = @_;
my $running = PVE::QemuServer::Helpers::vm_running_locally($vmid);
$task->{disks} = []; $task->{disks} = [];
my $conf = $self->{vmlist}->{$vmid} = PVE::QemuConfig->load_config($vmid); my $conf = $self->{vmlist}->{$vmid} = PVE::QemuConfig->load_config($vmid);
@ -64,11 +66,9 @@ sub prepare {
$self->loginfo("VM Name: $conf->{name}") $self->loginfo("VM Name: $conf->{name}")
if defined($conf->{name}); if defined($conf->{name});
$self->{vm_was_running} = 1; $self->{vm_was_running} = $running ? 1 : 0;
$self->{vm_was_paused} = 0; $self->{vm_was_paused} = 0;
if (!PVE::QemuServer::check_running($vmid)) { if ($running && PVE::QemuServer::vm_is_paused($vmid, 0)) {
$self->{vm_was_running} = 0;
} elsif (PVE::QemuServer::vm_is_paused($vmid, 0)) {
# Do not treat a suspended VM as paused, as it would cause us to skip # Do not treat a suspended VM as paused, as it would cause us to skip
# fs-freeze even if the VM wakes up before we reach qga_fs_freeze. # fs-freeze even if the VM wakes up before we reach qga_fs_freeze.
$self->{vm_was_paused} = 1; $self->{vm_was_paused} = 1;