*/
#include "actions.hpp"
+#include <boost/foreach.hpp>
#include <cstdlib>
#include "PendingIO.hpp"
#include "rbd_replay_debug.hpp"
}
}
+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) {
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();
}
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,
}
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));
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,
}
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);
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,
}
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);
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,
}
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);
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,
}
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();
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)
}
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 << "]";
+}
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;
const std::vector<dependency_d> m_predecessors;
};
+std::ostream& operator<<(std::ostream& o, const Action& a);
+
class DummyAction : public Action {
public:
void perform(ActionCtx &ctx) {
}
+
+private:
+ std::ostream& dump(std::ostream& o) const;
};
class StopThreadAction : public Action {
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
+
+private:
+ std::ostream& dump(std::ostream& o) const;
};
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;
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;
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;
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;
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;
static Action::ptr read_from(Action &src, Deser &d);
private:
+ std::ostream& dump(std::ostream& o) const;
+
imagectx_id_t m_imagectx_id;
};
bool is_start_thread();
static Action::ptr read_from(Action &src, Deser &d);
+
+private:
+ std::ostream& dump(std::ostream& o) const;
};
}