From: Kefu Chai <k.chai@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager 0/1] ceph: pool: fix pool statistics filter returning wrong pool's data
Date: Tue, 31 Mar 2026 10:07:38 +0800 [thread overview]
Message-ID: <20260331020739.818888-1-k.chai@proxmox.com> (raw)
While reading the code I noticed the condition:
next if !defined($d->{name}) && !$d->{name} ne "$pool";
I tried to simplify it using De Morgan's law:
next if !(defined($d->{name}) || $d->{name} ne "$pool");
That immediately looked wrong -- we use the pattern
'defined($foo) && $foo ne "needle"' as a null-safe equality check in
many languages, but here the operator was '&&' combined with negation
on both sides, which doesn't match that pattern at all.
Looking closer, I realised the original condition is simply a logic
error: '&&' short-circuits when the first clause is false, so the name
comparison is never reached for any entry that has a defined name. All
pools with a defined name pass through, and the loop overwrites
$data->{statistics} on every iteration, leaving the stats of whichever
pool happens to be last in the 'ceph df' output.
The !defined() guard also intrigued me -- could 'name' ever be absent
from the response? Reading the Ceph source (PGMap.cc:dump_pool_stats_full)
shows that f->dump_string("name", pool_name) is called unconditionally
for every pool entry. Multiple mgr modules (influx, prometheus, telegraf)
also access pool['name'] directly without any None check, confirming it
is part of the established contract.
The fix removes both the logic error and the now-unnecessary !defined()
guard, simplifying the condition to a plain string comparison.
Kefu Chai (1):
ceph: pool: fix pool statistics filter returning wrong pool's data
PVE/API2/Ceph/Pool.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.47.3
next 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 Kefu Chai [this message]
2026-03-31 2:07 ` [PATCH manager 1/1] " Kefu Chai
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-1-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