[PATCH ha-manager v3 27/40] usage: pass service data to add_service_usage

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

The method is already dependent on three members of the service data and
in a following patch a fourth member is needed for adding more
information to the Usage implementations.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
Reviewed-by: Dominik Rusovac <d.rusovac@proxmox.com>
---
changes v2 -> v3:
- fix $service_stats->%{qw(...)} to $service_stats->{$sid}->%{qw(...)}
as reported by @Dominik

src/PVE/HA/Manager.pm | 11 +++++------
src/PVE/HA/Usage.pm | 6 +++---
2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index fbc7f931..71f45b5c 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -284,17 +284,17 @@ sub recompute_online_node_usage {
foreach my $sid (sort keys %{ $self->{ss} }) {
my $sd = $self->{ss}->{$sid};

- $online_node_usage->add_service_usage($sid, $sd->{state}, $sd->{node}, $sd->{target});
+ $online_node_usage->add_service_usage($sid, $sd);
}

# add remaining non-HA resources to online node usage
for my $sid (sort keys %$service_stats) {
next if $self->{ss}->{$sid};

- my ($node, $state) = $service_stats->{$sid}->@{qw(node state)};
-
# the migration target is not known for non-HA resources
- $online_node_usage->add_service_usage($sid, $state, $node, undef);
+ my $sd = { $service_stats->{$sid}->%{qw(node state)} };
+
+ $online_node_usage->add_service_usage($sid, $sd);
}

$self->{online_node_usage} = $online_node_usage;
@@ -332,8 +332,7 @@ my $change_service_state = sub {
}

$self->{online_node_usage}->remove_service_usage($sid);
- $self->{online_node_usage}
- ->add_service_usage($sid, $sd->{state}, $sd->{node}, $sd->{target});
+ $self->{online_node_usage}->add_service_usage($sid, $sd);

$sd->{uid} = compute_new_uuid($new_state);

diff --git a/src/PVE/HA/Usage.pm b/src/PVE/HA/Usage.pm
index 9f19a82b..6d53f956 100644
--- a/src/PVE/HA/Usage.pm
+++ b/src/PVE/HA/Usage.pm
@@ -40,12 +40,12 @@ sub add_service_usage_to_node {
die "implement in subclass";
}

-# Adds service $sid's usage to the online nodes according to their $state,
-# $service_node and $migration_target.
+# Adds service $sid's usage to the online nodes according to their service data $sd.
sub add_service_usage {
- my ($self, $sid, $service_state, $service_node, $migration_target) = @_;
+ 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);

--
2.47.3