#include "AuthSupported.h"
#include "common/Mutex.h"
-static bool _initialized = false;
-static Mutex _lock("auth_service_handler_init");
-static map<int, AuthAuthorizeHandler *> authorizers;
-
-static void _init_authorizers(CephContext *cct)
+AuthAuthorizeHandler *AuthAuthorizeHandlerRegistry::get_handler(int protocol)
{
- if (is_supported_auth(CEPH_AUTH_NONE, cct)) {
- authorizers[CEPH_AUTH_NONE] = new AuthNoneAuthorizeHandler();
+ if (!is_supported_auth(protocol, cct)) {
+ return NULL;
}
- if (is_supported_auth(CEPH_AUTH_CEPHX, cct)) {
- authorizers[CEPH_AUTH_CEPHX] = new CephxAuthorizeHandler();
+
+ Mutex::Locker l(m_lock);
+ map<int,AuthAuthorizeHandler*>::iterator iter = m_authorizers.find(protocol);
+ if (iter != m_authorizers.end())
+ return iter->second;
+
+ switch (protocol) {
+ case CEPH_AUTH_NONE:
+ m_authorizers[protocol] = new AuthNoneAuthorizeHandler();
+ return m_authorizers[protocol];
+
+ case CEPH_AUTH_CEPHX:
+ m_authorizers[protocol] = new CephxAuthorizeHandler();
+ return m_authorizers[protocol];
}
- _initialized = true;
+ return NULL;
}
-AuthAuthorizeHandler *get_authorize_handler(int protocol, CephContext *cct)
+AuthAuthorizeHandlerRegistry::~AuthAuthorizeHandlerRegistry()
{
- Mutex::Locker l(_lock);
- if (!_initialized) {
- _init_authorizers(cct);
- }
-
- map<int, AuthAuthorizeHandler *>::iterator iter = authorizers.find(protocol);
- if (iter != authorizers.end())
- return iter->second;
- return NULL;
+ for (map<int,AuthAuthorizeHandler*>::iterator iter = m_authorizers.begin();
+ iter != m_authorizers.end();
+ ++iter)
+ delete iter->second;
}
AuthCapsInfo& caps_info, uint64_t *auid = NULL) = 0;
};
-extern AuthAuthorizeHandler *get_authorize_handler(int protocol, CephContext *cct);
+class AuthAuthorizeHandlerRegistry {
+ Mutex m_lock;
+ map<int,AuthAuthorizeHandler*> m_authorizers;
+ CephContext *cct;
+
+public:
+ AuthAuthorizeHandlerRegistry(CephContext *cct_)
+ : m_lock("AuthAuthorizeHandlerRegistry::m_lock"), cct(cct_)
+ {}
+ ~AuthAuthorizeHandlerRegistry();
+
+ AuthAuthorizeHandler *get_handler(int protocol);
+};
#endif
Dispatcher(m->cct),
mds_lock("MDS::mds_lock"),
timer(m->cct, mds_lock),
+ authorize_handler_registry(new AuthAuthorizeHandlerRegistry(m->cct)),
name(n),
whoami(-1), incarnation(0),
standby_for_rank(MDSMap::MDS_NO_STANDBY_PREF),
MDS::~MDS() {
Mutex::Locker lock(mds_lock);
+ delete authorize_handler_registry;
+
if (mdcache) { delete mdcache; mdcache = NULL; }
if (mdlog) { delete mdlog; mdlog = NULL; }
if (balancer) { delete balancer; balancer = NULL; }
Mutex::Locker l(mds_lock);
AuthAuthorizeHandler *authorize_handler =
- get_authorize_handler(protocol, g_ceph_context);
+ authorize_handler_registry->get_handler(protocol);
if (!authorize_handler) {
dout(0) << "No AuthAuthorizeHandler found for protocol " << protocol << dendl;
is_valid = false;
class MDSTableServer;
class MDSTableClient;
+class AuthAuthorizeHandlerRegistry;
+
class MDS : public Dispatcher {
public:
Mutex mds_lock;
SafeTimer timer;
+ AuthAuthorizeHandlerRegistry *authorize_handler_registry;
+
string name;
int whoami;
int incarnation;
Dispatcher(external_messenger->cct),
osd_lock("OSD::osd_lock"),
timer(external_messenger->cct, osd_lock),
+ authorize_handler_registry(new AuthAuthorizeHandlerRegistry(external_messenger->cct)),
cluster_messenger(internal_messenger),
client_messenger(external_messenger),
monc(mc),
OSD::~OSD()
{
+ delete authorize_handler_registry;
delete map_in_progress_cond;
delete class_handler;
g_ceph_context->GetPerfCountersCollection()->logger_remove(logger);
int protocol, bufferlist& authorizer_data, bufferlist& authorizer_reply,
bool& isvalid)
{
- AuthAuthorizeHandler *authorize_handler =
- get_authorize_handler(protocol, g_ceph_context);
+ AuthAuthorizeHandler *authorize_handler = authorize_handler_registry->get_handler(protocol);
if (!authorize_handler) {
dout(0) << "No AuthAuthorizeHandler found for protocol " << protocol << dendl;
isvalid = false;
class Notification;
class ReplicatedPG;
+class AuthAuthorizeHandlerRegistry;
+
extern const coll_t meta_coll;
class OSD : public Dispatcher {
Mutex osd_lock; // global lock
SafeTimer timer; // safe timer (osd_lock)
+ AuthAuthorizeHandlerRegistry *authorize_handler_registry;
+
Messenger *cluster_messenger;
Messenger *client_messenger;
MonClient *monc;