Merge pull request #22123 from liewegas/wip-24211

os/bluestore: simplify and fix SharedBlob::put()

Reviewed-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
Reviewed-by: Adam Kupczyk <akupczyk@redhat.com>
This commit is contained in:
Kefu Chai 2018-05-23 14:55:29 +08:00 committed by GitHub
commit 6d30a32922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 17 deletions

View File

@ -1672,16 +1672,9 @@ void BlueStore::SharedBlob::put()
<< " removing self from set " << get_parent()
<< dendl;
if (get_parent()) {
if (get_parent()->try_remove(this)) {
delete this;
} else {
ldout(coll->store->cct, 20)
<< __func__ << " " << this << " lost race to remove myself from set"
<< dendl;
}
} else {
delete this;
get_parent()->remove_last(this);
}
delete this;
}
}

View File

@ -437,7 +437,8 @@ public:
SharedBlobRef lookup(uint64_t sbid) {
std::lock_guard<std::mutex> l(lock);
auto p = sb_map.find(sbid);
if (p == sb_map.end()) {
if (p == sb_map.end() ||
p->second->nref == 0) {
return nullptr;
}
return p->second;
@ -449,14 +450,11 @@ public:
sb->coll = coll;
}
bool try_remove(SharedBlob *sb) {
void remove_last(SharedBlob *sb) {
std::lock_guard<std::mutex> l(lock);
if (sb->nref == 0) {
assert(sb->get_parent() == this);
sb_map.erase(sb->get_sbid());
return true;
}
return false;
assert(sb->nref == 0);
assert(sb->get_parent() == this);
sb_map.erase(sb->get_sbid());
}
void remove(SharedBlob *sb) {