From: Jason Dillaman Date: Mon, 6 Apr 2020 14:55:28 +0000 (-0400) Subject: rbd: ignore tx-only mirror peers when adding new peers X-Git-Tag: v15.2.2~64^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3f9f0c832397fa417e5159c60b621850d2087ddf;p=ceph.git rbd: ignore tx-only mirror peers when adding new peers There is a restriction for supporting only a single RX peer but we should support multiple TX-only peers. Fixes: https://tracker.ceph.com/issues/44938 Signed-off-by: Jason Dillaman (cherry picked from commit 366ecdb26d90b9dfa483458ce5c28712e47a6341) --- diff --git a/src/tools/rbd/action/MirrorPool.cc b/src/tools/rbd/action/MirrorPool.cc index 3a595c1b1d01..bfdc63627a25 100644 --- a/src/tools/rbd/action/MirrorPool.cc +++ b/src/tools/rbd/action/MirrorPool.cc @@ -1017,8 +1017,19 @@ int execute_peer_add(const po::variables_map &vm, std::cerr << "rbd: failed to list mirror peers" << std::endl; return r; } + + // ignore tx-only peers since the restriction is for rx + mirror_peers.erase( + std::remove_if( + mirror_peers.begin(), mirror_peers.end(), + [](const librbd::mirror_peer_site_t& peer) { + return (peer.direction == RBD_MIRROR_PEER_DIRECTION_TX); + }), + mirror_peers.end()); + if (!mirror_peers.empty()) { - std::cerr << "rbd: multiple peers are not currently supported" << std::endl; + std::cerr << "rbd: multiple RX peers are not currently supported" + << std::endl; return -EINVAL; } @@ -1173,8 +1184,37 @@ int execute_peer_set(const po::variables_map &vm, return -EINVAL; } - r = rbd.mirror_peer_site_set_direction( - io_ctx, uuid, boost::any_cast(direction)); + auto peer_direction = boost::any_cast( + direction); + if (peer_direction != RBD_MIRROR_PEER_DIRECTION_TX) { + // TODO: temporary restriction to prevent adding multiple peers + // until rbd-mirror daemon can properly handle the scenario + std::vector mirror_peers; + r = rbd.mirror_peer_site_list(io_ctx, &mirror_peers); + if (r < 0) { + std::cerr << "rbd: failed to list mirror peers" << std::endl; + return r; + } + + // ignore peer to be updated and tx-only peers since the restriction is + // for rx + mirror_peers.erase( + std::remove_if( + mirror_peers.begin(), mirror_peers.end(), + [uuid](const librbd::mirror_peer_site_t& peer) { + return (peer.uuid == uuid || + peer.direction == RBD_MIRROR_PEER_DIRECTION_TX); + }), + mirror_peers.end()); + + if (!mirror_peers.empty()) { + std::cerr << "rbd: multiple RX peers are not currently supported" + << std::endl; + return -EINVAL; + } + } + + r = rbd.mirror_peer_site_set_direction(io_ctx, uuid, peer_direction); } else { r = update_peer_config_key(io_ctx, uuid, key, value); }