CLS_ERR("object map footer read failed");
return r;
}
-
+
try {
bufferlist::iterator it = footer_bl.begin();
object_map.decode_footer(it);
}
bool updated = false;
- for (uint64_t object_no = start_object_no; object_no < end_object_no;
- ++object_no) {
- uint8_t state = object_map[object_no];
+ auto it = object_map.begin() + start_object_no;
+ auto end_it = object_map.begin() + end_object_no;
+ for (; it != end_it; ++it) {
+ uint8_t state = *it;
if ((!current_object_state || state == *current_object_state ||
(*current_object_state == OBJECT_EXISTS &&
state == OBJECT_EXISTS_CLEAN)) && state != new_object_state) {
- object_map[object_no] = new_object_state;
+ *it = new_object_state;
updated = true;
}
}
return 0;
}
+int list_watchers(cls_method_context_t hctx,
+ std::set<entity_inst_t> *entities) {
+ obj_list_watch_response_t watchers;
+ int r = cls_cxx_list_watchers(hctx, &watchers);
+ if (r < 0 && r != -ENOENT) {
+ CLS_ERR("error listing watchers: '%s'", cpp_strerror(r).c_str());
+ return r;
+ }
+
+ entities->clear();
+ for (auto &w : watchers.entries) {
+ entities->emplace(w.name, w.addr);
+ }
+ return 0;
+}
+
int read_peers(cls_method_context_t hctx,
std::vector<cls::rbd::MirrorPeer> *peers) {
std::string last_read = PEER_KEY_PREFIX;
}
int image_status_get(cls_method_context_t hctx, const string &global_image_id,
+ const std::set<entity_inst_t> &watchers,
cls::rbd::MirrorImageStatus *status) {
bufferlist bl;
return -EIO;
}
- obj_list_watch_response_t watchers;
- r = cls_cxx_list_watchers(hctx, &watchers);
- if (r < 0 && r != -ENOENT) {
- CLS_ERR("error listing watchers: '%s'", cpp_strerror(r).c_str());
- return r;
- }
*status = static_cast<cls::rbd::MirrorImageStatus>(ondisk_status);
- status->up = false;
- for (auto &w : watchers.entries) {
- if (w.name == ondisk_status.origin.name &&
- w.addr == ondisk_status.origin.addr) {
- status->up = true;
- break;
- }
- }
-
+ status->up = (watchers.find(ondisk_status.origin) != watchers.end());
return 0;
}
int max_read = RBD_MAX_KEYS_READ;
bool more = true;
+ std::set<entity_inst_t> watchers;
+ int r = list_watchers(hctx, &watchers);
+ if (r < 0) {
+ return r;
+ }
+
while (more && mirror_images->size() < max_return) {
std::map<std::string, bufferlist> vals;
CLS_LOG(20, "last_read = '%s'", last_read.c_str());
- int r = cls_cxx_map_get_vals(hctx, last_read, IMAGE_KEY_PREFIX, max_read,
- &vals, &more);
+ r = cls_cxx_map_get_vals(hctx, last_read, IMAGE_KEY_PREFIX, max_read, &vals,
+ &more);
if (r < 0) {
CLS_ERR("error reading mirror image directory by name: %s",
cpp_strerror(r).c_str());
(*mirror_images)[image_id] = mirror_image;
cls::rbd::MirrorImageStatus status;
- int r1 = image_status_get(hctx, mirror_image.global_image_id, &status);
+ int r1 = image_status_get(hctx, mirror_image.global_image_id, watchers,
+ &status);
if (r1 < 0) {
continue;
}
int image_status_get_summary(cls_method_context_t hctx,
std::map<cls::rbd::MirrorImageStatusState, int> *states) {
- obj_list_watch_response_t watchers_;
- int r = cls_cxx_list_watchers(hctx, &watchers_);
+ std::set<entity_inst_t> watchers;
+ int r = list_watchers(hctx, &watchers);
if (r < 0) {
- if (r != -ENOENT) {
- CLS_ERR("error listing watchers: '%s'", cpp_strerror(r).c_str());
- }
return r;
}
- set<entity_inst_t> watchers;
- for (auto &w : watchers_.entries) {
- watchers.insert(entity_inst_t(w.name, w.addr));
- }
-
states->clear();
string last_read = IMAGE_KEY_PREFIX;
}
cls::rbd::MirrorImageStatus status;
- image_status_get(hctx, mirror_image.global_image_id, &status);
+ image_status_get(hctx, mirror_image.global_image_id, watchers, &status);
cls::rbd::MirrorImageStatusState state = status.up ? status.state :
cls::rbd::MIRROR_IMAGE_STATUS_STATE_UNKNOWN;
}
int image_status_remove_down(cls_method_context_t hctx) {
- obj_list_watch_response_t watchers_;
- int r = cls_cxx_list_watchers(hctx, &watchers_);
+ std::set<entity_inst_t> watchers;
+ int r = list_watchers(hctx, &watchers);
if (r < 0) {
- if (r != -ENOENT) {
- CLS_ERR("error listing watchers: '%s'", cpp_strerror(r).c_str());
- }
return r;
}
- set<entity_inst_t> watchers;
- for (auto &w : watchers_.entries) {
- watchers.insert(entity_inst_t(w.name, w.addr));
- }
-
string last_read = STATUS_GLOBAL_KEY_PREFIX;
int max_read = RBD_MAX_KEYS_READ;
bool more = true;
return -EINVAL;
}
+ std::set<entity_inst_t> watchers;
+ int r = mirror::list_watchers(hctx, &watchers);
+ if (r < 0) {
+ return r;
+ }
+
cls::rbd::MirrorImageStatus status;
- int r = mirror::image_status_get(hctx, global_image_id, &status);
+ r = mirror::image_status_get(hctx, global_image_id, watchers, &status);
if (r < 0) {
return r;
}