From: Mykola Golub Date: Thu, 28 Apr 2016 06:23:35 +0000 (+0300) Subject: rbd-mirror: make image replayer asok commands available when not started X-Git-Tag: v11.0.0~734^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=21790484dc66e97e7625b5b2afabb7efe3a92b08;p=ceph-ci.git rbd-mirror: make image replayer asok commands available when not started Initially the asok commands were registered only after the image replayer start (and unregistered on stop) because their names were built using remote pool and image names, which became known only after start. Now, the asok commands are registered on the image replayer construction using the temporary name "remote_pool_name/global_image_id". They are re-registered using "remote_pool_name/remote_image_name" when the image replayer is started. Also the commands are not unregistered on the image replayer stop. Signed-off-by: Mykola Golub --- diff --git a/qa/workunits/rbd/rbd_mirror.sh b/qa/workunits/rbd/rbd_mirror.sh index fc549186aa7..93ed76c1d0b 100755 --- a/qa/workunits/rbd/rbd_mirror.sh +++ b/qa/workunits/rbd/rbd_mirror.sh @@ -302,7 +302,11 @@ test_image_replay_state() test -S "${asok_file}" ceph --admin-daemon ${asok_file} help | - fgrep "\"rbd mirror status ${POOL}/${image}\"" && current_state=started + fgrep "\"rbd mirror status ${POOL}/${image}\"" && + ceph --admin-daemon ${asok_file} rbd mirror status ${POOL}/${image} | + grep -i 'state.*Replaying' && + current_state=started + test "${test_state}" = "${current_state}" } diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index e59d49dec78..9cf445aa24f 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -197,6 +197,21 @@ ImageReplayer::ImageReplayer(Threads *threads, RadosRef local, RadosRef remot remote_image_id), m_progress_cxt(this) { + // Register asok commands using a temporary "remote_pool_name/global_image_id" + // name. When the image name becomes known on start the asok commands will be + // re-registered using "remote_pool_name/remote_image_name" name. + + std::string pool_name; + int r = m_remote->pool_reverse_lookup(m_remote_pool_id, &pool_name); + if (r < 0) { + derr << "error resolving remote pool " << m_remote_pool_id + << ": " << cpp_strerror(r) << dendl; + pool_name = stringify(m_remote_pool_id); + } + m_name = pool_name + "/" + m_global_image_id; + + CephContext *cct = static_cast(m_local->cct()); + m_asok_hook = new ImageReplayerAdminSocketHook(cct, m_name, this); } template @@ -309,11 +324,21 @@ void ImageReplayer::handle_bootstrap(int r) { { Mutex::Locker locker(m_lock); - m_name = m_local_ioctx.get_pool_name() + "/" + m_local_image_ctx->name; - CephContext *cct = static_cast(m_local->cct()); - delete m_asok_hook; - m_asok_hook = new ImageReplayerAdminSocketHook(cct, m_name, this); + std::string name = m_local_ioctx.get_pool_name() + "/" + + m_local_image_ctx->name; + if (m_name != name) { + m_name = name; + if (m_asok_hook) { + // Re-register asok commands using the new name. + delete m_asok_hook; + m_asok_hook = nullptr; + } + } + if (!m_asok_hook) { + CephContext *cct = static_cast(m_local->cct()); + m_asok_hook = new ImageReplayerAdminSocketHook(cct, m_name, this); + } } update_mirror_image_status(); @@ -596,9 +621,6 @@ void ImageReplayer::on_stop_local_image_close_finish(int r) m_remote_ioctx.close(); - delete m_asok_hook; - m_asok_hook = nullptr; - Context *on_finish(nullptr); {