]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: use pool/image names in asok commands 8159/head
authorMykola Golub <mgolub@mirantis.com>
Wed, 16 Mar 2016 14:29:56 +0000 (16:29 +0200)
committerMykola Golub <mgolub@mirantis.com>
Wed, 16 Mar 2016 20:55:00 +0000 (22:55 +0200)
Now the commands look similar to rbd cache asok commands.

Signed-off-by: Mykola Golub <mgolub@mirantis.com>
qa/workunits/rbd/rbd_mirror.sh
qa/workunits/rbd/rbd_mirror_image_replay.sh
src/tools/rbd_mirror/ImageReplayer.cc

index b84fd241b6ccc400993b1246811764ce2bab865b..901a308c065d0411862bd9f3446a8bee05cf3db5 100755 (executable)
@@ -158,25 +158,20 @@ flush()
 
     test -n "${RBD_MIRROR_ASOK}"
 
-    image_id=$(remote_image_id ${image})
-    test -n "${image_id}"
-
-    cmd=$(ceph --admin-daemon ${RBD_MIRROR_ASOK} help |
-                sed -nEe 's/^.*"(rbd mirror flush.*'${image_id}'])":.*$/\1/p')
-    test -n "${cmd}"
-    ceph --admin-daemon ${TEMPDIR}/rbd-mirror.asok ${cmd}
+    ceph --admin-daemon ${TEMPDIR}/rbd-mirror.asok \
+        rbd mirror flush ${POOL}/${image}
 }
 
 test_image_replay_state()
 {
-    local image_id=$1
+    local image=$1
     local test_state=$2
     local current_state=stopped
 
     test -n "${RBD_MIRROR_ASOK}"
 
-    ceph --admin-daemon ${RBD_MIRROR_ASOK} help | fgrep "${image_id}" &&
-       current_state=started
+    ceph --admin-daemon ${RBD_MIRROR_ASOK} help |
+       fgrep "rbd mirror status ${POOL}/${image}" && current_state=started
     test "${test_state}" = "${current_state}"
 }
 
@@ -184,15 +179,12 @@ wait_for_image_replay_state()
 {
     local image=$1
     local state=$2
-    local image_id s
-
-    image_id=$(remote_image_id ${image})
-    test -n "${image_id}"
+    local s
 
     # TODO: add a way to force rbd-mirror to update replayers
     for s in 1 2 4 8 8 8 8 8 8 8 8; do
        sleep ${s}
-       test_image_replay_state "${image_id}" "${state}" && return 0
+       test_image_replay_state "${image}" "${state}" && return 0
     done
     return 1
 }
@@ -285,29 +277,6 @@ create_local_image()
     create_image ${LOC_CLUSTER} ${image}
 }
 
-image_id()
-{
-    local cluster=$1
-    local image=$2
-
-    rbd --cluster ${cluster} -p ${POOL} info --image ${image} |
-       sed -ne 's/^.*block_name_prefix: rbd_data\.//p'
-}
-
-remote_image_id()
-{
-    local image=$1
-
-    image_id ${RMT_CLUSTER} ${image}
-}
-
-local_image_id()
-{
-    local image=$1
-
-    image_id ${LOC_CLUSTER} ${image}
-}
-
 write_image()
 {
     local image=$1
index e5c701391bfcad1f40f22c82882878326e777149..a786d09966bd65b01c6cf0ad2f58c88af48713bd 100755 (executable)
@@ -71,6 +71,8 @@ start_replay()
        --debug-rbd_mirror=30 \
        --daemonize=true \
        ${CLIENT_ID} ${LOC_POOL} ${RMT_POOL} ${IMAGE}
+
+    wait_for_replay_started
 }
 
 stop_replay()
@@ -96,14 +98,24 @@ stop_replay()
     RBD_IMAGE_REPLAY_PID_FILE=
 }
 
-flush()
+wait_for_replay_started()
 {
-    local cmd
+    local s
 
-    cmd=$(ceph --admin-daemon ${TEMPDIR}/rbd-mirror-image-replay.asok help |
-                sed -nEe 's/^.*"(rbd mirror flush [^"]*)":.*$/\1/p')
-    test -n "${cmd}"
-    ceph --admin-daemon ${TEMPDIR}/rbd-mirror-image-replay.asok ${cmd}
+    for s in 0.1 0.2 0.4 0.8 1.6 3.2 6.4; do
+       sleep ${s}
+       ceph --admin-daemon ${TEMPDIR}/rbd-mirror-image-replay.asok help || :
+       test -S ${TEMPDIR}/rbd-mirror-image-replay.asok &&
+           ceph --admin-daemon ${TEMPDIR}/rbd-mirror-image-replay.asok help |
+               fgrep "rbd mirror status ${LOC_POOL}/${IMAGE}" && return 0
+    done
+    return 1
+}
+
+flush()
+{
+    ceph --admin-daemon ${TEMPDIR}/rbd-mirror-image-replay.asok \
+        rbd mirror flush ${LOC_POOL}/${IMAGE}
 }
 
 get_position()
index e1be6c0d7cd7dc77a4a49c30a7538c190f29b92d..25afe93189d9d8978a6d453620860ac32718eae4 100644 (file)
@@ -117,23 +117,22 @@ private:
 
 class ImageReplayerAdminSocketHook : public AdminSocketHook {
 public:
-  ImageReplayerAdminSocketHook(CephContext *cct, ImageReplayer *replayer) :
+  ImageReplayerAdminSocketHook(CephContext *cct, const std::string &name,
+                              ImageReplayer *replayer) :
     admin_socket(cct->get_admin_socket()) {
     std::string command;
     int r;
 
-    command = "rbd mirror status " + stringify(*replayer);
+    command = "rbd mirror status " + name;
     r = admin_socket->register_command(command, command, this,
-                                      "get status for rbd mirror " +
-                                      stringify(*replayer));
+                                      "get status for rbd mirror " + name);
     if (r == 0) {
       commands[command] = new StatusCommand(replayer);
     }
 
-    command = "rbd mirror flush " + stringify(*replayer);
+    command = "rbd mirror flush " + name;
     r = admin_socket->register_command(command, command, this,
-                                      "flush rbd mirror " +
-                                      stringify(*replayer));
+                                      "flush rbd mirror " + name);
     if (r == 0) {
       commands[command] = new FlushCommand(replayer);
     }
@@ -185,11 +184,9 @@ ImageReplayer::ImageReplayer(Threads *threads, RadosRef local, RadosRef remote,
   m_local_replay(nullptr),
   m_remote_journaler(nullptr),
   m_replay_handler(nullptr),
-  m_on_finish(nullptr)
+  m_on_finish(nullptr),
+  m_asok_hook(nullptr)
 {
-  CephContext *cct = static_cast<CephContext *>(m_local->cct());
-
-  m_asok_hook = new ImageReplayerAdminSocketHook(cct, this);
 }
 
 ImageReplayer::~ImageReplayer()
@@ -452,6 +449,14 @@ void ImageReplayer::on_start_wait_for_local_journal_ready_start()
 {
   dout(20) << "enter" << dendl;
 
+  if (!m_asok_hook) {
+    CephContext *cct = static_cast<CephContext *>(m_local->cct());
+    std::string name = m_local_ioctx.get_pool_name() + "/" +
+      m_local_image_ctx->name;
+
+    m_asok_hook = new ImageReplayerAdminSocketHook(cct, name, this);
+  }
+
   FunctionContext *ctx = new FunctionContext(
     [this](int r) {
       on_start_wait_for_local_journal_ready_finish(r);