From 505c0be011e06208531cb7c0c69d05161eaf3330 Mon Sep 17 00:00:00 2001 From: songweibin Date: Sat, 11 Jul 2020 15:48:34 +0800 Subject: [PATCH] tools/rados: add a parameter "-i infile" to `setomapval` command Signed-off-by: songweibin --- src/tools/rados/rados.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 9af05cfdf6d..0f9437a2694 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -115,7 +115,7 @@ void usage(ostream& out) " listomapvals list the keys and vals in the object map \n" " getomapval [file] show the value for the specified key\n" " in the object's object map\n" -" setomapval \n" +" setomapval \n" " rmomapkey \n" " clearomap [obj-name2 obj-name3...] clear all the omap keys for the specified objects\n" " getomapheader [file]\n" @@ -189,6 +189,8 @@ void usage(ostream& out) " -s name\n" " --snap name\n" " select given snap name for (read) IO\n" +" --input-file file\n" +" use the content of the specified file in place of \n" " --create\n" " create the pool or directory that was specified\n" " -N namespace\n" @@ -1883,6 +1885,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, bool omap_key_valid = false; std::string omap_key; std::string omap_key_pretty; + std::string input_file; bool with_reference = false; Rados rados; @@ -2113,6 +2116,10 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, if (i != opts.end()) { with_reference = true; } + i = opts.find("input_file"); + if (i != opts.end()) { + input_file = i->second; + } // open rados ret = rados.init_with_context(g_ceph_context); @@ -2760,7 +2767,14 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, } bufferlist bl; - if (nargs.size() > min_args) { + if (!input_file.empty()) { + string err; + ret = bl.read_file(input_file.c_str(), &err); + if (ret < 0) { + cerr << "error reading file " << input_file.c_str() << ": " << err << std::endl; + return 1; + } + } else if (nargs.size() > min_args) { string val(nargs[min_args]); bl.append(val); } else { @@ -4047,6 +4061,8 @@ int main(int argc, const char **argv) opts["with-reference"] = "true"; } else if (ceph_argparse_witharg(args, i, &val, "--pgid", (char*)NULL)) { opts["pgid"] = val; + } else if (ceph_argparse_witharg(args, i, &val, "--input-file", (char*)NULL)) { + opts["input_file"] = val; } else { if (val[0] == '-') usage_exit(); -- 2.39.5