]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix unlock of shared lock in RGWCache 29558/head
authorAbhishek Lekshmanan <abhishek@suse.com>
Thu, 8 Aug 2019 15:38:43 +0000 (17:38 +0200)
committerAbhishek Lekshmanan <abhishek@suse.com>
Fri, 9 Aug 2019 15:54:22 +0000 (17:54 +0200)
similar to https://github.com/ceph/ceph/pull/29538/ we unlock a shared_lock with
unlock causing a crash. Also scope the single line if statements to make the
code more concise

Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
src/rgw/rgw_cache.cc

index 38f7b739c5df7cdea3b29df58891dac69e7e4b54..26bac8258306ee5170393417388c154a65c25594 100644 (file)
 
 int ObjectCache::get(const string& name, ObjectCacheInfo& info, uint32_t mask, rgw_cache_entry_info *cache_info)
 {
-  std::shared_lock l{lock};
 
+  std::shared_lock rl{lock};
   if (!enabled) {
     return -ENOENT;
   }
-
   auto iter = cache_map.find(name);
   if (iter == cache_map.end()) {
     ldout(cct, 10) << "cache get: name=" << name << " : miss" << dendl;
-    if (perfcounter)
+    if (perfcounter) {
       perfcounter->inc(l_rgw_cache_miss);
+    }
     return -ENOENT;
   }
+
   if (expiry.count() &&
        (ceph::coarse_mono_clock::now() - iter->second.info.time_added) > expiry) {
     ldout(cct, 10) << "cache get: name=" << name << " : expiry miss" << dendl;
-    lock.unlock();
-    lock.lock();
+    rl.unlock();
+    std::unique_lock wl{lock};  // write lock for insertion
     // check that wasn't already removed by other thread
     iter = cache_map.find(name);
     if (iter != cache_map.end()) {
@@ -37,8 +38,9 @@ int ObjectCache::get(const string& name, ObjectCacheInfo& info, uint32_t mask, r
       remove_lru(name, iter->second.lru_iter);
       cache_map.erase(iter);
     }
-    if(perfcounter)
+    if (perfcounter) {
       perfcounter->inc(l_rgw_cache_miss);
+    }
     return -ENOENT;
   }
 
@@ -47,9 +49,8 @@ int ObjectCache::get(const string& name, ObjectCacheInfo& info, uint32_t mask, r
   if (lru_counter - entry->lru_promotion_ts > lru_window) {
     ldout(cct, 20) << "cache get: touching lru, lru_counter=" << lru_counter
                    << " promotion_ts=" << entry->lru_promotion_ts << dendl;
-    lock.unlock();
-    lock.lock(); /* promote lock to writer */
-
+    rl.unlock();
+    std::unique_lock wl{lock};  // write lock for insertion
     /* need to redo this because entry might have dropped off the cache */
     iter = cache_map.find(name);
     if (iter == cache_map.end()) {