From d29895a45ac465ebfcf8769f65087318112030e8 Mon Sep 17 00:00:00 2001 From: songweibin Date: Thu, 13 Jul 2017 14:41:04 +0800 Subject: [PATCH] api/Mirror: make it more understandable when adding peer returns error Signed-off-by: songweibin --- src/tools/rbd/action/MirrorPool.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tools/rbd/action/MirrorPool.cc b/src/tools/rbd/action/MirrorPool.cc index 929ac446d02c..0090a42060b9 100644 --- a/src/tools/rbd/action/MirrorPool.cc +++ b/src/tools/rbd/action/MirrorPool.cc @@ -528,10 +528,25 @@ int execute_peer_add(const po::variables_map &vm) { if (r < 0) { return r; } + + librbd::RBD rbd; + rbd_mirror_mode_t mirror_mode; + r = rbd.mirror_mode_get(io_ctx, &mirror_mode); + if (r < 0) { + std::cerr << "rbd: failed to retrieve mirror mode: " + << cpp_strerror(r) << std::endl; + return r; + } + + if (mirror_mode == RBD_MIRROR_MODE_DISABLED) { + std::cerr << "rbd: failed to add mirror peer: " + << "mirroring must be enabled on the pool " + << pool_name << std::endl; + return -EINVAL; + } // TODO: temporary restriction to prevent adding multiple peers // until rbd-mirror daemon can properly handle the scenario - librbd::RBD rbd; std::vector mirror_peers; r = rbd.mirror_peer_list(io_ctx, &mirror_peers); if (r < 0) { -- 2.47.3