public inbox for pve-devel@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 4/5] introduce QMPHelpers module
Date: Mon,  4 Sep 2023 13:39:48 +0200	[thread overview]
Message-ID: <20230904113949.940431-5-f.ebner@proxmox.com> (raw)
In-Reply-To: <20230904113949.940431-1-f.ebner@proxmox.com>

moving qemu_{device,object}{add,del} helpers there for now.

In preparation to remove the cyclic include of PVE::QemuServer in the
memory module and generally for better modularity in the future.

No functional change intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/QemuServer.pm            | 32 +-----------------------
 PVE/QemuServer/Makefile      |  1 +
 PVE/QemuServer/Memory.pm     |  9 ++++---
 PVE/QemuServer/QMPHelpers.pm | 48 ++++++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 35 deletions(-)
 create mode 100644 PVE/QemuServer/QMPHelpers.pm

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 61409a58..af63987a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -58,6 +58,7 @@ use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory;
 use PVE::QemuServer::Monitor qw(mon_cmd);
 use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr print_pcie_root_port parse_hostpci);
+use PVE::QemuServer::QMPHelpers qw(qemu_deviceadd qemu_devicedel qemu_objectadd qemu_objectdel);
 use PVE::QemuServer::USB;
 
 my $have_sdn;
@@ -4377,21 +4378,6 @@ sub qemu_spice_usbredir_chardev_add {
     ));
 }
 
-sub qemu_deviceadd {
-    my ($vmid, $devicefull) = @_;
-
-    $devicefull = "driver=".$devicefull;
-    my %options =  split(/[=,]/, $devicefull);
-
-    mon_cmd($vmid, "device_add" , %options);
-}
-
-sub qemu_devicedel {
-    my ($vmid, $deviceid) = @_;
-
-    my $ret = mon_cmd($vmid, "device_del", id => $deviceid);
-}
-
 sub qemu_iothread_add {
     my ($vmid, $deviceid, $device) = @_;
 
@@ -4410,22 +4396,6 @@ sub qemu_iothread_del {
     }
 }
 
