m_remote_tag_class = client_meta->tag_class;
dout(10) << ": remote tag class=" << m_remote_tag_class << dendl;
+ open_remote_image();
+}
+
+template <typename I>
+void BootstrapRequest<I>::open_remote_image() {
+ dout(20) << dendl;
+
+ update_progress("OPEN_REMOTE_IMAGE");
+
+ Context *ctx = create_context_callback<
+ BootstrapRequest<I>, &BootstrapRequest<I>::handle_open_remote_image>(
+ this);
+ OpenImageRequest<I> *request = OpenImageRequest<I>::create(
+ m_remote_io_ctx, &m_remote_image_ctx, m_remote_image_id, false,
+ ctx);
+ request->send();
+}
+
+template <typename I>
+void BootstrapRequest<I>::handle_open_remote_image(int r) {
+ dout(20) << ": r=" << r << dendl;
+
+ if (r < 0) {
+ derr << ": failed to open remote image: " << cpp_strerror(r) << dendl;
+ assert(m_remote_image_ctx == nullptr);
+ finish(r);
+ return;
+ }
+
get_client();
}
dout(10) << ": client not registered" << dendl;
} else if (r < 0) {
derr << ": failed to retrieve client: " << cpp_strerror(r) << dendl;
- finish(r);
+ m_ret_val = r;
+ close_remote_image();
return;
} else if (decode_client_meta()) {
// skip registration if it already exists
- open_remote_image();
+ is_primary();
return;
}
if (r < 0) {
derr << ": failed to register with remote journal: " << cpp_strerror(r)
<< dendl;
- finish(r);
+ m_ret_val = r;
+ close_remote_image();
return;
}
+ m_client = {};
*m_client_meta = librbd::journal::MirrorPeerClientMeta(m_local_image_id);
- open_remote_image();
-}
-
-template <typename I>
-void BootstrapRequest<I>::open_remote_image() {
- dout(20) << dendl;
-
- update_progress("OPEN_REMOTE_IMAGE");
-
- Context *ctx = create_context_callback<
- BootstrapRequest<I>, &BootstrapRequest<I>::handle_open_remote_image>(
- this);
- OpenImageRequest<I> *request = OpenImageRequest<I>::create(
- m_remote_io_ctx, &m_remote_image_ctx, m_remote_image_id, false,
- ctx);
- request->send();
-}
-
-template <typename I>
-void BootstrapRequest<I>::handle_open_remote_image(int r) {
- dout(20) << ": r=" << r << dendl;
-
- if (r < 0) {
- derr << ": failed to open remote image: " << cpp_strerror(r) << dendl;
- assert(m_remote_image_ctx == nullptr);
- finish(r);
- return;
- }
-
is_primary();
}
}
if (m_local_image_id.empty()) {
- create_local_image();
+ update_client_image();
return;
}
if (r < 0) {
derr << ": failed to update client: " << cpp_strerror(r) << dendl;
} else {
- m_client_meta->state = librbd::journal::MIRROR_PEER_STATE_REPLAYING;;
+ m_client_meta->state = librbd::journal::MIRROR_PEER_STATE_REPLAYING;
}
close_remote_image();
if (r == -ENOENT) {
assert(*m_local_image_ctx == nullptr);
dout(10) << ": local image missing" << dendl;
- create_local_image();
+ unregister_client();
return;
} else if (r == -EREMOTEIO) {
assert(*m_local_image_ctx == nullptr);
return;
}
- update_client_image();
+ get_remote_tags();
}
template <typename I>
-void BootstrapRequest<I>::create_local_image() {
+void BootstrapRequest<I>::unregister_client() {
dout(20) << dendl;
+ update_progress("UNREGISTER_CLIENT");
m_local_image_id = "";
- update_progress("CREATE_LOCAL_IMAGE");
-
- m_remote_image_ctx->snap_lock.get_read();
- std::string image_name = m_remote_image_ctx->name;
- m_remote_image_ctx->snap_lock.put_read();
-
Context *ctx = create_context_callback<
- BootstrapRequest<I>, &BootstrapRequest<I>::handle_create_local_image>(
+ BootstrapRequest<I>, &BootstrapRequest<I>::handle_unregister_client>(
this);
- CreateImageRequest<I> *request = CreateImageRequest<I>::create(
- m_local_io_ctx, m_work_queue, m_global_image_id, m_remote_mirror_uuid,
- image_name, m_remote_image_ctx, &m_local_image_id, ctx);
- request->send();
+ m_journaler->unregister_client(ctx);
}
template <typename I>
-void BootstrapRequest<I>::handle_create_local_image(int r) {
+void BootstrapRequest<I>::handle_unregister_client(int r) {
dout(20) << ": r=" << r << dendl;
-
if (r < 0) {
- derr << ": failed to create local image: " << cpp_strerror(r) << dendl;
+ derr << ": failed to unregister with remote journal: " << cpp_strerror(r)
+ << dendl;
m_ret_val = r;
close_remote_image();
return;
}
- open_local_image();
+ *m_client_meta = librbd::journal::MirrorPeerClientMeta("");
+ register_client();
}
template <typename I>
void BootstrapRequest<I>::update_client_image() {
dout(20) << dendl;
-
update_progress("UPDATE_CLIENT_IMAGE");
- if (m_client_meta->image_id == (*m_local_image_ctx)->id) {
- // already registered local image with remote journal
- get_remote_tags();
- return;
- }
- m_local_image_id = (*m_local_image_ctx)->id;
-
- dout(20) << dendl;
+ assert(m_local_image_id.empty());
+ m_local_image_id = librbd::util::generate_image_id<I>(m_local_io_ctx);
librbd::journal::MirrorPeerClientMeta client_meta{m_local_image_id};
client_meta.state = librbd::journal::MIRROR_PEER_STATE_SYNCING;
if (r < 0) {
derr << ": failed to update client: " << cpp_strerror(r) << dendl;
m_ret_val = r;
- close_local_image();
+ close_remote_image();
return;
}
if (m_canceled) {
dout(10) << ": request canceled" << dendl;
m_ret_val = -ECANCELED;
- close_local_image();
+ close_remote_image();
return;
}
*m_client_meta = {m_local_image_id};
m_client_meta->state = librbd::journal::MIRROR_PEER_STATE_SYNCING;
- get_remote_tags();
+ create_local_image();
+}
+
+template <typename I>
+void BootstrapRequest<I>::create_local_image() {
+ dout(20) << dendl;
+ update_progress("CREATE_LOCAL_IMAGE");
+
+ m_remote_image_ctx->snap_lock.get_read();
+ std::string image_name = m_remote_image_ctx->name;
+ m_remote_image_ctx->snap_lock.put_read();
+
+ Context *ctx = create_context_callback<
+ BootstrapRequest<I>, &BootstrapRequest<I>::handle_create_local_image>(
+ this);
+ CreateImageRequest<I> *request = CreateImageRequest<I>::create(
+ m_local_io_ctx, m_work_queue, m_global_image_id, m_remote_mirror_uuid,
+ image_name, m_local_image_id, m_remote_image_ctx, ctx);
+ request->send();
+}
+
+template <typename I>
+void BootstrapRequest<I>::handle_create_local_image(int r) {
+ dout(20) << ": r=" << r << dendl;
+
+ if (r < 0) {
+ derr << ": failed to create local image: " << cpp_strerror(r) << dendl;
+ m_ret_val = r;
+ close_remote_image();
+ return;
+ }
+
+ open_local_image();
}
template <typename I>