From: Kefu Chai <k.chai@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager 1/1] ceph: pool: fix pool statistics filter returning wrong pool's data
Date: Tue, 31 Mar 2026 10:07:39 +0800 [thread overview]
Message-ID: <20260331020739.818888-2-k.chai@proxmox.com> (raw)
In-Reply-To: <20260331020739.818888-1-k.chai@proxmox.com>
The condition filtering the 'ceph df' response to the requested pool
had a logic error:
next if !defined($d->{name}) && !$d->{name} ne "$pool";
With '&&', short-circuit evaluation means the name comparison is never
reached when $d->{name} is defined. All entries with a defined name
pass through, and $data->{statistics} ends up holding the stats of
whichever pool appears last in the output.
The combination of double negation and '&&' also makes the condition
difficult to reason about: a reader must mentally apply De Morgan's law
to understand what is being skipped, increasing the chance of
misreading the logic.
The !defined() guard is also unnecessary. The 'ceph df' response always
includes a 'name' field for every pool entry: PGMap.cc:dump_pool_stats_full
calls f->dump_string("name", pool_name) unconditionally for each pool in
the OSD map. Multiple mgr modules (influx, prometheus, telegraf) access
pool['name'] directly from the df output without any None/missing check,
confirming that 'name' is part of the established contract for this
response.
Simplify to a plain string comparison.
Signed-off-by: Kefu Chai <k.chai@proxmox.com>
---
PVE/API2/Ceph/Pool.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/PVE/API2/Ceph/Pool.pm b/PVE/API2/Ceph/Pool.pm
index 73166cdf..587c6c96 100644
--- a/PVE/API2/Ceph/Pool.pm
+++ b/PVE/API2/Ceph/Pool.pm
@@ -787,7 +787,7 @@ __PACKAGE__->register_method({
foreach my $d (@{ $res->{pools} }) {
next if !$d->{stats};
- next if !defined($d->{name}) && !$d->{name} ne "$pool";
+ next if $d->{name} ne $pool;
$data->{statistics} = $d->{stats};
}
--
2.47.3
prev parent reply other threads:[~2026-03-31 2:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 2:07 [PATCH manager 0/1] " Kefu Chai
2026-03-31 2:07 ` 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=20260331020739.818888-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