]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: simplify fragment printing
authorPatrick Donnelly <pdonnell@ibm.com>
Thu, 13 Nov 2025 19:47:24 +0000 (14:47 -0500)
committerPatrick Donnelly <pdonnell@ibm.com>
Wed, 18 Mar 2026 00:33:16 +0000 (20:33 -0400)
There's better tooling for this now and we can avoid magic numbers.

Fixes: https://tracker.ceph.com/issues/73792
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
(cherry picked from commit 647de21c85f14d67e7941428c3af2ebeef39ad4f)

src/common/frag.cc

index 13a8e154559346e07295c2df91d0043b4d3b139b..452f30ff5dc8e818822169b89b7e851b2edfa8e9 100644 (file)
@@ -17,6 +17,8 @@
 #include "common/debug.h"
 #include "common/Formatter.h"
 
+#include <fmt/format.h>
+
 #include <iostream>
 #include <sstream>
 
@@ -52,13 +54,12 @@ void frag_t::generate_test_instances(std::list<frag_t*>& ls) {
 std::ostream& operator<<(std::ostream& out, const frag_t& hb)
 {
   //out << std::hex << hb.value() << std::dec << "/" << hb.bits() << '=';
-  unsigned num = hb.bits();
-  if (num) {
-    unsigned val = hb.value();
-    for (unsigned bit = 23; num; num--, bit--) 
-      out << ((val & (1<<bit)) ? '1':'0');
+  if (auto b = hb.bits(); b > 0) {
+    auto v = hb.value() >> hb.mask_shift();
+    return out << fmt::format("{0:0{1}b}*", v, b);
+  } else {
+    return out << '*';
   }
-  return out << '*';
 }
 
 bool fragtree_t::force_to_leaf(CephContext *cct, frag_t x) {