#include "none/AuthNoneClientHandler.h"
-template<ceph::LockPolicy lp>
AuthClientHandler*
-AuthClientHandler::create(CephContext *cct, int proto,
- RotatingKeyRing<lp> *rkeys)
+AuthClientHandler::create(CephContext* cct, int proto,
+ RotatingKeyRing* rkeys)
{
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
#include "auth/Auth.h"
-#include "common/lock_policy.h"
class CephContext;
struct MAuthReply;
-template<ceph::LockPolicy> class RotatingKeyRing;
+class RotatingKeyRing;
class AuthClientHandler {
protected:
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;
};
#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();
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};
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
#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;
#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;
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
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;
}
-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;
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;
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();
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
class CephContext;
class KeyRing;
-template<LockPolicy lock_policy>
class CephxClientHandler : public AuthClientHandler {
bool starting;
CephXTicketManager tickets;
CephXTicketHandler* ticket_handler;
- RotatingKeyRing<lock_policy> *rotating_secrets;
+ RotatingKeyRing* rotating_secrets;
KeyRing *keyring;
public:
CephxClientHandler(CephContext *cct_,
- RotatingKeyRing<lock_policy> *rsecrets)
+ RotatingKeyRing *rsecrets)
: AuthClientHandler(cct_),
starting(false),
server_challenge(0),
+++ /dev/null
-// -*- 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
+++ /dev/null
-// -*- 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
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-
-#pragma once
-
-namespace ceph {
-
-enum class LockPolicy {
- SINGLE,
- MUTEX,
-};
-
-}
+++ /dev/null
-// -*- 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
-
+++ /dev/null
-// -*- 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>;
-};
-
-}
#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;
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);
}
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;
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);
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
#include "MonMap.h"
#include "MonSub.h"
-#include "common/lock_policy.h"
#include "common/Timer.h"
#include "common/Finisher.h"
#include "common/config.h"
class AuthMethodList;
class AuthClientHandler;
class KeyRing;
-template<LockPolicy> class RotatingKeyRing;
+class RotatingKeyRing;
struct MonClientPinger : public Dispatcher {
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,
int _negotiate(MAuthReply *m,
const EntityName& entity_name,
uint32_t want_keys,
- RotatingKeyRing<LockPolicy::MUTEX>* keyring);
+ RotatingKeyRing* keyring);
private:
CephContext *cct;
}
std::unique_ptr<KeyRing> keyring;
- std::unique_ptr<RotatingKeyRing<LockPolicy::MUTEX>> rotating_secrets;
+ std::unique_ptr<RotatingKeyRing> rotating_secrets;
public:
explicit MonClient(CephContext *cct_);