[pve-devel] [PATCH qemu-server 4/5] introduce QMPHelpers module

Fiona Ebner f.ebner at proxmox.com
Mon Sep 4 13:39:48 CEST 2023


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 at 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






More information about the pve-devel mailing list