]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore: divide the role of open_device_read_header into device.mount()
authormyoungwon oh <ohmyoungwon@gmail.com>
Thu, 2 Jun 2022 06:43:14 +0000 (15:43 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Fri, 19 Aug 2022 03:39:42 +0000 (12:39 +0900)
and open_for_mount()

Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/crimson/os/seastore/journal/circular_bounded_journal.cc
src/crimson/os/seastore/journal/circular_bounded_journal.h
src/crimson/os/seastore/random_block_manager/rbm_device.h
src/test/crimson/seastore/test_cbjournal.cc
src/test/crimson/seastore/transaction_manager_test_state.h

index 2bc4672319bd1490488a42a7425b50c4c8745e10..c112fb4bf614e98e27619136cb70aa0ef909b669 100644 (file)
@@ -35,46 +35,27 @@ CircularBoundedJournal::mkfs_ret
 CircularBoundedJournal::mkfs(const mkfs_config_t& config)
 {
   LOG_PREFIX(CircularBoundedJournal::mkfs);
-  return _open_device(path
-  ).safe_then([this, config, FNAME]() mutable -> mkfs_ret {
-    assert(static_cast<seastore_off_t>(config.block_size) ==
-      device->get_block_size());
-    ceph::bufferlist bl;
-    CircularBoundedJournal::cbj_header_t head;
-    head.block_size = config.block_size;
-    head.size = config.total_size - device->get_block_size();
-    head.journal_tail = device->get_block_size();
-    head.device_id = config.device_id;
-    encode(head, bl);
-    header = head;
-    set_written_to(head.journal_tail);
-    DEBUG(
-      "initialize header block in CircularBoundedJournal, length {}",
-      bl.length());
-    return write_header(
-    ).handle_error(
-      mkfs_ertr::pass_further{},
-      crimson::ct_error::assert_all{
-        "Invalid error in CircularBoundedJournal::mkfs"
-      }
-    );
-  }).safe_then([this]() -> mkfs_ret {
-    if (device) {
-      return device->close();
-    }
-    return mkfs_ertr::now();
-  });
-}
-
-CircularBoundedJournal::open_for_mount_ertr::future<>
-CircularBoundedJournal::_open_device(const std::string &path)
-{
-  ceph_assert(device);
-  return device->open(path, seastar::open_flags::rw
+  assert(device);
+  assert(static_cast<seastore_off_t>(config.block_size) ==
+    device->get_block_size());
+  ceph::bufferlist bl;
+  CircularBoundedJournal::cbj_header_t head;
+  head.block_size = config.block_size;
+  head.size = config.total_size - device->get_block_size();
+  head.journal_tail = device->get_block_size();
+  head.device_id = config.device_id;
+  encode(head, bl);
+  header = head;
+  set_written_to(head.journal_tail);
+  initialized = true;
+  DEBUG(
+    "initialize header block in CircularBoundedJournal, length {}",
+    bl.length());
+  return write_header(
   ).handle_error(
-    open_for_mount_ertr::pass_further{},
+    mkfs_ertr::pass_further{},
     crimson::ct_error::assert_all{
-      "Invalid error device->open"
+      "Invalid error in CircularBoundedJournal::mkfs"
     }
   );
 }
@@ -105,10 +86,10 @@ CircularBoundedJournal::open_for_mkfs()
 CircularBoundedJournal::open_for_mount_ret
 CircularBoundedJournal::open_for_mount()
 {
-  ceph_assert(initialized);
   paddr_t paddr = convert_abs_addr_to_paddr(
     get_written_to(),
     header.device_id);
+  ceph_assert(initialized);
   if (circulation_seq == NULL_SEG_SEQ) {
     circulation_seq = 0;
   }
@@ -116,8 +97,7 @@ CircularBoundedJournal::open_for_mount()
     open_for_mount_ertr::ready_future_marker{},
     journal_seq_t{
       circulation_seq,
-      paddr
-  });
+      paddr});
 }
 
 CircularBoundedJournal::close_ertr::future<> CircularBoundedJournal::close()
@@ -125,7 +105,7 @@ CircularBoundedJournal::close_ertr::future<> CircularBoundedJournal::close()
   return write_header(
   ).safe_then([this]() -> close_ertr::future<> {
     initialized = false;
-    return device->close();
+    return close_ertr::now();
   }).handle_error(
     open_for_mount_ertr::pass_further{},
     crimson::ct_error::assert_all{
@@ -134,40 +114,6 @@ CircularBoundedJournal::close_ertr::future<> CircularBoundedJournal::close()
   );
 }
 
