Skip to content

Commit

Permalink
os/bluestore: fix the allocate in bluefs
Browse files Browse the repository at this point in the history
backport from pr ceph#19030

Signed-off-by: tangwenjun <tang.wenjun3@zte.com.cn>
  • Loading branch information
tangwenjun3 committed Nov 23, 2017
1 parent ecec659 commit f8171d3
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/os/bluestore/BlueFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1834,10 +1834,29 @@ int BlueFS::_allocate(uint8_t id, uint64_t len,

uint64_t left = ROUND_UP_TO(len, min_alloc_size);
int r = -ENOSPC;
int64_t alloc_len = 0;
AllocExtentVector extents;

if (alloc[id]) {
r = alloc[id]->reserve(left);
}
if (r < 0) {

if (r == 0) {
uint64_t hint = 0;
if (!ev->empty()) {
hint = ev->back().end();
}
extents.reserve(4); // 4 should be (more than) enough for most allocations
alloc_len = alloc[id]->allocate(left, min_alloc_size, hint, &extents);
}

if (r < 0 || (alloc_len < (int64_t)left)) {
if (r == 0) {
alloc[id]->unreserve(left - alloc_len);
for (auto& p : extents) {
alloc[id]->release(p.offset, p.length);
}
}
if (id != BDEV_SLOW) {
if (bdev[id]) {
dout(1) << __func__ << " failed to allocate 0x" << std::hex << left
Expand All @@ -1855,27 +1874,11 @@ int BlueFS::_allocate(uint8_t id, uint64_t len,
else
derr << __func__ << " failed to allocate 0x" << std::hex << left
<< " on bdev " << (int)id << ", dne" << std::dec << dendl;
if (alloc[id])
alloc[id]->dump();
return r;
}

uint64_t hint = 0;
if (!ev->empty()) {
hint = ev->back().end();
}

AllocExtentVector extents;
extents.reserve(4); // 4 should be (more than) enough for most allocations
int64_t alloc_len = alloc[id]->allocate(left, min_alloc_size, hint,
&extents);
if (alloc_len < (int64_t)left) {
derr << __func__ << " allocate failed on 0x" << std::hex << left
<< " min_alloc_size 0x" << min_alloc_size
<< " hint 0x" << hint << std::dec << dendl;
alloc[id]->dump();
assert(0 == "allocate failed... wtf");
return -ENOSPC;
}

for (auto& p : extents) {
bluefs_extent_t e = bluefs_extent_t(id, p.offset, p.length);
if (!ev->empty() &&
Expand Down

0 comments on commit f8171d3

Please sign in to comment.