Merge pull request #8159 from trociny/wip-rbd-mirror-asok

rbd-mirror: use pool/image names in asok commands

Reviewed-by: Josh Durgin <jdurgin@redhat.com>
Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Josh Durgin 2016-03-18 14:58:58 -07:00
commit c6c4f6095a
3 changed files with 41 additions and 55 deletions

View File

@ -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

View File

@ -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=
}
wait_for_replay_started()
{
local s
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()
{
local cmd
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}
ceph --admin-daemon ${TEMPDIR}/rbd-mirror-image-replay.asok \
rbd mirror flush ${LOC_POOL}/${IMAGE}
}
get_position()

View 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);