|
| 1 | +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
| 2 | +// vim: ts=8 sw=2 smarttab |
| 3 | +/* |
| 4 | + * Ceph - scalable distributed file system |
| 5 | + * |
| 6 | + * Copyright (C) 2023 IBM |
| 7 | + * |
| 8 | + * This is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU Lesser General Public |
| 10 | + * License version 2.1, as published by the Free Software |
| 11 | + * Foundation. See file COPYING. |
| 12 | + * |
| 13 | + */ |
| 14 | +#include <cstdint> |
| 15 | +#include <ostream> |
| 16 | +#include "BlueStore.h" |
| 17 | + |
| 18 | +static const std::string transition_table[26] = { |
| 19 | +"bcdfghjklmnprstuvxyz", //a |
| 20 | +"aeiloruy",//b |
| 21 | +"aeiloruvy",//c |
| 22 | +"aeilmnoruvy",//d |
| 23 | +"bcdfghjklmnprstvxz",//e |
| 24 | + |
| 25 | +"ailou",//f |
| 26 | +"aeilnoru",//g |
| 27 | +"aeiloru",//h |
| 28 | +"dfghklmnpqrstvwx",//i |
| 29 | +"aeiou",//j |
| 30 | + |
| 31 | +"aeiloru",//k |
| 32 | +"aeimnou",//l |
| 33 | +"aeinotuy",//m |
| 34 | +"aeiou",//n |
| 35 | +"bcdfghjklmnpqrstvwxz",//o |
| 36 | +"aehiloruy",//p |
| 37 | + |
| 38 | +"aeiloru",//q |
| 39 | +"adefiklmnotuvy",//r |
| 40 | +"aehiklmnopqrtuvwy",//s |
| 41 | +"acefhiklmnorsuvwy",//t |
| 42 | +"bcdfghklmnpqrsvwxyz",//u |
| 43 | + |
| 44 | +"acdeiklmorsu",//v |
| 45 | +"aehilnorstu",//w |
| 46 | +"aeilnorstuy",//x |
| 47 | +"aehinorsuxz",//y |
| 48 | +"aeiouy" //z |
| 49 | +}; |
| 50 | + |
| 51 | +std::string int_to_fancy_name(uint64_t x) |
| 52 | +{ |
| 53 | + std::string result; |
| 54 | + uint8_t c = x % 26; |
| 55 | + x = x / 26; |
| 56 | + result.push_back(c+'a'); |
| 57 | + while (x > 0) { |
| 58 | + uint8_t range = transition_table[c].length(); |
| 59 | + uint8_t p = x % range; |
| 60 | + c = transition_table[c][p] - 'a'; |
| 61 | + x = x / range; |
| 62 | + result.push_back(c+'a'); |
| 63 | + } |
| 64 | + return result; |
| 65 | +} |
| 66 | + |
| 67 | +// Use special printing for multiplies of 1024; print K suffix |
| 68 | +struct maybe_K { |
| 69 | + uint32_t x; |
| 70 | + maybe_K(uint32_t x) : x(x) {} |
| 71 | +}; |
| 72 | +std::ostream &operator<<(std::ostream &out, const maybe_K &k) { |
| 73 | + if (((k.x & 0x3ff) == 0) && (k.x != 0)) { |
| 74 | + if (k.x != 0x400) |
| 75 | + out << (k.x / 0x400); |
| 76 | + out << "K"; |
| 77 | + } else { |
| 78 | + out << std::hex << k.x << std::dec; |
| 79 | + } |
| 80 | + return out; |
| 81 | +} |
| 82 | +// cheap, not very reliable but portable detector where heap starts |
| 83 | +static std::unique_ptr<char> heap_begin(new char); |
| 84 | +std::ostream& operator<<(std::ostream& out, const BlueStore::Buffer& b); |
| 85 | +std::ostream& operator<<(std::ostream& out, const BlueStore::Blob::printer &p) |
| 86 | +{ |
| 87 | + using P = BlueStore::printer; |
| 88 | + out << "Blob("; |
| 89 | + if (p.mode & P::PTR) { |
| 90 | + out << &p.blob; |
| 91 | + } |
| 92 | + if (p.mode & P::NICK) { |
| 93 | + uint64_t v = uint64_t(&p.blob); |
| 94 | + //Assume allocated Blobs will be 16 bytes aligned. |
| 95 | + v = (v - (uintptr_t)heap_begin.get()) / 16; |
| 96 | + out << int_to_fancy_name(v); |
| 97 | + } |
| 98 | + const bluestore_blob_t& bblob = p.blob.get_blob(); |
| 99 | + if (p.mode & P::DISK) { |
| 100 | + //use default printer for std::vector * bluestore_pextent_t |
| 101 | + out << " disk=" << bblob.get_extents(); |
| 102 | + } |
| 103 | + if (p.mode & P::SDISK) { |
| 104 | + const PExtentVector& ev = bblob.get_extents(); |
| 105 | + uint64_t bits = 0; |
| 106 | + for (auto i : ev) { |
| 107 | + if (i.is_valid()) bits |= i.offset; |
| 108 | + bits |= i.length; |
| 109 | + } |
| 110 | + uint32_t zeros = 0; //zeros to apply to all values |
| 111 | + while ((bits & 0xf) == 0) { |
| 112 | + bits = bits >> 4; |
| 113 | + ++zeros; |
| 114 | + } |
| 115 | + out << " disk=0x[" << std::hex; |
| 116 | + for (size_t i = 0; i < ev.size(); ++i) { |
| 117 | + if (i != 0) { |
| 118 | + out << ","; |
| 119 | + } |
| 120 | + if (ev[i].is_valid()) { |
| 121 | + out << (ev[i].offset >> zeros * 4) << "~"; |
| 122 | + } else { |
| 123 | + out << "!"; |
| 124 | + } |
| 125 | + out << (ev[i].length >> zeros * 4); |
| 126 | + } |
| 127 | + out << "]" << std::dec; |
| 128 | + while (zeros > 0) { |
| 129 | + out << "0"; |
| 130 | + --zeros; |
| 131 | + } |
| 132 | + } |
| 133 | + //always print lengths, if not printing use tracker |
| 134 | + if ((!(p.mode & (P::USE | P::SUSE)) || bblob.is_compressed()) |
| 135 | + && !(p.mode & P::JUSTID)) { |
| 136 | + // Need to print blob logical length, no tracker printing |
| 137 | + // + there is no real tracker for compressed blobs |
| 138 | + if (bblob.is_compressed()) { |
| 139 | + out << " len=" << std::hex << bblob.get_logical_length() << "->" |
| 140 | + << bblob.get_compressed_payload_length() << std::dec; |
| 141 | + } else { |
| 142 | + out << " len=" << std::hex << bblob.get_logical_length() << std::dec; |
| 143 | + } |
| 144 | + } |
| 145 | + if ((p.mode & P::USE) && !bblob.is_compressed()) { |
| 146 | + out << " " << p.blob.get_blob_use_tracker(); |
| 147 | + } |
| 148 | + if (p.mode & P::SUSE) { |
| 149 | + auto& tracker = p.blob.get_blob_use_tracker(); |
| 150 | + if (bblob.is_compressed()) { |
| 151 | + out << " [" << std::hex << tracker.get_referenced_bytes() << std::dec << "]"; |
| 152 | + } else { |
| 153 | + const uint32_t* au_array = tracker.get_au_array(); |
| 154 | + uint16_t zeros = 0; |
| 155 | + uint16_t full = 0; |
| 156 | + uint16_t num_au = tracker.get_num_au(); |
| 157 | + uint32_t au_size = tracker.au_size; |
| 158 | + uint32_t def = std::numeric_limits<uint32_t>::max(); |
| 159 | + out << " track=" << tracker.get_num_au() << "*" << maybe_K(tracker.au_size); |
| 160 | + for (size_t i = 0; i < num_au; i++) { |
| 161 | + if (au_array[i] == 0) ++zeros; |
| 162 | + if (au_array[i] == au_size) ++full; |
| 163 | + } |
| 164 | + if (zeros >= num_au - 3 && num_au > 6) def = 0; |
| 165 | + if (full >= num_au - 3 && num_au > 6) def = au_size; |
| 166 | + if (def != std::numeric_limits<uint32_t>::max()) { |
| 167 | + out << " {" << maybe_K(def) << "}["; |
| 168 | + for (size_t i = 0; i < num_au; i++) { |
| 169 | + if (au_array[i] != def) { |
| 170 | + out << i << "=" << maybe_K(au_array[i]); |
| 171 | + ++i; |
| 172 | + for (; i < num_au; i++) { |
| 173 | + if (au_array[i] != def) { |
| 174 | + out << "," << i << "=" << maybe_K(au_array[i]); |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | + out << "]"; |
| 180 | + } else { |
| 181 | + out << " ["; |
| 182 | + for (size_t i = 0; i < num_au; i++) { |
| 183 | + if (i != 0) out << ","; |
| 184 | + out << maybe_K(au_array[i]); |
| 185 | + } |
| 186 | + out << "]"; |
| 187 | + } |
| 188 | + } |
| 189 | + } |
| 190 | + if (bblob.has_csum()) { |
| 191 | + if (p.mode & (P::SCHK | P::CHK)) { |
| 192 | + out << " " << Checksummer::get_csum_type_string(bblob.csum_type) << "/" |
| 193 | + << (int)bblob.csum_chunk_order << "/" << bblob.csum_data.length(); |
| 194 | + } |
| 195 | + if (p.mode & P::CHK) { |
| 196 | + std::vector<uint64_t> v; |
| 197 | + unsigned n = bblob.get_csum_count(); |
| 198 | + for (unsigned i = 0; i < n; ++i) |
| 199 | + v.push_back(bblob.get_csum_item(i)); |
| 200 | + out << " " << std::hex << v << std::dec; |
| 201 | + } |
| 202 | + } |
| 203 | + if (!(p.mode & P::JUSTID) && p.blob.is_spanning()) { |
| 204 | + out << " spanning.id=" << p.blob.id; |
| 205 | + } |
| 206 | + if (!(p.mode & P::JUSTID) && |
| 207 | + p.blob.shared_blob && |
| 208 | + (p.blob.shared_blob->get_sbid() != 0)) { |
| 209 | + out << " " << *p.blob.shared_blob; |
| 210 | + } |
| 211 | + out << ")"; |
| 212 | + return out; |
| 213 | +} |
| 214 | + |
| 215 | +std::ostream& operator<<(std::ostream& out, const BlueStore::Extent::printer &p) |
| 216 | +{ |
| 217 | + out << std::hex << "0x" << p.ext.logical_offset << "~" << p.ext.length |
| 218 | + << ": 0x" << p.ext.blob_offset << "~" << p.ext.length << std::dec |
| 219 | + << " " << p.ext.blob->print(p.mode); |
| 220 | + return out; |
| 221 | +} |
| 222 | + |
| 223 | +std::ostream& operator<<(std::ostream& out, const BlueStore::Onode::printer &p) |
| 224 | +{ |
| 225 | + using P = BlueStore::printer; |
| 226 | + const BlueStore::Onode& o = p.onode; |
| 227 | + uint16_t mode = p.mode; |
| 228 | + out << &o << " " << o.oid |
| 229 | + << " nid " << o.onode.nid |
| 230 | + << " size 0x" << std::hex << o.onode.size |
| 231 | + << " (" << std::dec << o.onode.size << ")" |
| 232 | + << " expected_object_size " << o.onode.expected_object_size |
| 233 | + << " expected_write_size " << o.onode.expected_write_size |
| 234 | + << " in " << o.onode.extent_map_shards.size() << " shards" |
| 235 | + << ", " << o.extent_map.spanning_blob_map.size() |
| 236 | + << " spanning blobs"; |
| 237 | + const BlueStore::ExtentMap& map = o.extent_map; |
| 238 | + std::set<BlueStore::Blob*> visited; |
| 239 | + // to make printing extents in-sync with blobs |
| 240 | + uint16_t mode_extent = (mode & (P::PTR | P::NICK)) | P::JUSTID; |
| 241 | + auto i = map.seek_lextent(p.from); |
| 242 | + while (i != map.extent_map.end() && i->logical_offset < p.end) { |
| 243 | + BlueStore::Blob* b = i->blob.get(); |
| 244 | + out << std::endl << i->print(mode_extent); |
| 245 | + if (!visited.contains(b)) { |
| 246 | + visited.insert(b); |
| 247 | + } |
| 248 | + ++i; |
| 249 | + } |
| 250 | + for (const auto& i : visited) { |
| 251 | + out << std::endl << i->print(mode); |
| 252 | + } |
| 253 | + // here printing Buffers |
| 254 | + if (p.mode & (P::BUF | P::SBUF)) { |
| 255 | + std::lock_guard l(o.c->cache->lock); |
| 256 | + if (p.mode & P::SBUF) { |
| 257 | + // summary buf mode, only print what is mapped what options are, one liner |
| 258 | + out << " bufs("; |
| 259 | + bool space = false; |
| 260 | + for (auto& i : o.bc.buffer_map) { |
| 261 | + if (space) out << " "; |
| 262 | + out << "0x" << std::hex << i.offset << "~" << i.length << std::dec |
| 263 | + << BlueStore::Buffer::get_state_name_short(i.state); |
| 264 | + if (i.flags) { |
| 265 | + out << "," << BlueStore::Buffer::get_flag_name(i.flags); |
| 266 | + } |
| 267 | + space = true; |
| 268 | + } |
| 269 | + out << ")"; |
| 270 | + } else { |
| 271 | + for (auto& i : o.bc.buffer_map) { |
| 272 | + out << std::endl << " 0x" << std::hex << i.offset |
| 273 | + << "~" << i.length << std::dec |
| 274 | + << " " << i; |
| 275 | + } |
| 276 | + } |
| 277 | + } |
| 278 | + if (mode & P::ATTRS) { |
| 279 | + for (const auto& p : o.onode.attrs) { |
| 280 | + out << std::endl << "attr " << p.first << " len " << p.second.length(); |
| 281 | + } |
| 282 | + } |
| 283 | + return out; |
| 284 | +} |
0 commit comments