From 48939f7a62cd12e5ab99e95d194311f6509f1708 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 18 Jan 2017 06:24:06 -0600 Subject: [PATCH] os/bluestore/BlueFS: handle failure to reclaim blocks without crashing We shouldn't fail to reclaim space in general, but if we do, do not treat it as a fatal error. Log loudly. Signed-off-by: Sage Weil (cherry picked from commit 6dc1bcd9e72b01c3fbf09c7eb91cd7cf4e01f94a) --- src/os/bluestore/BlueFS.cc | 11 ++++++++--- src/os/bluestore/BlueStore.cc | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index b9d7bf0568726..93bc7ec6aca41 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -179,9 +179,14 @@ int BlueFS::reclaim_blocks(unsigned id, uint64_t want, assert(r == 0); // caller shouldn't ask for more than they can get int64_t got = alloc[id]->allocate(want, g_conf->bluefs_alloc_size, 0, extents); - assert(got > 0); - if (got < (int64_t)want) - alloc[id]->unreserve(want - got); + if (got < (int64_t)want) { + alloc[id]->unreserve(want - MAX(0, got)); + } + if (got <= 0) { + derr << __func__ << " failed to allocate space to return to bluestore" + << dendl; + return got; + } for (auto& p : *extents) { block_all[id].erase(p.offset, p.length); diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 36004808e84ed..f876aa581e324 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -3656,8 +3656,11 @@ int BlueStore::_balance_bluefs_freespace(vector *extents) AllocExtentVector extents; int r = bluefs->reclaim_blocks(bluefs_shared_bdev, reclaim, &extents); - assert(r >= 0); - + if (r < 0) { + derr << __func__ << " failed to reclaim space from bluefs" + << dendl; + break; + } for (auto e : extents) { bluefs_extents.erase(e.offset, e.length); bluefs_extents_reclaiming.insert(e.offset, e.length); -- 2.39.5