From b2a8751bf31b5dc403dbff3a0f321840553d1d01 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Mon, 26 Nov 2018 16:27:28 +0100 Subject: [PATCH] bluestore/tools: Add option 'dump' to ceph-kvstore-tool to print both key and values. Signed-off-by: Adam Kupczyk --- doc/man/8/ceph-kvstore-tool.rst | 3 +++ src/test/cli/ceph-kvstore-tool/help.t | 1 + src/tools/ceph_kvstore_tool.cc | 23 +++++++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/man/8/ceph-kvstore-tool.rst b/doc/man/8/ceph-kvstore-tool.rst index 7ef0ab3e2b9..d7b88f08aac 100644 --- a/doc/man/8/ceph-kvstore-tool.rst +++ b/doc/man/8/ceph-kvstore-tool.rst @@ -30,6 +30,9 @@ which are as follows: :command:`list-crc [prefix]` Print CRC of all KV pairs stored with the URL encoded prefix. +:command:`dump [prefix]` + Print key and value of all KV pairs stored with the URL encoded prefix. + :command:`exists [key]` Check if there is any KV pair stored with the URL encoded prefix. If key is also specified, check for the key with the prefix instead. diff --git a/src/test/cli/ceph-kvstore-tool/help.t b/src/test/cli/ceph-kvstore-tool/help.t index 0d6041a44bf..d27fddc0844 100644 --- a/src/test/cli/ceph-kvstore-tool/help.t +++ b/src/test/cli/ceph-kvstore-tool/help.t @@ -4,6 +4,7 @@ Commands: list [prefix] list-crc [prefix] + dump [prefix] exists [key] get [out ] crc diff --git a/src/tools/ceph_kvstore_tool.cc b/src/tools/ceph_kvstore_tool.cc index 4f73b1ea8e8..bf446cd233a 100644 --- a/src/tools/ceph_kvstore_tool.cc +++ b/src/tools/ceph_kvstore_tool.cc @@ -89,6 +89,7 @@ class StoreTool uint32_t traverse(const string &prefix, const bool do_crc, + const bool do_value_dump, ostream *out) { KeyValueDB::WholeSpaceIterator iter = db->get_wholespace_iterator(); @@ -119,14 +120,22 @@ class StoreTool } if (out) *out << std::endl; + if (out && do_value_dump) { + bufferptr bp = iter->value_as_ptr(); + bufferlist value; + value.append(bp); + ostringstream os; + value.hexdump(os); + std::cout << os.str() << std::endl; + } iter->next(); } return crc; } - void list(const string &prefix, const bool do_crc) { - traverse(prefix, do_crc, &std::cout); + void list(const string &prefix, const bool do_crc, const bool do_value_dump) { + traverse(prefix, do_crc, do_value_dump, &std::cout); } bool exists(const string &prefix) { @@ -297,6 +306,7 @@ void usage(const char *pname) << "Commands:\n" << " list [prefix]\n" << " list-crc [prefix]\n" + << " dump [prefix]\n" << " exists [key]\n" << " get [out ]\n" << " crc \n" @@ -378,8 +388,13 @@ int main(int argc, const char *argv[]) prefix = url_unescape(argv[4]); bool do_crc = (cmd == "list-crc"); + st.list(prefix, do_crc, false); - st.list(prefix, do_crc); + } else if (cmd == "dump") { + string prefix; + if (argc > 4) + prefix = url_unescape(argv[4]); + st.list(prefix, false, true); } else if (cmd == "exists") { string key; @@ -580,7 +595,7 @@ int main(int argc, const char *argv[]) return 1; } std::ofstream fs(argv[4]); - uint32_t crc = st.traverse(string(), true, &fs); + uint32_t crc = st.traverse(string(), true, false, &fs); std::cout << "store at '" << argv[4] << "' crc " << crc << std::endl; } else if (cmd == "compact") { -- 2.39.5