tools/rados: support for high precision time using stat2

This commit introduces `stat2` option for the rados cli, which is
similar to `stat` except that it returns the mtime in high precision,
which is useful for inspecting objects for example if the application
had used the related librados api calls (like radosgw using `mtime2`)

Fixes: http://tracker.ceph.com/issues/21199
Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
This commit is contained in:
Abhishek Lekshmanan 2017-08-31 12:56:48 +02:00
parent 270f1edaae
commit 1e67308679

View File

@ -94,6 +94,7 @@ void usage(ostream& out)
" setxattr <obj-name> attr val\n"
" rmxattr <obj-name> attr\n"
" stat <obj-name> stat the named object\n"
" stat2 <obj-name> stat2 the named object (with high precision time)\n"
" mapext <obj-name>\n"
" rollback <obj-name> <snap-name> roll back object to snap <snap-name>\n"
"\n"
@ -2253,6 +2254,27 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
<< " mtime " << t << ", size " << size << std::endl;
}
}
else if (strcmp(nargs[0], "stat2") == 0) {
if (!pool_name || nargs.size() < 2)
usage_exit();
string oid(nargs[1]);
uint64_t size;
struct timespec mtime;
if (use_striper) {
ret = striper.stat2(oid, &size, &mtime);
} else {
ret = io_ctx.stat2(oid, &size, &mtime);
}
if (ret < 0) {
cerr << " error stat-ing " << pool_name << "/" << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
} else {
utime_t t(mtime);
cout << pool_name << "/" << oid
<< " mtime " << t << ", size " << size << std::endl;
}
}
else if (strcmp(nargs[0], "get") == 0) {
if (!pool_name || nargs.size() < 3)
usage_exit();