From 6641482ce8e13940003bedfec217b5fafc287f4f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 23 Dec 2015 10:19:49 -0500 Subject: [PATCH] os/bluestore/Allocator: add unreserve() Signed-off-by: Sage Weil --- src/os/bluestore/Allocator.h | 1 + src/os/bluestore/StupidAllocator.cc | 11 ++++++++++- src/os/bluestore/StupidAllocator.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/os/bluestore/Allocator.h b/src/os/bluestore/Allocator.h index 63df4c98f4516..6df2267ca41c1 100644 --- a/src/os/bluestore/Allocator.h +++ b/src/os/bluestore/Allocator.h @@ -23,6 +23,7 @@ public: virtual ~Allocator() {} virtual int reserve(uint64_t need) = 0; + virtual void unreserve(uint64_t unused) = 0; virtual int allocate( uint64_t need_size, uint64_t alloc_unit, int64_t hint, diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index be4d5633e454e..a1ee90ed97156 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -58,12 +58,21 @@ int StupidAllocator::reserve(uint64_t need) Mutex::Locker l(lock); dout(10) << __func__ << " need " << need << " num_free " << num_free << " num_reserved " << num_reserved << dendl; - if (need > num_free - num_reserved) + if ((int64_t)need > num_free - num_reserved) return -ENOSPC; num_reserved += need; return 0; } +void StupidAllocator::unreserve(uint64_t unused) +{ + Mutex::Locker l(lock); + dout(10) << __func__ << " unused " << unused << " num_free " << num_free + << " num_reserved " << num_reserved << dendl; + assert(unused >= num_reserved); + num_reserved -= unused; +} + int StupidAllocator::allocate( uint64_t need_size, uint64_t alloc_unit, int64_t hint, uint64_t *offset, uint32_t *length) diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index cad115d417c08..ec71b863df192 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -30,6 +30,7 @@ public: ~StupidAllocator(); int reserve(uint64_t need); + void unreserve(uint64_t unused); int allocate( uint64_t need_size, uint64_t alloc_unit, int64_t hint, -- 2.39.5