mirror of
https://github.com/ceph/ceph
synced 2026-08-02 07:03:18 +00:00
librbd/mirror: cleanup EnableRequest::handle_get_mirror_image()
In the EnableRequest state machine, clean up the handling of the async
request to fetch the mirror image, particularly when a non-primary image
is being created by the rbd-mirror daemon.
Signed-off-by: Ramana Raja <rraja@redhat.com>
(cherry picked from commit 415bf4dd77)
This commit is contained in:
parent
43726f6eb1
commit
c51a296f6f
@ -68,41 +68,49 @@ void EnableRequest<I>::handle_get_mirror_image(int r) {
|
||||
r = cls_client::mirror_image_get_finish(&iter, &m_mirror_image);
|
||||
}
|
||||
|
||||
if (r == 0 && m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_CREATING &&
|
||||
!m_non_primary_global_image_id.empty()) {
|
||||
// special case where rbd-mirror injects a disabled record to record the
|
||||
// local image id prior to creating ther image
|
||||
ldout(m_cct, 10) << "enabling mirroring on in-progress image replication"
|
||||
<< dendl;
|
||||
} else if (r == 0) {
|
||||
if (r == 0) {
|
||||
if (m_mirror_image.mode != m_mode) {
|
||||
lderr(m_cct) << "invalid current image mirror mode" << dendl;
|
||||
r = -EINVAL;
|
||||
finish(-EINVAL);
|
||||
return;
|
||||
} else if (m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
|
||||
ldout(m_cct, 10) << "mirroring is already enabled" << dendl;
|
||||
} else {
|
||||
finish(0);
|
||||
return;
|
||||
} else if (
|
||||
m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_CREATING &&
|
||||
m_mirror_image.global_image_id == m_non_primary_global_image_id) {
|
||||
// special case where rbd-mirror injects a quasi-enabled mirror image
|
||||
// entry to record the local image id prior to creating the image
|
||||
ceph_assert(!m_mirror_image.global_image_id.empty());
|
||||
ldout(m_cct, 10) << "enabling mirroring on in-progress image replication"
|
||||
<< dendl;
|
||||
} else if (
|
||||
m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_DISABLING) {
|
||||
lderr(m_cct) << "currently disabling" << dendl;
|
||||
r = -EINVAL;
|
||||
finish(-EINVAL);
|
||||
return;
|
||||
} else {
|
||||
lderr(m_cct) << "unexpected mirror image state" << dendl;
|
||||
finish(-EINVAL);
|
||||
return;
|
||||
}
|
||||
finish(r);
|
||||
return;
|
||||
} else if (r != -ENOENT) {
|
||||
} else if (r == -ENOENT) {
|
||||
m_mirror_image.mode = m_mode;
|
||||
if (m_non_primary_global_image_id.empty()) {
|
||||
uuid_d uuid_gen;
|
||||
uuid_gen.generate_random();
|
||||
m_mirror_image.global_image_id = uuid_gen.to_string();
|
||||
} else {
|
||||
m_mirror_image.global_image_id = m_non_primary_global_image_id;
|
||||
}
|
||||
} else {
|
||||
lderr(m_cct) << "failed to retrieve mirror image: " << cpp_strerror(r)
|
||||
<< dendl;
|
||||
finish(r);
|
||||
return;
|
||||
}
|
||||
|
||||
r = 0;
|
||||
m_mirror_image.mode = m_mode;
|
||||
if (m_non_primary_global_image_id.empty()) {
|
||||
uuid_d uuid_gen;
|
||||
uuid_gen.generate_random();
|
||||
m_mirror_image.global_image_id = uuid_gen.to_string();
|
||||
} else {
|
||||
m_mirror_image.global_image_id = m_non_primary_global_image_id;
|
||||
}
|
||||
|
||||
get_tag_owner();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user