]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h"
5 #include "common/debug.h"
6 #include "common/errno.h"
7 #include "cls/rbd/cls_rbd_client.h"
8 #include "librbd/Utils.h"
11 #define dout_context g_ceph_context
12 #define dout_subsys ceph_subsys_rbd_mirror
14 #define dout_prefix *_dout << "rbd::mirror::pool_watcher::RefreshImagesRequest " \
15 << this << " " << __func__ << ": "
19 namespace pool_watcher
{
21 static const uint32_t MAX_RETURN
= 1024;
23 using librbd::util::create_rados_callback
;
26 void RefreshImagesRequest
<I
>::send() {
32 void RefreshImagesRequest
<I
>::mirror_image_list() {
35 librados::ObjectReadOperation op
;
36 librbd::cls_client::mirror_image_list_start(&op
, m_start_after
, MAX_RETURN
);
38 librados::AioCompletion
*aio_comp
= create_rados_callback
<
39 RefreshImagesRequest
<I
>,
40 &RefreshImagesRequest
<I
>::handle_mirror_image_list
>(this);
41 int r
= m_remote_io_ctx
.aio_operate(RBD_MIRRORING
, aio_comp
, &op
, &m_out_bl
);
47 void RefreshImagesRequest
<I
>::handle_mirror_image_list(int r
) {
48 dout(10) << "r=" << r
<< dendl
;
50 std::map
<std::string
, std::string
> ids
;
52 bufferlist::iterator it
= m_out_bl
.begin();
53 r
= librbd::cls_client::mirror_image_list_finish(&it
, &ids
);
56 if (r
< 0 && r
!= -ENOENT
) {
57 derr
<< "failed to list mirrored images: " << cpp_strerror(r
) << dendl
;
62 // store as global -> local image ids
63 for (auto &id
: ids
) {
64 m_image_ids
->emplace(id
.second
, id
.first
);
67 if (ids
.size() == MAX_RETURN
) {
68 m_start_after
= ids
.rbegin()->first
;
77 void RefreshImagesRequest
<I
>::finish(int r
) {
78 dout(10) << "r=" << r
<< dendl
;
80 m_on_finish
->complete(r
);
84 } // namespace pool_watcher
88 template class rbd::mirror::pool_watcher::RefreshImagesRequest
<librbd::ImageCtx
>;