Skip to content

Commit

Permalink
librbd: record original snap name in snap rename journal event
Browse files Browse the repository at this point in the history
Remote peers need a key to map snapshot ids between clusters.

Signed-off-by: Jason Dillaman <[email protected]>
  • Loading branch information
Jason Dillaman committed Jul 19, 2016
1 parent 77699bf commit f70b90c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/librbd/journal/Types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,21 @@ void SnapLimitEvent::dump(Formatter *f) const {
void SnapRenameEvent::encode(bufferlist& bl) const {
SnapEventBase::encode(bl);
::encode(snap_id, bl);
::encode(src_snap_name, bl);
}

void SnapRenameEvent::decode(__u8 version, bufferlist::iterator& it) {
SnapEventBase::decode(version, it);
::decode(snap_id, it);
if (version >= 2) {
::decode(src_snap_name, it);
}
}

void SnapRenameEvent::dump(Formatter *f) const {
SnapEventBase::dump(f);
f->dump_unsigned("src_snap_id", snap_id);
f->dump_string("src_snap_name", src_snap_name);
f->dump_string("dest_snap_name", snap_name);
}

Expand Down Expand Up @@ -239,7 +244,7 @@ EventType EventEntry::get_event_type() const {
}

void EventEntry::encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
ENCODE_START(2, 1, bl);
boost::apply_visitor(EncodeVisitor(bl), event);
ENCODE_FINISH(bl);
}
Expand Down Expand Up @@ -327,7 +332,7 @@ void EventEntry::generate_test_instances(std::list<EventEntry *> &o) {
o.push_back(new EventEntry(SnapRemoveEvent(345, "snap")));

o.push_back(new EventEntry(SnapRenameEvent()));
o.push_back(new EventEntry(SnapRenameEvent(456, 1, "snap")));
o.push_back(new EventEntry(SnapRenameEvent(456, 1, "src snap", "dest snap")));

o.push_back(new EventEntry(SnapProtectEvent()));
o.push_back(new EventEntry(SnapProtectEvent(567, "snap")));
Expand Down
5 changes: 4 additions & 1 deletion src/librbd/journal/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,15 @@ struct SnapRenameEvent : public SnapEventBase {
static const EventType TYPE = EVENT_TYPE_SNAP_RENAME;

uint64_t snap_id;
std::string src_snap_name;

SnapRenameEvent() : snap_id(CEPH_NOSNAP) {
}
SnapRenameEvent(uint64_t op_tid, uint64_t src_snap_id,
const std::string &src_snap_name,
const std::string &dest_snap_name)
: SnapEventBase(op_tid, dest_snap_name), snap_id(src_snap_id) {
: SnapEventBase(op_tid, dest_snap_name), snap_id(src_snap_id),
src_snap_name(src_snap_name) {
}

void encode(bufferlist& bl) const;
Expand Down
15 changes: 15 additions & 0 deletions src/librbd/operation/SnapshotRenameRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ SnapshotRenameRequest<I>::SnapshotRenameRequest(I &image_ctx,
: Request<I>(image_ctx, on_finish), m_snap_id(snap_id), m_snap_name(snap_name) {
}

template <typename I>
journal::Event SnapshotRenameRequest<I>::create_event(uint64_t op_tid) const {
I &image_ctx = this->m_image_ctx;
assert(image_ctx.snap_lock.is_locked());

std::string src_snap_name;
auto snap_info_it = image_ctx.snap_info.find(m_snap_id);
if (snap_info_it != image_ctx.snap_info.end()) {
src_snap_name = snap_info_it->second.name;
}

return journal::SnapRenameEvent(op_tid, m_snap_id, src_snap_name,
m_snap_name);
}

template <typename I>
void SnapshotRenameRequest<I>::send_op() {
send_rename_snap();
Expand Down
4 changes: 1 addition & 3 deletions src/librbd/operation/SnapshotRenameRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ class SnapshotRenameRequest : public Request<ImageCtxT> {
SnapshotRenameRequest(ImageCtxT &image_ctx, Context *on_finish,
uint64_t snap_id, const std::string &snap_name);

virtual journal::Event create_event(uint64_t op_tid) const {
return journal::SnapRenameEvent(op_tid, m_snap_id, m_snap_name);
}
virtual journal::Event create_event(uint64_t op_tid) const;

protected:
virtual void send_op();
Expand Down
3 changes: 2 additions & 1 deletion src/test/librbd/journal/test_Replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ TEST_F(TestJournalReplay, SnapRename) {
get_journal_commit_position(ictx, &initial_tag, &initial_entry);

// inject snapshot ops into journal
inject_into_journal(ictx, librbd::journal::SnapRenameEvent(1, snap_id, "snap2"));
inject_into_journal(ictx, librbd::journal::SnapRenameEvent(1, snap_id, "snap",
"snap2"));
inject_into_journal(ictx, librbd::journal::OpFinishEvent(1, 0));
close_image(ictx);

Expand Down
4 changes: 2 additions & 2 deletions src/test/librbd/journal/test_mock_Replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ TEST_F(TestMockJournalReplay, SnapRenameEvent) {
C_SaferCond on_start_ready;
C_SaferCond on_start_safe;
when_process(mock_journal_replay,
EventEntry{SnapRenameEvent(123, 234, "snap")},
EventEntry{SnapRenameEvent(123, 234, "snap1", "snap")},
&on_start_ready, &on_start_safe);
ASSERT_EQ(0, on_start_ready.wait());

Expand Down Expand Up @@ -862,7 +862,7 @@ TEST_F(TestMockJournalReplay, SnapRenameEventExists) {
C_SaferCond on_start_ready;
C_SaferCond on_start_safe;
when_process(mock_journal_replay,
EventEntry{SnapRenameEvent(123, 234, "snap")},
EventEntry{SnapRenameEvent(123, 234, "snap1", "snap")},
&on_start_ready, &on_start_safe);
ASSERT_EQ(0, on_start_ready.wait());

Expand Down

0 comments on commit f70b90c

Please sign in to comment.