]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/os/seastore/rbm: remove block_size and size in RBMDevice
authormyoungwon oh <ohmyoungwon@gmail.com>
Fri, 14 Oct 2022 07:27:50 +0000 (16:27 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Tue, 18 Oct 2022 02:32:45 +0000 (11:32 +0900)
Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/crimson/os/seastore/random_block_manager/nvme_block_device.cc
src/crimson/os/seastore/random_block_manager/rbm_device.h
src/test/crimson/seastore/test_cbjournal.cc
src/test/crimson/seastore/test_randomblock_manager.cc
src/test/crimson/seastore/transaction_manager_test_state.h

index e6b7d449f9f33cce751122a2e6a400530f2e2efa..7a5ae18ce057f5675741b5e8795c0fff5735b696 100644 (file)
@@ -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<size_t> {
@@ -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(),
index b2565fffda0eee84ca8e56348a60bfefda7c1887..4a94805199e6ca1ad0d3731d8de053d1ca2f380b 100644 (file)
@@ -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([]() {
index 73e5ac0048ee8978e8ae5140b69ed21d3701ee27..ef1fb23303c0f55897df3222fc482e3f360f7ec3 100644 (file)
@@ -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<device_id_t>::digits - 1);
     config.block_size = CBTEST_DEFAULT_BLOCK_SIZE;
index 05b97e440bbbd8a1fc07d6bd983b9d27678b43c1..2f5bed810191e9c55606cb0023f0c06d37b1ef57 100644 (file)
@@ -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 
    );
  });
index 7f383f71a30efb1751f96e63964477907ccb9867..5ffb8fd7f6d27411cf014f610f19eaac12a295ad 100644 (file)
@@ -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<device_id_t>::digits - 1));
     return rb_device->mount().handle_error(crimson::ct_error::assert_all{}