" load-gen [options] generate load on the cluster\n"
" listomapkeys <obj-name> list the keys in the object map\n"
" listomapvals <obj-name> list the keys and vals in the object map \n"
-" getomapval <obj-name> <key> show the value for the specified key\n"
+" getomapval <obj-name> <key> [file] show the value for the specified key\n"
" in the object's object map\n"
" setomapval <obj-name> <key> <val>\n"
" rmomapkey <obj-name> <key>\n"
-" getomapheader <obj-name>\n"
+" getomapheader <obj-name> [file]\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"
" --snap name\n"
" select given snap name for (read) IO\n"
" -i infile\n"
-" -o outfile\n"
-" specify input or output file (for certain commands)\n"
" --create\n"
" create the pool or directory that was specified\n"
" -N namespace\n"
exit(1);
}
+
+static int dump_data(std::string const &filename, bufferlist const &data)
+{
+ int fd;
+ if (filename == "-") {
+ fd = 1;
+ } else {
+ fd = TEMP_FAILURE_RETRY(::open(filename.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0644));
+ if (fd < 0) {
+ int err = errno;
+ cerr << "failed to open file: " << cpp_strerror(err) << std::endl;
+ return -err;
+ }
+ }
+
+ int r = data.write_fd(fd);
+
+ if (fd != 1) {
+ VOID_TEMP_FAILURE_RETRY(::close(fd));
+ }
+
+ return r;
+}
+
+
static int do_get(IoCtx& io_ctx, const char *objname, const char *outfile, unsigned op_size)
{
string oid(objname);
usage_exit();
string oid(nargs[1]);
+ string outfile;
+ if (nargs.size() >= 3) {
+ outfile = nargs[2];
+ }
bufferlist header;
ret = io_ctx.omap_get_header(oid, &header);
<< ": " << cpp_strerror(ret) << std::endl;
goto out;
} else {
- cout << "header (" << header.length() << " bytes) :\n";
- header.hexdump(cout);
- cout << std::endl;
+ if (!outfile.empty()) {
+ cerr << "Writing to " << outfile << std::endl;
+ dump_data(outfile, header);
+ } else {
+ cout << "header (" << header.length() << " bytes) :\n";
+ header.hexdump(cout);
+ cout << std::endl;
+ }
ret = 0;
}
} else if (strcmp(nargs[0], "setomapheader") == 0) {
set<string> keys;
keys.insert(key);
+ std::string outfile;
+ if (nargs.size() >= 4) {
+ outfile = nargs[3];
+ }
+
map<string, bufferlist> values;
ret = io_ctx.omap_get_vals_by_keys(oid, keys, &values);
if (ret < 0) {
if (values.size() && values.begin()->first == key) {
cout << " (length " << values.begin()->second.length() << ") : ";
- values.begin()->second.hexdump(cout);
- cout << std::endl;
+ if (!outfile.empty()) {
+ cerr << "Writing to " << outfile << std::endl;
+ dump_data(outfile, values.begin()->second);
+ } else {
+ values.begin()->second.hexdump(cout);
+ cout << std::endl;
+ }
+ ret = 0;
} else {
cout << "No such key: " << pool_name << "/" << oid << "/" << key
<< std::endl;