From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id F21F71FF16F for ; Tue, 14 Oct 2025 16:40:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E1DDB78F2; Tue, 14 Oct 2025 16:39:59 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Tue, 14 Oct 2025 16:39:21 +0200 Message-ID: <20251014143946.160679-11-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251014143946.160679-1-f.ebner@proxmox.com> References: <20251014143946.160679-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760452752990 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.021 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 10/16] monitor: align interface of qmp_cmd() with other helpers 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" Since all callers of qmp_cmd() construct the $cmd argument the same way, this can also be done directly in qmp_cmd(). This aligns the interface of qmp_cmd() to other helpers like mon_cmd(), except for having a peer rather than just a VM ID. It's much more straightforward to switch calls from mon_cmd() to qmp_cmd() after this change. Signed-off-by: Fiona Ebner --- src/PVE/QemuServer/Monitor.pm | 33 +++++++++++++++------------------ src/test/snapshot-test.pm | 4 +++- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/PVE/QemuServer/Monitor.pm b/src/PVE/QemuServer/Monitor.pm index efdee8e7..0b15808b 100644 --- a/src/PVE/QemuServer/Monitor.pm +++ b/src/PVE/QemuServer/Monitor.pm @@ -14,9 +14,8 @@ our @EXPORT_OK = qw( =head3 qmp_cmd - my $cmd = { execute => $qmp_command_name, arguments => \%params }; my $peer = { vmid => $vmid, type => $type }; - my $result = qmp_cmd($peer, $cmd); + my $result = qmp_cmd($peer, $execute, %arguments); Execute the C<$qmp_command_name> with arguments C<%params> for the peer C<$peer>. The type C<$type> of the peer can be C for the QEMU instance of the VM, C for the guest agent of the VM or @@ -41,9 +40,10 @@ C for the VM's guest agent or C for the QEMU storage daemon assoicated =back -=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: +=item C<$execute>: The QMP command name. + +=item C<%arguments>: Additional arguments for the QMP command. The following custom arguments are +not part of the QMP schema and supported for all commands: =over @@ -60,7 +60,9 @@ handle the error that is returned as a structured result. =cut sub qmp_cmd { - my ($peer, $cmd) = @_; + my ($peer, $execute, %arguments) = @_; + + my $cmd = { execute => $execute, arguments => \%arguments }; my $vmid = $peer->{vmid}; my $res; @@ -101,30 +103,25 @@ sub qmp_cmd { sub qsd_cmd { my ($vmid, $execute, %params) = @_; - my $cmd = { execute => $execute, arguments => \%params }; - - return qmp_cmd({ vmid => $vmid, type => 'qsd' }, $cmd); + return qmp_cmd({ vmid => $vmid, type => 'qsd' }, $execute, %params); } sub mon_cmd { my ($vmid, $execute, %params) = @_; - my $cmd = { execute => $execute, arguments => \%params }; - my $type = ($execute =~ /^guest\-+/) ? 'qga' : 'qmp'; - return qmp_cmd({ vmid => $vmid, type => $type }, $cmd); + return qmp_cmd({ vmid => $vmid, type => $type }, $execute, %params); } sub hmp_cmd { my ($vmid, $cmdline, $timeout) = @_; - my $cmd = { - execute => 'human-monitor-command', - arguments => { 'command-line' => $cmdline, timeout => $timeout }, - }; - - return qmp_cmd({ vmid => $vmid, type => 'qmp' }, $cmd); + return qmp_cmd( + { vmid => $vmid, type => 'qmp' }, 'human-monitor-command', + 'command-line' => $cmdline, + timeout => $timeout, + ); } 1; diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm index 5808f032..e28107b9 100644 --- a/src/test/snapshot-test.pm +++ b/src/test/snapshot-test.pm @@ -356,7 +356,9 @@ sub vm_running_locally { # BEGIN mocked PVE::QemuServer::Monitor methods sub qmp_cmd { - my ($peer, $cmd) = @_; + my ($peer, $execute, %arguments) = @_; + + my $cmd = { execute => $execute, arguments => \%arguments }; my $exec = $cmd->{execute}; if ($exec eq "guest-ping") { -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel