From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 86BD31FF187 for ; Mon, 3 Nov 2025 11:21:49 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4A4DB17B69; Mon, 3 Nov 2025 11:21:35 +0100 (CET) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Mon, 3 Nov 2025 11:20:00 +0100 Message-ID: <20251103102118.153666-17-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251103102118.153666-1-d.kral@proxmox.com> References: <20251103102118.153666-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762165267390 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 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 ha-manager v3 16/21] api: status: sync active service counting with lrm's helper 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" There are some inconsistencies between the status API endpoint's and the LRM's active_service_count(...) helper's counting of active services. Sync these by: - Counting a migrating service as active on both the source and target node's LRM as has been introduced in commit a94a38f9 ("LRM: count incoming migrations towards a nodes active resources"). - Not counting services as active if these are in error or request_start state as has been introduced in commit 38545741 ("LRM: do not count erroneous service as active") and commit 4931b586 ("manager: add new intermediate state for stop->start transitions") respectively. - Removing the `sort` as sorting the services is not required for counting active services. While at it, move the counting code in the node loop, where it will be moved in an upcoming patch, to make it easier to see that the logic is the same as the LRM's helper. Signed-off-by: Daniel Kral --- changes since v2: - none src/PVE/API2/HA/Status.pm | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/PVE/API2/HA/Status.pm b/src/PVE/API2/HA/Status.pm index 6e13c2c8..3966a4b3 100644 --- a/src/PVE/API2/HA/Status.pm +++ b/src/PVE/API2/HA/Status.pm @@ -193,20 +193,22 @@ __PACKAGE__->register_method({ }; } - # compute active services for all nodes - my $active_count = {}; - foreach my $sid (sort keys %{ $status->{service_status} }) { - my $sd = $status->{service_status}->{$sid}; - next if !$sd->{node}; - $active_count->{ $sd->{node} } = 0 if !defined($active_count->{ $sd->{node} }); - my $req_state = $sd->{state}; - next if !defined($req_state); - next if $req_state eq 'stopped'; - next if $req_state eq 'freeze'; - $active_count->{ $sd->{node} }++; - } - foreach my $node (sort keys %{ $status->{node_status} }) { + my $active_count = 0; + for my $sid (keys $status->{service_status}->%*) { + my $sd = $status->{service_status}->{$sid}; + my $target = $sd->{target}; + next + if (!$sd->{node} || $sd->{node} ne $nodename) + && (!$target || $target ne $nodename); + my $req_state = $sd->{state}; + next if !defined($req_state); + next if $req_state eq 'stopped'; + next if $req_state eq 'freeze'; + next if $req_state eq 'error'; + next if $req_state eq 'request_start'; + $active_count++; + } my $lrm_status = PVE::HA::Config::read_lrm_status($node); my $id = "lrm:$node"; if (!$lrm_status->{timestamp}) { @@ -227,7 +229,7 @@ __PACKAGE__->register_method({ if ($lrm_mode ne 'active') { $status_str = "$lrm_mode mode"; } else { - if ($lrm_state eq 'wait_for_agent_lock' && !$active_count->{$node}) { + if ($lrm_state eq 'wait_for_agent_lock' && !$active_count) { $status_str = 'idle'; } else { $status_str = $lrm_state; -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel