From: Yang Honggang Date: Mon, 30 Oct 2017 03:10:00 +0000 (-0400) Subject: os/bluestore/bluestore_tool: add bluefs-log-dump command to dump bluefs's log X-Git-Tag: v13.0.1~359^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F18535%2Fhead;p=ceph.git os/bluestore/bluestore_tool: add bluefs-log-dump command to dump bluefs's log ./bin/ceph-bluestore-tool --command bluefs-log-dump --path dev/osd0/ ... 0x1000: txn(seq 2 len 0xd7 crc 0x306e389b) 0x1000: op_dir_create db 0x1000: op_dir_create db.wal 0x1000: op_dir_create db.slow 0x1000: op_file_update file Signed-off-by: Yang Honggang --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 2550e3e941b..95d23521271 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -403,7 +403,7 @@ int BlueFS::mount() block_all.resize(MAX_BDEV); _init_alloc(); - r = _replay(false); + r = _replay(false, false); if (r < 0) { derr << __func__ << " failed to replay log: " << cpp_strerror(r) << dendl; _stop_alloc(); @@ -523,7 +523,7 @@ int BlueFS::_open_super() return 0; } -int BlueFS::_replay(bool noop) +int BlueFS::_replay(bool noop, bool to_stdout) { dout(10) << __func__ << (noop ? " NO-OP" : "") << dendl; ino_last = 1; // by the log @@ -537,6 +537,9 @@ int BlueFS::_replay(bool noop) } log_file->fnode = super.log_fnode; dout(10) << __func__ << " log_fnode " << super.log_fnode << dendl; + if (unlikely(to_stdout)) { + std::cout << " log_fnode " << super.log_fnode << std::endl; + } FileReader *log_reader = new FileReader( log_file, cct->_conf->bluefs_max_prefetch, @@ -611,6 +614,10 @@ int BlueFS::_replay(bool noop) assert(seq == t.seq); dout(10) << __func__ << " 0x" << std::hex << pos << std::dec << ": " << t << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": " << t << std::endl; + } bufferlist::iterator p = t.op_bl.begin(); while (!p.end()) { @@ -621,6 +628,11 @@ int BlueFS::_replay(bool noop) case bluefs_transaction_t::OP_INIT: dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_init" << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_init" << std::endl; + } + assert(t.seq == 1); break; @@ -633,6 +645,13 @@ int BlueFS::_replay(bool noop) dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_jump seq " << next_seq << " offset 0x" << std::hex << offset << std::dec << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_jump seq " << next_seq + << " offset 0x" << std::hex << offset << std::dec + << std::endl; + } + assert(next_seq >= log_seq); log_seq = next_seq - 1; // we will increment it below uint64_t skip = offset - read_pos; @@ -656,6 +675,11 @@ int BlueFS::_replay(bool noop) ::decode(next_seq, p); dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_jump_seq " << next_seq << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_jump_seq " << next_seq << std::endl; + } + assert(next_seq >= log_seq); log_seq = next_seq - 1; // we will increment it below } @@ -672,6 +696,13 @@ int BlueFS::_replay(bool noop) << ": op_alloc_add " << " " << (int)id << ":0x" << std::hex << offset << "~" << length << std::dec << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_alloc_add " << " " << (int)id + << ":0x" << std::hex << offset << "~" << length << std::dec + << std::endl; + } + if (!noop) { block_all[id].insert(offset, length); alloc[id]->init_add_free(offset, length); @@ -690,6 +721,13 @@ int BlueFS::_replay(bool noop) << ": op_alloc_rm " << " " << (int)id << ":0x" << std::hex << offset << "~" << length << std::dec << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_alloc_rm " << " " << (int)id + << ":0x" << std::hex << offset << "~" << length << std::dec + << std::endl; + } + if (!noop) { block_all[id].erase(offset, length); alloc[id]->init_rm_free(offset, length); @@ -708,6 +746,13 @@ int BlueFS::_replay(bool noop) << ": op_dir_link " << " " << dirname << "/" << filename << " to " << ino << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_dir_link " << " " << dirname << "/" << filename + << " to " << ino + << std::endl; + } + if (!noop) { FileRef file = _get_file(ino); assert(file->fnode.ino); @@ -729,6 +774,12 @@ int BlueFS::_replay(bool noop) dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_dir_unlink " << " " << dirname << "/" << filename << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_dir_unlink " << " " << dirname << "/" << filename + << std::endl; + } + if (!noop) { map::iterator q = dir_map.find(dirname); assert(q != dir_map.end()); @@ -747,6 +798,11 @@ int BlueFS::_replay(bool noop) ::decode(dirname, p); dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_dir_create " << dirname << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_dir_create " << dirname << std::endl; + } + if (!noop) { map::iterator q = dir_map.find(dirname); assert(q == dir_map.end()); @@ -761,6 +817,11 @@ int BlueFS::_replay(bool noop) ::decode(dirname, p); dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_dir_remove " << dirname << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_dir_remove " << dirname << std::endl; + } + if (!noop) { map::iterator q = dir_map.find(dirname); assert(q != dir_map.end()); @@ -776,6 +837,11 @@ int BlueFS::_replay(bool noop) ::decode(fnode, p); dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_file_update " << " " << fnode << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_file_update " << " " << fnode << std::endl; + } + if (!noop) { FileRef f = _get_file(fnode.ino); f->fnode = fnode; @@ -792,6 +858,11 @@ int BlueFS::_replay(bool noop) ::decode(ino, p); dout(20) << __func__ << " 0x" << std::hex << pos << std::dec << ": op_file_remove " << ino << dendl; + if (unlikely(to_stdout)) { + std::cout << " 0x" << std::hex << pos << std::dec + << ": op_file_remove " << ino << std::endl; + } + if (!noop) { auto p = file_map.find(ino); assert(p != file_map.end()); @@ -816,6 +887,11 @@ int BlueFS::_replay(bool noop) dout(10) << __func__ << " log file size was 0x" << std::hex << log_file->fnode.size << std::dec << dendl; + if (unlikely(to_stdout)) { + std::cout << " log file size was 0x" + << std::hex << log_file->fnode.size << std::dec << std::endl; + } + delete log_reader; if (!noop) { @@ -834,6 +910,27 @@ int BlueFS::_replay(bool noop) return 0; } +int BlueFS::log_dump( + CephContext *cct, + const string& path, + const vector& devs) +{ + int r = _open_super(); + if (r < 0) { + derr << __func__ << " failed to open super: " << cpp_strerror(r) << dendl; + return r; + } + + // only dump log file's content + r = _replay(true, true); + if (r < 0) { + derr << __func__ << " failed to replay log: " << cpp_strerror(r) << dendl; + return r; + } + + return 0; +} + BlueFS::FileRef BlueFS::_get_file(uint64_t ino) { auto p = file_map.find(ino); diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 72a12eac0fe..fc864353141 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -309,7 +309,7 @@ private: int _open_super(); int _write_super(); - int _replay(bool noop); ///< replay journal + int _replay(bool noop, bool to_stdout = false); ///< replay journal FileWriter *_create_writer(FileRef f); void _close_writer(FileWriter *h); @@ -331,6 +331,11 @@ public: int mkfs(uuid_d osd_uuid); int mount(); void umount(); + + int log_dump( + CephContext *cct, + const string& path, + const vector& devs); void collect_metadata(map *pm); int fsck(); diff --git a/src/os/bluestore/bluestore_tool.cc b/src/os/bluestore/bluestore_tool.cc index 728ad4f60a3..c1770405e22 100644 --- a/src/os/bluestore/bluestore_tool.cc +++ b/src/os/bluestore/bluestore_tool.cc @@ -66,14 +66,11 @@ void validate_path(CephContext *cct, const string& path, bool bluefs) } } -BlueFS *open_bluefs( +void add_devices( + BlueFS *fs, CephContext *cct, - const string& path, const vector& devs) { - validate_path(cct, path, true); - BlueFS *fs = new BlueFS(cct); - string main; set got; for (auto& i : devs) { @@ -113,6 +110,37 @@ BlueFS *open_bluefs( exit(EXIT_FAILURE); } } +} + +void log_dump( + CephContext *cct, + const string& path, + const vector& devs) +{ + validate_path(cct, path, true); + BlueFS *fs = new BlueFS(cct); + + add_devices(fs, cct, devs); + + int r = fs->log_dump(cct, path, devs); + if (r < 0) { + cerr << "log_dump failed" << ": " + << cpp_strerror(r) << std::endl; + exit(EXIT_FAILURE); + } + + delete fs; +} + +BlueFS *open_bluefs( + CephContext *cct, + const string& path, + const vector& devs) +{ + validate_path(cct, path, true); + BlueFS *fs = new BlueFS(cct); + + add_devices(fs, cct, devs); int r = fs->mount(); if (r < 0) { @@ -147,7 +175,7 @@ int main(int argc, char **argv) ; po::options_description po_positional("Positional options"); po_positional.add_options() - ("command", po::value(&action), "fsck, repair, bluefs-export, bluefs-bdev-sizes, bluefs-bdev-expand, show-label, set-label-key, rm-label-key, prime-osd-dir") + ("command", po::value(&action), "fsck, repair, bluefs-export, bluefs-bdev-sizes, bluefs-bdev-expand, show-label, set-label-key, rm-label-key, prime-osd-dir, bluefs-log-dump") ; po::options_description po_all("All options"); po_all.add(po_options).add(po_positional); @@ -224,12 +252,12 @@ int main(int argc, char **argv) } } } - if (action == "bluefs-export") { + if (action == "bluefs-export" || action == "bluefs-log-dump") { if (path.empty()) { cerr << "must specify bluestore path" << std::endl; exit(EXIT_FAILURE); } - if (out_dir.empty()) { + if ((action == "bluefs-export") && out_dir.empty()) { cerr << "must specify out-dir to export bluefs" << std::endl; exit(EXIT_FAILURE); } @@ -525,6 +553,8 @@ int main(int argc, char **argv) } fs->umount(); delete fs; + } else if (action == "bluefs-log-dump") { + log_dump(cct.get(), path, devs); } else { cerr << "unrecognized action " << action << std::endl; return 1;