]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: RevokeThread is now a part of RGWKeystoneTokenCache.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 4 Apr 2016 17:27:50 +0000 (19:27 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 2 Jun 2016 13:12:10 +0000 (15:12 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_keystone.cc
src/rgw/rgw_keystone.h

index 619fd29765c3f6299f9bea7755f00a158625762d..7d261dc028eb9dd27ba940fb43eb4027670f81d5 100644 (file)
 #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
index 18ee53bac85a6ff0220564478ea95ee6364cbd86..10e8dd0ef937e5a413d44978c33c5be6e81338c9 100644 (file)
@@ -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<string>::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<string, token_entry> tokens;
-  list<string> tokens_lru;
+  std::string admin_token_id;
+  std::map<std::string, token_entry> tokens;
+  std::list<std::string> 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;
 };