#ifndef CEPH_OS_BLUESTORE_ALLOCATOR_H
#define CEPH_OS_BLUESTORE_ALLOCATOR_H
+#include <atomic>
#include <functional>
#include <ostream>
#include "include/ceph_assert.h"
virtual const std::string& get_name() const = 0;
int64_t get_capacity() const
{
- return device_size;
+ return device_size.load();
}
int64_t get_block_size() const
{
return block_size;
}
virtual void expand(int64_t new_size){
- ceph_assert(new_size >= device_size);
- device_size = new_size;
+ ceph_assert(new_size >= device_size.load());
+ device_size.store(new_size);
}
protected:
- int64_t device_size = 0;
+ std::atomic<int64_t> device_size{0};
const int64_t block_size = 0;
};
for (auto& [offset, len] : release_set) {
ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << len
<< std::dec << dendl;
- ceph_assert(offset + len <= (uint64_t)device_size);
+ ceph_assert(offset + len <= (uint64_t)device_size.load());
}
}
_free_l2(release_set);
auto mas = get_min_alloc_size();
uint64_t offs = round_up_to(offset, mas);
uint64_t l = p2align(offset + length - offs, mas);
- ceph_assert(offs + l <= (uint64_t)device_size);
+ ceph_assert(offs + l <= (uint64_t)device_size.load());
_mark_free(offs, l);
ldout(cct, 10) << __func__ << " done" << dendl;
auto mas = get_min_alloc_size();
uint64_t offs = round_up_to(offset, mas);
uint64_t l = p2align(offset + length - offs, mas);
- ceph_assert(offs + l <= (uint64_t)device_size);
+ ceph_assert(offs + l <= (uint64_t)device_size.load());
_mark_allocated(offs, l);
ldout(cct, 10) << __func__ << " done" << dendl;
}
void BitmapAllocator::expand(int64_t new_size)
{
+ std::lock_guard l(expand_lock);
int64_t old_size = get_capacity();
ceph_assert(new_size >= old_size);
class BitmapAllocator : public AllocatorBase,
public AllocatorLevel02<AllocatorLevel01Loose> {
CephContext* cct;
+ ceph::mutex expand_lock = ceph::make_mutex("BitmapAllocator::expand_lock");
public:
BitmapAllocator(CephContext* _cct, int64_t capacity, int64_t alloc_unit,
std::string_view name);