[pve-devel] [PATCH qemu-server 09/11] extract register_qmeventd_handle to QemuServer.pm

Stefan Reiter s.reiter at proxmox.com
Mon Jan 11 12:14:07 CET 2021


...to be reused by live-restore.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 PVE/QemuServer.pm        | 28 ++++++++++++++++++++++++++++
 PVE/VZDump/QemuServer.pm | 32 ++------------------------------
 2 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 4c34595..aa88a9d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7432,6 +7432,34 @@ sub device_bootorder {
     return $bootorder;
 }
 
+sub register_qmeventd_handle {
+    my ($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) {
+	    die "unable to connect to qmeventd socket (vmid: $vmid) - $!\n";
+	}
+	if ($count > 4) {
+	    die "unable to connect to qmeventd socket (vmid: $vmid) - timeout "
+	      . "after $count retries\n";
+	}
+	usleep(25000);
+    }
+
+    # send handshake to mark VM as backing up
+    print $fh to_json({vzdump => {vmid => "$vmid"}});
+
+    # return handle to be closed later when inhibit is no longer required
+    return $fh;
+}
+
 # bash completion helper
 
 sub complete_backup_archives {
diff --git a/PVE/VZDump/QemuServer.pm b/PVE/VZDump/QemuServer.pm
index b322701..d689e3d 100644
--- a/PVE/VZDump/QemuServer.pm
+++ b/PVE/VZDump/QemuServer.pm
@@ -512,7 +512,7 @@ sub archive_pbs {
     my $devlist = _get_task_devlist($task);
 
     $self->enforce_vm_running_for_backup($vmid);
-    $self->register_qmeventd_handle($vmid);
+    $self->{qmeventd_fh} = PVE::QemuServer::register_qmeventd_handle($vmid);
 
     my $backup_job_uuid;
     eval {
@@ -681,7 +681,7 @@ sub archive_vma {
     my $devlist = _get_task_devlist($task);
 
     $self->enforce_vm_running_for_backup($vmid);
-    $self->register_qmeventd_handle($vmid);
+    $self->{qmeventd_fh} = PVE::QemuServer::register_qmeventd_handle($vmid);
 
     my $cpid;
     my $backup_job_uuid;
@@ -840,34 +840,6 @@ 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) = @_;
-- 
2.20.1





More information about the pve-devel mailing list