]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/lba_mapping.h: allow null direct_cursor in indirect
authorXuehan Xu <xuxuehan@qianxin.com>
Mon, 31 Mar 2025 08:44:59 +0000 (16:44 +0800)
committerXuehan Xu <xuxuehan@qianxin.com>
Thu, 31 Jul 2025 02:03:49 +0000 (10:03 +0800)
mappings

Signed-off-by: Xuehan Xu <xuxuehan@qianxin.com>
src/crimson/os/seastore/lba/btree_lba_manager.cc
src/crimson/os/seastore/lba_mapping.cc
src/crimson/os/seastore/lba_mapping.h

index 6e0859d54d0e98a663bf3598b5b05e60655ba742..e019211c82613a93f4723677f6fc2f719133cfc4 100644 (file)
@@ -728,7 +728,6 @@ BtreeLBAManager::get_physical_extent_if_live(
 BtreeLBAManager::refresh_lba_mapping_ret
 BtreeLBAManager::refresh_lba_mapping(Transaction &t, LBAMapping mapping)
 {
-  assert(mapping.is_linked_direct());
   if (mapping.is_viewable()) {
     return refresh_lba_mapping_iertr::make_ready_future<
       LBAMapping>(std::move(mapping));
@@ -740,8 +739,12 @@ BtreeLBAManager::refresh_lba_mapping(Transaction &t, LBAMapping mapping)
     std::move(mapping),
     [c, this](LBABtree &btree, LBAMapping &mapping) mutable
   {
-    return refresh_lba_cursor(c, btree, *mapping.direct_cursor
-    ).si_then([c, this, &btree, &mapping] {
+    return seastar::futurize_invoke([c, this, &btree, &mapping] {
+      if (mapping.direct_cursor) {
+        return refresh_lba_cursor(c, btree, *mapping.direct_cursor);
+      }
+      return refresh_lba_cursor_iertr::make_ready_future();
+    }).si_then([c, this, &btree, &mapping] {
       if (mapping.indirect_cursor) {
        return refresh_lba_cursor(c, btree, *mapping.indirect_cursor);
       }
index 77c564c2d7ebea623430ce96862e46eef6235394..f475fd47d7b709d537aca4ff542af0b904a8534b 100644 (file)
@@ -8,9 +8,14 @@ namespace crimson::os::seastore {
 std::ostream &operator<<(std::ostream &out, const LBAMapping &rhs)
 {
   out << "LBAMapping(" << rhs.get_key()
-      << "~0x" << std::hex << rhs.get_length() << std::dec
-      << "->" << rhs.get_val();
-  if (rhs.is_indirect()) {
+      << "~0x" << std::hex << rhs.get_length();
+  if (rhs.is_complete()) {
+    out << std::dec
+       << "->" << rhs.get_val();
+  } else {
+    out << std::dec << "->" << rhs.indirect_cursor->val;
+  }
+  if (rhs.is_complete_indirect()) {
     out << ",indirect(" << rhs.get_intermediate_base()
         << "~0x" << std::hex << rhs.get_intermediate_length()
         << "@0x" << rhs.get_intermediate_offset() << std::dec
index 1f7e61d7073df197d3f5d086ceb88ebf759c0720..a9342bfd4b139c9f8fabfc10d588c583b69a15df 100644 (file)
@@ -19,8 +19,7 @@ class LBAMapping {
     : direct_cursor(std::move(direct)),
       indirect_cursor(std::move(indirect))
   {
-    assert(is_linked_direct());
-    assert(!direct_cursor->is_indirect());
+    assert(!is_linked_direct() || !direct_cursor->is_indirect());
     assert(!indirect_cursor || indirect_cursor->is_indirect());
   }
 
@@ -45,14 +44,15 @@ public:
   }
 
   bool is_indirect() const {
-    assert(is_linked_direct());
+    assert(!is_null());
     return (bool)indirect_cursor;
   }
 
   bool is_viewable() const {
-    assert(is_linked_direct());
-    return direct_cursor->is_viewable()
-       && (!indirect_cursor || indirect_cursor->is_viewable());
+    assert(!is_null());
+    return is_indirect()
+      ? indirect_cursor->is_viewable()
+      : direct_cursor->is_viewable();
   }
 
   // For reserved mappings, the return values are
@@ -69,7 +69,7 @@ public:
   }
 
   extent_len_t get_length() const {
-    assert(is_linked_direct());
+    assert(!is_null());
     if (is_indirect()) {
       return indirect_cursor->get_length();
     }
@@ -87,7 +87,7 @@ public:
   }
 
   laddr_t get_key() const {
-    assert(is_linked_direct());
+    assert(!is_null());
     if (is_indirect()) {
       return indirect_cursor->get_laddr();
     }
@@ -130,9 +130,30 @@ public:
     };
     return LBAMapping(dup_iter(direct_cursor), dup_iter(indirect_cursor));
   }
-
 private:
   friend lba::BtreeLBAManager;
+  friend class TransactionManager;
+  friend std::ostream &operator<<(std::ostream&, const LBAMapping&);
+
+  LBACursor& get_effective_cursor() {
+    if (is_indirect()) {
+      return *indirect_cursor;
+    }
+    return *direct_cursor;
+  }
+
+  bool is_null() const {
+    return !indirect_cursor && !direct_cursor;
+  }
+
+  bool is_complete_indirect() const {
+    assert(!is_null());
+    return (bool)indirect_cursor && (bool)direct_cursor;
+  }
+
+  bool is_complete() const {
+    return !is_indirect() || is_complete_indirect();
+  }
 
   // To support cloning, there are two kinds of lba mappings:
   //    1. direct lba mapping: the pladdr in the value of which is the paddr of