]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/rbm: create a device file if it doesn't exist
authormyoungwon oh <ohmyoungwon@gmail.com>
Fri, 21 Feb 2025 11:59:07 +0000 (11:59 +0000)
committermyoungwon oh <ohmyoungwon@gmail.com>
Fri, 7 Mar 2025 02:01:24 +0000 (02:01 +0000)
Signed-off-by: Myoungwon Oh <ohmyoungwon@gmail.com>
src/crimson/os/seastore/device.cc
src/crimson/os/seastore/device.h
src/crimson/os/seastore/random_block_manager/rbm_device.cc
src/crimson/os/seastore/segment_manager/block.cc

index cc83eb54826a6bfdf368ec36d26b55659e70e341..8940afb3590a26f920200ef47e1e0c4c8736eb79 100644 (file)
@@ -7,6 +7,8 @@
 #include "random_block_manager.h"
 #include "random_block_manager/rbm_device.h"
 
+SET_SUBSYS(seastore);
+
 namespace crimson::os::seastore {
 
 std::ostream& operator<<(std::ostream& out, const device_spec_t& ds)
@@ -48,4 +50,54 @@ Device::make_device(const std::string& device, device_type_t dtype)
   });
 }
 
+check_create_device_ret check_create_device(
+  const std::string path,
+  size_t size)
+{
+  LOG_PREFIX(block_check_create_device);
+  INFO("path={}, size=0x{:x}", path, size);
+  return seastar::open_file_dma(
+    path,
+    seastar::open_flags::exclusive |
+    seastar::open_flags::rw |
+    seastar::open_flags::create
+  ).then([size, FNAME, path](auto file) {
+    return seastar::do_with(
+      file,
+      [size, FNAME, path](auto &f) -> seastar::future<>
+    {
+      DEBUG("path={} created, truncating to 0x{:x}", path, size);
+      ceph_assert(f);
+      return f.truncate(
+        size
+      ).then([&f, size] {
+        return f.allocate(0, size);
+      }).finally([&f] {
+        return f.close();
+      });
+    });
+  }).then_wrapped([path, FNAME](auto f) -> check_create_device_ret {
+    if (f.failed()) {
+      try {
+       f.get();
+       return seastar::now();
+      } catch (const std::system_error &e) {
+       if (e.code().value() == EEXIST) {
+          ERROR("path={} exists", path);
+         return seastar::now();
+       } else {
+          ERROR("path={} creation error -- {}", path, e);
+         return crimson::ct_error::input_output_error::make();
+       }
+      } catch (...) {
+        ERROR("path={} creation error", path);
+       return crimson::ct_error::input_output_error::make();
+      }
+    }
+
+    DEBUG("path={} complete", path);
+    std::ignore = f.discard_result();
+    return seastar::now();
+  });
+}
 }
index 56d0c889b7b5297f7752aefc8aae2ae9f65d0fd5..3040d86296bf0b0d05312dde79ae39bc40f61cc1 100644 (file)
@@ -168,6 +168,11 @@ public:
   }
 };
 
+using check_create_device_ertr = Device::access_ertr;
+using check_create_device_ret = check_create_device_ertr::future<>;
+check_create_device_ret check_create_device(
+  const std::string path,
+  size_t size);
 }
 
 WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::device_spec_t)
