1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
8 #include <boost/intrusive_ptr.hpp>
9 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
10 #include <seastar/core/future.hh>
12 #include "include/ceph_assert.h"
13 #include "include/buffer_fwd.h"
14 #include "include/interval_set.h"
15 #include "common/interval_map.h"
16 #include "crimson/osd/exceptions.h"
18 #include "crimson/os/seastore/btree/fixed_kv_btree.h"
19 #include "crimson/os/seastore/seastore_types.h"
20 #include "crimson/os/seastore/lba_manager.h"
21 #include "crimson/os/seastore/cache.h"
23 #include "crimson/os/seastore/lba_manager/btree/lba_btree_node.h"
24 #include "crimson/os/seastore/btree/btree_range_pin.h"
26 namespace crimson::os::seastore::lba_manager::btree
{
28 class BtreeLBAMapping
: public BtreeNodeMapping
<laddr_t
, paddr_t
> {
30 BtreeLBAMapping(op_context_t
<laddr_t
> ctx
)
31 : BtreeNodeMapping(ctx
) {}
33 op_context_t
<laddr_t
> c
,
34 CachedExtentRef parent
,
37 lba_node_meta_t
&&meta
)
44 std::forward
<lba_node_meta_t
>(meta
))
48 using LBABtree
= FixedKVBtree
<
49 laddr_t
, lba_map_val_t
, LBAInternalNode
,
50 LBALeafNode
, BtreeLBAMapping
, LBA_BLOCK_SIZE
, true>;
55 * Uses a wandering btree to track two things:
56 * 1) lba state including laddr_t -> paddr_t mapping
57 * 2) reverse paddr_t -> laddr_t mapping for gc (TODO)
59 * Generally, any transaction will involve
60 * 1) deltas against lba tree nodes
61 * 2) new lba tree nodes
62 * - Note, there must necessarily be a delta linking
63 * these new nodes into the tree -- might be a
64 * bootstrap_state_t delta if new root
66 * get_mappings, alloc_extent_*, etc populate a Transaction
67 * which then gets submitted
69 class BtreeLBAManager
: public LBAManager
{
71 BtreeLBAManager(Cache
&cache
)
78 Transaction
&t
) final
;
80 get_mappings_ret
get_mappings(
82 laddr_t offset
, extent_len_t length
) final
;
84 get_mappings_ret
get_mappings(
86 laddr_list_t
&&list
) final
;
88 get_mapping_ret
get_mapping(
90 laddr_t offset
) final
;
92 alloc_extent_ret
alloc_extent(
97 LogicalCachedExtent
*) final
;
99 ref_ret
decref_extent(
101 laddr_t addr
) final
{
102 return update_refcount(t
, addr
, -1);
105 ref_ret
incref_extent(
107 laddr_t addr
) final
{
108 return update_refcount(t
, addr
, 1);
114 * Checks whether e is live (reachable from lba tree) and drops or initializes
117 * Returns if e is live.
119 init_cached_extent_ret
init_cached_extent(
121 CachedExtentRef e
) final
;
123 check_child_trackers_ret
check_child_trackers(Transaction
&t
) final
;
125 scan_mappings_ret
scan_mappings(
129 scan_mappings_func_t
&&f
) final
;
131 rewrite_extent_ret
rewrite_extent(
133 CachedExtentRef extent
) final
;
135 update_mapping_ret
update_mapping(
140 LogicalCachedExtent
*) final
;
142 get_physical_extent_if_live_ret
get_physical_extent_if_live(
147 extent_len_t len
) final
;
153 uint64_t num_alloc_extents
= 0;
154 uint64_t num_alloc_extents_iter_nexts
= 0;
157 op_context_t
<laddr_t
> get_context(Transaction
&t
) {
158 return op_context_t
<laddr_t
>{cache
, t
};
161 seastar::metrics::metric_group metrics
;
162 void register_metrics();
167 * Updates refcount, returns resulting refcount
169 using update_refcount_ret
= ref_ret
;
170 update_refcount_ret
update_refcount(
178 * Updates mapping, removes if f returns nullopt
180 using _update_mapping_iertr
= ref_iertr
;
181 using _update_mapping_ret
= ref_iertr::future
<lba_map_val_t
>;
182 using update_func_t
= std::function
<
183 lba_map_val_t(const lba_map_val_t
&v
)
185 _update_mapping_ret
_update_mapping(
189 LogicalCachedExtent
*);
191 using BtreeLBAManagerRef
= std::unique_ptr
<BtreeLBAManager
>;