From: Kefu Chai <k.chai@proxmox.com>
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 [thread overview]
Message-ID: <20260331012746.763863-2-k.chai@proxmox.com> (raw)
In-Reply-To: <20260331012746.763863-1-k.chai@proxmox.com>
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 <k.chai@proxmox.com>
---
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
prev parent reply other threads:[~2026-03-31 1:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 1:27 [PATCH manager 0/1] " Kefu Chai
2026-03-31 1:27 ` Kefu Chai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260331012746.763863-2-k.chai@proxmox.com \
--to=k.chai@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox