From 1901c02001648c8723467fa4eb21a05fe499d986 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Mon, 14 Mar 2022 13:38:55 +0800 Subject: [PATCH] crimson/os/seastore/EPM: introduce open() and close() Signed-off-by: Yingxin Cheng --- .../os/seastore/extent_placement_manager.cc | 18 ++--- .../os/seastore/extent_placement_manager.h | 74 +++++++++++++------ .../os/seastore/transaction_manager.cc | 10 ++- .../seastore/test_btree_lba_manager.cc | 8 +- 4 files changed, 72 insertions(+), 38 deletions(-) diff --git a/src/crimson/os/seastore/extent_placement_manager.cc b/src/crimson/os/seastore/extent_placement_manager.cc index 5fafc234c93f2..e838fdd08ceb1 100644 --- a/src/crimson/os/seastore/extent_placement_manager.cc +++ b/src/crimson/os/seastore/extent_placement_manager.cc @@ -22,6 +22,12 @@ SegmentedAllocator::SegmentedAllocator( ); } +SegmentedAllocator::Writer::open_ertr::future<> +SegmentedAllocator::Writer::open() +{ + return segment_allocator.open().discard_result(); +} + SegmentedAllocator::Writer::write_iertr::future<> SegmentedAllocator::Writer::_write( Transaction& t, @@ -165,18 +171,6 @@ SegmentedAllocator::Writer::write( return write_iertr::now(); } return seastar::with_gate(write_guard, [this, &t, &extents] { - if (!roll_promise.has_value() && - !segment_allocator.can_write()) { - roll_promise = seastar::shared_promise<>(); - return trans_intr::make_interruptible( - segment_allocator.open().discard_result() - ).finally([this] { - roll_promise->set_value(); - roll_promise.reset(); - }).si_then([this, &t, &extents] { - return do_write(t, extents); - }); - } return do_write(t, extents); }); } diff --git a/src/crimson/os/seastore/extent_placement_manager.h b/src/crimson/os/seastore/extent_placement_manager.h index 3223a39c4a971..f9444bf7eb303 100644 --- a/src/crimson/os/seastore/extent_placement_manager.h +++ b/src/crimson/os/seastore/extent_placement_manager.h @@ -19,20 +19,21 @@ namespace crimson::os::seastore { * Interface through which final write to ool segment is performed. */ class ExtentOolWriter { + using base_ertr = crimson::errorator< + crimson::ct_error::input_output_error>; public: - using write_iertr = trans_iertr>; - - using stop_ertr = Segment::close_ertr; - virtual stop_ertr::future<> stop() = 0; + virtual ~ExtentOolWriter() {} + + using open_ertr = base_ertr; + virtual open_ertr::future<> open() = 0; + + using write_iertr = trans_iertr; virtual write_iertr::future<> write( Transaction& t, std::list& extent) = 0; - virtual ~ExtentOolWriter() {} + + using stop_ertr = base_ertr; + virtual stop_ertr::future<> stop() = 0; }; /** @@ -42,13 +43,10 @@ public: */ class ExtentAllocator { public: - using alloc_paddr_iertr = trans_iertr>; + using open_ertr = ExtentOolWriter::open_ertr; + virtual open_ertr::future<> open() = 0; + using alloc_paddr_iertr = ExtentOolWriter::write_iertr; virtual alloc_paddr_iertr::future<> alloc_ool_extents_paddr( Transaction& t, std::list&) = 0; @@ -82,6 +80,8 @@ class SegmentedAllocator : public ExtentAllocator { Writer(Writer &&) = default; + open_ertr::future<> open() final; + write_iertr::future<> write( Transaction& t, std::list& extent) final; @@ -89,6 +89,8 @@ class SegmentedAllocator : public ExtentAllocator { stop_ertr::future<> stop() final { return write_guard.close().then([this] { return segment_allocator.close(); + }).safe_then([this] { + write_guard = seastar::gate(); }); } @@ -119,6 +121,12 @@ public: } } + open_ertr::future<> open() { + return crimson::do_for_each(writers, [](auto& writer) { + return writer.open(); + }); + } + alloc_paddr_iertr::future<> alloc_ool_extents_paddr( Transaction& t, std::list& extents) final { @@ -153,6 +161,25 @@ class ExtentPlacementManager { public: ExtentPlacementManager() = default; + void add_allocator(device_type_t type, ExtentAllocatorRef&& allocator) { + allocators[type].emplace_back(std::move(allocator)); + LOG_PREFIX(ExtentPlacementManager::add_allocator); + SUBDEBUG(seastore_tm, "allocators for {}: {}", + type, + allocators[type].size()); + } + + using open_ertr = ExtentOolWriter::open_ertr; + open_ertr::future<> open() { + LOG_PREFIX(ExtentPlacementManager::open); + SUBINFO(seastore_tm, "started"); + return crimson::do_for_each(allocators, [](auto& allocators_item) { + return crimson::do_for_each(allocators_item.second, [](auto& allocator) { + return allocator->open(); + }); + }); + } + struct alloc_result_t { paddr_t paddr; bufferptr bp; @@ -221,12 +248,15 @@ public: }); } - void add_allocator(device_type_t type, ExtentAllocatorRef&& allocator) { - allocators[type].emplace_back(std::move(allocator)); - LOG_PREFIX(ExtentPlacementManager::add_allocator); - SUBDEBUG(seastore_tm, "allocators for {}: {}", - type, - allocators[type].size()); + using close_ertr = ExtentOolWriter::stop_ertr; + close_ertr::future<> close() { + LOG_PREFIX(ExtentPlacementManager::close); + SUBINFO(seastore_tm, "started"); + return crimson::do_for_each(allocators, [](auto& allocators_item) { + return crimson::do_for_each(allocators_item.second, [](auto& allocator) { + return allocator->stop(); + }); + }); } private: diff --git a/src/crimson/os/seastore/transaction_manager.cc b/src/crimson/os/seastore/transaction_manager.cc index 61170ac8b6290..266a064857e86 100644 --- a/src/crimson/os/seastore/transaction_manager.cc +++ b/src/crimson/os/seastore/transaction_manager.cc @@ -51,8 +51,10 @@ TransactionManager::mkfs_ertr::future<> TransactionManager::mkfs() scanner.get_segment_managers() ).safe_then([this] { return journal->open_for_write(); - }).safe_then([this, FNAME](auto addr) { + }).safe_then([this](auto addr) { segment_cleaner->init_mkfs(addr); + return epm->open(); + }).safe_then([this, FNAME]() { return with_transaction_intr( Transaction::src_t::MUTATE, "mkfs_tm", @@ -136,7 +138,9 @@ TransactionManager::mount_ertr::future<> TransactionManager::mount() }); }); }); - }).safe_then([this, FNAME] { + }).safe_then([this] { + return epm->open(); + }).safe_then([FNAME, this] { segment_cleaner->complete_init(); INFO("completed"); }).handle_error( @@ -156,6 +160,8 @@ TransactionManager::close_ertr::future<> TransactionManager::close() { }).safe_then([this] { cache->dump_contents(); return journal->close(); + }).safe_then([this] { + return epm->close(); }).safe_then([FNAME] { INFO("completed"); return seastar::now(); diff --git a/src/test/crimson/seastore/test_btree_lba_manager.cc b/src/test/crimson/seastore/test_btree_lba_manager.cc index a8275715474b4..f73038da2e204 100644 --- a/src/test/crimson/seastore/test_btree_lba_manager.cc +++ b/src/test/crimson/seastore/test_btree_lba_manager.cc @@ -94,8 +94,10 @@ struct btree_test_base : return segment_manager->init( ).safe_then([this] { - return journal->open_for_write(); - }).safe_then([this](auto addr) { + return journal->open_for_write().discard_result(); + }).safe_then([this] { + return epm->open(); + }).safe_then([this] { return seastar::do_with( cache->create_transaction( Transaction::src_t::MUTATE, "test_set_up_fut", false), @@ -122,6 +124,8 @@ struct btree_test_base : return cache->close( ).safe_then([this] { return journal->close(); + }).safe_then([this] { + return epm->close(); }).safe_then([this] { test_structure_reset(); segment_manager.reset(); -- 2.39.5