Skip to content

Commit 228fbaa

Browse files
authored
Merge pull request ceph#55334 from trociny/wip-rados-setomapheader
tools/rados: allow to read setomapheader value from file Reviewed-by: Igor Fedotov <[email protected]>
2 parents e6ebaf1 + 8e61af9 commit 228fbaa

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/tools/rados/rados.cc

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ void usage(ostream& out)
136136
" getomapval <obj-name> <key> [file] show the value for the specified key\n"
137137
" in the object's object map\n"
138138
" setomapval <obj-name> <key> <val | --input-file file>\n"
139-
" rmomapkey <obj-name> <key> Remove key from the object map of <obj-name>\n"
139+
" rmomapkey <obj-name> <key> remove key from the object map of <obj-name>\n"
140140
" clearomap <obj-name> [obj-name2 obj-name3...] clear all the omap keys for the specified objects\n"
141-
" getomapheader <obj-name> [file] Dump the hexadecimal value of the object map header of <obj-name>\n"
142-
" setomapheader <obj-name> <val> Set the value of the object map header of <obj-name>\n"
141+
" getomapheader <obj-name> [file] dump the hexadecimal value of the object map header of <obj-name>\n"
142+
" setomapheader <obj-name> <val | --input-file file>\n"
143+
" set the value of the object map header of <obj-name>\n"
143144
" watch <obj-name> add watcher on this object\n"
144145
" notify <obj-name> <message> notify watcher of this object with message\n"
145146
" listwatchers <obj-name> list the watchers of this object\n"
@@ -2844,17 +2845,33 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
28442845
ret = 0;
28452846
}
28462847
} else if (strcmp(nargs[0], "setomapheader") == 0) {
2847-
if (!pool_name || nargs.size() < (obj_name ? 2 : 3)) {
2848+
uint32_t min_args = 3;
2849+
if (obj_name) {
2850+
min_args--;
2851+
}
2852+
if (!input_file.empty()) {
2853+
min_args--;
2854+
}
2855+
2856+
if (!pool_name || nargs.size() < min_args) {
28482857
usage(cerr);
28492858
return 1;
28502859
}
28512860

2852-
bufferlist bl;
28532861
if (!obj_name) {
28542862
obj_name = nargs[1];
2855-
bl.append(nargs[2]); // val
2863+
}
2864+
2865+
bufferlist bl;
2866+
if (!input_file.empty()) {
2867+
string err;
2868+
ret = bl.read_file(input_file.c_str(), &err);
2869+
if (ret < 0) {
2870+
cerr << "error reading file " << input_file.c_str() << ": " << err << std::endl;
2871+
return 1;
2872+
}
28562873
} else {
2857-
bl.append(nargs[1]); // val
2874+
bl.append(nargs[min_args - 1]); // val
28582875
}
28592876
ret = io_ctx.omap_set_header(*obj_name, bl);
28602877
if (ret < 0) {

0 commit comments

Comments
 (0)