From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id B98DF1FF16F for ; Tue, 5 Aug 2025 11:29:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4ECA8AA7D; Tue, 5 Aug 2025 11:31:23 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Tue, 5 Aug 2025 11:25:31 +0200 Message-ID: <20250805093045.27959-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250805093045.27959-1-f.ebner@proxmox.com> References: <20250805093045.27959-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1754386229865 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.024 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server 1/3] qmp client: add $noerr argument 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Using the $noerr argument will allow callers to opt-in to handling errors themselves. Signed-off-by: Fiona Ebner --- src/PVE/QMPClient.pm | 8 ++++--- src/PVE/QemuServer/Monitor.pm | 40 ++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/PVE/QMPClient.pm b/src/PVE/QMPClient.pm index 87d61144..7b19be9d 100644 --- a/src/PVE/QMPClient.pm +++ b/src/PVE/QMPClient.pm @@ -86,7 +86,7 @@ sub queue_cmd { # execute a single command sub cmd { - my ($self, $vmid, $cmd, $timeout) = @_; + my ($self, $vmid, $cmd, $timeout, $noerr) = @_; my $result; @@ -155,8 +155,10 @@ sub cmd { $self->queue_execute($timeout, 2); - die "VM $vmid qmp command '$cmd->{execute}' failed - $queue_info->{error}" - if defined($queue_info->{error}); + if (defined($queue_info->{error})) { + die "VM $vmid qmp command '$cmd->{execute}' failed - $queue_info->{error}" if !$noerr; + $result = { error => $queue_info->{error} }; + } return $result; } diff --git a/src/PVE/QemuServer/Monitor.pm b/src/PVE/QemuServer/Monitor.pm index 5956e1c4..062e71be 100644 --- a/src/PVE/QemuServer/Monitor.pm +++ b/src/PVE/QemuServer/Monitor.pm @@ -12,14 +12,48 @@ our @EXPORT_OK = qw( mon_cmd ); +=head3 qmp_cmd + + my $cmd = { execute => $qmp_command_name, arguments => \%params }; + my $result = qmp_cmd($vmid, $cmd); + +Execute the C<$qmp_command_name> with arguments C<%params> for VM C<$vmid>. Dies if the VM is not +running or the monitor socket cannot be reached, even if the C argument is used. Returns the +structured result from the QMP side converted from JSON to structured Perl data. In case the +C argument is used and the QMP command failed or timed out, the result is a hash reference +with an C key containing the error message. + +Parameters: + +=over + +=item C<$vmid>: The ID of the virtual machine. + +=item C<$cmd>: Hash reference containing the QMP command name for the C key and additional +arguments for the QMP command under the C key. The following custom arguments are not +part of the QMP schema and supported for all commands: + +=over + +=item C: wait at most for this amount of time. If there was no actual error, the QMP/QGA +command will still continue to be executed even after the timeout reached. + +=item C: do not die when the command gets an error or the timeout is hit. The caller needs to +handle the error that is returned as a structured result. + +=back + +=back + +=cut sub qmp_cmd { my ($vmid, $cmd) = @_; my $res; - my $timeout; + my ($noerr, $timeout); if ($cmd->{arguments}) { - $timeout = delete $cmd->{arguments}->{timeout}; + ($noerr, $timeout) = delete($cmd->{arguments}->@{qw(noerr timeout)}); } eval { @@ -28,7 +62,7 @@ sub qmp_cmd { if (-e $sname) { # test if VM is reasonably new and supports qmp/qga my $qmpclient = PVE::QMPClient->new(); - $res = $qmpclient->cmd($vmid, $cmd, $timeout); + $res = $qmpclient->cmd($vmid, $cmd, $timeout, $noerr); } else { die "unable to open monitor socket\n"; } -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel