From b77e08ced86f5b64c7a9ce9da0a8ecd9f8bc17a0 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Mon, 4 Apr 2016 19:27:50 +0200 Subject: [PATCH] rgw: RevokeThread is now a part of RGWKeystoneTokenCache. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_keystone.cc | 33 ++++++++++++-------------------- src/rgw/rgw_keystone.h | 42 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/rgw/rgw_keystone.cc b/src/rgw/rgw_keystone.cc index 619fd29765c3f..7d261dc028eb9 100644 --- a/src/rgw/rgw_keystone.cc +++ b/src/rgw/rgw_keystone.cc @@ -13,11 +13,7 @@ #include "rgw_keystone.h" #include "common/ceph_crypto_cms.h" #include "common/armor.h" - -#if 0 -// FIXME -#include "rgw_swift.h" -#endif +#include "common/Cond.h" #define dout_subsys ceph_subsys_rgw @@ -299,11 +295,7 @@ void RGWKeystoneTokenCache::invalidate(const string& token_id) tokens.erase(iter); } - -#if 0 -//FIXME -typedef RGWPostHTTPData RGWGetRevokedTokens; -int RGWSwift::check_revoked() +int RGWKeystoneTokenCache::RevokeThread::check_revoked() { string url; string token; @@ -311,10 +303,10 @@ int RGWSwift::check_revoked() bufferlist bl; RGWGetRevokedTokens req(cct, &bl); - if (get_keystone_admin_token(token) < 0) { + if (RGWSwift::get_keystone_admin_token(cct, token) < 0) { return -EINVAL; } - if (get_keystone_url(url) < 0) { + if (RGWSwift::get_keystone_url(cct, url) < 0) { return -EINVAL; } req.append_header("X-Auth-Token", token); @@ -347,7 +339,7 @@ int RGWSwift::check_revoked() if (iter.end()) { ldout(cct, 0) << "revoked tokens response is missing signed section" << dendl; return -EINVAL; - } + } JSONObj *signed_obj = *iter; @@ -395,39 +387,38 @@ int RGWSwift::check_revoked() } string token_id = token->get_data(); - RGWKeystoneTokenCache::get_instance().invalidate(token_id); + cache->invalidate(token_id); } return 0; } -bool RGWSwift::going_down() +bool RGWKeystoneTokenCache::going_down() const { return (down_flag.read() != 0); } -void *RGWSwift::KeystoneRevokeThread::entry() { +void *RGWKeystoneTokenCache::RevokeThread::entry() { do { dout(2) << "keystone revoke thread: start" << dendl; - int r = swift->check_revoked(); + int r = check_revoked(); if (r < 0) { dout(0) << "ERROR: keystone revocation processing returned error r=" << r << dendl; } - if (swift->going_down()) + if (cache->going_down()) break; lock.Lock(); cond.WaitInterval(cct, lock, utime_t(cct->_conf->rgw_keystone_revocation_interval, 0)); lock.Unlock(); - } while (!swift->going_down()); + } while (!cache->going_down()); return NULL; } -void RGWSwift::KeystoneRevokeThread::stop() +void RGWKeystoneTokenCache::RevokeThread::stop() { Mutex::Locker l(lock); cond.Signal(); } -#endif diff --git a/src/rgw/rgw_keystone.h b/src/rgw/rgw_keystone.h index 18ee53bac85a6..10e8dd0ef937e 100644 --- a/src/rgw/rgw_keystone.h +++ b/src/rgw/rgw_keystone.h @@ -5,6 +5,8 @@ #define CEPH_RGW_KEYSTONE_H #include "rgw_common.h" +#include "rgw_http_client.h" +#include "common/Cond.h" int rgw_open_cms_envelope(CephContext *cct, const std::string& src, @@ -102,21 +104,52 @@ class RGWKeystoneTokenCache { list::iterator lru_iter; }; + atomic_t down_flag; + + class RevokeThread : public Thread { + friend class RGWKeystoneTokenCache; + typedef RGWPostHTTPData RGWGetRevokedTokens; + + CephContext * const cct; + RGWKeystoneTokenCache * const cache; + Mutex lock; + Cond cond; + + RevokeThread(CephContext * const cct, RGWKeystoneTokenCache * cache) + : cct(cct), + cache(cache), + lock("RGWKeystoneTokenCache::RevokeThread") { + } + void *entry(); + void stop(); + int check_revoked(); + } revocator; + CephContext * const cct; - string admin_token_id; - map tokens; - list tokens_lru; + std::string admin_token_id; + std::map tokens; + std::list tokens_lru; Mutex lock; const size_t max; RGWKeystoneTokenCache() - : cct(g_ceph_context), + : revocator(g_ceph_context, this), + cct(g_ceph_context), lock("RGWKeystoneTokenCache", true /* recursive */), max(cct->_conf->rgw_keystone_token_cache_size) { + /* The thread name has been kept for backward compliance. */ + revocator.create("rgw_swift_k_rev"); } + ~RGWKeystoneTokenCache() { + down_flag.set(1); + + revocator.stop(); + revocator.join(); + } + public: RGWKeystoneTokenCache(const RGWKeystoneTokenCache&) = delete; void operator=(const RGWKeystoneTokenCache&) = delete; @@ -128,6 +161,7 @@ public: void add(const string& token_id, const KeystoneToken& token); void add_admin(const KeystoneToken& token); void invalidate(const string& token_id); + bool going_down() const; }; -- 2.39.5