From: Ilya Dryomov Date: Sat, 18 Jun 2022 10:35:51 +0000 (+0200) Subject: rbd-mirror: strengthen is_local_primary() and is_linked() X-Git-Tag: v18.0.0~643^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c60f1d5813c7fe248593731bbffb43d12cdd3b62;p=ceph.git rbd-mirror: strengthen is_local_primary() and is_linked() Initialize local_promotion_state and remote_promotion_state to UNKNOWN instead of counterintuitive PRIMARY and NON_PRIMARY -- half the time the final values are flipped. Then is_local_primary() and is_linked() can be strengthened as a non-existent image should stay in UNKNOWN. Signed-off-by: Ilya Dryomov --- diff --git a/src/tools/rbd_mirror/image_replayer/StateBuilder.cc b/src/tools/rbd_mirror/image_replayer/StateBuilder.cc index 3c7274ec56e5..c8649ab2fa83 100644 --- a/src/tools/rbd_mirror/image_replayer/StateBuilder.cc +++ b/src/tools/rbd_mirror/image_replayer/StateBuilder.cc @@ -36,16 +36,21 @@ StateBuilder::~StateBuilder() { } template -bool StateBuilder::is_local_primary() const { - return (!local_image_id.empty() && - local_promotion_state == librbd::mirror::PROMOTION_STATE_PRIMARY); +bool StateBuilder::is_local_primary() const { + if (local_promotion_state == librbd::mirror::PROMOTION_STATE_PRIMARY) { + ceph_assert(!local_image_id.empty()); + return true; + } + return false; } template bool StateBuilder::is_linked() const { - return ((local_promotion_state == - librbd::mirror::PROMOTION_STATE_NON_PRIMARY) && - is_linked_impl()); + if (local_promotion_state == librbd::mirror::PROMOTION_STATE_NON_PRIMARY) { + ceph_assert(!local_image_id.empty()); + return is_linked_impl(); + } + return false; } template diff --git a/src/tools/rbd_mirror/image_replayer/StateBuilder.h b/src/tools/rbd_mirror/image_replayer/StateBuilder.h index 99007ba5e21a..4c839a3efcee 100644 --- a/src/tools/rbd_mirror/image_replayer/StateBuilder.h +++ b/src/tools/rbd_mirror/image_replayer/StateBuilder.h @@ -81,13 +81,13 @@ public: std::string local_image_id; librbd::mirror::PromotionState local_promotion_state = - librbd::mirror::PROMOTION_STATE_PRIMARY; + librbd::mirror::PROMOTION_STATE_UNKNOWN; ImageCtxT* local_image_ctx = nullptr; std::string remote_mirror_uuid; std::string remote_image_id; librbd::mirror::PromotionState remote_promotion_state = - librbd::mirror::PROMOTION_STATE_NON_PRIMARY; + librbd::mirror::PROMOTION_STATE_UNKNOWN; ImageCtxT* remote_image_ctx = nullptr; protected: