From: Abhishek Lekshmanan Date: Thu, 8 Aug 2019 15:38:43 +0000 (+0200) Subject: rgw: fix unlock of shared lock in RGWCache X-Git-Tag: v15.1.0~1914^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2b6dbe31c8f7fc12aef255e99b59f6926f4bbca9;p=ceph-ci.git rgw: fix unlock of shared lock in RGWCache 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 --- diff --git a/src/rgw/rgw_cache.cc b/src/rgw/rgw_cache.cc index 38f7b739c5d..26bac825830 100644 --- a/src/rgw/rgw_cache.cc +++ b/src/rgw/rgw_cache.cc @@ -11,24 +11,25 @@ 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()) {