]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: move AuthAuthorizeHandler registry into class
authorSage Weil <sage@newdream.net>
Fri, 7 Oct 2011 23:45:22 +0000 (16:45 -0700)
committerSage Weil <sage@newdream.net>
Fri, 7 Oct 2011 23:47:35 +0000 (16:47 -0700)
Static classes with constructors and destructors are dangerous.  Explicitly
manage these as part of the server components (OSD, MDS).

Fixes: #1608
Signed-off-by: Sage Weil <sage@newdream.net>
src/auth/AuthAuthorizeHandler.cc
src/auth/AuthAuthorizeHandler.h
src/mds/MDS.cc
src/mds/MDS.h
src/osd/OSD.cc
src/osd/OSD.h

index 03f301a861077082f8d718e2088b20990f063998..be364d706228760a023c0ef2ed54bcf9c8eeadfa 100644 (file)
 #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;
 }
index 7837d0ca2ab5a9f6b9d86792d547a5cbccb4b60b..fb5d823bff0fea13e2b180cc83542a80ead2e969 100644 (file)
@@ -30,6 +30,18 @@ struct AuthAuthorizeHandler {
                                 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
index 0d93f061f67a8aeccf25afa3b965efaab6bf66c7..7a8b34a64bd4d7f33ab4eb170391ac1423ba0e23 100644 (file)
@@ -94,6 +94,7 @@ MDS::MDS(const std::string &n, Messenger *m, MonClient *mc) :
   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),
@@ -155,6 +156,8 @@ MDS::MDS(const std::string &n, Messenger *m, MonClient *mc) :
 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; }
@@ -2027,7 +2030,7 @@ bool MDS::ms_verify_authorizer(Connection *con, int peer_type,
   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;
index 9b324b007375499f9be38230094dae7fb0a77b50..4ea26dec20d85121cce38c26248d055efe4336c1 100644 (file)
@@ -137,11 +137,15 @@ class AnchorClient;
 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;
index d86153b1cc500fa3504e18915beb759cab0ef4d4..4d37a6b027bd353793e2097660c38747c8cd89e8 100644 (file)
@@ -514,6 +514,7 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger,
   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),
@@ -575,6 +576,7 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger,
 
 OSD::~OSD()
 {
+  delete authorize_handler_registry;
   delete map_in_progress_cond;
   delete class_handler;
   g_ceph_context->GetPerfCountersCollection()->logger_remove(logger);
@@ -2596,8 +2598,7 @@ bool OSD::ms_verify_authorizer(Connection *con, int peer_type,
                               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;
index 046e8976b30605d5d523631f73e2706f936809c3..3a6437d0ac3111b0b4c332dd76c68753545726cb 100644 (file)
@@ -114,6 +114,8 @@ class Watch;
 class Notification;
 class ReplicatedPG;
 
+class AuthAuthorizeHandlerRegistry;
+
 extern const coll_t meta_coll;
 
 class OSD : public Dispatcher {
@@ -122,6 +124,8 @@ protected:
   Mutex osd_lock;                      // global lock
   SafeTimer timer;    // safe timer (osd_lock)
 
+  AuthAuthorizeHandlerRegistry *authorize_handler_registry;
+
   Messenger   *cluster_messenger;
   Messenger   *client_messenger;
   MonClient   *monc;