]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
*: s/isp2/has_single_bit/
authorKefu Chai <tchaikov@gmail.com>
Sun, 21 Aug 2022 16:28:43 +0000 (00:28 +0800)
committerKefu Chai <tchaikov@gmail.com>
Mon, 22 Aug 2022 10:03:59 +0000 (18:03 +0800)
prefer the facilities provided by standard library over the homebrew
ones for better readability and maintainability.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
12 files changed:
src/common/options/rbd.yaml.in
src/librbd/crypto/BlockCrypto.cc
src/os/bluestore/AvlAllocator.cc
src/os/bluestore/BitmapFreelistManager.cc
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/bluestore/BtreeAllocator.cc
src/os/bluestore/HybridAllocator.cc
src/os/bluestore/bluestore_types.h
src/os/bluestore/fastbmap_allocator_impl.h
src/osd/OSDMap.cc
src/test/objectstore/Allocator_aging_fragmentation.cc

index 2dc357ae766f2b1c60fc382307677d2bcc5d4571..c2da27aaaaf7c2f4cbac7933a2c4ad59376af2e7 100644 (file)
@@ -2,6 +2,7 @@
 ---
 
 headers: |
+  #include <bit>
   #include <regex>
   // rbd feature and io operation validation
   #include "include/stringify.h"
@@ -321,7 +322,7 @@ options:
       uint64_t f = strict_si_cast<uint64_t>(*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;
       }
index f9e2a9d21903ae3798f83cb22ca4f1cdd53bc94e..cce90d2e306231f33da8850d428d766536b607a2 100644 (file)
@@ -6,6 +6,7 @@
 #include "include/ceph_assert.h"
 #include "include/scope_guard.h"
 
+#include <bit>
 #include <stdlib.h>
 
 namespace librbd {
@@ -16,7 +17,7 @@ BlockCrypto<T>::BlockCrypto(CephContext* cct, DataCryptor<T>* 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);
 }
index 3ab12c0a9339366001bf27fc1fdcdfcac1b29219..4584bfae713fdeb353dbc38dda7cd3918cdefa8a 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "AvlAllocator.h"
 
+#include <bit>
 #include <limits>
 
 #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) {
index e03a6ecacb748dc74e1997689ce3745abe230086..bec6ace868b1577a5aa94c297103c9d66274288c 100644 (file)
@@ -2,6 +2,8 @@
 // vim: ts=8 sw=2 smarttab
 
 #include "BitmapFreelistManager.h"
+
+#include <bit>
 #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();
index a61ce21f35d34d04a46f86f0991d805dec5823f4..e96ccbc5b4389f756b303c99dc78e80ec838995c 100644 (file)
@@ -12,6 +12,7 @@
  *
  */
 
+#include <bit>
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -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!"
index 157f5309ca99a17abf0d35dbf423463a435851e7..315e6c516dfea7a4538af8dd21bf520dbcae9820 100644 (file)
@@ -20,6 +20,7 @@
 #include <unistd.h>
 
 #include <atomic>
+#include <bit>
 #include <chrono>
 #include <ratio>
 #include <mutex>
@@ -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);
index 6b919f18c021dc29d4b6bc4edabbb3982aad08fc..cf08d7ae7d31f0fa14af2df2a157022b7339f849 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "BtreeAllocator.h"
 
+#include <bit>
 #include <limits>
 
 #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) {
index 126d902cf3a5db278e12357e1eddc6ac1e9d1478..2201d5958246b0072043a2d755aa584a4cf6e39d 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "HybridAllocator.h"
 
+#include <bit>
 #include <limits>
 
 #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) {
index 41f20542985e0725eebd6eb506c4852af7fdb633..84461daf2ae7345d38b9d37ce3485534c562bb0f 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef CEPH_OSD_BLUESTORE_BLUESTORE_TYPES_H
 #define CEPH_OSD_BLUESTORE_BLUESTORE_TYPES_H
 
+#include <bit>
 #include <ostream>
 #include <type_traits>
 #include <vector>
@@ -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);
index e44fc76d750023a5ad9e677f6890f7c11e36d373..550214b62a874d42f1b5ee604b5fc8372e9c3ac9 100644 (file)
@@ -10,6 +10,7 @@
 #define __FAST_BITMAP_ALLOCATOR_IMPL_H
 #include "include/intarith.h"
 
+#include <bit>
 #include <vector>
 #include <algorithm>
 #include <mutex>
@@ -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 =
index 99dfbce1978e1c25d33a9db40a5b4385f2086a53..0cbe7ca5934c79f9f857e43eddaef7ed3dbbff8c 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <algorithm>
+#include <bit>
 #include <optional>
 #include <random>
 
@@ -6421,7 +6422,7 @@ void OSDMap::check_health(CephContext *cct,
   if (cct->_conf.get_val<bool>("mon_warn_on_pool_pg_num_not_power_of_two")) {
     list<string> 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()
index e0b27fd67c6574704a04cce772abdda3d7199a5e..220f8841b8eda9020a69571592ad177408f456eb 100755 (executable)
@@ -4,6 +4,7 @@
  * Bitmap allocator fragmentation benchmarks.
  * Author: Adam Kupczyk, akupczyk@redhat.com
  */
+#include <bit>
 #include <iostream>
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
@@ -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);