From 8dc6a8ed6a498fda249ca93ccad1b0ce2f5563df Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Mon, 22 May 2023 10:01:39 +0530 Subject: [PATCH] mds: display sane hex value (0x0) for empty feature bit 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 (cherry picked from commit 2ee9b3af82c788ecd68d09d5bd97d80f07dae0ca) --- src/mds/mdstypes.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mds/mdstypes.cc b/src/mds/mdstypes.cc index d8b03915a00..a914b9f3015 100644 --- a/src/mds/mdstypes.cc +++ b/src/mds/mdstypes.cc @@ -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); } -- 2.39.5