]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-mirror: make image replayer asok commands available when not started
authorMykola Golub <mgolub@mirantis.com>
Thu, 28 Apr 2016 06:23:35 +0000 (09:23 +0300)
committerMykola Golub <mgolub@mirantis.com>
Sun, 1 May 2016 15:33:54 +0000 (18:33 +0300)
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 <mgolub@mirantis.com>
qa/workunits/rbd/rbd_mirror.sh
src/tools/rbd_mirror/ImageReplayer.cc

index fc549186aa79fc23010bc61b5cc8dc1b68cab8c3..93ed76c1d0bf9039e8ca07c82723ea42a4ff9458 100755 (executable)
@@ -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}"
 }
 
index e59d49dec7897761079c63c9ed5d63c0360c4f7f..9cf445aa24fd57ddec3bd0109ba60c8295f472d9 100644 (file)
@@ -197,6 +197,21 @@ ImageReplayer<I>::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<CephContext *>(m_local->cct());
+  m_asok_hook = new ImageReplayerAdminSocketHook<I>(cct, m_name, this);
 }
 
 template <typename I>
@@ -309,11 +324,21 @@ void ImageReplayer<I>::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<CephContext *>(m_local->cct());
-    delete m_asok_hook;
-    m_asok_hook = new ImageReplayerAdminSocketHook<I>(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<CephContext *>(m_local->cct());
+      m_asok_hook = new ImageReplayerAdminSocketHook<I>(cct, m_name, this);
+    }
   }
 
   update_mirror_image_status();
@@ -596,9 +621,6 @@ void ImageReplayer<I>::on_stop_local_image_close_finish(int r)
 
   m_remote_ioctx.close();
 
-  delete m_asok_hook;
-  m_asok_hook = nullptr;
-
   Context *on_finish(nullptr);
 
   {