-sub qemu_objectadd {
-    my ($vmid, $objectid, $qomtype) = @_;
-
-    mon_cmd($vmid, "object-add", id => $objectid, "qom-type" => $qomtype);
-
-    return 1;
-}
-
-sub qemu_objectdel {
-    my ($vmid, $objectid) = @_;
-
-    mon_cmd($vmid, "object-del", id => $objectid);
-
-    return 1;
-}
-
 sub qemu_driveadd {
     my ($storecfg, $vmid, $device) = @_;
 
diff --git a/PVE/QemuServer/Makefile b/PVE/QemuServer/Makefile
index e4ed184c..ac26e56f 100644
--- a/PVE/QemuServer/Makefile
+++ b/PVE/QemuServer/Makefile
@@ -11,6 +11,7 @@ SOURCES=PCI.pm		\
 	CPUConfig.pm	\
 	CGroup.pm	\
 	Drive.pm	\
+	QMPHelpers.pm
 
 .PHONY: install
 install: ${SOURCES}
diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm
index 6ec5ceec..023d1a91 100644
--- a/PVE/QemuServer/Memory.pm
+++ b/PVE/QemuServer/Memory.pm
@@ -10,6 +10,7 @@ use PVE::Exception qw(raise raise_param_exc);
 use PVE::QemuServer;
 use PVE::QemuServer::Helpers qw(parse_number_sets);
 use PVE::QemuServer::Monitor qw(mon_cmd);
+use PVE::QemuServer::QMPHelpers qw(qemu_devicedel qemu_objectdel);
 
 our $MAX_NUMA = 8;
 
@@ -226,13 +227,13 @@ sub qemu_memory_hotplug {
 		}
 
 		if (my $err = $@) {
-		    eval { PVE::QemuServer::qemu_objectdel($vmid, "mem-$name"); };
+		    eval { qemu_objectdel($vmid, "mem-$name"); };
 		    die $err;
 		}
 
 		eval { mon_cmd($vmid, "device_add", driver => "pc-dimm", id => "$name", memdev => "mem-$name", node => $numanode) };
 		if (my $err = $@) {
-		    eval { PVE::QemuServer::qemu_objectdel($vmid, "mem-$name"); };
+		    eval { qemu_objectdel($vmid, "mem-$name"); };
 		    die $err;
 		}
 		#update conf after each succesful module hotplug
@@ -255,7 +256,7 @@ sub qemu_memory_hotplug {
 
 	    my $retry = 0;
 	    while (1) {
-		eval { PVE::QemuServer::qemu_devicedel($vmid, $name) };
+		eval { qemu_devicedel($vmid, $name) };
 		sleep 3;
 		my $dimm_list = qemu_memdevices_list($vmid, 'dimm');
 		last if !$dimm_list->{$name};
@@ -266,7 +267,7 @@ sub qemu_memory_hotplug {
 	    #update conf after each succesful module unplug
 	    $conf->{memory} = $current_size;
 
-	    eval { PVE::QemuServer::qemu_objectdel($vmid, "mem-$name"); };
+	    eval { qemu_objectdel($vmid, "mem-$name"); };
 	    PVE::QemuConfig->write_config($vmid, $conf);
 	}
     }
diff --git a/PVE/QemuServer/QMPHelpers.pm b/PVE/QemuServer/QMPHelpers.pm
new file mode 100644
index 00000000..d3a52327
--- /dev/null
+++ b/PVE/QemuServer/QMPHelpers.pm
@@ -0,0 +1,48 @@
+package PVE::QemuServer::QMPHelpers;
+
+use warnings;
+use strict;
+
+use PVE::QemuServer::Monitor qw(mon_cmd);
+
+use base 'Exporter';
+
+our @EXPORT_OK = qw(
+qemu_deviceadd
+qemu_devicedel
+qemu_objectadd
+qemu_objectdel
+);
+
+sub qemu_deviceadd {
+    my ($vmid, $devicefull) = @_;
+
+    $devicefull = "driver=".$devicefull;
+    my %options =  split(/[=,]/, $devicefull);
+
+    mon_cmd($vmid, "device_add" , %options);
+}
+
+sub qemu_devicedel {
+    my ($vmid, $deviceid) = @_;
+
+    my $ret = mon_cmd($vmid, "device_del", id => $deviceid);
+}
+
+sub qemu_objectadd {
+    my ($vmid, $objectid, $qomtype) = @_;
+
+    mon_cmd($vmid, "object-add", id => $objectid, "qom-type" => $qomtype);
+
+    return 1;
+}
+
+sub qemu_objectdel {
+    my ($vmid, $objectid) = @_;
+
+    mon_cmd($vmid, "object-del", id => $objectid);
+
+    return 1;
+}
+
+1;
-- 
2.39.2





  parent reply	other threads:[~2023-09-04 11:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04 11:39 [pve-devel] [PATCH-SERIES qemu-server] avoid cyclic use of main module in memory module Fiona Ebner
2023-09-04 11:39 ` [pve-devel] [PATCH qemu-server 1/5] move parse_number_sets() helper to helpers module Fiona Ebner
2023-09-04 11:39 ` [pve-devel] [PATCH qemu-server 2/5] move NUMA-related code into memory module Fiona Ebner
2023-09-04 11:39 ` [pve-devel] [PATCH qemu-server 3/5] memory: replace deprecated check_running() call Fiona Ebner
2023-09-04 11:39 ` Fiona Ebner [this message]
2023-09-04 11:39 ` [pve-devel] [PATCH qemu-server 5/5] add memory parser Fiona Ebner
2023-09-18 15:12 ` [pve-devel] applied-series: [PATCH-SERIES qemu-server] avoid cyclic use of main module in memory module Thomas Lamprecht

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=20230904113949.940431-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal