From 1e673086795b4318636525ecea9720febe008d6a Mon Sep 17 00:00:00 2001 From: Abhishek Lekshmanan Date: Thu, 31 Aug 2017 12:56:48 +0200 Subject: [PATCH] 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 --- src/tools/rados/rados.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 156647c307717..7877b7b485836 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -94,6 +94,7 @@ void usage(ostream& out) " setxattr attr val\n" " rmxattr attr\n" " stat stat the named object\n" +" stat2 stat2 the named object (with high precision time)\n" " mapext \n" " rollback roll back object to snap \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(); -- 2.39.5