Skip to content

Commit

Permalink
Add assert
Browse files Browse the repository at this point in the history
  • Loading branch information
shosseinimotlagh committed Sep 23, 2024
1 parent 1fbb18d commit b44e697
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/engine/blkalloc/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ struct BlkId {
static constexpr uint64_t s_chunk_num_mask{(static_cast< uint64_t >(1) << CHUNK_NUM_BITS) - 1};

public:
[[nodiscard]] static constexpr blk_count_t max_blks_in_op() { return (1 << NBLKS_BITS); }
[[nodiscard]] static constexpr blk_count_t max_blks_in_op() {
static_assert(NBLKS_BITS <= std::numeric_limits< blk_count_t >::digits,
"NBLKS_BITS is too large and may cause overflow in blk_count_t");
return (1 << NBLKS_BITS);
}
[[nodiscard]] static constexpr uint64_t max_id_int() {
return (1ull << (BLK_NUM_BITS + NBLKS_BITS + CHUNK_NUM_BITS)) - 1;
}
Expand Down
9 changes: 5 additions & 4 deletions src/engine/blkstore/blkstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,14 @@ class BlkStore {
BlkAllocStatus alloc_contiguous_blk(const uint32_t size, blk_alloc_hints& hints, BlkId* const out_blkid) {
// Allocate a block from the device manager
assert(size % m_pagesz == 0);
const uint32_t nblks{static_cast< uint32_t >(size / m_pagesz)};
static uint32_t max_suppoted_size = m_pagesz * std::numeric_limits< blk_count_t >::max();
HS_REL_ASSERT_LE(size, max_suppoted_size, "size {} more than max size limit of {}", size, max_suppoted_size);

const blk_count_t nblks{static_cast< blk_count_t >(size / m_pagesz)};
hints.is_contiguous = true;
HS_DBG_ASSERT_LE(nblks, BlkId::max_blks_in_op(), "nblks {} more than max blks {}", nblks,
BlkId::max_blks_in_op());
return (m_vdev.alloc_contiguous_blk(static_cast< blk_count_t >(nblks), hints, out_blkid));
return (m_vdev.alloc_contiguous_blk(nblks, hints, out_blkid));
}

/* Allocate a new block of the size based on the hints provided */
Expand All @@ -341,8 +344,6 @@ class BlkStore {
// pages * 4096 bytes/page).
uint32_t nblks{static_cast< uint32_t >(size / m_pagesz)};
if (nblks <= BlkId::max_blks_in_op()) {
auto max_val = std::numeric_limits< blk_count_t >::max();
HS_DBG_ASSERT_LE(nblks, max_val, "max_blks_in_op must be less than {}", max_val);
return (m_vdev.alloc_blk(static_cast< blk_count_t >(nblks), hints, out_blkid));
} else {
while (nblks != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/homeblks/volume/tests/vol_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,7 @@ SISL_OPTION_GROUP(
(oob_unmap_enable, "", "oob_unmap_enable", "out-of-band unmap enable 0 or 1",
::cxxopts::value< uint32_t >()->default_value("0"), "flag"),
(max_disk_capacity, "", "max_disk_capacity", "max disk capacity",
::cxxopts::value< uint64_t >()->default_value("10"), "GB"),
::cxxopts::value< uint64_t >()->default_value("20"), "GB"),
(max_volume, "", "max_volume", "max volume", ::cxxopts::value< uint64_t >()->default_value("50"), "number"),
(max_num_writes, "", "max_num_writes", "max num of writes", ::cxxopts::value< uint64_t >()->default_value("100000"),
"number"),
Expand Down
2 changes: 1 addition & 1 deletion src/homeblks/volume/tool/hs_svc_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SISL_OPTION_GROUP(hs_svc_tool,
(device_list, "", "device_list", "List of device paths",
::cxxopts::value< std::vector< std::string > >(), "path [...]"),
(dev_size_gb, "", "dev_size_gb", "size of each device in GB",
::cxxopts::value< uint64_t >()->default_value("5"), "number"),
::cxxopts::value< uint64_t >()->default_value("10"), "number"),
(zero_boot_sb, "", "zero_boot_sb", "mark homestore init state",
::cxxopts::value< bool >()->default_value("false"), "true or false"),
(spdk, "", "spdk", "spdk", ::cxxopts::value< bool >()->default_value("false"), "true or false"));
Expand Down

0 comments on commit b44e697

Please sign in to comment.