index cd0675f220dc9a81d8db9cae60283ec0b6bd0e9c..bc592d12bcbad76ae444fdc8512f8b67926691ec 100644 (file)
@@ -21,52 +21,61 @@ SET_SUBSYS(seastore_device);
 RBMDevice::mkfs_ret RBMDevice::do_primary_mkfs(device_config_t config,
   int shard_num, size_t journal_size) {
   LOG_PREFIX(RBMDevice::do_primary_mkfs);
-  return stat_device(
-  ).handle_error(
-    mkfs_ertr::pass_further{},
-    crimson::ct_error::assert_all{
-    "Invalid error stat_device in RBMDevice::do_primary_mkfs"}
-  ).safe_then(
-    [this, FNAME, config=std::move(config), shard_num, journal_size](auto st) {
-    super.block_size = st.block_size;
-    super.size = st.size;
-    super.config = std::move(config);
-    super.journal_size = journal_size;
-    ceph_assert_always(super.journal_size > 0);
-    ceph_assert_always(super.size >= super.journal_size);
-    ceph_assert_always(shard_num > 0);
-
-    std::vector<rbm_shard_info_t> shard_infos(shard_num);
-    for (int i = 0; i < shard_num; i++) {
-      uint64_t aligned_size = 
-       (super.size / shard_num) -
-       ((super.size / shard_num) % super.block_size);
-      shard_infos[i].size = aligned_size;
-      shard_infos[i].start_offset = i * aligned_size;
-      assert(shard_infos[i].size > super.journal_size);
-    }
-    super.shard_infos = shard_infos;
-    super.shard_num = shard_num;
-    shard_info = shard_infos[seastar::this_shard_id()];
-    DEBUG("super {} ", super);
-
-    // write super block
-    return open(get_device_path(),
-      seastar::open_flags::rw | seastar::open_flags::dsync
+  check_create_device_ret maybe_create = check_create_device_ertr::now();
+  using crimson::common::get_conf;
+  if (get_conf<bool>("seastore_block_create") && !get_device_path().empty()) {
+    auto size = get_conf<Option::size_t>("seastore_device_size");
+    maybe_create = check_create_device(get_device_path(), size);
+  }
+  return maybe_create.safe_then([this, FNAME, config=std::move(config),
+    shard_num, journal_size] {
+    return stat_device(
     ).handle_error(
       mkfs_ertr::pass_further{},
       crimson::ct_error::assert_all{
-      "Invalid error open in RBMDevice::do_primary_mkfs"}
-    ).safe_then([this] {
-      return initialize_nvme_features(
+      "Invalid error stat_device in RBMDevice::do_primary_mkfs"}
+    ).safe_then(
+      [this, FNAME, config=std::move(config), shard_num, journal_size](auto st) {
+      super.block_size = st.block_size;
+      super.size = st.size;
+      super.config = std::move(config);
+      super.journal_size = journal_size;
+      ceph_assert_always(super.journal_size > 0);
+      ceph_assert_always(super.size >= super.journal_size);
+      ceph_assert_always(shard_num > 0);
+
+      std::vector<rbm_shard_info_t> shard_infos(shard_num);
+      for (int i = 0; i < shard_num; i++) {
+       uint64_t aligned_size = 
+         (super.size / shard_num) -
+         ((super.size / shard_num) % super.block_size);
+       shard_infos[i].size = aligned_size;
+       shard_infos[i].start_offset = i * aligned_size;
+       assert(shard_infos[i].size > super.journal_size);
+      }
+      super.shard_infos = shard_infos;
+      super.shard_num = shard_num;
+      shard_info = shard_infos[seastar::this_shard_id()];
+      DEBUG("super {} ", super);
+
+      // write super block
+      return open(get_device_path(),
+       seastar::open_flags::rw | seastar::open_flags::dsync
+      ).handle_error(
+       mkfs_ertr::pass_further{},
+       crimson::ct_error::assert_all{
+       "Invalid error open in RBMDevice::do_primary_mkfs"}
       ).safe_then([this] {
-       return write_rbm_superblock(
+       return initialize_nvme_features(
        ).safe_then([this] {
-         return close();
-       }).handle_error(
-         mkfs_ertr::pass_further{},
-         crimson::ct_error::assert_all{
-         "Invalid error write_rbm_superblock in RBMDevice::do_primary_mkfs"
+         return write_rbm_superblock(
+         ).safe_then([this] {
+           return close();
+         }).handle_error(
+           mkfs_ertr::pass_further{},
+           crimson::ct_error::assert_all{
+           "Invalid error write_rbm_superblock in RBMDevice::do_primary_mkfs"
+         });
        });
       });
     });
index 7077aad7407065b249bfe73e409bb6e4c0fc9e70..98a3d1bb9282de5ff9cce0ebea563a541e134313 100644 (file)
@@ -248,59 +248,6 @@ block_sm_superblock_t make_superblock(
   };
 }
 
-using check_create_device_ertr = BlockSegmentManager::access_ertr;
-using check_create_device_ret = check_create_device_ertr::future<>;
-static check_create_device_ret check_create_device(
-  const std::string &path,
-  size_t size)
-{
-  LOG_PREFIX(block_check_create_device);
-  INFO("path={}, size=0x{:x}", path, size);
-  return seastar::open_file_dma(
-    path,
-    seastar::open_flags::exclusive |
-    seastar::open_flags::rw |
-    seastar::open_flags::create
-  ).then([size, FNAME, &path](auto file) {
-    return seastar::do_with(
-      file,
-      [size, FNAME, &path](auto &f) -> seastar::future<>
-    {
-      DEBUG("path={} created, truncating to 0x{:x}", path, size);
-      ceph_assert(f);
-      return f.truncate(
-        size
-      ).then([&f, size] {
-        return f.allocate(0, size);
-      }).finally([&f] {
-        return f.close();
-      });
-    });
-  }).then_wrapped([&path, FNAME](auto f) -> check_create_device_ret {
-    if (f.failed()) {
-      try {
-       f.get();
-       return seastar::now();
-      } catch (const std::system_error &e) {
-       if (e.code().value() == EEXIST) {
-          ERROR("path={} exists", path);
-         return seastar::now();
-       } else {
-          ERROR("path={} creation error -- {}", path, e);
-         return crimson::ct_error::input_output_error::make();
-       }
-      } catch (...) {
-        ERROR("path={} creation error", path);
-       return crimson::ct_error::input_output_error::make();
-      }
-    }
-
-    DEBUG("path={} complete", path);
-    std::ignore = f.discard_result();
-    return seastar::now();
-  });
-}
-
 using open_device_ret = 
   BlockSegmentManager::access_ertr::future<
   std::pair<seastar::file, seastar::stat_data>