From: Kefu Chai Date: Sun, 21 Aug 2022 16:28:43 +0000 (+0800) Subject: *: s/isp2/has_single_bit/ X-Git-Tag: v18.0.0~196^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=05e355b5921f10ac16268b7ef4829e740b621c2b;p=ceph.git *: s/isp2/has_single_bit/ prefer the facilities provided by standard library over the homebrew ones for better readability and maintainability. Signed-off-by: Kefu Chai --- diff --git a/src/common/options/rbd.yaml.in b/src/common/options/rbd.yaml.in index 2dc357ae766f..c2da27aaaaf7 100644 --- a/src/common/options/rbd.yaml.in +++ b/src/common/options/rbd.yaml.in @@ -2,6 +2,7 @@ --- headers: | + #include #include // rbd feature and io operation validation #include "include/stringify.h" @@ -321,7 +322,7 @@ options: uint64_t f = strict_si_cast(*value, error_message); if (!error_message->empty()) { return -EINVAL; - } else if (!isp2(f)) { + } else if (!std::has_single_bit(f)) { *error_message = "value must be a power of two"; return -EINVAL; } diff --git a/src/librbd/crypto/BlockCrypto.cc b/src/librbd/crypto/BlockCrypto.cc index f9e2a9d21903..cce90d2e3062 100644 --- a/src/librbd/crypto/BlockCrypto.cc +++ b/src/librbd/crypto/BlockCrypto.cc @@ -6,6 +6,7 @@ #include "include/ceph_assert.h" #include "include/scope_guard.h" +#include #include namespace librbd { @@ -16,7 +17,7 @@ BlockCrypto::BlockCrypto(CephContext* cct, DataCryptor* data_cryptor, uint64_t block_size, uint64_t data_offset) : m_cct(cct), m_data_cryptor(data_cryptor), m_block_size(block_size), m_data_offset(data_offset), m_iv_size(data_cryptor->get_iv_size()) { - ceph_assert(isp2(block_size)); + ceph_assert(std::has_single_bit(block_size)); ceph_assert((block_size % data_cryptor->get_block_size()) == 0); ceph_assert((block_size % 512) == 0); } diff --git a/src/os/bluestore/AvlAllocator.cc b/src/os/bluestore/AvlAllocator.cc index 3ab12c0a9339..4584bfae713f 100644 --- a/src/os/bluestore/AvlAllocator.cc +++ b/src/os/bluestore/AvlAllocator.cc @@ -3,6 +3,7 @@ #include "AvlAllocator.h" +#include #include #include "common/config_proxy.h" @@ -372,7 +373,7 @@ int64_t AvlAllocator::allocate( << " 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) { diff --git a/src/os/bluestore/BitmapFreelistManager.cc b/src/os/bluestore/BitmapFreelistManager.cc index e03a6ecacb74..bec6ace868b1 100644 --- a/src/os/bluestore/BitmapFreelistManager.cc +++ b/src/os/bluestore/BitmapFreelistManager.cc @@ -2,6 +2,8 @@ // vim: ts=8 sw=2 smarttab #include "BitmapFreelistManager.h" + +#include #include "kv/KeyValueDB.h" #include "os/kv.h" #include "include/stringify.h" @@ -69,7 +71,7 @@ int BitmapFreelistManager::create(uint64_t new_size, uint64_t granularity, KeyValueDB::Transaction txn) { bytes_per_block = granularity; - ceph_assert(isp2(bytes_per_block)); + ceph_assert(std::has_single_bit(bytes_per_block)); size = p2align(new_size, bytes_per_block); blocks_per_key = cct->_conf->bluestore_freelist_blocks_per_key; @@ -115,7 +117,7 @@ int BitmapFreelistManager::create(uint64_t new_size, uint64_t granularity, int BitmapFreelistManager::_expand(uint64_t old_size, KeyValueDB* db) { assert(old_size < size); - ceph_assert(isp2(bytes_per_block)); + ceph_assert(std::has_single_bit(bytes_per_block)); KeyValueDB::Transaction txn; txn = db->get_transaction(); diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index a61ce21f35d3..e96ccbc5b438 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -12,6 +12,7 @@ * */ +#include #include #include #include @@ -7077,7 +7078,7 @@ int BlueStore::mkfs() _validate_bdev(); // make sure min_alloc_size is power of 2 aligned. - if (!isp2(min_alloc_size)) { + if (!std::has_single_bit(min_alloc_size)) { derr << __func__ << " min_alloc_size 0x" << std::hex << min_alloc_size << std::dec << " is not power of 2 aligned!" diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 157f5309ca99..315e6c516dfe 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -3836,7 +3837,7 @@ public: uint64_t min_alloc_size, uint64_t mem_cap = DEF_MEM_CAP) { ceph_assert(!granularity); // not initialized yet - ceph_assert(min_alloc_size && isp2(min_alloc_size)); + ceph_assert(std::has_single_bit(min_alloc_size)); ceph_assert(mem_cap); total = round_up_to(total, min_alloc_size); diff --git a/src/os/bluestore/BtreeAllocator.cc b/src/os/bluestore/BtreeAllocator.cc index 6b919f18c021..cf08d7ae7d31 100644 --- a/src/os/bluestore/BtreeAllocator.cc +++ b/src/os/bluestore/BtreeAllocator.cc @@ -3,6 +3,7 @@ #include "BtreeAllocator.h" +#include #include #include "common/config_proxy.h" @@ -373,7 +374,7 @@ int64_t BtreeAllocator::allocate( << " 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) { diff --git a/src/os/bluestore/HybridAllocator.cc b/src/os/bluestore/HybridAllocator.cc index 126d902cf3a5..2201d5958246 100644 --- a/src/os/bluestore/HybridAllocator.cc +++ b/src/os/bluestore/HybridAllocator.cc @@ -3,6 +3,7 @@ #include "HybridAllocator.h" +#include #include #include "common/config_proxy.h" @@ -27,7 +28,7 @@ int64_t HybridAllocator::allocate( << " 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) { diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 41f20542985e..84461daf2ae7 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -15,6 +15,7 @@ #ifndef CEPH_OSD_BLUESTORE_BLUESTORE_TYPES_H #define CEPH_OSD_BLUESTORE_BLUESTORE_TYPES_H +#include #include #include #include @@ -1220,7 +1221,7 @@ public: shared_blob_2hash_tracker_t(uint64_t mem_cap, size_t alloc_unit) : ref_counter_2hash_tracker_t(mem_cap) { ceph_assert(alloc_unit); - ceph_assert(isp2(alloc_unit)); + ceph_assert(std::has_single_bit(alloc_unit)); au_void_bits = ctz(alloc_unit); } void inc(uint64_t sbid, uint64_t offset, int n); diff --git a/src/os/bluestore/fastbmap_allocator_impl.h b/src/os/bluestore/fastbmap_allocator_impl.h index e44fc76d7500..550214b62a87 100644 --- a/src/os/bluestore/fastbmap_allocator_impl.h +++ b/src/os/bluestore/fastbmap_allocator_impl.h @@ -10,6 +10,7 @@ #define __FAST_BITMAP_ALLOCATOR_IMPL_H #include "include/intarith.h" +#include #include #include #include @@ -617,7 +618,7 @@ protected: void _init(uint64_t capacity, uint64_t _alloc_unit, bool mark_as_free = true) { - ceph_assert(isp2(_alloc_unit)); + ceph_assert(std::has_single_bit(_alloc_unit)); l1._init(capacity, _alloc_unit, mark_as_free); l2_granularity = diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 99dfbce1978e..0cbe7ca5934c 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -6421,7 +6422,7 @@ void OSDMap::check_health(CephContext *cct, if (cct->_conf.get_val("mon_warn_on_pool_pg_num_not_power_of_two")) { list detail; for (auto it : get_pools()) { - if (!isp2(it.second.get_pg_num_target())) { + if (!std::has_single_bit(it.second.get_pg_num_target())) { ostringstream ss; ss << "pool '" << get_pool_name(it.first) << "' pg_num " << it.second.get_pg_num_target() diff --git a/src/test/objectstore/Allocator_aging_fragmentation.cc b/src/test/objectstore/Allocator_aging_fragmentation.cc index e0b27fd67c65..220f8841b8ed 100755 --- a/src/test/objectstore/Allocator_aging_fragmentation.cc +++ b/src/test/objectstore/Allocator_aging_fragmentation.cc @@ -4,6 +4,7 @@ * Bitmap allocator fragmentation benchmarks. * Author: Adam Kupczyk, akupczyk@redhat.com */ +#include #include #include #include @@ -234,7 +235,7 @@ void AllocTest::doAgingTest( uint64_t capacity, uint32_t alloc_unit, uint64_t high_mark, uint64_t low_mark, uint32_t iterations, double leak_factor) { - assert(isp2(alloc_unit)); + assert(std::has_single_bit(alloc_unit)); cct->_conf->bdev_block_size = alloc_unit; PExtentVector allocated, tmp; init_alloc(allocator_name, capacity, alloc_unit);