]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_realm_watcher.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "common/errno.h"
6 #include "rgw_realm_watcher.h"
10 #define dout_subsys ceph_subsys_rgw
13 #define dout_prefix (*_dout << "rgw realm watcher: ")
16 RGWRealmWatcher::RGWRealmWatcher(CephContext
* cct
, const RGWRealm
& realm
)
19 // no default realm, nothing to watch
20 if (realm
.get_id().empty()) {
21 ldout(cct
, 4) << "No realm, disabling dynamic reconfiguration." << dendl
;
25 // establish the watch on RGWRealm
26 int r
= watch_start(realm
);
28 lderr(cct
) << "Failed to establish a watch on RGWRealm, "
29 "disabling dynamic reconfiguration." << dendl
;
34 RGWRealmWatcher::~RGWRealmWatcher()
39 void RGWRealmWatcher::add_watcher(RGWRealmNotify type
, Watcher
& watcher
)
41 watchers
.emplace(type
, watcher
);
44 void RGWRealmWatcher::handle_notify(uint64_t notify_id
, uint64_t cookie
,
45 uint64_t notifier_id
, bufferlist
& bl
)
47 if (cookie
!= watch_handle
)
50 // send an empty notify ack
52 pool_ctx
.notify_ack(watch_oid
, notify_id
, cookie
, reply
);
57 RGWRealmNotify notify
;
59 auto watcher
= watchers
.find(notify
);
60 if (watcher
== watchers
.end()) {
61 lderr(cct
) << "Failed to find a watcher for notify type "
62 << static_cast<int>(notify
) << dendl
;
65 watcher
->second
.handle_notify(notify
, p
);
67 } catch (const buffer::error
&e
) {
68 lderr(cct
) << "Failed to decode realm notifications." << dendl
;
72 void RGWRealmWatcher::handle_error(uint64_t cookie
, int err
)
74 if (cookie
!= watch_handle
)
77 if (err
== -ENOTCONN
) {
78 ldout(cct
, 4) << "Disconnected watch on " << watch_oid
<< dendl
;
83 int RGWRealmWatcher::watch_start(const RGWRealm
& realm
)
85 // initialize a Rados client
86 int r
= rados
.init_with_context(cct
);
88 lderr(cct
) << "Rados client initialization failed with "
89 << cpp_strerror(-r
) << dendl
;
94 lderr(cct
) << "Rados client connection failed with "
95 << cpp_strerror(-r
) << dendl
;
99 // open an IoCtx for the realm's pool
100 rgw_pool
pool(realm
.get_pool(cct
));
101 r
= rgw_init_ioctx(&rados
, pool
, pool_ctx
);
103 lderr(cct
) << "Failed to open pool " << pool
104 << " with " << cpp_strerror(-r
) << dendl
;
109 // register a watch on the realm's control object
110 auto oid
= realm
.get_control_oid();
111 r
= pool_ctx
.watch2(oid
, &watch_handle
, this);
113 lderr(cct
) << "Failed to watch " << oid
114 << " with " << cpp_strerror(-r
) << dendl
;
120 ldout(cct
, 10) << "Watching " << oid
<< dendl
;
121 std::swap(watch_oid
, oid
);
125 int RGWRealmWatcher::watch_restart()
127 ceph_assert(!watch_oid
.empty());
128 int r
= pool_ctx
.unwatch2(watch_handle
);
130 lderr(cct
) << "Failed to unwatch on " << watch_oid
131 << " with " << cpp_strerror(-r
) << dendl
;
133 r
= pool_ctx
.watch2(watch_oid
, &watch_handle
, this);
135 lderr(cct
) << "Failed to restart watch on " << watch_oid
136 << " with " << cpp_strerror(-r
) << dendl
;
143 void RGWRealmWatcher::watch_stop()
145 if (!watch_oid
.empty()) {
146 pool_ctx
.unwatch2(watch_handle
);