int order = 0;
ASSERT_EQ(0, librbd::create(ioctx, name.c_str(), 1 << 22, false,
features, &order, 0, 0));
- if (mirrored)
+ if (mirrored) {
+ librbd::Image image;
+ librbd::RBD rbd;
+ rbd.open(ioctx, image, name.c_str());
+ image.mirror_image_enable();
+ image.close();
m_mirrored_images[ioctx.get_id()].insert(get_image_id(&ioctx, name));
+ }
if (image_name != nullptr)
*image_name = name;
}
int order = 0;
librbd::clone(pioctx, parent_image_name.c_str(), snap_name.c_str(),
cioctx, name.c_str(), features, &order, 0, 0);
- if (mirrored)
+ if (mirrored) {
+ librbd::Image image;
+ librbd::RBD rbd;
+ rbd.open(cioctx, image, name.c_str());
+ image.mirror_image_enable();
+ image.close();
m_mirrored_images[cioctx.get_id()].insert(get_image_id(&cioctx, name));
+ }
if (image_name != nullptr)
*image_name = name;
}
check_images();
clone_image(first_pool, parent_image, first_pool, true, &parent_image2);
check_images();
+ create_image(first_pool, false);
+ check_images();
create_pool(false, peer_t(), &local_pool);
check_images();
check_images();
create_image(base1);
check_images();
+ create_image(base1, false);
+ check_images();
create_pool(false, peer_t(), &base2);
create_cache_pool(base2, &cache2);
using librados::Rados;
using librados::IoCtx;
-using librbd::cls_client::dir_list;
+using librbd::cls_client::mirror_image_list;
namespace rbd {
namespace mirror {
continue;
}
- // TODO: read mirrored images from mirroring settings object. For
- // now just treat all images in a pool with mirroring enabled as mirrored
rbd_mirror_mode_t mirror_mode;
r = librbd::mirror_mode_get(ioctx, &mirror_mode);
if (r < 0) {
continue;
}
- set<string> image_ids;
-
// only format 2 images can be mirrored, so only check the format
// 2 rbd_directory structure
- int max_read = 1024;
- string last_read = "";
- do {
- map<string, string> pool_images;
- r = dir_list(&ioctx, RBD_DIRECTORY,
- last_read, max_read, &pool_images);
- if (r == -ENOENT)
- r = 0;
- if (r < 0) {
- derr << "error listing images in pool " << pool_name << ": "
- << cpp_strerror(r) << dendl;
- continue;
- }
- for (auto& pair : pool_images) {
- image_ids.insert(pair.second);
- }
- if (!pool_images.empty()) {
- last_read = pool_images.rbegin()->first;
- }
- r = pool_images.size();
- } while (r == max_read);
-
- if (r > 0) {
- images[pool_id] = std::move(image_ids);
+ std::vector<std::string> image_ids;
+ r = mirror_image_list(&ioctx, &image_ids);
+ if (r < 0) {
+ derr << "error listing mirrored images in pool " << pool_name << ": "
+ << cpp_strerror(r) << dendl;
+ continue;
+ }
+
+ if (!image_ids.empty()) {
+ std::set<std::string> image_set(image_ids.begin(), image_ids.end());
+ images[pool_id] = std::move(image_set);
}
}