[pve-devel] [PATCH qemu-server 06/11] qmp client: add $noerr argument
Fiona Ebner
f.ebner at proxmox.com
Mon May 5 14:57:19 CEST 2025
Using the $noerr argument will allow callers to opt-in to handling
errors themselves.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
PVE/QMPClient.pm | 8 +++++---
PVE/QemuServer/Monitor.pm | 11 ++++++++---
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/PVE/QMPClient.pm b/PVE/QMPClient.pm
index eefd17a5..0f08e678 100644
--- a/PVE/QMPClient.pm
+++ b/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;
@@ -143,8 +143,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/PVE/QemuServer/Monitor.pm b/PVE/QemuServer/Monitor.pm
index 937006ae..5e16edac 100644
--- a/PVE/QemuServer/Monitor.pm
+++ b/PVE/QemuServer/Monitor.pm
@@ -12,14 +12,19 @@ our @EXPORT_OK = qw(
mon_cmd
);
+# Supported custom options not in the QMP schema:
+# timeout - 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.
+# noerr - 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.
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 +33,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.39.5
More information about the pve-devel
mailing list