From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D321995BF for ; Mon, 4 Sep 2023 13:39:58 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AD29DE27D for ; Mon, 4 Sep 2023 13:39:58 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 4 Sep 2023 13:39:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 707D041003 for ; Mon, 4 Sep 2023 13:39:57 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Mon, 4 Sep 2023 13:39:48 +0200 Message-Id: <20230904113949.940431-5-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230904113949.940431-1-f.ebner@proxmox.com> References: <20230904113949.940431-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.079 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 4/5] introduce QMPHelpers module 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: , X-List-Received-Date: Mon, 04 Sep 2023 11:39:58 -0000 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 --- 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