]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/immutable_object_cache: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Sun, 7 Jul 2019 04:45:01 +0000 (12:45 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:20 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/immutable_object_cache/test_common.h
src/tools/immutable_object_cache/CacheClient.cc
src/tools/immutable_object_cache/CacheClient.h
src/tools/immutable_object_cache/ObjectCacheStore.cc
src/tools/immutable_object_cache/ObjectCacheStore.h
src/tools/immutable_object_cache/SimplePolicy.cc
src/tools/immutable_object_cache/SimplePolicy.h

index 9fe944ffd6298fd5338ea3fcb5c8967ec75568d2..9d6fd14c722e0bf32532f5e56238a34b74d0e567 100644 (file)
@@ -3,8 +3,7 @@
 #ifndef CACHE_TEST_COMMON_H
 #define CACHE_TEST_COMMON_H
 
-#include "common/Mutex.h"
-#include "common/Cond.h"
+#include <pthread.h>
 
 class WaitEvent {
 public:
index b50491ce8dd57ec3951bbe838d3f53cabfb15524..9d883c0f7ea0a3bf7132e5dfd6c3608868073cd9 100644 (file)
@@ -2,6 +2,7 @@
 // vim: ts=8 sw=2 smarttab
 
 #include "CacheClient.h"
+#include "common/Cond.h"
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_immutable_obj_cache
@@ -16,8 +17,7 @@ namespace immutable_obj_cache {
     : m_cct(ceph_ctx), m_io_service_work(m_io_service),
       m_dm_socket(m_io_service), m_ep(stream_protocol::endpoint(file)),
       m_io_thread(nullptr), m_session_work(false), m_writing(false),
-      m_reading(false), m_sequence_id(0),
-      m_lock("ceph::cache::cacheclient::m_lock") {
+      m_reading(false), m_sequence_id(0) {
     m_worker_thread_num =
       m_cct->_conf.get_val<uint64_t>(
         "immutable_object_cache_client_dedicated_thread_num");
@@ -120,7 +120,7 @@ namespace immutable_obj_cache {
     req->encode();
 
     {
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       m_outcoming_bl.append(req->get_payload_bufferlist());
       ceph_assert(m_seq_to_req.find(req->seq) == m_seq_to_req.end());
       m_seq_to_req[req->seq] = req;
@@ -145,7 +145,7 @@ namespace immutable_obj_cache {
     ldout(m_cct, 20) << dendl;
     bufferlist bl;
     {
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       bl.swap(m_outcoming_bl);
       ceph_assert(m_outcoming_bl.length() == 0);
     }
@@ -163,7 +163,7 @@ namespace immutable_obj_cache {
         ceph_assert(cb == bl.length());
 
         {
-           Mutex::Locker locker(m_lock);
+         std::lock_guard locker{m_lock};
            if (m_outcoming_bl.length() == 0) {
              m_writing.store(false);
              return;
@@ -258,7 +258,7 @@ namespace immutable_obj_cache {
     process(reply, reply->seq);
 
     {
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       if (m_seq_to_req.size() == 0 && m_outcoming_bl.length()) {
         m_reading.store(false);
         return;
@@ -273,7 +273,7 @@ namespace immutable_obj_cache {
     ldout(m_cct, 20) << dendl;
     ObjectCacheRequest* current_request = nullptr;
     {
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       ceph_assert(m_seq_to_req.find(seq_id) != m_seq_to_req.end());
       current_request = m_seq_to_req[seq_id];
       m_seq_to_req.erase(seq_id);
@@ -360,7 +360,7 @@ namespace immutable_obj_cache {
     /* all pending request, which have entered into ASIO,
      * will be re-dispatched to RADOS.*/
     {
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       for (auto it : m_seq_to_req) {
         it.second->type = RBDSC_READ_RADOS;
         it.second->process_msg->complete(it.second);
index d437ed0c9a6a49f15f9f02469cb62a56ebffd583..3294e56048ab28373082b842cf3a6da92695828b 100644 (file)
@@ -11,9 +11,8 @@
 #include <boost/algorithm/string.hpp>
 
 #include "include/ceph_assert.h"
+#include "common/ceph_mutex.h"
 #include "include/Context.h"
-#include "common/Cond.h"
-#include "common/Mutex.h"
 #include "Types.h"
 #include "SocketCommon.h"
 
@@ -74,7 +73,8 @@ class CacheClient {
   std::atomic<bool> m_writing;
   std::atomic<bool> m_reading;
   std::atomic<uint64_t> m_sequence_id;
-  Mutex m_lock;
+  ceph::mutex m_lock =
+    ceph::make_mutex("ceph::cache::cacheclient::m_lock");
   std::map<uint64_t, ObjectCacheRequest*> m_seq_to_req;
   bufferlist m_outcoming_bl;
   bufferptr m_bp_header;
index d89935424ef9a69f3d560158f1cbe59499459e6f..33f8dc1adeddfc26363291d152358f640cc5d57a 100644 (file)
@@ -17,8 +17,7 @@ namespace ceph {
 namespace immutable_obj_cache {
 
 ObjectCacheStore::ObjectCacheStore(CephContext *cct)
-      : m_cct(cct), m_rados(new librados::Rados()),
-        m_ioctx_map_lock("ceph::cache::ObjectCacheStore::m_ioctx_map_lock") {
+      : m_cct(cct), m_rados(new librados::Rados()) {
 
   m_cache_root_dir =
     m_cct->_conf.get_val<std::string>("immutable_object_cache_path");
@@ -103,7 +102,7 @@ int ObjectCacheStore::do_promote(std::string pool_nspace,
   std::string cache_file_name = get_cache_file_name(pool_nspace, pool_id, snap_id, object_name);
   librados::IoCtx ioctx;
   {
-    Mutex::Locker _locker(m_ioctx_map_lock);
+    std::lock_guard _locker{m_ioctx_map_lock};
     if (m_ioctx_map.find(pool_id) == m_ioctx_map.end()) {
       ret = m_rados->ioctx_create2(pool_id, ioctx);
       if (ret < 0) {
index 57aec63c3d0942809ddadd9b56770628a06d614e..eba003412e0cd3c99f61abd7fa3c86ce63ddfae3 100644 (file)
@@ -5,7 +5,7 @@
 #define CEPH_CACHE_OBJECT_CACHE_STORE_H
 
 #include "common/ceph_context.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "include/rados/librados.hpp"
 
 #include "SimplePolicy.h"
@@ -50,7 +50,8 @@ class ObjectCacheStore {
   CephContext *m_cct;
   RadosRef m_rados;
   std::map<uint64_t, librados::IoCtx> m_ioctx_map;
-  Mutex m_ioctx_map_lock;
+  ceph::mutex m_ioctx_map_lock =
+    ceph::make_mutex("ceph::cache::ObjectCacheStore::m_ioctx_map_lock");
   Policy* m_policy;
   std::string m_cache_root_dir;
 };
index 6b008b1750229273583274554ee6d94b870c4f58..b24ec7d675fa50253e958080af7e2c2e2efcd7a4 100644 (file)
@@ -16,8 +16,7 @@ namespace immutable_obj_cache {
 SimplePolicy::SimplePolicy(CephContext *cct, uint64_t cache_size,
                            uint64_t max_inflight, double watermark)
   : cct(cct), m_watermark(watermark), m_max_inflight_ops(max_inflight),
-    m_max_cache_size(cache_size),
-    m_cache_map_lock("rbd::cache::SimplePolicy::m_cache_map_lock") {
+    m_max_cache_size(cache_size) {
 
   ldout(cct, 20) << "max cache size= " << m_max_cache_size
                  << " ,watermark= " << m_watermark
@@ -39,7 +38,7 @@ SimplePolicy::~SimplePolicy() {
 cache_status_t SimplePolicy::alloc_entry(std::string file_name) {
   ldout(cct, 20) << "alloc entry for: " << file_name << dendl;
 
-  RWLock::WLocker wlocker(m_cache_map_lock);
+  std::unique_lock wlocker{m_cache_map_lock};
 
   // cache hit when promoting
   if (m_cache_map.find(file_name) != m_cache_map.end()) {
@@ -64,7 +63,7 @@ cache_status_t SimplePolicy::alloc_entry(std::string file_name) {
 cache_status_t SimplePolicy::lookup_object(std::string file_name) {
   ldout(cct, 20) << "lookup: " << file_name << dendl;
 
-  RWLock::RLocker rlocker(m_cache_map_lock);
+  std::shared_lock rlocker{m_cache_map_lock};
 
   auto entry_it = m_cache_map.find(file_name);
   // simply promote on first lookup
@@ -88,7 +87,7 @@ void SimplePolicy::update_status(std::string file_name,
   ldout(cct, 20) << "update status for: " << file_name
                  << " new status = " << new_status << dendl;
 
-  RWLock::WLocker locker(m_cache_map_lock);
+  std::unique_lock locker{m_cache_map_lock};
 
   auto entry_it = m_cache_map.find(file_name);
   if (entry_it == m_cache_map.end()) {
@@ -155,7 +154,7 @@ int SimplePolicy::evict_entry(std::string file_name) {
 cache_status_t SimplePolicy::get_status(std::string file_name) {
   ldout(cct, 20) << file_name << dendl;
 
-  RWLock::RLocker locker(m_cache_map_lock);
+  std::shared_lock locker{m_cache_map_lock};
   auto entry_it = m_cache_map.find(file_name);
   if (entry_it == m_cache_map.end()) {
     return OBJ_CACHE_NONE;
@@ -167,7 +166,7 @@ cache_status_t SimplePolicy::get_status(std::string file_name) {
 void SimplePolicy::get_evict_list(std::list<std::string>* obj_list) {
   ldout(cct, 20) << dendl;
 
-  RWLock::WLocker locker(m_cache_map_lock);
+  std::unique_lock locker{m_cache_map_lock};
   // check free ratio, pop entries from LRU
   if ((double)m_cache_size / m_max_cache_size > (1 - m_watermark)) {
     // TODO(dehao): make this configurable
@@ -190,7 +189,7 @@ uint64_t SimplePolicy::get_free_size() {
 
 uint64_t SimplePolicy::get_promoting_entry_num() {
   uint64_t index = 0;
-  RWLock::RLocker rlocker(m_cache_map_lock);
+  std::shared_lock rlocker{m_cache_map_lock};
   for (auto it : m_cache_map) {
     if (it.second->status == OBJ_CACHE_SKIP) {
       index++;
index aac96519edfc000547629cf58408390f2a0b4950..671cbd518991003180f55d0b5fe882c4396b37d6 100644 (file)
@@ -5,8 +5,7 @@
 #define CEPH_CACHE_SIMPLE_POLICY_H
 
 #include "common/ceph_context.h"
-#include "common/RWLock.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "include/lru.h"
 #include "Policy.h"
 
@@ -56,7 +55,8 @@ class SimplePolicy : public Policy {
   std::atomic<uint64_t> inflight_ops = 0;
 
   std::unordered_map<std::string, Entry*> m_cache_map;
-  RWLock m_cache_map_lock;
+  ceph::shared_mutex m_cache_map_lock =
+    ceph::make_shared_mutex("rbd::cache::SimplePolicy::m_cache_map_lock");
 
   std::atomic<uint64_t> m_cache_size;