Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yamingk committed May 15, 2024
1 parent 55f5a3d commit 3cac0e1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
9 changes: 6 additions & 3 deletions src/lib/device/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ static int determine_open_flags(io_flag oflags) {

switch (oflags) {
case io_flag::BUFFERED_IO:
open_flags = O_RDWR | O_CREAT;
// open_flags = O_RDWR | O_CREAT;
open_flags = O_RDWR;
break;
case io_flag::READ_ONLY:
open_flags = O_RDONLY;
break;
case io_flag::DIRECT_IO:
open_flags = O_RDWR | O_CREAT | O_DIRECT;
// open_flags = O_RDWR | O_CREAT | O_DIRECT;
open_flags = O_RDWR | O_DIRECT;
break;
default:
open_flags = O_RDWR | O_CREAT;
// open_flags = O_RDWR | O_CREAT;
open_flags = O_RDWR;
}

return open_flags;
Expand Down
38 changes: 20 additions & 18 deletions src/tests/test_common/homestore_test_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <homestore/index_service.hpp>
#include <homestore/replication_service.hpp>
#include <homestore/checkpoint/cp_mgr.hpp>
#include <../lib/device/hs_super_blk.h>
#include <device/hs_super_blk.h>
#include <iomgr/iomgr_config_generated.h>
#include <common/homestore_assert.hpp>

Expand Down Expand Up @@ -200,27 +200,29 @@ class HSTestHelper {
s_dev_names.begin(), s_dev_names.end(), std::string(""),
[](const std::string& ss, const std::string& s) { return ss.empty() ? s : ss + "," + s; }));

// zero the homestore pdev's first block for each device;
auto const zero_size = hs_super_blk::first_block_size();
std::vector< int > zeros(zero_size, 0);
for (auto const& d : cust_dev_names) {
if (!std::filesystem::exists(d)) {
LOGINFO("Device {} does not exist", d);
HS_REL_ASSERT(false, "Device does not exist");
if (init_device && !fake_restart) {
// zero the homestore pdev's first block for each device;
auto const zero_size = hs_super_blk::first_block_size() * 1024;
std::vector< int > zeros(zero_size, 0);
for (auto const& d : s_dev_names) {
if (!std::filesystem::exists(d)) {
LOGINFO("Device {} does not exist", d);
HS_REL_ASSERT(false, "Device does not exist");
}

auto fd = ::open(d.c_str(), O_RDWR, 0640);
HS_REL_ASSERT(fd != -1, "Failed to open device");

auto const write_sz =
pwrite(fd, zeros.data(), zero_size /* size */, hs_super_blk::first_block_offset() /* offset */);
HS_REL_ASSERT(write_sz == zero_size, "Failed to write to device");
LOGINFO("Successfully zeroed the 1st {} of device {}", zero_size, d);
::close(fd);
}

auto fd = ::open(d.c_str(), O_RDWR | O_CREAT, 0640);
HS_REL_ASSERT(fd != -1, "Failed to open device");

auto const write_sz =
pwrite(fd, zeros.data(), zero_size /* size */, hs_super_blk::first_block_offset() /* offset */);
HS_REL_ASSERT(write_sz == zero_size, "Failed to write to device");
LOGINFO("Successfully zeroed the 1st {} of device {}", zero_size, d);
::close(fd);
}

for (const auto& name : s_dev_names) {
iomgr::DriveInterface::emulate_drive_type(name, iomgr::drive_type::block_hdd);
// iomgr::DriveInterface::emulate_drive_type(name, iomgr::drive_type::block_hdd);
device_info.emplace_back(name, homestore::HSDevType::Data);
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test_common/hs_repl_test_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ class HSReplTestHelper {
void teardown() {
LOGINFO("Stopping Homestore replica={}", replica_num_);
// sisl::GrpcAsyncClientWorker::shutdown_all();
test_common::HSTestHelper::shutdown_homestore();
// don't remove device if it is real drive;
test_common::HSTestHelper::shutdown_homestore(dev_list_.empty() /* cleanup */);
sisl::GrpcAsyncClientWorker::shutdown_all();
}

Expand Down

0 comments on commit 3cac0e1

Please sign in to comment.