[pve-devel] [PATCH ha-manager 2/2] usage: basic: avoid node autovivification when adding service usage

Fiona Ebner f.ebner at proxmox.com
Thu Oct 5 16:05:46 CEST 2023


Part of what caused bug #4984. Make the code future-proof and warn
when the node was never registered in the plugin, similar to what the
'static' usage plugin already does.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 src/PVE/HA/Usage/Basic.pm | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/PVE/HA/Usage/Basic.pm b/src/PVE/HA/Usage/Basic.pm
index f066350..d6b3d6c 100644
--- a/src/PVE/HA/Usage/Basic.pm
+++ b/src/PVE/HA/Usage/Basic.pm
@@ -10,6 +10,7 @@ sub new {
 
     return bless {
 	nodes => {},
+	haenv => $haenv,
     }, $class;
 }
 
@@ -40,7 +41,14 @@ sub contains_node {
 sub add_service_usage_to_node {
     my ($self, $nodename, $sid, $service_node, $migration_target) = @_;
 
-    $self->{nodes}->{$nodename}++;
+    if ($self->contains_node($nodename)) {
+	$self->{nodes}->{$nodename}++;
+    } else {
+	$self->{haenv}->log(
+	    'warning',
+	    "unable to add service '$sid' usage to node '$nodename' - node not in usage hash",
+	);
+    }
 }
 
 sub score_nodes_to_start_service {
-- 
2.39.2






More information about the pve-devel mailing list