From 1ff043ed30ecd1a8f2822d4dadb9e1f5f1791e7f Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Tue, 16 Jul 2019 17:16:16 +0300 Subject: [PATCH] os/bluestore: cleanup around allocator calls 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 (cherry picked from commit a1246da5705e2a699656c2561cebc5ed29628c90) --- src/os/bluestore/BlueFS.cc | 8 ++++---- src/os/bluestore/BlueStore.cc | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index dd3a4a226f127..825e7a9a6f6d5 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -2571,8 +2571,8 @@ int BlueFS::_allocate_without_fallback(uint8_t id, uint64_t len, } extents->reserve(4); // 4 should be (more than) enough for most allocations int64_t alloc_len = alloc[id]->allocate(left, min_alloc_size, 0, 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 (bdev[id]) @@ -2610,7 +2610,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len, 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 || alloc_len < (int64_t)left) { if (alloc_len > 0) { alloc[id]->release(extents); } @@ -2640,7 +2640,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len, ceph_assert(last_alloc); // try again alloc_len = last_alloc->allocate(left, min_alloc_size, hint, &extents); - if (alloc_len < (int64_t)left) { + if (alloc_len < 0 || alloc_len < (int64_t)left) { if (alloc_len > 0) { last_alloc->release(extents); } diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 3a0740a202e81..2ad9f3a7dc419 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5478,18 +5478,19 @@ int BlueStore::allocate_bluefs_freespace( alloc_len = alloc->allocate(gift, cct->_conf->bluefs_alloc_size, 0, 0, extents); - if (alloc_len) { + if (alloc_len > 0) { allocated += alloc_len; size -= alloc_len; } - if (alloc_len < (int64_t)gift && (min_size > allocated)) { + if (alloc_len < 0 || + (alloc_len < (int64_t)gift && (min_size > allocated))) { derr << __func__ << " failed to allocate on 0x" << std::hex << gift << " min_size 0x" << min_size << " > allocated total 0x" << allocated << " bluefs_alloc_size 0x" << cct->_conf->bluefs_alloc_size - << " allocated 0x" << alloc_len + << " allocated 0x" << (alloc_len < 0 ? 0 : alloc_len) << " available 0x " << alloc->get_free() << std::dec << dendl; @@ -7516,10 +7517,10 @@ int BlueStore::_fsck(bool deep, bool repair) PExtentVector exts; int64_t alloc_len = alloc->allocate(e->length, min_alloc_size, 0, 0, &exts); - if (alloc_len < (int64_t)e->length) { + if (alloc_len < 0 || alloc_len < (int64_t)e->length) { derr << __func__ << " failed to allocate 0x" << std::hex << e->length - << " allocated 0x " << alloc_len + << " allocated 0x " << (alloc_len < 0 ? 0 : alloc_len) << " min_alloc_size 0x" << min_alloc_size << " available 0x " << alloc->get_free() << std::dec << dendl; @@ -12056,9 +12057,9 @@ int BlueStore::_do_alloc_write( prealloc_left = alloc->allocate( need, min_alloc_size, need, 0, &prealloc); - if (prealloc_left < (int64_t)need) { + if (prealloc_left < 0 || prealloc_left < (int64_t)need) { derr << __func__ << " failed to allocate 0x" << std::hex << need - << " allocated 0x " << prealloc_left + << " allocated 0x " << (prealloc_left < 0 ? 0 : prealloc_left) << " min_alloc_size 0x" << min_alloc_size << " available 0x " << alloc->get_free() << std::dec << dendl; -- 2.39.5