From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2637C60950 for ; Thu, 3 Sep 2020 10:59:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1193116E2B for ; Thu, 3 Sep 2020 10:59:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 8E95516DE8 for ; Thu, 3 Sep 2020 10:59:03 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 51C95449FB for ; Thu, 3 Sep 2020 10:59:03 +0200 (CEST) From: Stefan Reiter To: pve-devel@lists.proxmox.com Date: Thu, 3 Sep 2020 10:58:47 +0200 Message-Id: <20200903085851.5073-4-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903085851.5073-1-s.reiter@proxmox.com> References: <20200903085851.5073-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.053 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemuserver.pm] Subject: [pve-devel] [PATCH qemu-server 3/7] vzdump: connect to qmeventd for duration of backup X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2020 08:59:36 -0000 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 --- PVE/VZDump/QemuServer.pm | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/PVE/VZDump/QemuServer.pm b/PVE/VZDump/QemuServer.pm index 7297795..196739d 100644 --- a/PVE/VZDump/QemuServer.pm +++ b/PVE/VZDump/QemuServer.pm @@ -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; @@ -507,6 +508,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 { @@ -675,6 +677,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; @@ -833,6 +836,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) = @_; @@ -886,7 +917,9 @@ sub snapshot { sub cleanup { my ($self, $task, $vmid) = @_; - # nothing to do ? + if ($self->{qmeventd_fh}) { + close($self->{qmeventd_fh}); + } } 1; -- 2.20.1