]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-replay: Support writing Actions to ostreams
authorAdam Crume <adamcrume@gmail.com>
Fri, 18 Jul 2014 20:57:16 +0000 (13:57 -0700)
committerSage Weil <sage@redhat.com>
Thu, 21 Aug 2014 17:57:30 +0000 (10:57 -0700)
Signed-off-by: Adam Crume <adamcrume@gmail.com>
src/rbd_replay/actions.cc
src/rbd_replay/actions.hpp

index 9070c91b1bffdf24b917f3bfa5da598b76621c41..622a6c6bcfd719503478453deb8d32dcad64b30f 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include "actions.hpp"
+#include <boost/foreach.hpp>
 #include <cstdlib>
 #include "PendingIO.hpp"
 #include "rbd_replay_debug.hpp"
@@ -77,6 +78,30 @@ Action::ptr Action::read_from(Deser &d) {
   }
 }
 
+std::ostream& Action::dump_action_fields(std::ostream& o) const {
+  o << "id=" << m_id << ", thread_id=" << m_thread_id << ", predecessors=[";
+  bool first = true;
+  BOOST_FOREACH(const dependency_d &d, m_predecessors) {
+    if (!first) {
+      o << ",";
+    }
+    o << d.id;
+    first = false;
+  }
+  return o << "]";
+}
+
+std::ostream& rbd_replay::operator<<(std::ostream& o, const Action& a) {
+  return a.dump(o);
+}
+
+
+std::ostream& DummyAction::dump(std::ostream& o) const {
+  o << "DummyAction[";
+  dump_action_fields(o);
+  return o << "]";
+}
+
 
 StartThreadAction::StartThreadAction(Action &src)
   : Action(src) {
@@ -95,13 +120,19 @@ Action::ptr StartThreadAction::read_from(Action &src, Deser &d) {
   return Action::ptr(new StartThreadAction(src));
 }
 
+std::ostream& StartThreadAction::dump(std::ostream& o) const {
+  o << "StartThreadAction[";
+  dump_action_fields(o);
+  return o << "]";
+}
+
 
 StopThreadAction::StopThreadAction(Action &src)
   : Action(src) {
 }
 
 void StopThreadAction::perform(ActionCtx &ctx) {
-  dout(ACTION_LEVEL) << "Performing stop thread action #" << id() << dendl;
+  dout(ACTION_LEVEL) << "Performing " << *this << dendl;
   ctx.stop();
 }
 
@@ -109,6 +140,13 @@ Action::ptr StopThreadAction::read_from(Action &src, Deser &d) {
   return Action::ptr(new StopThreadAction(src));
 }
 
+std::ostream& StopThreadAction::dump(std::ostream& o) const {
+  o << "StopThreadAction[";
+  dump_action_fields(o);
+  return o << "]";
+}
+
+
 AioReadAction::AioReadAction(const Action &src,
                              imagectx_id_t imagectx_id,
                              uint64_t offset,
@@ -127,7 +165,7 @@ Action::ptr AioReadAction::read_from(Action &src, Deser &d) {
 }
 
 void AioReadAction::perform(ActionCtx &worker) {
-  dout(ACTION_LEVEL) << "Performing AIO read action #" << id() << dendl;
+  dout(ACTION_LEVEL) << "Performing " << *this << dendl;
   librbd::Image *image = worker.get_image(m_imagectx_id);
   assert(image);
   PendingIO::ptr io(new PendingIO(pending_io_id(), worker));
@@ -135,6 +173,12 @@ void AioReadAction::perform(ActionCtx &worker) {
   image->aio_read(m_offset, m_length, io->bufferlist(), &io->completion());
 }
 
+std::ostream& AioReadAction::dump(std::ostream& o) const {
+  o << "AioReadAction[";
+  dump_action_fields(o);
+  return o << ", imagectx_id=" << m_imagectx_id << ", offset=" << m_offset << ", length=" << m_length << "]";
+}
+
 
 ReadAction::ReadAction(const Action &src,
                        imagectx_id_t imagectx_id,
@@ -154,7 +198,7 @@ Action::ptr ReadAction::read_from(Action &src, Deser &d) {
 }
 
 void ReadAction::perform(ActionCtx &worker) {
-  dout(ACTION_LEVEL) << "Performing read action #" << id() << dendl;
+  dout(ACTION_LEVEL) << "Performing " << *this << dendl;
   librbd::Image *image = worker.get_image(m_imagectx_id);
   PendingIO::ptr io(new PendingIO(pending_io_id(), worker));
   worker.add_pending(io);
@@ -162,6 +206,12 @@ void ReadAction::perform(ActionCtx &worker) {
   worker.remove_pending(io);
 }
 
+std::ostream& ReadAction::dump(std::ostream& o) const {
+  o << "ReadAction[";
+  dump_action_fields(o);
+  return o << ", imagectx_id=" << m_imagectx_id << ", offset=" << m_offset << ", length=" << m_length << "]";
+}
+
 
 AioWriteAction::AioWriteAction(const Action &src,
                                imagectx_id_t imagectx_id,
@@ -181,7 +231,7 @@ Action::ptr AioWriteAction::read_from(Action &src, Deser &d) {
 }
 
 void AioWriteAction::perform(ActionCtx &worker) {
-  dout(ACTION_LEVEL) << "Performing AIO write action #" << id() << dendl;
+  dout(ACTION_LEVEL) << "Performing " << *this << dendl;
   librbd::Image *image = worker.get_image(m_imagectx_id);
   PendingIO::ptr io(new PendingIO(pending_io_id(), worker));
   io->bufferlist().append_zero(m_length);
@@ -189,6 +239,12 @@ void AioWriteAction::perform(ActionCtx &worker) {
   image->aio_write(m_offset, m_length, io->bufferlist(), &io->completion());
 }
 
+std::ostream& AioWriteAction::dump(std::ostream& o) const {
+  o << "AioWriteAction[";
+  dump_action_fields(o);
+  return o << ", imagectx_id=" << m_imagectx_id << ", offset=" << m_offset << ", length=" << m_length << "]";
+}
+
 
 WriteAction::WriteAction(const Action &src,
                          imagectx_id_t imagectx_id,
@@ -208,7 +264,7 @@ Action::ptr WriteAction::read_from(Action &src, Deser &d) {
 }
 
 void WriteAction::perform(ActionCtx &worker) {
-  dout(ACTION_LEVEL) << "Performing write action #" << id() << dendl;
+  dout(ACTION_LEVEL) << "Performing " << *this << dendl;
   librbd::Image *image = worker.get_image(m_imagectx_id);
   PendingIO::ptr io(new PendingIO(pending_io_id(), worker));
   worker.add_pending(io);
@@ -217,6 +273,12 @@ void WriteAction::perform(ActionCtx &worker) {
   worker.remove_pending(io);
 }
 
+std::ostream& WriteAction::dump(std::ostream& o) const {
+  o << "WriteAction[";
+  dump_action_fields(o);
+  return o << ", imagectx_id=" << m_imagectx_id << ", offset=" << m_offset << ", length=" << m_length << "]";
+}
+
 
 OpenImageAction::OpenImageAction(Action &src,
                                  imagectx_id_t imagectx_id,
@@ -239,7 +301,7 @@ Action::ptr OpenImageAction::read_from(Action &src, Deser &d) {
 }
 
 void OpenImageAction::perform(ActionCtx &worker) {
-  dout(ACTION_LEVEL) << "Performing open image action #" << id() << dendl;
+  dout(ACTION_LEVEL) << "Performing " << *this << dendl;
   PendingIO::ptr io(new PendingIO(pending_io_id(), worker));
   worker.add_pending(io);
   librbd::Image *image = new librbd::Image();
@@ -258,6 +320,12 @@ void OpenImageAction::perform(ActionCtx &worker) {
   worker.remove_pending(io);
 }
 
+std::ostream& OpenImageAction::dump(std::ostream& o) const {
+  o << "OpenImageAction[";
+  dump_action_fields(o);
+  return o << ", imagectx_id=" << m_imagectx_id << ", name='" << m_name << "', snap_name='" << m_snap_name << "', readonly=" << m_readonly << "]";
+}
+
 
 CloseImageAction::CloseImageAction(Action &src,
                                    imagectx_id_t imagectx_id)
@@ -271,7 +339,13 @@ Action::ptr CloseImageAction::read_from(Action &src, Deser &d) {
 }
 
 void CloseImageAction::perform(ActionCtx &worker) {
-  dout(ACTION_LEVEL) << "Performing close image action #" << id() << dendl;
+  dout(ACTION_LEVEL) << "Performing " << *this << dendl;
   worker.erase_image(m_imagectx_id);
   worker.set_action_complete(pending_io_id());
 }
+
+std::ostream& CloseImageAction::dump(std::ostream& o) const {
+  o << "CloseImageAction[";
+  dump_action_fields(o);
+  return o << ", imagectx_id=" << m_imagectx_id << "]";
+}
index 95f12d92e2e46126f8fcbadb00b55aa8210ba7c0..9d728ac20865876d9c8cd91faa4d48f1406a589b 100644 (file)
@@ -105,7 +105,14 @@ public:
 
   static ptr read_from(Deser &d);
 
+protected:
+  std::ostream& dump_action_fields(std::ostream& o) const;
+
 private:
+  friend std::ostream& operator<<(std::ostream&, const Action&);
+
+  virtual std::ostream& dump(std::ostream& o) const = 0;
+
   const action_id_t m_id;
   const thread_id_t m_thread_id;
   const int m_num_successors;
@@ -113,6 +120,8 @@ private:
   const std::vector<dependency_d> m_predecessors;
 };
 
+std::ostream& operator<<(std::ostream& o, const Action& a);
+
 
 class DummyAction : public Action {
 public:
@@ -126,6 +135,9 @@ public:
 
   void perform(ActionCtx &ctx) {
   }
+
+private:
+  std::ostream& dump(std::ostream& o) const;
 };
 
 class StopThreadAction : public Action {
@@ -135,6 +147,9 @@ public:
   void perform(ActionCtx &ctx);
 
   static Action::ptr read_from(Action &src, Deser &d);
+
+private:
+  std::ostream& dump(std::ostream& o) const;
 };
 
 
@@ -150,6 +165,8 @@ public:
   static Action::ptr read_from(Action &src, Deser &d);
 
 private:
+  std::ostream& dump(std::ostream& o) const;
+
   imagectx_id_t m_imagectx_id;
   uint64_t m_offset;
   uint64_t m_length;
@@ -168,6 +185,8 @@ public:
   static Action::ptr read_from(Action &src, Deser &d);
 
 private:
+  std::ostream& dump(std::ostream& o) const;
+
   imagectx_id_t m_imagectx_id;
   uint64_t m_offset;
   uint64_t m_length;
@@ -186,6 +205,8 @@ public:
   static Action::ptr read_from(Action &src, Deser &d);
 
 private:
+  std::ostream& dump(std::ostream& o) const;
+
   imagectx_id_t m_imagectx_id;
   uint64_t m_offset;
   uint64_t m_length;
@@ -204,6 +225,8 @@ public:
   static Action::ptr read_from(Action &src, Deser &d);
 
 private:
+  std::ostream& dump(std::ostream& o) const;
+
   imagectx_id_t m_imagectx_id;
   uint64_t m_offset;
   uint64_t m_length;
@@ -223,6 +246,8 @@ public:
   static Action::ptr read_from(Action &src, Deser &d);
 
 private:
+  std::ostream& dump(std::ostream& o) const;
+
   imagectx_id_t m_imagectx_id;
   std::string m_name;
   std::string m_snap_name;
@@ -240,6 +265,8 @@ public:
   static Action::ptr read_from(Action &src, Deser &d);
 
 private:
+  std::ostream& dump(std::ostream& o) const;
+
   imagectx_id_t m_imagectx_id;
 };
 
@@ -253,6 +280,9 @@ public:
   bool is_start_thread();
 
   static Action::ptr read_from(Action &src, Deser &d);
+
+private:
+  std::ostream& dump(std::ostream& o) const;
 };
 
 }