]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: display sane hex value (0x0) for empty feature bit 51655/head
authorJos Collin <jcollin@redhat.com>
Mon, 22 May 2023 04:31:39 +0000 (10:01 +0530)
committerJos Collin <jcollin@redhat.com>
Mon, 19 Jun 2023 07:54:19 +0000 (13:24 +0530)
Print a valid hex (0x0) during empty feature bit, so that the clients could recognize it.
When the _vec size becomes 0, print() function creates an invalid hex (0x) and 'perf stats'
crashes with the below error:
"
File "/opt/ceph/src/pybind/mgr/stats/fs/perf_stats.py", line 177, in notify_cmd
metric_features = int(metadata[CLIENT_METADATA_KEY]["metric_spec"]["metric_flags"]["feature_bits"], 16)
ValueError: invalid literal for int() with base 16: '0x'
"
This patch creates  a valid hex (0x0), when _vec size is 0.

Fixes: https://tracker.ceph.com/issues/59551
Signed-off-by: Jos Collin <jcollin@redhat.com>
src/mds/mdstypes.cc

index d8b03915a0030c1666e5263785c06138fa349f24..a914b9f3015dbc04a6157f0aff8de1a22b83a601 100644 (file)
@@ -492,10 +492,15 @@ void feature_bitset_t::dump(Formatter *f) const {
 void feature_bitset_t::print(ostream& out) const
 {
   std::ios_base::fmtflags f(out.flags());
-  out << "0x";
-  for (int i = _vec.size() - 1; i >= 0; --i)
-    out << std::setfill('0') << std::setw(sizeof(block_type) * 2)
-        << std::hex << _vec[i];
+  int size = _vec.size();
+  if (!size) {
+    out << "0x0";
+  } else {
+    out << "0x";
+    for (int i = size - 1; i >= 0; --i)
+      out << std::setfill('0') << std::setw(sizeof(block_type) * 2)
+          << std::hex << _vec[i];
+  }
   out.flags(f);
 }