]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/rados: add a parameter "-i infile" to `setomapval` command 36051/head
authorsongweibin <song.weibin@zte.com.cn>
Sat, 11 Jul 2020 07:48:34 +0000 (15:48 +0800)
committersongweibin <song.weibin@zte.com.cn>
Mon, 13 Jul 2020 13:58:23 +0000 (21:58 +0800)
Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/tools/rados/rados.cc

index 9af05cfdf6d5b8cb41afd808f3551065aad48aad..0f9437a2694c6c57284b246701aaa37464a1b7ba 100644 (file)
@@ -115,7 +115,7 @@ void usage(ostream& out)
 "   listomapvals <obj-name>          list the keys and vals in the object map \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"
+"   setomapval <obj-name> <key> <val | --input-file file>\n"
 "   rmomapkey <obj-name> <key>\n"
 "   clearomap <obj-name> [obj-name2 obj-name3...] clear all the omap keys for the specified objects\n"
 "   getomapheader <obj-name> [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 <val>\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();