From 84c028674a77fcc09a367c6ae399e205cfeb7493 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 1 Oct 2013 17:19:24 -0700 Subject: [PATCH] rados: add 'tmap-to-omap' command Explicitly convert tmap object data to omap keys. Removes the old tmap content at the same time. Signed-off-by: Sage Weil --- qa/workunits/rados/test_tmap_to_omap.sh | 28 +++++++++++++++ src/tools/rados/rados.cc | 45 +++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 qa/workunits/rados/test_tmap_to_omap.sh diff --git a/qa/workunits/rados/test_tmap_to_omap.sh b/qa/workunits/rados/test_tmap_to_omap.sh new file mode 100755 index 000000000000..76656ad726ba --- /dev/null +++ b/qa/workunits/rados/test_tmap_to_omap.sh @@ -0,0 +1,28 @@ +#!/bin/sh -ex + +expect_false() +{ + set -x + if "$@"; then return 1; else return 0; fi +} + +pool="pool-$$" +rados mkpool $pool + +rados -p $pool tmap set foo key1 value1 +rados -p $pool tmap set foo key2 value2 +rados -p $pool tmap set foo key2 value2 +rados -p $pool tmap dump foo | grep key1 +rados -p $pool tmap dump foo | grep key2 +rados -p $pool tmap-to-omap foo +expect_false rados -p $pool tmap dump foo +expect_false rados -p $pool tmap dump foo + +rados -p $pool listomapkeys foo | grep key1 +rados -p $pool listomapkeys foo | grep key2 +rados -p $pool getomapval foo key1 | grep value1 +rados -p $pool getomapval foo key2 | grep value2 + +rados rmpool $pool $pool --yes-i-really-really-mean-it + +echo OK diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 009df5cd0af5..ad8eaa3e1a4a 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -98,6 +98,7 @@ void usage(ostream& out) " rmomapkey \n" " getomapheader \n" " setomapheader \n" +" tmap-to-omap convert tmap keys/values to omap\n" " listwatchers list the watchers of this object\n" "\n" "IMPORT AND EXPORT\n" @@ -1848,6 +1849,50 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, } } + else if (strcmp(nargs[0], "tmap-to-omap") == 0) { + if (!pool_name || nargs.size() < 2) + usage_exit(); + string oid(nargs[1]); + + bufferlist bl; + int r = io_ctx.tmap_get(oid, bl); + if (r < 0) { + ret = r; + cerr << "error reading tmap " << pool_name << "/" << oid + << ": " << cpp_strerror(ret) << std::endl; + goto out; + } + bufferlist hdr; + map kv; + bufferlist::iterator p = bl.begin(); + try { + ::decode(hdr, p); + ::decode(kv, p); + } + catch (buffer::error& e) { + cerr << "error decoding tmap " << pool_name << "/" << oid << std::endl; + ret = -EINVAL; + goto out; + } + if (!p.end()) { + cerr << "error decoding tmap (stray trailing data) in " << pool_name << "/" << oid << std::endl; + ret = -EINVAL; + goto out; + } + librados::ObjectWriteOperation wr; + wr.omap_set_header(hdr); + wr.omap_set(kv); + wr.truncate(0); // delete the old tmap data + r = io_ctx.operate(oid, &wr); + if (r < 0) { + ret = r; + cerr << "error writing tmap data as omap on " << pool_name << "/" << oid + << ": " << cpp_strerror(ret) << std::endl; + goto out; + } + ret = 0; + } + else if (strcmp(nargs[0], "mkpool") == 0) { int auid = 0; __u8 crush_rule = 0; -- 2.47.3