From: Jason Dillaman Date: Wed, 29 Jul 2015 19:43:02 +0000 (-0400) Subject: librbd: new journal types for maintenance commands X-Git-Tag: v10.0.2~193^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c4247f5f5b2be8cd44d32d2b6b079ec0169b6133;p=ceph.git librbd: new journal types for maintenance commands Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/JournalReplay.cc b/src/librbd/JournalReplay.cc index 7daf10c254fc..6f54eb157895 100644 --- a/src/librbd/JournalReplay.cc +++ b/src/librbd/JournalReplay.cc @@ -76,6 +76,58 @@ void JournalReplay::handle_event(const journal::AioFlushEvent &event) { AioImageRequest::aio_flush(&m_image_ctx, aio_comp); } +void JournalReplay::handle_event(const journal::OpFinishEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Op finish event" << dendl; +} + +void JournalReplay::handle_event(const journal::SnapCreateEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Snap create event" << dendl; +} + +void JournalReplay::handle_event(const journal::SnapRemoveEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Snap remove event" << dendl; +} + +void JournalReplay::handle_event(const journal::SnapRenameEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Snap rename event" << dendl; +} + +void JournalReplay::handle_event(const journal::SnapProtectEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Snap protect event" << dendl; +} + +void JournalReplay::handle_event(const journal::SnapUnprotectEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Snap unprotect event" + << dendl; +} + +void JournalReplay::handle_event(const journal::SnapRollbackEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Snap rollback start event" + << dendl; +} + +void JournalReplay::handle_event(const journal::RenameEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Rename event" << dendl; +} + +void JournalReplay::handle_event(const journal::ResizeEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Resize start event" << dendl; +} + +void JournalReplay::handle_event(const journal::FlattenEvent &event) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << this << " " << __func__ << ": Flatten start event" << dendl; +} + void JournalReplay::handle_event(const journal::UnknownEvent &event) { CephContext *cct = m_image_ctx.cct; ldout(cct, 20) << this << " " << __func__ << ": unknown event" << dendl; diff --git a/src/librbd/JournalReplay.h b/src/librbd/JournalReplay.h index 7b857138872d..62be2dfb36ef 100644 --- a/src/librbd/JournalReplay.h +++ b/src/librbd/JournalReplay.h @@ -53,6 +53,16 @@ private: void handle_event(const journal::AioDiscardEvent &event); void handle_event(const journal::AioWriteEvent &event); void handle_event(const journal::AioFlushEvent &event); + void handle_event(const journal::OpFinishEvent &event); + void handle_event(const journal::SnapCreateEvent &event); + void handle_event(const journal::SnapRemoveEvent &event); + void handle_event(const journal::SnapRenameEvent &event); + void handle_event(const journal::SnapProtectEvent &event); + void handle_event(const journal::SnapUnprotectEvent &event); + void handle_event(const journal::SnapRollbackEvent &event); + void handle_event(const journal::RenameEvent &event); + void handle_event(const journal::ResizeEvent &event); + void handle_event(const journal::FlattenEvent &event); void handle_event(const journal::UnknownEvent &event); AioCompletion *create_aio_completion(); diff --git a/src/librbd/JournalTypes.cc b/src/librbd/JournalTypes.cc index 4dcd2f5aff56..cda35aabb2f1 100644 --- a/src/librbd/JournalTypes.cc +++ b/src/librbd/JournalTypes.cc @@ -105,6 +105,79 @@ void AioFlushEvent::decode(__u8 version, bufferlist::iterator& it) { void AioFlushEvent::dump(Formatter *f) const { } +void OpEventBase::encode(bufferlist& bl) const { + ::encode(tid, bl); +} + +void OpEventBase::decode(__u8 version, bufferlist::iterator& it) { + ::decode(tid, it); +} + +void OpEventBase::dump(Formatter *f) const { + f->dump_unsigned("tid", tid); +} + +void SnapEventBase::encode(bufferlist& bl) const { + OpStartEventBase::encode(bl); + ::encode(snap_name, bl); +} + +void SnapEventBase::decode(__u8 version, bufferlist::iterator& it) { + OpStartEventBase::decode(version, it); + ::decode(snap_name, it); +} + +void SnapEventBase::dump(Formatter *f) const { + OpStartEventBase::dump(f); + f->dump_string("snap_name", snap_name); +} + +void SnapRenameEvent::encode(bufferlist& bl) const { + SnapEventBase::encode(bl); + ::encode(snap_id, bl); +} + +void SnapRenameEvent::decode(__u8 version, bufferlist::iterator& it) { + SnapEventBase::decode(version, it); + ::decode(snap_id, it); +} + +void SnapRenameEvent::dump(Formatter *f) const { + OpStartEventBase::dump(f); + f->dump_unsigned("src_snap_id", snap_id); + f->dump_string("dest_snap_name", snap_name); +} + +void RenameEvent::encode(bufferlist& bl) const { + OpStartEventBase::encode(bl); + ::encode(image_name, bl); +} + +void RenameEvent::decode(__u8 version, bufferlist::iterator& it) { + OpStartEventBase::decode(version, it); + ::decode(image_name, it); +} + +void RenameEvent::dump(Formatter *f) const { + OpStartEventBase::dump(f); + f->dump_string("image_name", image_name); +} + +void ResizeEvent::encode(bufferlist& bl) const { + OpStartEventBase::encode(bl); + ::encode(size, bl); +} + +void ResizeEvent::decode(__u8 version, bufferlist::iterator& it) { + OpStartEventBase::decode(version, it); + ::decode(size, it); +} + +void ResizeEvent::dump(Formatter *f) const { + OpStartEventBase::dump(f); + f->dump_unsigned("size", size); +} + void UnknownEvent::encode(bufferlist& bl) const { assert(false); } @@ -142,6 +215,36 @@ void EventEntry::decode(bufferlist::iterator& it) { case EVENT_TYPE_AIO_FLUSH: event = AioFlushEvent(); break; + case EVENT_TYPE_OP_FINISH: + event = OpFinishEvent(); + break; + case EVENT_TYPE_SNAP_CREATE: + event = SnapCreateEvent(); + break; + case EVENT_TYPE_SNAP_REMOVE: + event = SnapRemoveEvent(); + break; + case EVENT_TYPE_SNAP_RENAME: + event = SnapRenameEvent(); + break; + case EVENT_TYPE_SNAP_PROTECT: + event = SnapProtectEvent(); + break; + case EVENT_TYPE_SNAP_UNPROTECT: + event = SnapUnprotectEvent(); + break; + case EVENT_TYPE_SNAP_ROLLBACK: + event = SnapRollbackEvent(); + break; + case EVENT_TYPE_RENAME: + event = RenameEvent(); + break; + case EVENT_TYPE_RESIZE: + event = ResizeEvent(); + break; + case EVENT_TYPE_FLATTEN: + event = FlattenEvent(); + break; default: event = UnknownEvent(); break; @@ -165,6 +268,34 @@ void EventEntry::generate_test_instances(std::list &o) { o.push_back(new EventEntry(AioWriteEvent(123, 456, bl))); o.push_back(new EventEntry(AioFlushEvent())); + + o.push_back(new EventEntry(OpFinishEvent(123, -1))); + + o.push_back(new EventEntry(SnapCreateEvent())); + o.push_back(new EventEntry(SnapCreateEvent(234, "snap"))); + + o.push_back(new EventEntry(SnapRemoveEvent())); + o.push_back(new EventEntry(SnapRemoveEvent(345, "snap"))); + + o.push_back(new EventEntry(SnapRenameEvent())); + o.push_back(new EventEntry(SnapRenameEvent(345, 1, "snap"))); + + o.push_back(new EventEntry(SnapProtectEvent())); + o.push_back(new EventEntry(SnapProtectEvent(456, "snap"))); + + o.push_back(new EventEntry(SnapUnprotectEvent())); + o.push_back(new EventEntry(SnapUnprotectEvent(567, "snap"))); + + o.push_back(new EventEntry(SnapRollbackEvent())); + o.push_back(new EventEntry(SnapRollbackEvent(678, "snap"))); + + o.push_back(new EventEntry(RenameEvent())); + o.push_back(new EventEntry(RenameEvent(789, "image name"))); + + o.push_back(new EventEntry(ResizeEvent())); + o.push_back(new EventEntry(ResizeEvent(890, 1234))); + + o.push_back(new EventEntry(FlattenEvent(901))); } } // namespace journal @@ -184,6 +315,36 @@ std::ostream &operator<<(std::ostream &out, case EVENT_TYPE_AIO_FLUSH: out << "AioFlush"; break; + case EVENT_TYPE_OP_FINISH: + out << "OpFinish"; + break; + case EVENT_TYPE_SNAP_CREATE: + out << "SnapCreate"; + break; + case EVENT_TYPE_SNAP_REMOVE: + out << "SnapRemove"; + break; + case EVENT_TYPE_SNAP_RENAME: + out << "SnapRename"; + break; + case EVENT_TYPE_SNAP_PROTECT: + out << "SnapProtect"; + break; + case EVENT_TYPE_SNAP_UNPROTECT: + out << "SnapUnprotect"; + break; + case EVENT_TYPE_SNAP_ROLLBACK: + out << "SnapRollback"; + break; + case EVENT_TYPE_RENAME: + out << "Rename"; + break; + case EVENT_TYPE_RESIZE: + out << "Resize"; + break; + case EVENT_TYPE_FLATTEN: + out << "Flatten"; + break; default: out << "Unknown (" << static_cast(type) << ")"; break; diff --git a/src/librbd/JournalTypes.h b/src/librbd/JournalTypes.h index 59bd13fa275a..ce8ff03b7801 100644 --- a/src/librbd/JournalTypes.h +++ b/src/librbd/JournalTypes.h @@ -7,6 +7,7 @@ #include "include/int_types.h" #include "include/buffer.h" #include "include/encoding.h" +#include "include/types.h" #include #include @@ -18,9 +19,19 @@ namespace librbd { namespace journal { enum EventType { - EVENT_TYPE_AIO_DISCARD = 0, - EVENT_TYPE_AIO_WRITE = 1, - EVENT_TYPE_AIO_FLUSH = 2 + EVENT_TYPE_AIO_DISCARD = 0, + EVENT_TYPE_AIO_WRITE = 1, + EVENT_TYPE_AIO_FLUSH = 2, + EVENT_TYPE_OP_FINISH = 3, + EVENT_TYPE_SNAP_CREATE = 4, + EVENT_TYPE_SNAP_REMOVE = 5, + EVENT_TYPE_SNAP_RENAME = 6, + EVENT_TYPE_SNAP_PROTECT = 7, + EVENT_TYPE_SNAP_UNPROTECT = 8, + EVENT_TYPE_SNAP_ROLLBACK = 9, + EVENT_TYPE_RENAME = 10, + EVENT_TYPE_RESIZE = 11, + EVENT_TYPE_FLATTEN = 12 }; struct AioDiscardEvent { @@ -58,16 +69,172 @@ struct AioWriteEvent { void dump(Formatter *f) const; }; -struct UnknownEvent { - static const EventType EVENT_TYPE = static_cast(-1); +struct AioFlushEvent { + static const EventType EVENT_TYPE = EVENT_TYPE_AIO_FLUSH; void encode(bufferlist& bl) const; void decode(__u8 version, bufferlist::iterator& it); void dump(Formatter *f) const; }; -struct AioFlushEvent { - static const EventType EVENT_TYPE = EVENT_TYPE_AIO_FLUSH; +struct OpEventBase { + uint64_t tid; + + virtual void encode(bufferlist& bl) const; + virtual void decode(__u8 version, bufferlist::iterator& it); + virtual void dump(Formatter *f) const; + +protected: + OpEventBase() : tid(0) { + } + OpEventBase(uint64_t _tid) : tid(_tid) { + } + virtual ~OpEventBase() {} +}; + +struct OpStartEventBase : public OpEventBase { +protected: + OpStartEventBase() { + } + OpStartEventBase(uint64_t tid) : OpEventBase(tid) { + } +}; + +struct OpFinishEvent : public OpEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_OP_FINISH; + + int r; + + OpFinishEvent() : r(0) { + } + OpFinishEvent(uint64_t tid, int _r) : OpEventBase(tid), r(_r) { + } +}; + +struct SnapEventBase : public OpStartEventBase { + std::string snap_name; + + SnapEventBase() { + } + SnapEventBase(uint64_t tid, const std::string &_snap_name) + : OpStartEventBase(tid), snap_name(_snap_name) { + } + + virtual void encode(bufferlist& bl) const; + virtual void decode(__u8 version, bufferlist::iterator& it); + virtual void dump(Formatter *f) const; +}; + +struct SnapCreateEvent : public SnapEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_SNAP_CREATE; + + SnapCreateEvent() { + } + SnapCreateEvent(uint64_t tid, const std::string &snap_name) + : SnapEventBase(tid, snap_name) { + } +}; + +struct SnapRemoveEvent : public SnapEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_SNAP_REMOVE; + + SnapRemoveEvent() { + } + SnapRemoveEvent(uint64_t tid, const std::string &snap_name) + : SnapEventBase(tid, snap_name) { + } +}; + +struct SnapRenameEvent : public SnapEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_SNAP_RENAME; + + uint64_t snap_id; + + SnapRenameEvent() : snap_id(CEPH_NOSNAP) { + } + SnapRenameEvent(uint64_t tid, uint64_t src_snap_id, + const std::string &dest_snap_name) + : SnapEventBase(tid, dest_snap_name), snap_id(src_snap_id) { + } + + virtual void encode(bufferlist& bl) const; + virtual void decode(__u8 version, bufferlist::iterator& it); + virtual void dump(Formatter *f) const; +}; + +struct SnapProtectEvent : public SnapEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_SNAP_PROTECT; + + SnapProtectEvent() { + } + SnapProtectEvent(uint64_t tid, const std::string &snap_name) + : SnapEventBase(tid, snap_name) { + } +}; + +struct SnapUnprotectEvent : public SnapEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_SNAP_UNPROTECT; + + SnapUnprotectEvent() { + } + SnapUnprotectEvent(uint64_t tid, const std::string &snap_name) + : SnapEventBase(tid, snap_name) { + } +}; + +struct SnapRollbackEvent : public SnapEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_SNAP_ROLLBACK; + + SnapRollbackEvent() { + } + SnapRollbackEvent(uint64_t tid, const std::string &snap_name) + : SnapEventBase(tid, snap_name) { + } +}; + +struct RenameEvent : public OpStartEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_RENAME; + + std::string image_name; + + RenameEvent() { + } + RenameEvent(uint64_t tid, const std::string &_image_name) + : OpStartEventBase(tid), image_name(_image_name) { + } + + virtual void encode(bufferlist& bl) const; + virtual void decode(__u8 version, bufferlist::iterator& it); + virtual void dump(Formatter *f) const; +}; + +struct ResizeEvent : public OpStartEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_RESIZE; + + uint64_t size; + + ResizeEvent() : size(0) { + } + ResizeEvent(uint64_t tid, uint64_t _size) + : OpStartEventBase(tid), size(_size) { + } + + virtual void encode(bufferlist& bl) const; + virtual void decode(__u8 version, bufferlist::iterator& it); + virtual void dump(Formatter *f) const; +}; + +struct FlattenEvent : public OpStartEventBase { + static const EventType EVENT_TYPE = EVENT_TYPE_FLATTEN; + + FlattenEvent() { + } + FlattenEvent(uint64_t tid) : OpStartEventBase(tid) { + } +}; + +struct UnknownEvent { + static const EventType EVENT_TYPE = static_cast(-1); void encode(bufferlist& bl) const; void decode(__u8 version, bufferlist::iterator& it); @@ -77,6 +244,16 @@ struct AioFlushEvent { typedef boost::variant Event; struct EventEntry {