From: myoungwon oh Date: Fri, 14 Oct 2022 07:27:50 +0000 (+0900) Subject: crimson/os/seastore/rbm: remove block_size and size in RBMDevice X-Git-Tag: v18.1.0~336^2~1^2~9 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=18f11466adb983c999c2a20ea77815f86c31c5e9;p=ceph-ci.git crimson/os/seastore/rbm: remove block_size and size in RBMDevice Signed-off-by: Myoungwon Oh --- diff --git a/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc b/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc index e6b7d449f9f..7a5ae18ce05 100644 --- a/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc +++ b/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc @@ -19,6 +19,7 @@ namespace { return crimson::get_logger(ceph_subsys_seastore_tm); } } + namespace crimson::os::seastore::random_block_device { #include "crimson/os/seastore/logging.h" SET_SUBSYS(seastore_device); @@ -26,6 +27,7 @@ SET_SUBSYS(seastore_device); RBMDevice::mkfs_ret RBMDevice::mkfs(device_config_t config) { LOG_PREFIX(RBMDevice::mkfs); super.start = 0; + // TODO: improve mkfs() based on a file descriptor super.block_size = get_block_size(); super.size = get_available_size(); @@ -128,7 +130,8 @@ open_ertr::future<> NVMeBlockDevice::open( seastar::open_flags mode) { return seastar::do_with(in_path, [this, mode](auto& in_path) { return seastar::file_stat(in_path).then([this, mode, in_path](auto stat) { - size = stat.size; + super.size = stat.size; + super.block_size = stat.block_size; return seastar::open_file_dma(in_path, mode).then([=, this](auto file) { device = file; logger().debug("open"); @@ -145,14 +148,14 @@ open_ertr::future<> NVMeBlockDevice::open( auto id_namespace_data) { // LBA format provides LBA size which is power of 2. LBA is the // minimum size of read and write. - block_size = (1 << id_namespace_data.lbaf0.lbads); - atomic_write_unit = awupf * block_size; + super.block_size = (1 << id_namespace_data.lbaf0.lbads); + atomic_write_unit = awupf * super.block_size; data_protection_type = id_namespace_data.dps.protection_type; data_protection_enabled = (data_protection_type > 0); if (id_namespace_data.nsfeat.opterf == 1){ // NPWG and NPWA is 0'based value - write_granularity = block_size * (id_namespace_data.npwg + 1); - write_alignment = block_size * (id_namespace_data.npwa + 1); + write_granularity = super.block_size * (id_namespace_data.npwg + 1); + write_alignment = super.block_size * (id_namespace_data.npwa + 1); } return open_for_io(in_path, mode); }); @@ -193,7 +196,7 @@ write_ertr::future<> NVMeBlockDevice::write( bptr.length()); auto length = bptr.length(); - assert((length % block_size) == 0); + assert((length % super.block_size) == 0); uint16_t supported_stream = stream; if (stream >= stream_id_count) { supported_stream = WRITE_LIFE_NOT_SET; @@ -221,7 +224,7 @@ read_ertr::future<> NVMeBlockDevice::read( bptr.length()); auto length = bptr.length(); - assert((length % block_size) == 0); + assert((length % super.block_size) == 0); return device.dma_read(offset, bptr.c_str(), length).handle_exception( [](auto e) -> read_ertr::future { @@ -249,7 +252,7 @@ write_ertr::future<> NVMeBlockDevice::writev( if (stream >= stream_id_count) { supported_stream = WRITE_LIFE_NOT_SET; } - bl.rebuild_aligned(block_size); + bl.rebuild_aligned(super.block_size); return seastar::do_with( bl.prepare_iovs(), diff --git a/src/crimson/os/seastore/random_block_manager/rbm_device.h b/src/crimson/os/seastore/random_block_manager/rbm_device.h index b2565fffda0..4a94805199e 100644 --- a/src/crimson/os/seastore/random_block_manager/rbm_device.h +++ b/src/crimson/os/seastore/random_block_manager/rbm_device.h @@ -83,11 +83,6 @@ public: return read(rbm_addr, out); } protected: - uint64_t size = 0; - - // LBA Size - uint64_t block_size = 4096; - rbm_metadata_header_t super; public: RBMDevice() {} @@ -101,14 +96,11 @@ public: device_id_t get_device_id() const { return super.config.spec.id; } + // for test void set_device_id(device_id_t id) { super.config.spec.id = id; } - void set_block_size(uint64_t bs) { - block_size = bs; - } - magic_t get_magic() const final { return super.config.spec.magic; } @@ -128,8 +120,8 @@ public: secondary_device_set_t& get_secondary_devices() final { return super.config.secondary_devices; } - std::size_t get_available_size() const final { return size; } - extent_len_t get_block_size() const final { return block_size; } + std::size_t get_available_size() const { return super.size; } + extent_len_t get_block_size() const { return super.block_size; } virtual read_ertr::future<> read( uint64_t offset, @@ -172,9 +164,11 @@ public: class TestMemory : public RBMDevice { public: + uint64_t size = 0; + uint64_t block_size = 0; - TestMemory(size_t size) : buf(nullptr) { - RBMDevice::size = size; + TestMemory(size_t size, uint64_t block_size) : + size(size), block_size(block_size), buf(nullptr) { } ~TestMemory() { if (buf) { @@ -183,6 +177,9 @@ public: } } + std::size_t get_available_size() const final { return size; } + extent_len_t get_block_size() const final { return block_size; } + mount_ret mount() final { return open("", seastar::open_flags::rw ).safe_then([]() { diff --git a/src/test/crimson/seastore/test_cbjournal.cc b/src/test/crimson/seastore/test_cbjournal.cc index 73e5ac0048e..ef1fb23303c 100644 --- a/src/test/crimson/seastore/test_cbjournal.cc +++ b/src/test/crimson/seastore/test_cbjournal.cc @@ -132,7 +132,9 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer WritePipeline pipeline; cbjournal_test_t() { - device = new random_block_device::TestMemory(CBTEST_DEFAULT_TEST_SIZE + CBTEST_DEFAULT_BLOCK_SIZE); + device = new random_block_device::TestMemory( + CBTEST_DEFAULT_TEST_SIZE + CBTEST_DEFAULT_BLOCK_SIZE, + CBTEST_DEFAULT_BLOCK_SIZE); cbj.reset(new CircularBoundedJournal(*this, device, std::string())); device_id_t d_id = 1 << (std::numeric_limits::digits - 1); config.block_size = CBTEST_DEFAULT_BLOCK_SIZE; diff --git a/src/test/crimson/seastore/test_randomblock_manager.cc b/src/test/crimson/seastore/test_randomblock_manager.cc index 05b97e440bb..2f5bed81019 100644 --- a/src/test/crimson/seastore/test_randomblock_manager.cc +++ b/src/test/crimson/seastore/test_randomblock_manager.cc @@ -51,7 +51,7 @@ struct rbm_test_t : rbm_test_t() = default; seastar::future<> set_up_fut() final { - device.reset(new random_block_device::TestMemory(DEFAULT_TEST_SIZE)); + device.reset(new random_block_device::TestMemory(DEFAULT_TEST_SIZE, DEFAULT_BLOCK_SIZE)); rbm_manager.reset(new BlockRBManager(device.get(), std::string())); config = get_rbm_ephemeral_device_config(0, 1); return device->mount().handle_error(crimson::ct_error::assert_all{} @@ -122,11 +122,11 @@ TEST_F(rbm_test_t, mkfs_test) super.block_size == DEFAULT_BLOCK_SIZE && super.size == DEFAULT_TEST_SIZE ); - device->set_block_size(8196); + config.spec.id = DEVICE_ID_NULL; mkfs(); super = read_rbm_header(); ASSERT_TRUE( - super.block_size == 8196 && + super.config.spec.id == DEVICE_ID_NULL && super.size == DEFAULT_TEST_SIZE ); }); diff --git a/src/test/crimson/seastore/transaction_manager_test_state.h b/src/test/crimson/seastore/transaction_manager_test_state.h index 7f383f71a30..5ffb8fd7f6d 100644 --- a/src/test/crimson/seastore/transaction_manager_test_state.h +++ b/src/test/crimson/seastore/transaction_manager_test_state.h @@ -119,7 +119,7 @@ protected: auto config = journal::CircularBoundedJournal::mkfs_config_t::get_default(); rb_device.reset(new random_block_device::TestMemory( - config.total_size + config.block_size)); + config.total_size + config.block_size, config.block_size)); rb_device->set_device_id( 1 << (std::numeric_limits::digits - 1)); return rb_device->mount().handle_error(crimson::ct_error::assert_all{}