From a1246da5705e2a699656c2561cebc5ed29628c90 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 --- 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 3c5a605eb28..ca6c6d7f69e 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -2497,8 +2497,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]) @@ -2536,7 +2536,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); } @@ -2566,7 +2566,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 09ef6dc80fd..92dfbe8cf7c 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5615,18 +5615,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; @@ -7579,10 +7580,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; @@ -12129,9 +12130,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.47.3