Skip to content

Commit

Permalink
change number 1 which didn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
shosseinimotlagh committed Mar 4, 2024
1 parent b3d7e28 commit 6be0185
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/engine/blkalloc/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct BlkId {
bool operator==(const BlkId& other) noexcept { return (compare(*this, other) == 0); }

void invalidate() { set(blk_num_t{0}, blk_count_t{0}, s_chunk_num_mask); }

// return invalid_blk_id() { return blk_count_t{0}; }
[[nodiscard]] bool is_valid() const { return (m_chunk_num != s_chunk_num_mask); }

[[nodiscard]] BlkId get_blkid_at(const uint32_t offset, const uint32_t pagesz) const {
Expand Down
3 changes: 3 additions & 0 deletions src/homeblks/homeblks_config.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ table GeneralConfig {
// These fields should only be changed by agent through workflow
boot_restricted_mode: bool = false;
boot_safe_mode: bool = false;

// This field is for enabling thin provisioing on booting
boot_thin_provisioning: bool = true;
}

table HomeBlksSettings {
Expand Down
71 changes: 66 additions & 5 deletions src/homeblks/volume/tests/vol_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,8 @@ class IOTestJob : public TestJob {
// lba: [0, max_vol_blks - max_blks)
std::uniform_int_distribution< uint64_t > lba_random{0, vinfo->max_vol_blks - max_blks - 1};
// nlbas: [1, max_blks]
std::uniform_int_distribution< uint32_t > nlbas_random{1, max_blks};
// std::uniform_int_distribution< uint32_t > nlbas_random{1, max_blks};
std::uniform_int_distribution< uint32_t > nlbas_random{1, 5};

// we won't be writing more then 128 blocks in one io
uint32_t attempt{1};
Expand Down Expand Up @@ -1816,38 +1817,44 @@ class IOTestJob : public TestJob {
const uint64_t page_size{VolInterface::get_instance()->get_page_size(vol)};
const uint64_t size{nlbas * page_size};
boost::intrusive_ptr< io_req_t > vreq{};

static thread_local std::random_device rd{};
static thread_local std::default_random_engine engine{rd()};
static thread_local std::uniform_int_distribution< uint8_t > dist{0, 1};

if (tcfg.write_cache) {
uint8_t* const wbuf{iomanager.iobuf_alloc(512, size)};
HS_REL_ASSERT_NOTNULL(wbuf);

populate_buf(wbuf, size, lba, vinfo.get());

populate_zero_buf(wbuf, size, vinfo.get());
vreq = boost::intrusive_ptr< io_req_t >(
new io_req_t(vinfo, Op_type::WRITE, wbuf, lba, nlbas, tcfg.verify_csum(), tcfg.write_cache));
} else {
static bool send_iovec{true};
static bool send_iovec{false};
std::vector< iovec > iovecs{};
if (send_iovec) {
for (uint32_t lba_num{0}; lba_num < nlbas; ++lba_num) {
uint8_t* const wbuf{iomanager.iobuf_alloc(512, page_size)};
HS_REL_ASSERT_NOTNULL(wbuf);
iovec iov{static_cast< void* >(wbuf), static_cast< size_t >(page_size)};
iovecs.emplace_back(std::move(iov));

populate_buf(wbuf, page_size, lba + lba_num, vinfo.get());
populate_zero_buf(wbuf, size, vinfo.get());
}

vreq = boost::intrusive_ptr< io_req_t >(new io_req_t(vinfo, Op_type::WRITE, std::move(iovecs), lba,
nlbas, tcfg.verify_csum(), tcfg.write_cache));
} else {
uint8_t* const wbuf{iomanager.iobuf_alloc(512, size)};
populate_buf(wbuf, size, lba, vinfo.get());
populate_zero_buf(wbuf, size, vinfo.get());
HS_REL_ASSERT_NOTNULL(wbuf);

vreq = boost::intrusive_ptr< io_req_t >{
new io_req_t(vinfo, Op_type::WRITE, wbuf, lba, nlbas, tcfg.verify_csum(), tcfg.write_cache)};
}
send_iovec = !send_iovec;
// send_iovec = !send_iovec;
}
vreq->cookie = static_cast< void* >(this);

Expand All @@ -1862,6 +1869,40 @@ class IOTestJob : public TestJob {
return true;
}

void populate_zero_buf(uint8_t* buf, const uint64_t size, const vol_info_t* const vinfo) {
auto page_size = VolInterface::get_instance()->get_page_size(vinfo->vol);
auto nlbas = size / page_size;
static thread_local std::random_device rd{};
static thread_local std::default_random_engine engine{rd()};
static thread_local std::uniform_int_distribution< uint8_t > dist{0, 100};
// std::fill_n(buf + nlbas/2 * page_size, page_size, 0);
// {
// // first zero
// std::fill_n(buf, page_size, 0);
// }
{
// first x lbas the non_zero the rest zero

if (nlbas >= 2)
std::fill_n(buf + page_size, (nlbas -1) *page_size, 0);
}
// {
// // randomly 5% of lbas can be zero
// for (long unsigned int i = 0; i < nlbas; ++i) {
// if (dist(engine) < 5) { std::fill_n(buf + i * page_size, page_size, 0); }
// }
// }
// {
// // one lba in the middle can be zero (two sub non empty ranges)
// std::uniform_int_distribution< uint8_t > ran_lba{1, nlbas-1};
// auto l1= ran_lba(engine);
// auto l2= ran_lba(engine);
// auto lb1 = std::min(l1,l2);
// auto lb2 = std::max(l1,l2);
// std::fill_n(buf + l1 * page_size, (lb2 -lb1 +1) *page_size, 0);
// }
}

void populate_buf(uint8_t* const buf, const uint64_t size, const uint64_t lba, const vol_info_t* const vinfo) {
static thread_local std::random_device rd{};
static thread_local std::default_random_engine engine{rd()};
Expand All @@ -1881,6 +1922,7 @@ class IOTestJob : public TestJob {
}

bool read_vol(const uint32_t cur, const uint64_t lba, const uint32_t nlbas) {
return true;
const auto vinfo{m_voltest->m_vol_info[cur]};
const auto vol{vinfo->vol};
if (vol == nullptr) { return false; }
Expand Down Expand Up @@ -1958,6 +2000,8 @@ class IOTestJob : public TestJob {
}

bool verify(const boost::intrusive_ptr< io_req_t >& req, const bool can_panic = true) const {
return true;
#if 0
const auto& vol_req{static_cast< vol_interface_req_ptr >(req)};

const auto verify_buffer{[this, &req, &can_panic](const uint8_t* const validate_buffer,
Expand Down Expand Up @@ -2063,7 +2107,9 @@ class IOTestJob : public TestJob {
tcfg.verify_csum() ? (HS_REL_ASSERT_EQ(total_size_read_csum, req->verify_size))
: (HS_REL_ASSERT_EQ(total_size_read, req->original_size));
return true;
#endif
}

};

class VolVerifyJob : public IOTestJob {
Expand Down Expand Up @@ -2224,6 +2270,21 @@ TEST_F(VolTest, init_io_test) {
if (tcfg.remove_file_on_shutdown) { this->remove_files(); }
}

TEST_F(VolTest, thin_test) {
this->start_homestore();
std::unique_ptr< VolCreateDeleteJob > cdjob;
if (tcfg.create_del_with_io || tcfg.delete_with_io) {
cdjob = std::make_unique< VolCreateDeleteJob >(this);
this->start_job(cdjob.get(), wait_type::no_wait);
}

this->start_io_job();
output.print("init_io_test");

if (tcfg.create_del_with_io || tcfg.delete_with_io) { cdjob->wait_for_completion(); }
this->shutdown();
}

/*!
@test recovery_io_test
@brief Tests which does recovery. End up with a clean shutdown
Expand Down
Loading

0 comments on commit 6be0185

Please sign in to comment.