#include "AvlAllocator.h"
+#include <bit>
#include <limits>
#include "common/config_proxy.h"
<< " max_alloc_size 0x" << max_alloc_size
<< " hint 0x" << hint
<< std::dec << dendl;
- ceph_assert(isp2(unit));
+ ceph_assert(std::has_single_bit(unit));
ceph_assert(want % unit == 0);
if (max_alloc_size == 0) {
<< std::dec
<< dendl;
}
-
ldout(cct, 0) << __func__ << " range_size_tree: " << dendl;
for (auto& rs : range_size_tree) {
ldout(cct, 0) << std::hex
}
}
-void AvlAllocator::dump(std::function<void(uint64_t offset, uint64_t length)> notify)
+void AvlAllocator::foreach(
+ std::function<void(uint64_t offset, uint64_t length)> notify)
+{
+ std::lock_guard l(lock);
+ _foreach(notify);
+}
+
+void AvlAllocator::_foreach(
+ std::function<void(uint64_t offset, uint64_t length)> notify) const
{
for (auto& rs : range_tree) {
notify(rs.start, rs.end - rs.start);
void AvlAllocator::init_add_free(uint64_t offset, uint64_t length)
{
- if (!length)
- return;
- std::lock_guard l(lock);
- ceph_assert(offset + length <= uint64_t(device_size));
ldout(cct, 10) << __func__ << std::hex
<< " offset 0x" << offset
<< " length 0x" << length
<< std::dec << dendl;
+ if (!length)
+ return;
+ std::lock_guard l(lock);
+ ceph_assert(offset + length <= uint64_t(device_size));
_add_to_tree(offset, length);
}
void AvlAllocator::init_rm_free(uint64_t offset, uint64_t length)
{
- if (!length)
- return;
- std::lock_guard l(lock);
- ceph_assert(offset + length <= uint64_t(device_size));
ldout(cct, 10) << __func__ << std::hex
<< " offset 0x" << offset
<< " length 0x" << length
<< std::dec << dendl;
+ if (!length)
+ return;
+ std::lock_guard l(lock);
+ ceph_assert(offset + length <= uint64_t(device_size));
_remove_from_tree(offset, length);
}