]>
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 ft=cpp
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 lderr(cct
) << "RGWRealmWatcher::handle_error oid=" << watch_oid
<< " err=" << err
<< dendl
;
75 if (cookie
!= watch_handle
)
81 int RGWRealmWatcher::watch_start(const RGWRealm
& realm
)
83 // initialize a Rados client
84 int r
= rados
.init_with_context(cct
);
86 lderr(cct
) << "Rados client initialization failed with "
87 << cpp_strerror(-r
) << dendl
;
92 lderr(cct
) << "Rados client connection failed with "
93 << cpp_strerror(-r
) << dendl
;
97 // open an IoCtx for the realm's pool
98 rgw_pool
pool(realm
.get_pool(cct
));
99 r
= rgw_init_ioctx(&rados
, pool
, pool_ctx
);
101 lderr(cct
) << "Failed to open pool " << pool
102 << " with " << cpp_strerror(-r
) << dendl
;
107 // register a watch on the realm's control object
108 auto oid
= realm
.get_control_oid();
109 r
= pool_ctx
.watch2(oid
, &watch_handle
, this);
111 lderr(cct
) << "Failed to watch " << oid
112 << " with " << cpp_strerror(-r
) << dendl
;
118 ldout(cct
, 10) << "Watching " << oid
<< dendl
;
119 std::swap(watch_oid
, oid
);
123 int RGWRealmWatcher::watch_restart()
125 ceph_assert(!watch_oid
.empty());
126 int r
= pool_ctx
.unwatch2(watch_handle
);
128 lderr(cct
) << "Failed to unwatch on " << watch_oid
129 << " with " << cpp_strerror(-r
) << dendl
;
131 r
= pool_ctx
.watch2(watch_oid
, &watch_handle
, this);
133 lderr(cct
) << "Failed to restart watch on " << watch_oid
134 << " with " << cpp_strerror(-r
) << dendl
;
141 void RGWRealmWatcher::watch_stop()
143 if (!watch_oid
.empty()) {
144 pool_ctx
.unwatch2(watch_handle
);