]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/rados: support for high precision time using stat2
authorAbhishek Lekshmanan <abhishek@suse.com>
Thu, 31 Aug 2017 10:56:48 +0000 (12:56 +0200)
committerAbhishek Lekshmanan <abhishek@suse.com>
Thu, 31 Aug 2017 12:12:39 +0000 (14:12 +0200)
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>
src/tools/rados/rados.cc

index 156647c30771731c93ebe5b8035ec6473dfa617e..7877b7b48583640b860b699e8f11cbb1d9d9ae60 100644 (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();