From: shun-s Date: Fri, 23 Feb 2018 01:38:44 +0000 (+0800) Subject: rbd: output notifyOp request name when watching X-Git-Tag: v13.0.2~170^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=db58878d9da9f57c8ec358822e1f55edb7b8a918;p=ceph.git rbd: output notifyOp request name when watching output notifyOp request name when watching, which is more easier to dentify what happend. Signed-off-by: shun-s --- diff --git a/src/librbd/WatchNotifyTypes.cc b/src/librbd/WatchNotifyTypes.cc index 31f4c5fcc3b..a91e459f4cc 100644 --- a/src/librbd/WatchNotifyTypes.cc +++ b/src/librbd/WatchNotifyTypes.cc @@ -21,6 +21,14 @@ public: } }; +class GetNotifyOpVisitor : public boost::static_visitor { +public: + template + NotifyOp operator()(const Payload &payload) const { + return Payload::NOTIFY_OP; + } +}; + class DumpPayloadVisitor : public boost::static_visitor { 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 &o) { o.push_back(new NotifyMessage(AcquiredLockPayload(ClientId(1, 2)))); o.push_back(new NotifyMessage(ReleasedLockPayload(ClientId(1, 2)))); diff --git a/src/librbd/WatchNotifyTypes.h b/src/librbd/WatchNotifyTypes.h index 295b5e72ab7..c4bbebdfd75 100644 --- a/src/librbd/WatchNotifyTypes.h +++ b/src/librbd/WatchNotifyTypes.h @@ -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 &o); }; diff --git a/src/tools/rbd/action/Watch.cc b/src/tools/rbd/action/Watch.cc index f68e280fe05..15710d7735a 100644 --- a/src/tools/rbd/action/Watch.cc +++ b/src/tools/rbd/action/Watch.cc @@ -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 #include @@ -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); }