]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: allocate authorizers once
authorYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 30 Oct 2009 21:02:56 +0000 (14:02 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 30 Oct 2009 21:02:56 +0000 (14:02 -0700)
src/Makefile.am
src/auth/AuthAuthorizeHandler.cc
src/auth/AuthServiceHandler.cc
src/auth/AuthSupported.cc [new file with mode: 0644]
src/auth/AuthSupported.h [new file with mode: 0644]

index 472de52a052c51da1e4210ef097b0120e360fc63..a7c25a08a553205c13762d364643551e8c47c5c7 100644 (file)
@@ -293,6 +293,7 @@ libcommon_a_SOURCES = \
 libcommon_files = \
        auth/AuthAuthorizeHandler.cc \
        auth/AuthClientHandler.cc \
+       auth/AuthSupported.cc \
        auth/cephx/CephxAuthorizeHandler.cc \
        auth/cephx/CephxClientHandler.cc \
        auth/cephx/CephxProtocol.cc \
@@ -415,6 +416,7 @@ noinst_HEADERS = \
        auth/none/AuthNoneServiceHandler.h\
        auth/none/AuthNoneProtocol.h\
        auth/Auth.h\
+       auth/AuthSupported.h\
        auth/AuthServiceHandler.h\
        auth/AuthAuthorizeHandler.h\
        auth/KeyRing.h\
index 19c61dbcc4a7e3742b26c3b7c2763b1a67c6ef99..ea3f4ed7386039199f46d4c3601879734e702a4e 100644 (file)
@@ -2,16 +2,33 @@
 #include "AuthAuthorizeHandler.h"
 #include "cephx/CephxAuthorizeHandler.h"
 #include "none/AuthNoneAuthorizeHandler.h"
+#include "AuthSupported.h"
 
+static bool _initialized = false;
+static Mutex _lock("auth_service_handler_init");
+static map<int, AuthAuthorizeHandler *> authorizers;
+
+static void _init_authorizers(void)
+{
+  if (is_supported_auth(CEPH_AUTH_NONE)) {
+    authorizers[CEPH_AUTH_NONE] = new AuthNoneAuthorizeHandler(); 
+  }
+  if (is_supported_auth(CEPH_AUTH_CEPHX)) {
+    authorizers[CEPH_AUTH_CEPHX] = new CephxAuthorizeHandler(); 
+  }
+  _initialized = true;
+}
 
 AuthAuthorizeHandler *get_authorize_handler(int protocol)
 {
-  switch (protocol) {
-    case CEPH_AUTH_NONE:
-      return new AuthNoneAuthorizeHandler();
-    case CEPH_AUTH_CEPHX:
-      return new CephxAuthorizeHandler();
-    default:
-      return NULL;
+  Mutex::Locker l(_lock);
+  if (!_initialized) {
+   _init_authorizers();
   }
+
+  map<int, AuthAuthorizeHandler *>::iterator iter = authorizers.find(protocol);
+  if (iter != authorizers.end())
+    return iter->second;
+
+  return NULL;
 }
index 1848075358d35a961ef2ea0d11678377b5815ff6..9430d98f644cb0a3e5cbcb2cabf122ade766ed7c 100644 (file)
 #include "AuthServiceHandler.h"
 #include "cephx/CephxServiceHandler.h"
 #include "none/AuthNoneServiceHandler.h"
-#include "common/Mutex.h"
-#include "include/str_list.h"
+#include "AuthSupported.h"
 #include "config.h"
 
 #define DOUT_SUBSYS auth
 
-static bool _supported_initialized = false;
-static Mutex _supported_lock("auth_service_handler_init");
-static map<int, bool> auth_supported;
-
-static void _init_supported(void)
-{
-  string str = g_conf.supported_auth;
-  list<string> sup_list;
-  get_str_list(str, sup_list);
-  for (list<string>::iterator iter = sup_list.begin(); iter != sup_list.end(); ++iter) {
-    if (iter->compare("cephx") == 0) {
-      dout(10) << "supporting cephx auth protocol" << dendl;
-      auth_supported[CEPH_AUTH_CEPHX] = true;
-    } else if (iter->compare("none") == 0) {
-      auth_supported[CEPH_AUTH_NONE] = true;
-      dout(10) << "supporting *none* auth protocol" << dendl;
-    } else {
-      dout(0) << "WARNING: unknown auth protocol defined: " << *iter << dendl;
-    }
-  }
-  _supported_initialized = true;
-}
 
 AuthServiceHandler *get_auth_service_handler(KeyServer *ks, set<__u32>& supported)
 {
-  {
-    Mutex::Locker lock(_supported_lock);
-    if (!_supported_initialized) {
-      _init_supported();
-    }
-  }
-  if (auth_supported[CEPH_AUTH_CEPHX] && supported.count(CEPH_AUTH_CEPHX))
+  if (is_supported_auth(CEPH_AUTH_CEPHX) && supported.count(CEPH_AUTH_CEPHX))
     return new CephxServiceHandler(ks);
-  if (auth_supported[CEPH_AUTH_NONE] && supported.count(CEPH_AUTH_NONE))
+  if (is_supported_auth(CEPH_AUTH_NONE) && supported.count(CEPH_AUTH_NONE))
     return new AuthNoneServiceHandler();
   return NULL;
 }
diff --git a/src/auth/AuthSupported.cc b/src/auth/AuthSupported.cc
new file mode 100644 (file)
index 0000000..fb9a064
--- /dev/null
@@ -0,0 +1,56 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#include "common/Mutex.h"
+#include "include/str_list.h"
+#include "config.h"
+
+#define DOUT_SUBSYS auth
+
+static bool _supported_initialized = false;
+static Mutex _supported_lock("auth_service_handler_init");
+static map<int, bool> auth_supported;
+
+static void _init_supported(void)
+{
+  string str = g_conf.supported_auth;
+  list<string> sup_list;
+  get_str_list(str, sup_list);
+  for (list<string>::iterator iter = sup_list.begin(); iter != sup_list.end(); ++iter) {
+    if (iter->compare("cephx") == 0) {
+      dout(10) << "supporting cephx auth protocol" << dendl;
+      auth_supported[CEPH_AUTH_CEPHX] = true;
+    } else if (iter->compare("none") == 0) {
+      auth_supported[CEPH_AUTH_NONE] = true;
+      dout(10) << "supporting *none* auth protocol" << dendl;
+    } else {
+      dout(0) << "WARNING: unknown auth protocol defined: " << *iter << dendl;
+    }
+  }
+  _supported_initialized = true;
+}
+
+
+bool is_supported_auth(int auth_type)
+{
+  {
+    Mutex::Locker lock(_supported_lock);
+    if (!_supported_initialized) {
+      _init_supported();
+    }
+  }
+  return auth_supported[auth_type];
+}
+
+
diff --git a/src/auth/AuthSupported.h b/src/auth/AuthSupported.h
new file mode 100644 (file)
index 0000000..5544e09
--- /dev/null
@@ -0,0 +1,22 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#ifndef __AUTHSUPPORTED_H
+#define __AUTHSUPPORTED_H
+
+#include <map>
+
+extern bool is_supported_auth(int auth_type);
+
+#endif