diff --git a/.github/workflows/merge_build_3x.yml b/.github/workflows/merge_build_3x.yml index 8ecfca0ce..8fa6ad989 100644 --- a/.github/workflows/merge_build_3x.yml +++ b/.github/workflows/merge_build_3x.yml @@ -4,7 +4,8 @@ on: workflow_dispatch: push: branches: - - stable/v3.x + - master + - stable/** jobs: Build: diff --git a/.github/workflows/pr_conan_build.yml b/.github/workflows/pr_conan_build.yml index a16faae34..2c3202822 100644 --- a/.github/workflows/pr_conan_build.yml +++ b/.github/workflows/pr_conan_build.yml @@ -4,7 +4,7 @@ on: pull_request: branches: - master - - stable/v3.x + - stable/** jobs: Build: diff --git a/conanfile.py b/conanfile.py index f2c8a9ec5..151705aa5 100644 --- a/conanfile.py +++ b/conanfile.py @@ -2,7 +2,7 @@ class HomestoreConan(ConanFile): name = "homestore" - version = "3.8.3" + version = "3.8.4" homepage = "https://github.corp.ebay.com/SDS/homestore" description = "HomeStore" diff --git a/src/engine/blkalloc/blk.h b/src/engine/blkalloc/blk.h index 5429f77bf..a5e71296d 100644 --- a/src/engine/blkalloc/blk.h +++ b/src/engine/blkalloc/blk.h @@ -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; } diff --git a/src/engine/blkstore/blkstore.hpp b/src/engine/blkstore/blkstore.hpp index 34d830bb3..db6141ea3 100644 --- a/src/engine/blkstore/blkstore.hpp +++ b/src/engine/blkstore/blkstore.hpp @@ -54,7 +54,7 @@ VENUM(BlkStoreCacheType, uint8_t, PASS_THRU = 0, WRITEBACK_CACHE = 1, WRITETHRU_ * be either be discarded or copied into new buffer. This threshold dictates whats the value of (64K - N) upto which * it will copy. In other words ((64K - N) <= CACHE_DISCARD_THRESHOLD_SIZE) ? copy : discard */ -//#define CACHE_DISCARD_THRESHOLD_SIZE 16384 +// #define CACHE_DISCARD_THRESHOLD_SIZE 16384 class BlkStoreConfig { public: @@ -325,6 +325,9 @@ 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); + 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, @@ -336,15 +339,18 @@ class BlkStore { BlkAllocStatus alloc_blk(const uint32_t size, blk_alloc_hints& hints, std::vector< BlkId >& out_blkid) { // Allocate a block from the device manager assert(size % m_pagesz == 0); - blk_count_t nblks{static_cast< blk_count_t >(size / m_pagesz)}; + // Using a 16-bit value (blk_count_t) for page counts can lead to overflow issues when managing large storage + // devices. With a page size of 4096 bytes, a 16-bit value limits the addressable storage to 256 MB (65,536 + // pages * 4096 bytes/page). + uint32_t nblks{static_cast< uint32_t >(size / m_pagesz)}; if (nblks <= BlkId::max_blks_in_op()) { - return (m_vdev.alloc_blk(nblks, hints, out_blkid)); + return (m_vdev.alloc_blk(static_cast< blk_count_t >(nblks), hints, out_blkid)); } else { while (nblks != 0) { static thread_local std::vector< BlkId > result_blkid{}; result_blkid.clear(); - const blk_count_t nblks_op{std::min(static_cast< blk_count_t >(BlkId::max_blks_in_op()), nblks)}; - const auto ret{m_vdev.alloc_blk(nblks_op, hints, result_blkid)}; + const uint32_t nblks_op{std::min(static_cast< uint32_t >(BlkId::max_blks_in_op()), nblks)}; + const auto ret{m_vdev.alloc_blk(static_cast< blk_count_t >(nblks_op), hints, result_blkid)}; if (ret != BlkAllocStatus::SUCCESS) { return ret; } out_blkid.insert(std::end(out_blkid), std::make_move_iterator(std::begin(result_blkid)), std::make_move_iterator(std::end(result_blkid))); diff --git a/src/engine/meta/meta_blks_mgr.cpp b/src/engine/meta/meta_blks_mgr.cpp index 14d3c5f88..94cb4863a 100644 --- a/src/engine/meta/meta_blks_mgr.cpp +++ b/src/engine/meta/meta_blks_mgr.cpp @@ -1018,6 +1018,7 @@ void MetaBlkMgr::alloc_meta_blk(const uint64_t size, std::vector< BlkId >& bid) try { const auto ret{m_sb_blk_store->alloc_blk(size, hints, bid)}; HS_REL_ASSERT_EQ(ret, BlkAllocStatus::SUCCESS); + HS_REL_ASSERT_NE(bid.size(), 0); #ifndef NDEBUG uint64_t debug_size{0}; for (size_t i{0}; i < bid.size(); ++i) {