Now the commands look similar to rbd cache asok commands.
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
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}"
}
{
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
}
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
--debug-rbd_mirror=30 \
--daemonize=true \
${CLIENT_ID} ${LOC_POOL} ${RMT_POOL} ${IMAGE}
+
+ wait_for_replay_started
}
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()
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);
}
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()
{
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);