]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: output notifyOp request name when watching 20551/head
authorshun-s <song.shun3@zte.com.cn>
Fri, 23 Feb 2018 01:38:44 +0000 (09:38 +0800)
committershun-s <song.shun3@zte.com.cn>
Sat, 24 Feb 2018 00:33:06 +0000 (08:33 +0800)
  output notifyOp request name when watching,
  which is more easier to dentify what happend.

Signed-off-by: shun-s <song.shun3@zte.com.cn>
src/librbd/WatchNotifyTypes.cc
src/librbd/WatchNotifyTypes.h
src/tools/rbd/action/Watch.cc

index 31f4c5fcc3b80528035d17fea000dca23efb72ce..a91e459f4cce1f704e17f27fe78d07415062893d 100644 (file)
@@ -21,6 +21,14 @@ public:
   }
 };
 
+class GetNotifyOpVisitor  : public boost::static_visitor<NotifyOp> {
+public:
+  template <typename Payload>
+  NotifyOp operator()(const Payload &payload) const {
+    return Payload::NOTIFY_OP;
+  }
+};
+
 class DumpPayloadVisitor : public boost::static_visitor<void> {
 public:
   explicit DumpPayloadVisitor(Formatter *formatter) : m_formatter(formatter) {}
@@ -373,6 +381,10 @@ void NotifyMessage::dump(Formatter *f) const {
   apply_visitor(DumpPayloadVisitor(f), payload);
 }
 
+NotifyOp NotifyMessage::get_notify_op() const {
+  apply_visitor(GetNotifyOpVisitor(), payload);
+}
+
 void NotifyMessage::generate_test_instances(std::list<NotifyMessage *> &o) {
   o.push_back(new NotifyMessage(AcquiredLockPayload(ClientId(1, 2))));
   o.push_back(new NotifyMessage(ReleasedLockPayload(ClientId(1, 2))));
index 295b5e72ab769633303f47e711b8d0c1bfc97eae..c4bbebdfd7563a52ee1b61e954e054899c2db895 100644 (file)
@@ -339,6 +339,7 @@ struct NotifyMessage {
   void encode(bufferlist& bl) const;
   void decode(bufferlist::iterator& it);
   void dump(Formatter *f) const;
+  NotifyOp get_notify_op() const;
 
   static void generate_test_instances(std::list<NotifyMessage *> &o);
 };
index f68e280fe05c5ee6a2463ae7f40d464bc62e2275..15710d7735ae1a58822d0872ea489f5c67150b11 100644 (file)
@@ -5,6 +5,7 @@
 #include "tools/rbd/Shell.h"
 #include "tools/rbd/Utils.h"
 #include "include/rbd_types.h"
+#include "librbd/WatchNotifyTypes.h"
 #include "common/errno.h"
 #include <iostream>
 #include <boost/program_options.hpp>
@@ -30,9 +31,23 @@ public:
                              uint64_t cookie,
                              uint64_t notifier_id,
                              bufferlist& bl) override {
+    using namespace librbd::watch_notify;
+    NotifyMessage notify_message;
+    if (bl.length() == 0) {
+      notify_message = NotifyMessage(HeaderUpdatePayload());
+    } else {
+      try {
+        bufferlist::iterator iter = bl.begin();
+        notify_message.decode(iter);
+      } catch (const buffer::error &err) {
+        std::cerr << "rbd: failed to decode image notification" << std::endl;
+      }
+    }
+   
     std::cout << m_image_name << " received notification: notify_id="
               << notify_id << ", cookie=" << cookie << ", notifier_id="
-              << notifier_id << ", bl.length=" << bl.length() << std::endl;
+              << notifier_id << ", bl.length=" << bl.length() << ", notify_op=" 
+              << notify_message.get_notify_op()  << std::endl;
     bufferlist reply;
     m_io_ctx.notify_ack(m_header_oid, notify_id, cookie, reply);
   }