Skip to content

Commit 6959a7a

Browse files
Merge pull request #3 from shosseinimotlagh/cherry/ubsan-fix
blkstore: use dynamic_pointer_cast in to_blkstore_req to fix UBSan downcast error
2 parents 24fb309 + 121c1d9 commit 6959a7a

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

‎src/engine/blkstore/blkstore.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct blkstore_req : public virtualdev_req {
116116
}
117117
};
118118

119-
static auto to_blkstore_req(auto& req) { return boost::static_pointer_cast< blkstore_req< Buffer > >(req); }
119+
static auto to_blkstore_req(auto& req) { return boost::dynamic_pointer_cast< blkstore_req< Buffer > >(req); }
120120

121121
static boost::intrusive_ptr< blkstore_req< Buffer > > make_request() {
122122
return boost::intrusive_ptr< blkstore_req< Buffer > >(

‎src/engine/homeds/tests/test_wb_cache_integration.cpp‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,27 @@
6363
#include "engine/homeds/btree/btree.hpp"
6464
#include "engine/index/indx_mgr.hpp"
6565
#include "homeblks/home_blks.hpp"
66+
#include "homeblks/volume/mapping.hpp"
6667
#include "test_common/homestore_test_common.hpp"
6768

68-
// Reuse the key/value types already used by test_load's SSDBtreeTest
69-
#include "homeds/tests/loadgen_tests/keyspecs/simple_key_spec.hpp"
70-
#include "homeds/tests/loadgen_tests/valuespecs/fixedbyte_value_spec.hpp"
71-
7269
SISL_LOGGING_INIT(HOMESTORE_LOG_MODS)
7370
SISL_OPTIONS_ENABLE(logging)
7471

7572
RCU_REGISTER_INIT
7673

7774
using namespace homestore;
7875
using namespace homeds::btree;
79-
using namespace homeds::loadgen;
8076

8177
namespace fs = std::filesystem;
8278

8379
// ============================================================================
8480
// Types
8581
// ============================================================================
8682

87-
using WbTestKey = SimpleNumberKey;
88-
using WbTestVal = FixedBytesValue< 64 >;
89-
using WbTestBtree = Btree< btree_store_type::SSD_BTREE, WbTestKey, WbTestVal,
90-
btree_node_type::SIMPLE, btree_node_type::SIMPLE >;
83+
// Must match BLKSTORE_BUFFER_TYPE used by the index blkstore so that
84+
// dynamic_pointer_cast in blkstore's process_completions succeeds.
85+
using WbTestBtree = Btree< btree_store_type::SSD_BTREE, MappingKey, MappingValue,
86+
btree_node_type::VAR_VALUE, btree_node_type::VAR_VALUE >;
9187

9288
static constexpr uint64_t DISK_SIZE{2 * 1024 * 1024 * 1024ULL}; // 2 GiB
9389
static const std::string DISK_FILE{"wbcache_integration_test_disk"};
@@ -147,8 +143,8 @@ class WbCacheIntegrationTest : public ::testing::Test {
147143
// directly in TearDown to drain dirty wb_cache buffers.
148144
BtreeConfig cfg{4096};
149145
cfg.set_max_objs(100000);
150-
cfg.set_max_key_size(WbTestKey::get_max_size());
151-
cfg.set_max_value_size(WbTestVal::get_max_size());
146+
cfg.set_max_key_size(sizeof(uint32_t));
147+
cfg.set_max_value_size(4096);
152148
cfg.blkstore = HomeBlks::instance()->get_index_blkstore();
153149
m_btree = std::unique_ptr< WbTestBtree >(WbTestBtree::create_btree(cfg));
154150
m_bcp = m_btree->attach_prepare_cp(nullptr, false, false);
@@ -169,8 +165,8 @@ class WbCacheIntegrationTest : public ::testing::Test {
169165
}
170166

171167
void btree_put(uint64_t key_id) {
172-
WbTestKey k{key_id};
173-
WbTestVal v;
168+
MappingKey k{static_cast< lba_t >(key_id), 1};
169+
MappingValue v;
174170
m_btree->put(k, v, btree_put_type::REPLACE_IF_EXISTS_ELSE_INSERT, &v, m_bcp);
175171
}
176172

0 commit comments

Comments
 (0)