]> git.proxmox.com Git - qemu-server.git/commitdiff
vzdump: connect to qmeventd for duration of backup
authorStefan Reiter <s.reiter@proxmox.com>
Mon, 19 Oct 2020 12:18:38 +0000 (14:18 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 5 Nov 2020 10:22:47 +0000 (11:22 +0100)
Connect and send the vmid of the VM being backed up. This prevents
qmeventd from SIGTERMing the underlying QEMU instance, even if the guest
shuts itself down, until we close the socket connection (in cleanup,
which happens on success and abort, or if we crash the file handle will
be closed as well).

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
PVE/VZDump/QemuServer.pm

index 8792e766f27b3c1573edd90245ce83aabf57aa4d..9aad8b69c70dd03af2f32282f15faf34b57ae194 100644 (file)
@@ -8,6 +8,7 @@ use File::Path;
 use IO::File;
 use IPC::Open3;
 use JSON;
+use POSIX qw(EINTR EAGAIN);
 
 use PVE::Cluster qw(cfs_read_file);
 use PVE::INotify;
@@ -515,6 +516,7 @@ sub archive_pbs {
     my $devlist = _get_task_devlist($task);
 
     $self->enforce_vm_running_for_backup($vmid);
+    $self->register_qmeventd_handle($vmid);
 
     my $backup_job_uuid;
     eval {
@@ -683,6 +685,7 @@ sub archive_vma {
     my $devlist = _get_task_devlist($task);
 
     $self->enforce_vm_running_for_backup($vmid);
+    $self->register_qmeventd_handle($vmid);
 
     my $cpid;
     my $backup_job_uuid;
@@ -841,6 +844,34 @@ sub enforce_vm_running_for_backup {
     die $@ if $@;
 }
 
+sub register_qmeventd_handle {
+    my ($self, $vmid) = @_;
+
+    my $fh;
+    my $peer = "/var/run/qmeventd.sock";
+    my $count = 0;
+
+    for (;;) {
+       $count++;
+       $fh = IO::Socket::UNIX->new(Peer => $peer, Blocking => 0, Timeout => 1);
+       last if $fh;
+       if ($! != EINTR && $! != EAGAIN) {
+           $self->log("warn", "unable to connect to qmeventd socket (vmid: $vmid) - $!\n");
+           return;
+       }
+       if ($count > 4) {
+           $self->log("warn", "unable to connect to qmeventd socket (vmid: $vmid)"
+                            . " - timeout after $count retries\n");
+           return;
+       }
+       usleep(25000);
+    }
+
+    # send handshake to mark VM as backing up
+    print $fh to_json({vzdump => {vmid => "$vmid"}});
+    $self->{qmeventd_fh} = $fh;
+}
+
 # resume VM againe once we got in a clear state (stop mode backup of running VM)
 sub resume_vm_after_job_start {
     my ($self, $task, $vmid) = @_;
@@ -894,7 +925,9 @@ sub snapshot {
 sub cleanup {
     my ($self, $task, $vmid) = @_;
 
-    # nothing to do ?
+    if ($self->{qmeventd_fh}) {
+       close($self->{qmeventd_fh});
+    }
 }
 
 1;