]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: improve watch command output
authorSage Weil <sage@redhat.com>
Fri, 17 Oct 2014 03:12:22 +0000 (20:12 -0700)
committerSage Weil <sage@redhat.com>
Thu, 4 Dec 2014 18:32:38 +0000 (10:32 -0800)
- hexdump the notify payload, and include all of the new metadata
- print error events too

Signed-off-by: Sage Weil <sage@redhat.com>
src/tools/rados/rados.cc

index eb3ce55de98ad5f8f7c80cc78be027b62a00e3ac..449df682b3affda0461d82708c438ce92603c2bd 100644 (file)
@@ -486,20 +486,30 @@ static int do_put(IoCtx& io_ctx, const char *objname, const char *infile, int op
   return ret;
 }
 
-class RadosWatchCtx : public librados::WatchCtx {
+class RadosWatchCtx : public librados::WatchCtx2 {
+  IoCtx& ioctx;
   string name;
 public:
-  RadosWatchCtx(const char *imgname) : name(imgname) {}
+  RadosWatchCtx(IoCtx& io, const char *imgname) : ioctx(io), name(imgname) {}
   virtual ~RadosWatchCtx() {}
-  virtual void notify(uint8_t opcode, uint64_t ver, bufferlist& bl) {
-    string s;
-    try {
-      bufferlist::iterator iter = bl.begin();
-      ::decode(s, iter);
-    } catch (buffer::error *err) {
-      cout << "could not decode bufferlist, buffer length=" << bl.length() << std::endl;
-    }
-    cout << name << " got notification opcode=" << (int)opcode << " ver=" << ver << " msg='" << s << "'" << std::endl;
+  void handle_notify(uint64_t notify_id,
+                    uint64_t cookie,
+                    uint64_t notifier_id,
+                    bufferlist& bl) {
+    cout << "NOTIFY"
+        << " cookie " << cookie
+        << " notify_id " << notify_id
+        << " from " << notifier_id
+        << std::endl;
+    bl.hexdump(cout);
+    bufferlist empty;
+    ioctx.notify_ack(name, notify_id, cookie, empty);
+  }
+  void handle_error(uint64_t cookie, int err) {
+    cout << "ERROR"
+        << " cookie " << cookie
+        << " err " << cpp_strerror(err)
+        << std::endl;
   }
 };
 
@@ -2345,9 +2355,9 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
     if (!pool_name || nargs.size() < 2)
       usage_exit();
     string oid(nargs[1]);
-    RadosWatchCtx ctx(oid.c_str());
+    RadosWatchCtx ctx(io_ctx, oid.c_str());
     uint64_t cookie;
-    ret = io_ctx.watch(oid, 0, &cookie, &ctx);
+    ret = io_ctx.watch2(oid, &cookie, &ctx);
     if (ret != 0)
       cerr << "error calling watch: " << ret << std::endl;
     else {