From: Mykola Golub Date: Wed, 16 Mar 2016 14:29:56 +0000 (+0200) Subject: rbd-mirror: use pool/image names in asok commands X-Git-Tag: v10.1.0~30^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F8159%2Fhead;p=ceph.git rbd-mirror: use pool/image names in asok commands Now the commands look similar to rbd cache asok commands. Signed-off-by: Mykola Golub --- diff --git a/qa/workunits/rbd/rbd_mirror.sh b/qa/workunits/rbd/rbd_mirror.sh index b84fd241b6cc..901a308c065d 100755 --- a/qa/workunits/rbd/rbd_mirror.sh +++ b/qa/workunits/rbd/rbd_mirror.sh @@ -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 diff --git a/qa/workunits/rbd/rbd_mirror_image_replay.sh b/qa/workunits/rbd/rbd_mirror_image_replay.sh index e5c701391bfc..a786d09966bd 100755 --- a/qa/workunits/rbd/rbd_mirror_image_replay.sh +++ b/qa/workunits/rbd/rbd_mirror_image_replay.sh @@ -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() diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index e1be6c0d7cd7..25afe93189d9 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -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(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(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);