namespace {
+int validate_mirroring_enabled(librados::IoCtx& io_ctx) {
+ librbd::RBD rbd;
+ rbd_mirror_mode_t mirror_mode;
+ int 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: mirroring not enabled on the pool" << std::endl;
+ return -EINVAL;
+ }
+ return 0;
+}
+
int validate_uuid(const std::string &uuid) {
boost::regex pattern("^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$",
boost::regex::icase);
protected:
bool skip_action(const librbd::mirror_image_info_t &info) const override {
- return info.primary;
+ return (info.state != RBD_MIRROR_IMAGE_ENABLED || info.primary);
}
void execute_action(librbd::Image &image,
if (r >= 0) {
(*m_counter)++;
}
+ ImageRequestBase::handle_execute_action(r);
}
std::string get_action_type() const override {
protected:
bool skip_action(const librbd::mirror_image_info_t &info) const override {
- return !info.primary;
+ return (info.state != RBD_MIRROR_IMAGE_ENABLED || !info.primary);
}
void execute_action(librbd::Image &image,
}
void finalize_action() override {
+ if (m_mirror_image_status.info.global_id.empty()) {
+ return;
+ }
+
std::string state = utils::mirror_image_status_state(m_mirror_image_status);
std::string last_update = (
m_mirror_image_status.last_update == 0 ?
if (r < 0) {
return r;
}
-
- librbd::RBD rbd;
- rbd_mirror_mode_t mirror_mode;
- r = rbd.mirror_mode_get(io_ctx, &mirror_mode);
+
+ r = validate_mirroring_enabled(io_ctx);
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<librbd::mirror_peer_t> mirror_peers;
r = rbd.mirror_peer_list(io_ctx, &mirror_peers);
if (r < 0) {
return r;
}
+ r = validate_mirroring_enabled(io_ctx);
+ if (r < 0) {
+ return r;
+ }
+
librbd::RBD rbd;
r = rbd.mirror_peer_remove(io_ctx, uuid);
if (r < 0) {
return r;
}
+ r = validate_mirroring_enabled(io_ctx);
+ if (r < 0) {
+ return r;
+ }
+
librbd::RBD rbd;
if (key == "client") {
r = rbd.mirror_peer_set_client(io_ctx, uuid.c_str(), value.c_str());
return r;
}
+ r = validate_mirroring_enabled(io_ctx);
+ if (r < 0) {
+ return r;
+ }
+
librbd::RBD rbd;
std::map<librbd::mirror_image_status_state_t, int> states;
return r;
}
+ r = validate_mirroring_enabled(io_ctx);
+ if (r < 0) {
+ return r;
+ }
+
std::atomic<unsigned> counter = { 0 };
ImageRequestGenerator<PromoteImageRequest> generator(io_ctx, &counter,
vm["force"].as<bool>());
return r;
}
+ r = validate_mirroring_enabled(io_ctx);
+ if (r < 0) {
+ return r;
+ }
+
std::atomic<unsigned> counter { 0 };
ImageRequestGenerator<DemoteImageRequest> generator(io_ctx, &counter);
r = generator.execute();