all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v2 09/16] monitor: align interface of qmp_cmd() with other helpers
Date: Mon, 20 Oct 2025 16:12:56 +0200	[thread overview]
Message-ID: <20251020141335.124077-10-f.ebner@proxmox.com> (raw)
In-Reply-To: <20251020141335.124077-1-f.ebner@proxmox.com>

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 <f.ebner@proxmox.com>
---

Changes in v2:
* Use ID instead of VM ID for QSD peer.

 src/PVE/QemuServer/Monitor.pm | 34 ++++++++++++++++------------------
 src/test/snapshot-test.pm     |  4 +++-
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/PVE/QemuServer/Monitor.pm b/src/PVE/QemuServer/Monitor.pm
index 1f6aa17d..b4725a1f 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 = { name => $name, id => $id, 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<qmp> for the QEMU instance of the VM,  C<qga> for the guest agent of the VM or
@@ -43,9 +42,10 @@ C<qga> for the VM's guest agent or C<qsd> for the QEMU storage daemon assoicated
 
 =back
 
-=item C<$cmd>: Hash reference containing the QMP command name for the C<execute> key and additional
-arguments for the QMP command under the C<arguments> 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
 
@@ -62,7 +62,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 $res;
 
@@ -102,30 +104,26 @@ sub qmp_cmd {
 sub qsd_cmd {
     my ($id, $execute, %params) = @_;
 
-    my $cmd = { execute => $execute, arguments => \%params };
-
-    return qmp_cmd({ name => "QEMU storage daemon $id", id => $id, type => 'qsd' }, $cmd);
+    return qmp_cmd({ name => "QEMU storage daemon $id", id => $id, 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({ name => "VM $vmid", id => $vmid, type => $type }, $cmd);
+    return qmp_cmd({ name => "VM $vmid", id => $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({ name => "VM $vmid", id => $vmid, type => 'qmp' }, $cmd);
+    return qmp_cmd(
+        { name => "VM $vmid", id => $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


  parent reply	other threads:[~2025-10-20 14:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 14:12 [pve-devel] [PATCH-SERIES qemu/swtpm/storage/qemu-server/manager v2 00/16] fix #4693: drive: allow non-raw image formats for TPM state drive Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu v2 01/16] d/rules: enable fuse Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH swtpm v2 02/16] swtpm setup: file: always just clear header rather than unlinking Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH storage v2 03/16] common: add pve-vm-image-format standard option for VM image formats Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 04/16] tests: cfg2cmd: remove invalid mocking of qmp_cmd Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 05/16] migration: offline volumes: drop deprecated special casing for TPM state Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 06/16] qmp client: better abstract peer in preparation for qemu-storage-daemon Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 07/16] helpers: add functions for qemu-storage-daemon instances Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 08/16] monitor: qmp: allow 'qsd' peer type for qemu-storage-daemon Fiona Ebner
2025-10-20 14:12 ` Fiona Ebner [this message]
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 10/16] machine: include +pve version when getting installed machine version Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 11/16] blockdev: support attaching to qemu-storage-daemon Fiona Ebner
2025-10-20 14:12 ` [pve-devel] [PATCH qemu-server v2 12/16] blockdev: attach: also return whether attached blockdev is read-only Fiona Ebner
2025-10-20 14:13 ` [pve-devel] [PATCH qemu-server v2 13/16] introduce QSD module for qemu-storage-daemon functionality Fiona Ebner
2025-10-20 14:13 ` [pve-devel] [PATCH qemu-server v2 14/16] tpm: support non-raw volumes via FUSE exports for swtpm Fiona Ebner
2025-10-20 14:13 ` [pve-devel] [PATCH qemu-server v2 15/16] fix #4693: drive: allow non-raw image formats for TPM state drive Fiona Ebner
2025-10-20 14:13 ` [pve-devel] [PATCH manager v2 16/16] ui: qemu: tpm drive: follow back-end and allow non-raw formats Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251020141335.124077-10-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal