From: Mykola Golub Date: Sat, 27 Jan 2024 09:14:09 +0000 (+0000) Subject: tools/rados: allow to read setomapheader value from file X-Git-Tag: v20.0.0~926^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8e61af9614ebf2a5666e9ff6100502961b381235;p=ceph.git tools/rados: allow to read setomapheader value from file (similarly to setomapval) Signed-off-by: Mykola Golub --- diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index e6c5819666a7..3d24a1b48357 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -133,10 +133,11 @@ void usage(ostream& out) " getomapval [file] show the value for the specified key\n" " in the object's object map\n" " setomapval \n" -" rmomapkey Remove key from the object map of \n" +" rmomapkey remove key from the object map of \n" " clearomap [obj-name2 obj-name3...] clear all the omap keys for the specified objects\n" -" getomapheader [file] Dump the hexadecimal value of the object map header of \n" -" setomapheader Set the value of the object map header of \n" +" getomapheader [file] dump the hexadecimal value of the object map header of \n" +" setomapheader \n" +" set the value of the object map header of \n" " watch add watcher on this object\n" " notify notify watcher of this object with message\n" " listwatchers list the watchers of this object\n" @@ -2820,17 +2821,33 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, ret = 0; } } else if (strcmp(nargs[0], "setomapheader") == 0) { - if (!pool_name || nargs.size() < (obj_name ? 2 : 3)) { + uint32_t min_args = 3; + if (obj_name) { + min_args--; + } + if (!input_file.empty()) { + min_args--; + } + + if (!pool_name || nargs.size() < min_args) { usage(cerr); return 1; } - bufferlist bl; if (!obj_name) { obj_name = nargs[1]; - bl.append(nargs[2]); // val + } + + bufferlist bl; + 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 { - bl.append(nargs[1]); // val + bl.append(nargs[min_args - 1]); // val } ret = io_ctx.omap_set_header(*obj_name, bl); if (ret < 0) {