From 3cac0e13e2200c0bad7ed40fd2cffb4413271883 Mon Sep 17 00:00:00 2001 From: Yaming Kuang Date: Wed, 15 May 2024 11:58:16 -0700 Subject: [PATCH] fix --- src/lib/device/device_manager.cpp | 9 +++-- .../test_common/homestore_test_common.hpp | 38 ++++++++++--------- src/tests/test_common/hs_repl_test_common.hpp | 3 +- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/lib/device/device_manager.cpp b/src/lib/device/device_manager.cpp index fb0056cb6..df74ebd38 100644 --- a/src/lib/device/device_manager.cpp +++ b/src/lib/device/device_manager.cpp @@ -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; diff --git a/src/tests/test_common/homestore_test_common.hpp b/src/tests/test_common/homestore_test_common.hpp index 88c0655f0..945525eee 100644 --- a/src/tests/test_common/homestore_test_common.hpp +++ b/src/tests/test_common/homestore_test_common.hpp @@ -28,7 +28,7 @@ #include #include #include -#include <../lib/device/hs_super_blk.h> +#include #include #include @@ -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 { diff --git a/src/tests/test_common/hs_repl_test_common.hpp b/src/tests/test_common/hs_repl_test_common.hpp index e2e78f9cf..32babbe11 100644 --- a/src/tests/test_common/hs_repl_test_common.hpp +++ b/src/tests/test_common/hs_repl_test_common.hpp @@ -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(); }