diff --git a/doc/man/8/ceph-kvstore-tool.rst b/doc/man/8/ceph-kvstore-tool.rst index 7ef0ab3e2b9f1..d7b88f08aac7c 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 0d6041a44bfd2..d27fddc08446b 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 c66853a73abf6..cfb4304391403 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" @@ -336,6 +346,10 @@ int main(int argc, const char *argv[]) CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); common_init_finish(g_ceph_context); + ceph_assert((int)args.size() < argc); + for(size_t i=0; i 4) + prefix = url_unescape(argv[4]); + st.list(prefix, false, true); } else if (cmd == "exists") { string key; @@ -576,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") {