]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/os/seatore/cache: add get_extent_by_type
authorSamuel Just <sjust@redhat.com>
Thu, 11 Jun 2020 21:02:08 +0000 (14:02 -0700)
committerSamuel Just <sjust@redhat.com>
Fri, 19 Jun 2020 19:59:26 +0000 (12:59 -0700)
For now, just have a single static mechanism for resolving concrete
extent types.  If this becomes unwieldy, we can let users register
handlers with cache/transaction_manager.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/os/seastore/cache.cc
src/crimson/os/seastore/cache.h
src/crimson/os/seastore/seastore_types.h

index 45f2ebf69337a273590d765d78afd2276724ef92..e479a5ca310404c66b885c4414da82a0026d1883 100644 (file)
@@ -4,6 +4,11 @@
 #include "crimson/os/seastore/cache.h"
 #include "crimson/common/log.h"
 
+// included for get_extent_by_type
+#include "crimson/os/seastore/lba_manager/btree/lba_btree_node_impl.h"
+#include "crimson/os/seastore/onode_manager/simple-fltree/onode_block.h"
+#include "test/crimson/seastore/test_block.h"
+
 namespace {
   seastar::logger& logger() {
     return crimson::get_logger(ceph_subsys_filestore);
@@ -217,4 +222,49 @@ Cache::get_root_ret Cache::get_root(Transaction &t)
   }
 }
 
+Cache::get_extent_ertr::future<CachedExtentRef> Cache::get_extent_by_type(
+  extent_types_t type,
+  paddr_t offset,
+  segment_off_t length)
+{
+  switch (type) {
+  case extent_types_t::ROOT_LOCATION: {
+    ceph_assert(0 == "root location deltas are handled specially");
+    return get_extent_ertr::make_ready_future<CachedExtentRef>();
+  }
+  case extent_types_t::ROOT:
+    return get_extent<RootBlock>(offset, length
+    ).safe_then([](auto extent) {
+      return CachedExtentRef(extent.detach(), false /* add_ref */);
+    });
+  case extent_types_t::LADDR_INTERNAL:
+    return get_extent<lba_manager::btree::LBAInternalNode>(offset, length
+    ).safe_then([](auto extent) {
+      return CachedExtentRef(extent.detach(), false /* add_ref */);
+    });
+  case extent_types_t::LADDR_LEAF:
+    return get_extent<lba_manager::btree::LBALeafNode>(offset, length
+    ).safe_then([](auto extent) {
+      return CachedExtentRef(extent.detach(), false /* add_ref */);
+    });
+  case extent_types_t::ONODE_BLOCK:
+    return get_extent<OnodeBlock>(offset, length
+    ).safe_then([](auto extent) {
+      return CachedExtentRef(extent.detach(), false /* add_ref */);
+    });
+  case extent_types_t::TEST_BLOCK:
+    return get_extent<TestBlock>(offset, length
+    ).safe_then([](auto extent) {
+      return CachedExtentRef(extent.detach(), false /* add_ref */);
+    });
+  case extent_types_t::NONE: {
+    ceph_assert(0 == "NONE is an invalid extent type");
+    return get_extent_ertr::make_ready_future<CachedExtentRef>();
+  }
+  default:
+    ceph_assert(0 == "impossible");
+    return get_extent_ertr::make_ready_future<CachedExtentRef>();
+  }
+}
+
 }
index 7f511217d10d9989708a1ac5df245491d003ed86..bd9a992804e7ab92251d1ec64ca9420d32cc3c3b 100644 (file)
@@ -383,6 +383,18 @@ private:
 
   /// Remove extent from extents handling dirty and refcounting
   void retire_extent(CachedExtentRef ref);
+
+  /**
+   * get_extent_by_type
+   *
+   * Based on type, instantiate the correct concrete type
+   * and read in the extent at location offset~length.
+   */
+  get_extent_ertr::future<CachedExtentRef> get_extent_by_type(
+    extent_types_t type,  ///< [in] type tag
+    paddr_t offset,       ///< [in] starting addr
+    segment_off_t length  ///< [in] length
+  );
 };
 
 }
index a64778904e3b790d712eb86d7c23a6f3e50bd02c..3a0d9922169ade8742ca6eff6d7bfde62f801067 100644 (file)
@@ -202,7 +202,11 @@ std::ostream &operator<<(std::ostream &out, const laddr_list_t &rhs);
 std::ostream &operator<<(std::ostream &out, const paddr_list_t &rhs);
 
 /* identifies type of extent, used for interpretting deltas, managing
- * writeback */
+ * writeback.
+ *
+ * Note that any new extent type needs to be added to
+ * Cache::get_extent_by_type in cache.cc
+ */
 enum class extent_types_t : uint8_t {
   ROOT_LOCATION = 0, // delta only
   ROOT = 1,