[PATCH ha-manager v3 28/40] usage: pass service data to get_used_service_nodes

Daniel Kral
2026-03-30T14:44:18Z

Remove some unnecessary destructuring syntax for the helper.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
Reviewed-by: Dominik Rusovac <d.rusovac@proxmox.com>
---
changes v2 -> v3:
- reword documentation of get_used_service_nodes() as suggested by
@Dominik

src/PVE/HA/Rules/ResourceAffinity.pm | 3 +--
src/PVE/HA/Usage.pm | 13 ++++++-------
2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/PVE/HA/Rules/ResourceAffinity.pm b/src/PVE/HA/Rules/ResourceAffinity.pm
index 1c610430..474d3000 100644
--- a/src/PVE/HA/Rules/ResourceAffinity.pm
+++ b/src/PVE/HA/Rules/ResourceAffinity.pm
@@ -511,8 +511,7 @@ sub get_resource_affinity {
my $get_used_service_nodes = sub {
my ($sid) = @_;
return (undef, undef) if !defined($ss->{$sid});
- my ($state, $node, $target) = $ss->{$sid}->@{qw(state node target)};
- return PVE::HA::Usage::get_used_service_nodes($online_nodes, $state, $node, $target);
+ return PVE::HA::Usage::get_used_service_nodes($online_nodes, $ss->{$sid});
};

for my $csid (keys $positive->%*) {
diff --git a/src/PVE/HA/Usage.pm b/src/PVE/HA/Usage.pm
index 6d53f956..be3e64d6 100644
--- a/src/PVE/HA/Usage.pm
+++ b/src/PVE/HA/Usage.pm
@@ -45,9 +45,7 @@ sub add_service_usage {
my ($self, $sid, $sd) = @_;

my $online_nodes = { map { $_ => 1 } $self->list_nodes() };
- my ($service_state, $service_node, $migration_target) = $sd->@{qw(state node target)};
- my ($current_node, $target_node) =
- get_used_service_nodes($online_nodes, $service_state, $service_node, $migration_target);
+ my ($current_node, $target_node) = get_used_service_nodes($online_nodes, $sd);

$self->add_service_usage_to_node($current_node, $sid) if $current_node;
$self->add_service_usage_to_node($target_node, $sid) if $target_node;
@@ -66,11 +64,12 @@ sub score_nodes_to_start_service {
die "implement in subclass";
}

-# Returns the current and target node as a two-element array, that a service
-# puts load on according to the $online_nodes and the service's $state, $node
-# and $target.
+# Returns a two-element array of the nodes a service puts load on
+# (current and target), given $online_nodes and service data $sd.
sub get_used_service_nodes {
- my ($online_nodes, $state, $node, $target) = @_;
+ my ($online_nodes, $sd) = @_;
+
+ my ($state, $node, $target) = $sd->@{qw(state node target)};

return (undef, undef) if $state eq 'stopped' || $state eq 'request_start';

--
2.47.3