--- /dev/null
+#!/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
" rmomapkey <obj-name> <key>\n"
" getomapheader <obj-name>\n"
" setomapheader <obj-name> <val>\n"
+" tmap-to-omap <obj-name> convert tmap keys/values to omap\n"
" listwatchers <obj-name> list the watchers of this object\n"
"\n"
"IMPORT AND EXPORT\n"
}
}
+ 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<string, bufferlist> 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;