public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH manager 0/1] ceph: pool: fix pool statistics filter returning wrong pool's data
@ 2026-03-31  2:07 Kefu Chai
  2026-03-31  2:07 ` [PATCH manager 1/1] " Kefu Chai
  0 siblings, 1 reply; 2+ messages in thread
From: Kefu Chai @ 2026-03-31  2:07 UTC (permalink / raw)
  To: pve-devel

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-31  2:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-31  2:07 [PATCH manager 0/1] ceph: pool: fix pool statistics filter returning wrong pool's data Kefu Chai
2026-03-31  2:07 ` [PATCH manager 1/1] " Kefu Chai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal