1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "ClusterWatcher.h"
5 #include "common/debug.h"
6 #include "common/errno.h"
7 #include "librbd/internal.h"
8 #include "librbd/api/Mirror.h"
10 #define dout_context g_ceph_context
11 #define dout_subsys ceph_subsys_rbd_mirror
13 #define dout_prefix *_dout << "rbd::mirror::ClusterWatcher:" << this << " " \
20 using std::unique_ptr
;
23 using librados::Rados
;
24 using librados::IoCtx
;
29 ClusterWatcher::ClusterWatcher(RadosRef cluster
, Mutex
&lock
) :
35 const ClusterWatcher::PoolPeers
& ClusterWatcher::get_pool_peers() const
37 assert(m_lock
.is_locked());
41 void ClusterWatcher::refresh_pools()
43 dout(20) << "enter" << dendl
;
47 read_pool_peers(&pool_peers
, &pool_names
);
49 Mutex::Locker
l(m_lock
);
50 m_pool_peers
= pool_peers
;
51 // TODO: perhaps use a workqueue instead, once we get notifications
52 // about config changes for existing pools
55 void ClusterWatcher::read_pool_peers(PoolPeers
*pool_peers
,
56 PoolNames
*pool_names
)
58 list
<pair
<int64_t, string
> > pools
;
59 int r
= m_cluster
->pool_list2(pools
);
61 derr
<< "error listing pools: " << cpp_strerror(r
) << dendl
;
65 for (auto kv
: pools
) {
66 int64_t pool_id
= kv
.first
;
67 string pool_name
= kv
.second
;
69 r
= m_cluster
->pool_get_base_tier(pool_id
, &base_tier
);
71 dout(10) << "pool " << pool_name
<< " no longer exists" << dendl
;
74 derr
<< "Error retrieving base tier for pool " << pool_name
<< dendl
;
77 if (pool_id
!= base_tier
) {
78 // pool is a cache; skip it
83 r
= m_cluster
->ioctx_create2(pool_id
, ioctx
);
85 dout(10) << "pool " << pool_id
<< " no longer exists" << dendl
;
88 derr
<< "Error accessing pool " << pool_name
<< cpp_strerror(r
) << dendl
;
92 rbd_mirror_mode_t mirror_mode
;
93 r
= librbd::api::Mirror
<>::mode_get(ioctx
, &mirror_mode
);
95 derr
<< "could not tell whether mirroring was enabled for " << pool_name
96 << " : " << cpp_strerror(r
) << dendl
;
99 if (mirror_mode
== RBD_MIRROR_MODE_DISABLED
) {
100 dout(10) << "mirroring is disabled for pool " << pool_name
<< dendl
;
104 vector
<librbd::mirror_peer_t
> configs
;
105 r
= librbd::api::Mirror
<>::peer_list(ioctx
, &configs
);
107 derr
<< "error reading mirroring config for pool " << pool_name
108 << cpp_strerror(r
) << dendl
;
112 pool_peers
->insert({pool_id
, Peers
{configs
.begin(), configs
.end()}});
113 pool_names
->insert(pool_name
);
117 } // namespace mirror