auth,common: switch to ceph::mutex, etc
authorKefu Chai <kchai@redhat.com>
Tue, 25 Sep 2018 07:42:25 +0000 (15:42 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 27 Sep 2018 13:34:05 +0000 (21:34 +0800)
in this change, along with LockPolicy, src/common/lock_* are completely
removed.

instead of using LockPolicy based template specialization of LockMutex,
etc, it would be simpler if we can just rely on WITH_SEASTAR
preprocessor macro to tell if we are compiling code for crimson or not.
but please bear in mind, we cannot link against the plain libceph-common
in crimson anymore.

Signed-off-by: Kefu Chai <kchai@redhat.com>
14 files changed:
src/auth/AuthClientHandler.cc
src/auth/AuthClientHandler.h
src/auth/RotatingKeyRing.cc
src/auth/RotatingKeyRing.h
src/auth/cephx/CephxClientHandler.cc
src/auth/cephx/CephxClientHandler.h
src/common/lock_cond.h [deleted file]
src/common/lock_mutex.h [deleted file]
src/common/lock_policy.h [deleted file]
src/common/lock_shared_mutex.h [deleted file]
src/common/lock_shared_ptr.h [deleted file]
src/common/shared_cache.hpp
src/mon/MonClient.cc
src/mon/MonClient.h

index fe0a5238f5495c8a4c9068dc56b443aefef5852d..7f6804b47ba327b0c2ca56a130b132e3680dc5c2 100644 (file)
 #include "none/AuthNoneClientHandler.h"
 
 
-template<ceph::LockPolicy lp>
 AuthClientHandler*
-AuthClientHandler::create(CephContext *cct, int proto,
-                         RotatingKeyRing<lp> *rkeys)
+AuthClientHandler::create(CephContextcct, int proto,
+                         RotatingKeyRingrkeys)
 {
   switch (proto) {
   case CEPH_AUTH_CEPHX:
-    return new CephxClientHandler<lp>(cct, rkeys);
+    return new CephxClientHandler(cct, rkeys);
   case CEPH_AUTH_NONE:
     return new AuthNoneClientHandler{cct};
   default:
     return NULL;
   }
 }
-
-// explicitly instantiate only the classes we need
-#ifdef WITH_SEASTAR
-template AuthClientHandler*
-AuthClientHandler::create<ceph::LockPolicy::SINGLE>(
-  CephContext *cct,
-  int proto,
-  RotatingKeyRing<ceph::LockPolicy::SINGLE> *rkeys);
-#else
-template AuthClientHandler*
-AuthClientHandler::create<ceph::LockPolicy::MUTEX>(
-  CephContext *cct,
-  int proto,
-  RotatingKeyRing<ceph::LockPolicy::MUTEX> *rkeys);
-#endif
index a395c326838f32a0991901f2a0a7d595371490fb..7e9d0cc910da55e7efe8b85b4a9219c4945f8ecd 100644 (file)
 
 
 #include "auth/Auth.h"
-#include "common/lock_policy.h"
 
 class CephContext;
 struct MAuthReply;
-template<ceph::LockPolicy> class RotatingKeyRing;
+class RotatingKeyRing;
 
 class AuthClientHandler {
 protected:
@@ -59,9 +58,7 @@ public:
 
   virtual void set_global_id(uint64_t id) = 0;
 
-  template<ceph::LockPolicy lock_policy>
-  static AuthClientHandler*
-  create(CephContext *cct, int proto, RotatingKeyRing<lock_policy> *rkeys);
+  static AuthClientHandler* create(CephContext* cct, int proto, RotatingKeyRing* rkeys);
 protected:
   virtual void validate_tickets() = 0;
 };
index 6fade65c8a01d6d30a7869bbf3fe1809696a8724..c2d614a1432691663b002526bd8a7237d9c0ac15 100644 (file)
@@ -9,30 +9,26 @@
 #define dout_prefix *_dout << "auth: "
 
 
-template<LockPolicy lp>
-bool RotatingKeyRing<lp>::need_new_secrets() const
+bool RotatingKeyRing::need_new_secrets() const
 {
   std::lock_guard l{lock};
   return secrets.need_new_secrets();
 }
 
-template<LockPolicy lp>
-bool RotatingKeyRing<lp>::need_new_secrets(utime_t now) const
+bool RotatingKeyRing::need_new_secrets(utime_t now) const
 {
   std::lock_guard l{lock};
   return secrets.need_new_secrets(now);
 }
 
-template<LockPolicy lp>
-void RotatingKeyRing<lp>::set_secrets(RotatingSecrets&& s)
+void RotatingKeyRing::set_secrets(RotatingSecrets&& s)
 {
   std::lock_guard l{lock};
   secrets = std::move(s);
   dump_rotating();
 }
 
-template<LockPolicy lp>
-void RotatingKeyRing<lp>::dump_rotating() const
+void RotatingKeyRing::dump_rotating() const
 {
   ldout(cct, 10) << "dump_rotating:" << dendl;
   for (map<uint64_t, ExpiringCryptoKey>::const_iterator iter = secrets.secrets.begin();
@@ -41,15 +37,13 @@ void RotatingKeyRing<lp>::dump_rotating() const
     ldout(cct, 10) << " id " << iter->first << " " << iter->second << dendl;
 }
 
-template<LockPolicy lp>
-bool RotatingKeyRing<lp>::get_secret(const EntityName& name, CryptoKey& secret) const
+bool RotatingKeyRing::get_secret(const EntityName& name, CryptoKey& secret) const
 {
   std::lock_guard l{lock};
   return keyring->get_secret(name, secret);
 }
 
-template<LockPolicy lp>
-bool RotatingKeyRing<lp>::get_service_secret(uint32_t service_id_, uint64_t secret_id,
+bool RotatingKeyRing::get_service_secret(uint32_t service_id_, uint64_t secret_id,
                                         CryptoKey& secret) const
 {
   std::lock_guard l{lock};
@@ -72,15 +66,7 @@ bool RotatingKeyRing<lp>::get_service_secret(uint32_t service_id_, uint64_t secr
   return true;
 }
 
-template<LockPolicy lp>
-KeyRing *RotatingKeyRing<lp>::get_keyring()
+KeyRing* RotatingKeyRing::get_keyring()
 {
   return keyring;
 }
-
-// explicitly instantiate only the classes we need
-#ifdef WITH_SEASTAR
-template class RotatingKeyRing<LockPolicy::SINGLE>;
-#else
-template class RotatingKeyRing<LockPolicy::MUTEX>;
-#endif
index 6d094c22ef7beb46da17d490b231529c091d8af9..04277a8be8502069900a02cb4822890c6e4c978c 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef CEPH_ROTATINGKEYRING_H
 #define CEPH_ROTATINGKEYRING_H
 
-#include "common/lock_mutex.h"
+#include "common/ceph_mutex.h"
 #include "auth/Auth.h"
 
 /*
 class KeyRing;
 class CephContext;
 
-template<LockPolicy lock_policy>
 class RotatingKeyRing : public KeyStore {
   CephContext *cct;
   uint32_t service_id;
   RotatingSecrets secrets;
   KeyRing *keyring;
-  mutable LockMutexT<lock_policy> lock;
+  mutable ceph::mutex lock;
 
 public:
   RotatingKeyRing(CephContext *cct_, uint32_t s, KeyRing *kr) :
     cct(cct_),
     service_id(s),
     keyring(kr),
-    lock(LockMutex<lock_policy>::create("RotatingKeyRing::lock")) {}
+    lock{ceph::make_mutex("RotatingKeyRing::lock")}
+  {}
 
   bool need_new_secrets() const;
   bool need_new_secrets(utime_t now) const;
index 3559fd7372866b281b6741507c77dd7cc8dda631..b4bbdc6cc03b007fe81a832a9aa9fb355f9b7186 100644 (file)
@@ -28,8 +28,7 @@
 #undef dout_prefix
 #define dout_prefix *_dout << "cephx client: "
 
-template<LockPolicy lp>
-int CephxClientHandler<lp>::build_request(bufferlist& bl) const
+int CephxClientHandler::build_request(bufferlist& bl) const
 {
   ldout(cct, 10) << "build_request" << dendl;
 
@@ -97,8 +96,7 @@ int CephxClientHandler<lp>::build_request(bufferlist& bl) const
   return 0;
 }
 
-template<LockPolicy lp>
-bool CephxClientHandler<lp>::_need_tickets() const
+bool CephxClientHandler::_need_tickets() const
 {
   // do not bother (re)requesting tickets if we *only* need the MGR
   // ticket; that can happen during an upgrade and we want to avoid a
@@ -107,8 +105,7 @@ bool CephxClientHandler<lp>::_need_tickets() const
   return need && need != CEPH_ENTITY_TYPE_MGR;
 }
 
-template<LockPolicy lp>
-int CephxClientHandler<lp>::handle_response(int ret, bufferlist::const_iterator& indata)
+int CephxClientHandler::handle_response(int ret, bufferlist::const_iterator& indata)
 {
   ldout(cct, 10) << "handle_response ret = " << ret << dendl;
   
@@ -201,16 +198,14 @@ int CephxClientHandler<lp>::handle_response(int ret, bufferlist::const_iterator&
 }
 
 
-template<LockPolicy lp>
-AuthAuthorizer *CephxClientHandler<lp>::build_authorizer(uint32_t service_id) const
+AuthAuthorizer *CephxClientHandler::build_authorizer(uint32_t service_id) const
 {
   ldout(cct, 10) << "build_authorizer for service " << ceph_entity_type_name(service_id) << dendl;
   return tickets.build_authorizer(service_id);
 }
 
 
-template<LockPolicy lp>
-bool CephxClientHandler<lp>::build_rotating_request(bufferlist& bl) const
+bool CephxClientHandler::build_rotating_request(bufferlist& bl) const
 {
   ldout(cct, 10) << "build_rotating_request" << dendl;
   CephXRequestHeader header;
@@ -219,8 +214,7 @@ bool CephxClientHandler<lp>::build_rotating_request(bufferlist& bl) const
   return true;
 }
 
-template<LockPolicy lp>
-void CephxClientHandler<lp>::prepare_build_request()
+void CephxClientHandler::prepare_build_request()
 {
   ldout(cct, 10) << "validate_tickets: want=" << want << " need=" << need
                 << " have=" << have << dendl;
@@ -231,15 +225,13 @@ void CephxClientHandler<lp>::prepare_build_request()
   ticket_handler = &(tickets.get_handler(CEPH_ENTITY_TYPE_AUTH));
 }
 
-template<LockPolicy lp>
-void CephxClientHandler<lp>::validate_tickets()
+void CephxClientHandler::validate_tickets()
 {
   // lock should be held for write
   tickets.validate_tickets(want, have, need);
 }
 
-template<LockPolicy lp>
-bool CephxClientHandler<lp>::need_tickets()
+bool CephxClientHandler::need_tickets()
 {
   validate_tickets();
 
@@ -250,10 +242,3 @@ bool CephxClientHandler<lp>::need_tickets()
 
   return _need_tickets();
 }
-
-// explicitly instantiate only the classes we need
-#ifdef WITH_SEASTAR
-template class CephxClientHandler<LockPolicy::SINGLE>;
-#else
-template class CephxClientHandler<LockPolicy::MUTEX>;
-#endif
index 7a91e0322c07c858af0bcc4dcd24521c34e3291b..9d821281588d4bf01dde3536bc55a12ae2e11e8e 100644 (file)
@@ -22,7 +22,6 @@
 class CephContext;
 class KeyRing;
 
-template<LockPolicy lock_policy>
 class CephxClientHandler : public AuthClientHandler {
   bool starting;
 
@@ -32,12 +31,12 @@ class CephxClientHandler : public AuthClientHandler {
   CephXTicketManager tickets;
   CephXTicketHandler* ticket_handler;
 
-  RotatingKeyRing<lock_policy> *rotating_secrets;
+  RotatingKeyRingrotating_secrets;
   KeyRing *keyring;
 
 public:
   CephxClientHandler(CephContext *cct_,
-                    RotatingKeyRing<lock_policy> *rsecrets)
+                    RotatingKeyRing *rsecrets)
     : AuthClientHandler(cct_),
       starting(false),
       server_challenge(0),
diff --git a/src/common/lock_cond.h b/src/common/lock_cond.h
deleted file mode 100644 (file)
index 2cf067c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-
-#pragma once
-
-#include "lock_policy.h"
-#include "lock_mutex.h"
-#ifdef NDEBUG
-#include <condition_variable>
-#else
-#include "common/condition_variable_debug.h"
-#endif
-
-class SharedLRUTest;
-
-namespace ceph {
-
-// empty helper class except when the template argument is LockPolicy::MUTEX
-template<LockPolicy lock_policy>
-class LockCond {
-  // lockless condition_variable cannot be represented using
-  // std::condition_variables interfaces.
-};
-
-#ifdef NDEBUG
-template<>
-class LockCond<LockPolicy::MUTEX>
-{
-public:
-  using type = std::condition_variable;
-};
-#else
-template<>
-class LockCond<LockPolicy::MUTEX> {
-public:
-  using type = ceph::condition_variable_debug;
-};
-
-#endif // NDEBUG
-
-template<LockPolicy lp> using LockCondT = typename LockCond<lp>::type;
-
-} // namespace ceph
diff --git a/src/common/lock_mutex.h b/src/common/lock_mutex.h
deleted file mode 100644 (file)
index 8203d8d..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-
-#pragma once
-
-#include "lock_policy.h"
-#ifdef NDEBUG
-#include <mutex>
-#else
-#include "mutex_debug.h"
-#endif
-
-namespace ceph {
-
-// empty helper class except when the template argument is LockPolicy::MUTEX
-template<LockPolicy lp>
-class LockMutex {
-  struct Dummy {
-    void lock() {}
-    bool try_lock() {
-      return true;
-    }
-    void unlock() {}
-    bool is_locked() const {
-      return true;
-    }
-  };
-public:
-  using type = Dummy;
-  // discard the constructor params
-  template<typename... Args>
-  static Dummy create(Args&& ...) {
-    return Dummy{};
-  }
-};
-
-#ifdef NDEBUG
-template<>
-class LockMutex<LockPolicy::MUTEX> {
-public:
-  using type = std::mutex;
-  // discard the constructor params
-  template<typename... Args>
-  static std::mutex create(Args&& ...) {
-    return std::mutex{};
-  }
-};
-#else
-template<>
-class LockMutex<LockPolicy::MUTEX> {
-public:
-  using type = ceph::mutex_debug;
-  template<typename... Args>
-  static ceph::mutex_debug create(Args&& ...args) {
-    return ceph::mutex_debug{std::forward<Args>(args)...};
-  }
-};
-#endif // NDEBUG
-
-template<LockPolicy lp> using LockMutexT = typename LockMutex<lp>::type;
-
-} // namespace ceph
diff --git a/src/common/lock_policy.h b/src/common/lock_policy.h
deleted file mode 100644 (file)
index 0be74a8..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-
-#pragma once
-
-namespace ceph {
-
-enum class LockPolicy {
-  SINGLE,
-  MUTEX,
-};
-
-}
diff --git a/src/common/lock_shared_mutex.h b/src/common/lock_shared_mutex.h
deleted file mode 100644 (file)
index a5b0be1..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-
-#pragma once
-
-#include "lock_policy.h"
-#ifdef NDEBUG
-#include <shared_mutex>
-#else
-#include "shared_mutex_debug.h"
-#endif
-
-namespace ceph {
-
-// empty helper class except when the template argument is LockPolicy::MUTEX
-template<LockPolicy lp>
-class SharedMutex {
-  struct Dummy {
-    // exclusive lock
-    void lock() {}
-    bool try_lock() {
-      return true;
-    }
-    void unlock() {}
-    // shared lock
-    void lock_shared() {}
-    bool try_lock_shared() {
-      return true;
-    }
-    void unlock_shared() {}
-  };
-public:
-  using type = Dummy;
-  template<typename... Args>
-  static Dummy create(Args&& ...) {
-    return Dummy{};
-  }
-};
-
-#ifdef NDEBUG
-template<>
-class SharedMutex<LockPolicy::MUTEX>
-{
-public:
-  using type = std::shared_mutex;
-  // discard the constructor params
-  template<typename... Args>
-  static std::shared_mutex create(Args&&... args) {
-    return std::shared_mutex{};
-  }
-};
-#else
-template<>
-class SharedMutex<LockPolicy::MUTEX> {
-public:
-  using type = ceph::shared_mutex_debug;
-  template<typename... Args>
-  static ceph::shared_mutex_debug create(Args&&... args) {
-    return ceph::shared_mutex_debug{std::forward<Args>(args)...};
-  }
-};
-#endif // NDEBUG
-
-template<LockPolicy lp> using SharedMutexT = typename SharedMutex<lp>::type;
-
-} // namespace ceph
-
diff --git a/src/common/lock_shared_ptr.h b/src/common/lock_shared_ptr.h
deleted file mode 100644 (file)
index e915d7b..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-
-#pragma once
-
-#include "lock_policy.h"
-#include <memory>
-#include <boost/smart_ptr/local_shared_ptr.hpp>
-
-namespace ceph {
-
-template<LockPolicy lock_policy>
-struct SharedPtrTrait {
-  template<class T> using shared_ptr = boost::local_shared_ptr<T>;
-  template<class T> using weak_ptr = boost::weak_ptr<T>;
-};
-
-template<>
-struct SharedPtrTrait<LockPolicy::MUTEX> {
-  template<class T> using shared_ptr = std::shared_ptr<T>;
-  template<class T> using weak_ptr = std::weak_ptr<T>;
-};
-
-}
index 5aa4963722d0a80c128e8a653a88842cdd9be519..283bff401c5aa657554dbef710e3bb57a6dce33f 100644 (file)
 
 #include <map>
 #include <list>
+#ifdef WITH_SEASTAR
+#include <boost/smart_ptr/local_shared_ptr.hpp>
+#else
+#include <memory>
+#endif
+#include "common/ceph_mutex.h"
 #include "common/dout.h"
-#include "common/lock_cond.h"
-#include "common/lock_mutex.h"
-#include "common/lock_policy.h"
-#include "common/lock_shared_ptr.h"
 #include "include/unordered_map.h"
 
 // re-include our assert to clobber the system one; fix dout:
 #include "include/ceph_assert.h"
 
-template <class K, class V,
-         ceph::LockPolicy lock_policy = ceph::LockPolicy::MUTEX>
+template <class K, class V>
 class SharedLRU {
   CephContext *cct;
-  using shared_ptr_trait_t = SharedPtrTrait<lock_policy>;
-  using VPtr = typename shared_ptr_trait_t::template shared_ptr<V>;
-  using WeakVPtr = typename shared_ptr_trait_t::template weak_ptr<V>;
-  LockMutexT<lock_policy> lock;
+#ifdef WITH_SEASTAR
+  using VPtr = boost::local_shared_ptr<V>;
+  using WeakVPtr = boost::weak_ptr<V>;
+#else
+  using VPtr = std::shared_ptr<V>;
+  using WeakVPtr = std::weak_ptr<V>;
+#endif
+  ceph::mutex lock;
   size_t max_size;
-  LockCondT<lock_policy> cond;
+  ceph::condition_variable cond;
   unsigned size;
 public:
   int waiting;
@@ -99,7 +104,7 @@ private:
 public:
   SharedLRU(CephContext *cct = NULL, size_t max_size = 20)
     : cct(cct),
-      lock{LockMutex<lock_policy>::create("SharedLRU::lock")},
+      lock{ceph::make_mutex("SharedLRU::lock")},
       max_size(max_size),
       size(0), waiting(0) {
     contents.rehash(max_size); 
index 356e0cff9237d08a45db6202a5a6790e105d5f1c..058da24d48ba5cfd37d726720eb6eaf7c0e0d69b 100644 (file)
@@ -428,7 +428,7 @@ int MonClient::init()
   }
 
   rotating_secrets.reset(
-    new RotatingKeyRing<LockPolicy::MUTEX>(cct, cct->get_module_type(), keyring.get()));
+    new RotatingKeyRing(cct, cct->get_module_type(), keyring.get()));
 
   initialized = true;
 
@@ -1230,7 +1230,7 @@ void MonConnection::start(epoch_t epoch,
 int MonConnection::handle_auth(MAuthReply* m,
                               const EntityName& entity_name,
                               uint32_t want_keys,
-                              RotatingKeyRing<LockPolicy::MUTEX>* keyring)
+                              RotatingKeyRing* keyring)
 {
   if (state == State::NEGOTIATING) {
     int r = _negotiate(m, entity_name, want_keys, keyring);
@@ -1249,7 +1249,7 @@ int MonConnection::handle_auth(MAuthReply* m,
 int MonConnection::_negotiate(MAuthReply *m,
                              const EntityName& entity_name,
                              uint32_t want_keys,
-                             RotatingKeyRing<LockPolicy::MUTEX>* keyring)
+                             RotatingKeyRing* keyring)
 {
   if (auth && (int)m->protocol == auth->get_protocol()) {
     // good, negotiation completed
index fd3339a788e2276322cc54eef0ac8a1d80fc444a..baeedf5d60f61690560211830e01003784d55d80 100644 (file)
@@ -21,7 +21,6 @@
 #include "MonMap.h"
 #include "MonSub.h"
 
-#include "common/lock_policy.h"
 #include "common/Timer.h"
 #include "common/Finisher.h"
 #include "common/config.h"
@@ -38,7 +37,7 @@ class AuthAuthorizer;
 class AuthMethodList;
 class AuthClientHandler;
 class KeyRing;
-template<LockPolicy> class RotatingKeyRing;
+class RotatingKeyRing;
 
 struct MonClientPinger : public Dispatcher {
 
@@ -108,7 +107,7 @@ public:
   int handle_auth(MAuthReply *m,
                  const EntityName& entity_name,
                  uint32_t want_keys,
-                 RotatingKeyRing<LockPolicy::MUTEX>* keyring);
+                 RotatingKeyRing* keyring);
   int authenticate(MAuthReply *m);
   void start(epoch_t epoch,
              const EntityName& entity_name,
@@ -128,7 +127,7 @@ private:
   int _negotiate(MAuthReply *m,
                 const EntityName& entity_name,
                 uint32_t want_keys,
-                RotatingKeyRing<LockPolicy::MUTEX>* keyring);
+                RotatingKeyRing* keyring);
 
 private:
   CephContext *cct;
@@ -276,7 +275,7 @@ public:
   }
   
   std::unique_ptr<KeyRing> keyring;
-  std::unique_ptr<RotatingKeyRing<LockPolicy::MUTEX>> rotating_secrets;
+  std::unique_ptr<RotatingKeyRing> rotating_secrets;
 
  public:
   explicit MonClient(CephContext *cct_);