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 ADEBF1FF137 for ; Tue, 31 Mar 2026 03:27:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 79275AFB9; Tue, 31 Mar 2026 03:27:57 +0200 (CEST) From: Kefu Chai To: pve-devel@lists.proxmox.com Subject: [PATCH manager 1/1] ceph: tools: fix local monitor detection in purge_all_ceph_files Date: Tue, 31 Mar 2026 09:27:46 +0800 Message-ID: <20260331012746.763863-2-k.chai@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260331012746.763863-1-k.chai@proxmox.com> References: <20260331012746.763863-1-k.chai@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774920418180 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.134 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: FI7LT4N7PJRZXA462IVFGCMEO7YZX5SJ X-Message-ID-Hash: FI7LT4N7PJRZXA462IVFGCMEO7YZX5SJ X-MailFrom: k.chai@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The grep call checking whether a monitor's address is in the configured mon list did not reference $_, so it never performed a membership test: $is_local_mon = grep($type->{$name}->{addr}, @$monlist) In Perl, grep(EXPR, LIST) aliases $_ to each element, but EXPR here is '$type->{$name}->{addr}', which ignores $_. This is analogous to the following Python, where the filter predicate is a constant: # wrong: sum(bool(addr) for _ in monlist) -- always len(monlist) # right: sum(1 for x in monlist if x == addr) Because addr is a non-empty string (truthy), the wrong form returns the full list length regardless of whether addr is actually in the list. In Python terms, any(x == addr for x in monlist) would return False, but the Perl grep returned 3 for a 3-element list. This meant the foreign-monitor guard -- which exists to preserve config files and keyrings when the local node is not listed as a monitor -- never triggered, and 'pveceph purge' would always delete them. Use List::Util::any with an explicit equality check, which both expresses the intent clearly and short-circuits on the first match. Signed-off-by: Kefu Chai --- PVE/Ceph/Tools.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm index 97ff3bd5..c731ac14 100644 --- a/PVE/Ceph/Tools.pm +++ b/PVE/Ceph/Tools.pm @@ -7,6 +7,7 @@ use File::Path; use File::Basename; use IO::File; use JSON; +use List::Util qw(any); use PVE::Tools qw(run_command dir_glob_foreach extract_param); use PVE::Cluster qw(cfs_read_file); @@ -133,7 +134,7 @@ sub purge_all_ceph_files { foreach my $name (keys %$type) { my $dir_exists = $type->{$name}->{direxists}; - $is_local_mon = grep($type->{$name}->{addr}, @$monlist) + $is_local_mon = any { $_ eq $type->{$name}->{addr} } @$monlist if $service eq 'mon'; my $path = "/var/lib/ceph/$service"; -- 2.47.3