-CircularBoundedJournal::open_for_mount_ret
-CircularBoundedJournal::open_device_read_header()
-{
-  LOG_PREFIX(CircularBoundedJournal::open_device_read_header);
-  ceph_assert(!initialized);
-  return _open_device(path
-  ).safe_then([this, FNAME]() {
-    return read_header(
-    ).handle_error(
-      open_for_mount_ertr::pass_further{},
-      crimson::ct_error::assert_all{
-       "Invalid error read_header"
-    }).safe_then([this, FNAME](auto p) mutable {
-      auto &[head, bl] = *p;
-      header = head;
-      DEBUG("header : {}", header);
-      paddr_t paddr = convert_abs_addr_to_paddr(
-       get_written_to(),
-       header.device_id);
-      initialized = true;
-      return open_for_mount_ret(
-       open_for_mount_ertr::ready_future_marker{},
-       journal_seq_t{
-         circulation_seq,
-         paddr
-       });
-    });
-  }).handle_error(
-    open_for_mount_ertr::pass_further{},
-    crimson::ct_error::assert_all{
-      "Invalid error _open_device"
-  });
-}
-
 CircularBoundedJournal::submit_record_ret CircularBoundedJournal::submit_record(
   record_t &&record,
   OrderingHandle &handle)
@@ -310,8 +256,16 @@ Journal::replay_ret CircularBoundedJournal::replay(
    * read records from last applied record prior to written_to, and replay
    */
   LOG_PREFIX(CircularBoundedJournal::replay);
-  return open_device_read_header(
-  ).safe_then([this, FNAME, delta_handler=std::move(delta_handler)] (auto) {
+  return read_header(
+  ).handle_error(
+    open_for_mount_ertr::pass_further{},
+    crimson::ct_error::assert_all{
+      "Invalid error read_header"
+  }).safe_then([this, FNAME, delta_handler=std::move(delta_handler)](auto p) mutable {
+    auto &[head, bl] = *p;
+    header = head;
+    DEBUG("header : {}", header);
+    initialized = true;
     circulation_seq = NULL_SEG_SEQ;
     set_written_to(get_journal_tail());
     return seastar::do_with(
@@ -333,13 +287,13 @@ Journal::replay_ret CircularBoundedJournal::replay(
            if (expected_seq == NULL_SEG_SEQ || is_rolled) {
              DEBUG("no more records, stop replaying");
              return replay_ertr::make_ready_future<
-               seastar::stop_iteration>(seastar::stop_iteration::yes);
+               seastar::stop_iteration>(seastar::stop_iteration::yes);
            } else {
              cursor_addr = get_start_addr();
              ++expected_seq;
              is_rolled = true;
              return replay_ertr::make_ready_future<
-               seastar::stop_iteration>(seastar::stop_iteration::no);
+               seastar::stop_iteration>(seastar::stop_iteration::no);
            }
          }
          auto [r_header, bl] = *ret;
@@ -352,7 +306,7 @@ Journal::replay_ret CircularBoundedJournal::replay(
          if (!maybe_record_deltas_list) {
            // This should be impossible, we did check the crc on the mdbuf
            ERROR("unable to decode deltas for record {} at {}",
-                 r_header, record_block_base);
+                 r_header, record_block_base);
            return crimson::ct_error::input_output_error::make();
          }
          DEBUG("{} at {}", r_header, cursor_addr);
index c41d75405f0c7dd99ed1cda2eb3fd3331c668f7a..38d3d3d07acf66d409b03626e18547c46997a76c 100644 (file)
@@ -88,7 +88,6 @@ public:
 
   open_for_mount_ret open_for_mount() final;
 
-  open_for_mount_ret open_device_read_header();
   close_ertr::future<> close() final;
 
   journal_type_t get_type() final {
@@ -109,8 +108,6 @@ public:
 
   replay_ret replay(delta_handler_t &&delta_handler) final;
 
-  open_for_mount_ertr::future<> _open_device(const std::string &path);
-
   struct cbj_header_t;
   using write_ertr = submit_record_ertr;
   /*
index 7607962672c0d43bf5192893ec3deddda4982e76..c27057ca288f8350d8c24e87f744dca2a6de812c 100644 (file)
@@ -167,7 +167,15 @@ public:
   }
 
   mount_ret mount() final {
-    return mount_ertr::now();
+    return open("", seastar::open_flags::rw
+    ).safe_then([]() {
+      return mount_ertr::now();
+    }).handle_error(
+      mount_ertr::pass_further{},
+      crimson::ct_error::assert_all{
+       "Invalid error mount"
+      }
+    );
   }
 
   open_ertr::future<> open(
index 309118fa37d7c5fa23c69b4fa329d6ca2924da4d..dbcaf77855e3965e9dbb64aa2febc593e098b773 100644 (file)
@@ -226,12 +226,12 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer
   }
 
   auto replay() {
-    cbj->replay(
+    return cbj->replay(
       [this](const auto &offsets,
-             const auto &e,
-             auto &dirty_seq,
-             auto &alloc_seq,
-             auto last_modified) {
+            const auto &e,
+            auto &dirty_seq,
+            auto &alloc_seq,
+            auto last_modified) {
       bool found = false;
       for (auto &i : entries) {
        paddr_t base = offsets.write_result.start_seq.offset; 
@@ -248,11 +248,19 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer
   }
 
   auto mkfs() {
-    return cbj->mkfs(config).unsafe_get0();
+    return device->mount(
+    ).safe_then([this]() {
+      return cbj->mkfs(config
+      ).safe_then([]() {
+       return seastar::now();
+      });
+    }).unsafe_get0();
   }
   void open() {
-    cbj->open_device_read_header().unsafe_get0();
-    cbj->open_for_mkfs().unsafe_get0();
+    return cbj->open_for_mkfs(
+    ).safe_then([](auto q) {
+      return seastar::now();
+    }).unsafe_get0();
   }
   auto get_available_size() {
     return cbj->get_available_size();
index 1245999a2fa1add96a649b78f47763c3753b4a64..5d2feba5eb2d15cb48899c795d3289aad9c5f11f 100644 (file)
@@ -65,24 +65,13 @@ protected:
     _mount().handle_error(crimson::ct_error::assert_all{}).get0();
     SUBINFO(test, "finish");
   }
-
-  seastar::future<> tm_setup(
-      journal_type_t type = journal_type_t::SEGMENT_JOURNAL) {
-    LOG_PREFIX(EphemeralTestState::tm_setup);
-    SUBINFO(test, "begin with {} devices ...", get_num_devices());
-    journal_type = type;
-    // FIXME: should not initialize segment_manager with circularbounded-journal
+  seastar::future<> segment_setup()
+  {
+    LOG_PREFIX(EphemeralTestState::segment_setup);
     segment_manager = segment_manager::create_test_ephemeral();
     for (auto &sec_sm : secondary_segment_managers) {
       sec_sm = segment_manager::create_test_ephemeral();
     }
-    if (journal_type == journal_type_t::CIRCULARBOUNDED_JOURNAL) {
-      auto config =
-       journal::CircularBoundedJournal::mkfs_config_t::get_default();
-      rb_device.reset(new random_block_device::TestMemory(config.total_size));
-      rb_device->set_device_id(
-       1 << (std::numeric_limits<device_id_t>::digits - 1));
-    }
     return segment_manager->init(
     ).safe_then([this] {
       return crimson::do_for_each(
@@ -107,26 +96,55 @@ protected:
             segment_manager::get_ephemeral_device_config(cnt, get_num_devices()));
         });
       });
-    }).safe_then([this] {
+    }).safe_then([this, FNAME] {
       init();
-      return _mkfs();
-    }).safe_then([this] {
-      return _teardown();
-    }).safe_then([this] {
-      destroy();
-      segment_manager->remount();
-      for (auto &sec_sm : secondary_segment_managers) {
-        sec_sm->remount();
-      }
-      init();
-      return _mount();
+      return _mkfs(
+      ).safe_then([this] {
+       return _teardown();
+      }).safe_then([this] {
+       destroy();
+       segment_manager->remount();
+       for (auto &sec_sm : secondary_segment_managers) {
+         sec_sm->remount();
+       }
+       init();
+       return _mount();
+      }).handle_error(
+       crimson::ct_error::assert_all{}
+      ).then([FNAME] {
+       SUBINFO(test, "finish");
+      });
     }).handle_error(
       crimson::ct_error::assert_all{}
-    ).then([FNAME] {
-      SUBINFO(test, "finish");
+    );
+  }
+  seastar::future<> randomblock_setup()
+  {
+    auto config =
+      journal::CircularBoundedJournal::mkfs_config_t::get_default();
+    rb_device.reset(new random_block_device::TestMemory(config.total_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{}
+    ).then([this]() {
+      return segment_setup();
     });
   }
 
+  seastar::future<> tm_setup(
+    journal_type_t type = journal_type_t::SEGMENT_JOURNAL) {
+    LOG_PREFIX(EphemeralTestState::tm_setup);
+    SUBINFO(test, "begin with {} devices ...", get_num_devices());
+    journal_type = type;
+    // FIXME: should not initialize segment_manager with circularbounded-journal
+    if (journal_type == journal_type_t::SEGMENT_JOURNAL) {
+      return segment_setup();
+    } else {
+      assert(journal_type == journal_type_t::CIRCULARBOUNDED_JOURNAL);
+      return randomblock_setup();
+    }
+  }
+
   seastar::future<> tm_teardown() {
     LOG_PREFIX(EphemeralTestState::tm_teardown);
     SUBINFO(test, "begin");
@@ -209,14 +227,10 @@ protected:
       return static_cast<journal::CircularBoundedJournal*>(tm->get_journal())->mkfs(
        config
       ).safe_then([this]() {
-       return static_cast<journal::CircularBoundedJournal*>(tm->get_journal())->
-         open_device_read_header(
-       ).safe_then([this](auto) {
-         return tm->mkfs(
-         ).handle_error(
-           crimson::ct_error::assert_all{"Error in mkfs"}
-         );
-       });
+       return tm->mkfs(
+       ).handle_error(
+         crimson::ct_error::assert_all{"Error in mkfs"}
+       );
       }).handle_error(
        crimson::ct_error::assert_all{"Error in mkfs"}
       );