From: Adam Crume Date: Fri, 18 Jul 2014 20:57:16 +0000 (-0700) Subject: rbd-replay: Support writing Actions to ostreams X-Git-Tag: v0.86~231^2~54 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c651bf20db53b623cc7ad4842a06308cbd192470;p=ceph.git rbd-replay: Support writing Actions to ostreams Signed-off-by: Adam Crume --- diff --git a/src/rbd_replay/actions.cc b/src/rbd_replay/actions.cc index 9070c91b1bff..622a6c6bcfd7 100644 --- a/src/rbd_replay/actions.cc +++ b/src/rbd_replay/actions.cc @@ -13,6 +13,7 @@ */ #include "actions.hpp" +#include #include #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 << "]"; +} diff --git a/src/rbd_replay/actions.hpp b/src/rbd_replay/actions.hpp index 95f12d92e2e4..9d728ac20865 100644 --- a/src/rbd_replay/actions.hpp +++ b/src/rbd_replay/actions.hpp @@ -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 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; }; }