]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: simplify fragment printing
authorPatrick Donnelly <pdonnell@ibm.com>
Thu, 13 Nov 2025 19:47:24 +0000 (14:47 -0500)
committerVenky Shankar <vshankar@redhat.com>
Wed, 19 Nov 2025 13:06:49 +0000 (13:06 +0000)
Fixes: https://tracker.ceph.com/issues/73792
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
(cherry picked from commit a8bb5a891eef8aae11e7748f71eac666732f3cff)
Resolves: rhbz#2414841

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) {