Both stupid and bitmap allocator returs -ENOSPC if they're
unable to allocate any space. Existing callers aren't always
respect this - hence doing some cleanup.
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit
a1246da5705e2a699656c2561cebc5ed29628c90)
- allocator fallback not there
- allocator fallback not there
extents.reserve(4); // 4 should be (more than) enough for most allocations
alloc_len = alloc[id]->allocate(left, min_alloc_size, hint, &extents);
}
- if (alloc_len < (int64_t)left) {
- if (alloc_len != 0) {
+ if (alloc_len < 0 || alloc_len < (int64_t)left) {
+ if (alloc_len > 0) {
alloc[id]->release(extents);
}
if (id != BDEV_SLOW) {
prealloc_left = alloc->allocate(
need, min_alloc_size, need,
0, &prealloc);
- if (prealloc_left < 0) {
+ if (prealloc_left < 0 || prealloc_left < (int64_t)need) {
derr << __func__ << " failed to allocate 0x" << std::hex << need << std::dec
<< dendl;
+ if (prealloc_left > 0) {
+ alloc->release(prealloc);
+ }
return -ENOSPC;
}
assert(prealloc_left == (int64_t)need);