mirror of
https://github.com/ceph/ceph
synced 2024-12-29 06:52:35 +00:00
Merge pull request #8162 from rjfd/wip-15142
rbd-mirror: use the mirroring directory to detect candidate images Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
commit
22cac93ec7
@ -135,8 +135,14 @@ TestPoolWatcher() : m_lock("TestPoolWatcherLock"),
|
||||
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;
|
||||
}
|
||||
@ -168,8 +174,14 @@ TestPoolWatcher() : m_lock("TestPoolWatcherLock"),
|
||||
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;
|
||||
}
|
||||
@ -214,6 +226,8 @@ TEST_F(TestPoolWatcher, ReplicatedPools) {
|
||||
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();
|
||||
@ -249,6 +263,8 @@ TEST_F(TestPoolWatcher, CachePools) {
|
||||
check_images();
|
||||
create_image(base1);
|
||||
check_images();
|
||||
create_image(base1, false);
|
||||
check_images();
|
||||
|
||||
create_pool(false, peer_t(), &base2);
|
||||
create_cache_pool(base2, &cache2);
|
||||
|
@ -25,7 +25,7 @@ using std::vector;
|
||||
|
||||
using librados::Rados;
|
||||
using librados::IoCtx;
|
||||
using librbd::cls_client::dir_list;
|
||||
using librbd::cls_client::mirror_image_list;
|
||||
|
||||
namespace rbd {
|
||||
namespace mirror {
|
||||
@ -93,8 +93,6 @@ void PoolWatcher::refresh_images(bool reschedule)
|
||||
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) {
|
||||
@ -107,34 +105,19 @@ void PoolWatcher::refresh_images(bool reschedule)
|
||||
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);
|
||||
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 (r > 0) {
|
||||
images[pool_id] = std::move(image_ids);
|
||||
if (!image_ids.empty()) {
|
||||
std::set<std::string> image_set(image_ids.begin(), image_ids.end());
|
||||
images[pool_id] = std::move(image_set);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user