Skip to content

Commit

Permalink
rbd-mirror: store sync snapshot name in registered client
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
  • Loading branch information
Mykola Golub committed Feb 23, 2016
1 parent 79dcef2 commit 1a6dfa4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/tools/rbd_mirror/ImageReplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ int ImageReplayer::get_registered_client_status(bool *registered)
boost::get<librbd::journal::MirrorPeerClientMeta>(client_data.client_meta);
m_local_pool_id = cm.pool_id;
m_local_image_id = cm.image_id;
m_snap_name = cm.snap_name;

dout(20) << "client found, pool_id=" << m_local_pool_id << ", image_id="
<< m_local_image_id << dendl;

<< m_local_image_id << ", snap_name=" << m_snap_name << dendl;
return 0;
}
}
Expand All @@ -448,13 +448,16 @@ int ImageReplayer::register_client()
<< dendl;
return r;
}
std::string m_snap_name = ".rbd-mirror." + m_client_id;

dout(20) << "m_cluster_id=" << local_cluster_id << ", pool_id="
<< m_local_pool_id << ", image_id=" << m_local_image_id << dendl;
<< m_local_pool_id << ", image_id=" << m_local_image_id
<< ", snap_name=" << m_snap_name << dendl;

bufferlist client_data;
::encode(librbd::journal::ClientData{librbd::journal::MirrorPeerClientMeta{
local_cluster_id, m_local_pool_id, m_local_image_id}}, client_data);
local_cluster_id, m_local_pool_id, m_local_image_id, m_snap_name}},
client_data);

r = m_remote_journaler->register_client(client_data);
if (r < 0) {
Expand Down Expand Up @@ -611,8 +614,6 @@ int ImageReplayer::copy()
dout(20) << m_remote_pool_id << "/" << m_remote_image_id << "->"
<< m_local_pool_id << "/" << m_local_image_id << dendl;

// TODO: use internal snapshots
std::string snap_name = ".rbd-mirror." + m_client_id;
librados::IoCtx local_ioctx;
librbd::ImageCtx *remote_image_ctx, *local_image_ctx;
librbd::NoOpProgressContext prog_ctx;
Expand All @@ -628,29 +629,30 @@ int ImageReplayer::copy()
return r;
}

dout(20) << "creating temporary snapshot " << snap_name << dendl;
dout(20) << "creating temporary snapshot " << m_snap_name << dendl;

r = remote_image_ctx->operations->snap_create(snap_name.c_str());
// TODO: use internal snapshots
r = remote_image_ctx->operations->snap_create(m_snap_name.c_str());
if (r == -EEXIST) {
// Probably left after a previous unsuccessful bootsrapt.
dout(0) << "removing stale snapshot " << snap_name << " of remote image "
dout(0) << "removing stale snapshot " << m_snap_name << " of remote image "
<< m_remote_image_id << dendl;
(void)remote_image_ctx->operations->snap_remove(snap_name.c_str());
r = remote_image_ctx->operations->snap_create(snap_name.c_str());
(void)remote_image_ctx->operations->snap_remove(m_snap_name.c_str());
r = remote_image_ctx->operations->snap_create(m_snap_name.c_str());
}
if (r < 0) {
derr << "error creating snapshot " << snap_name << " of remote image "
derr << "error creating snapshot " << m_snap_name << " of remote image "
<< m_remote_image_id << ": " << cpp_strerror(r) << dendl;
goto cleanup;
}

remote_image_ctx->state->close();
remote_image_ctx = new librbd::ImageCtx("", m_remote_image_id,
snap_name.c_str(), m_remote_ioctx,
m_snap_name.c_str(), m_remote_ioctx,
true);
r = remote_image_ctx->state->open();
if (r < 0) {
derr << "error opening snapshot " << snap_name << " of remote image "
derr << "error opening snapshot " << m_snap_name << " of remote image "
<< m_remote_image_id << ": " << cpp_strerror(r) << dendl;
delete remote_image_ctx;
remote_image_ctx = nullptr;
Expand Down Expand Up @@ -680,7 +682,7 @@ int ImageReplayer::copy()
// TODO: show copy progress in image replay status
r = librbd::copy(remote_image_ctx, local_image_ctx, prog_ctx);
if (r < 0) {
derr << "error copying snapshot " << snap_name << " of remote image "
derr << "error copying snapshot " << m_snap_name << " of remote image "
<< m_remote_image_id << " to local image " << m_local_image_id
<< ": " << cpp_strerror(r) << dendl;
}
Expand Down Expand Up @@ -708,10 +710,10 @@ int ImageReplayer::copy()
<< ": " << cpp_strerror(r1) << dendl;
delete remote_image_ctx;
} else {
dout(20) << "removing temporary snapshot " << snap_name << dendl;
r1 = remote_image_ctx->operations->snap_remove(snap_name.c_str());
dout(20) << "removing temporary snapshot " << m_snap_name << dendl;
r1 = remote_image_ctx->operations->snap_remove(m_snap_name.c_str());
if (r1 < 0) {
derr << "error removing snapshot " << snap_name << " of remote image "
derr << "error removing snapshot " << m_snap_name << " of remote image "
<< m_remote_image_id << ": " << cpp_strerror(r1) << dendl;
}
remote_image_ctx->state->close();
Expand Down
1 change: 1 addition & 0 deletions src/tools/rbd_mirror/ImageReplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class ImageReplayer {
std::string m_client_id;
int64_t m_remote_pool_id, m_local_pool_id;
std::string m_remote_image_id, m_local_image_id;
std::string m_snap_name;
Mutex m_lock;
State m_state;
std::string m_local_pool_name, m_remote_pool_name;
Expand Down

0 comments on commit 1a6dfa4

Please sign in to comment.