@@ -29,206 +29,6 @@ class LogicalCachedExtent;
2929
3030namespace crimson ::os::seastore::lba_manager::btree {
3131
32- class BtreeLBAMapping : public LBAMapping {
33- // To support cloning, there are two kinds of lba mappings:
34- // 1. physical lba mapping: the pladdr in the value of which is the paddr of
35- // the corresponding extent;
36- // 2. indirect lba mapping: the pladdr in the value of which is an laddr pointing
37- // to the physical lba mapping that's pointing to the actual paddr of the
38- // extent being searched;
39- //
40- // Accordingly, BtreeLBAMapping may also work under two modes: indirect or direct
41- // 1. BtreeLBAMappings that come from quering an indirect lba mapping in the lba tree
42- // are indirect;
43- // 2. BtreeLBAMappings that come from quering a physical lba mapping in the lba tree
44- // are direct.
45- //
46- // For direct BtreeLBAMappings, there are two important fields:
47- // 1. key: the laddr of the lba mapping being queried;
48- // 2. paddr: the paddr recorded in the value of the lba mapping being queried.
49- // For indirect BtreeLBAMappings, BtreeLBAMapping has three important fields:
50- // 1. key: the laddr key of the lba entry being queried;
51- // 2. intermediate_key: the laddr within the scope of the physical lba mapping
52- // that the current indirect lba mapping points to; although an indirect mapping
53- // points to the start of the physical lba mapping, it may change to other
54- // laddr after remap
55- // 3. intermediate_base: the laddr key of the physical lba mapping, intermediate_key
56- // and intermediate_base should be the same when doing cloning
57- // 4. intermediate_offset: intermediate_key - intermediate_base
58- // 5. intermediate_length: the length of the actual physical lba mapping
59- // 6. paddr: the paddr recorded in the physical lba mapping pointed to by the
60- // indirect lba mapping being queried;
61- //
62- // NOTE THAT, for direct BtreeLBAMappings, their intermediate_keys are the same as
63- // their keys.
64- public:
65- BtreeLBAMapping (op_context_t ctx)
66- : LBAMapping(ctx) {}
67- BtreeLBAMapping (
68- op_context_t c,
69- LBALeafNodeRef parent,
70- uint16_t pos,
71- lba_map_val_t &val,
72- lba_node_meta_t meta)
73- : LBAMapping(
74- c,
75- parent,
76- pos,
77- val.pladdr.is_paddr() ? val.pladdr.get_paddr() : P_ADDR_NULL,
78- val.len,
79- meta),
80- key (meta.begin),
81- indirect(val.pladdr.is_laddr()),
82- intermediate_key(indirect ? val.pladdr.get_laddr() : L_ADDR_NULL),
83- intermediate_length(indirect ? val.len : 0 ),
84- raw_val(val.pladdr),
85- map_val(val),
86- parent_modifications(parent->modifications)
87- {}
88-
89- lba_map_val_t get_map_val () const {
90- return map_val;
91- }
92-
93- bool is_indirect () const final {
94- return indirect;
95- }
96-
97- void make_indirect (
98- laddr_t new_key,
99- extent_len_t length,
100- laddr_t interkey = L_ADDR_NULL)
101- {
102- assert (!indirect);
103- indirect = true ;
104- intermediate_base = key;
105- intermediate_length = len;
106- adjust_mutable_indirect_attrs (new_key, length, interkey);
107- }
108-
109- laddr_t get_key () const final {
110- return key;
111- }
112-
113- pladdr_t get_raw_val () const {
114- return raw_val;
115- }
116-
117- laddr_t get_intermediate_key () const final {
118- assert (is_indirect ());
119- assert (intermediate_key != L_ADDR_NULL);
120- return intermediate_key;
121- }
122-
123- laddr_t get_intermediate_base () const final {
124- assert (is_indirect ());
125- assert (intermediate_base != L_ADDR_NULL);
126- return intermediate_base;
127- }
128-
129- extent_len_t get_intermediate_offset () const final {
130- assert (intermediate_key >= intermediate_base);
131- assert ((intermediate_key == L_ADDR_NULL)
132- == (intermediate_base == L_ADDR_NULL));
133- return intermediate_key.get_byte_distance <extent_len_t >(intermediate_base);
134- }
135-
136- extent_len_t get_intermediate_length () const final {
137- assert (is_indirect ());
138- assert (intermediate_length);
139- return intermediate_length;
140- }
141-
142- bool is_clone () const final {
143- return get_map_val ().refcount > 1 ;
144- }
145-
146- uint32_t get_checksum () const final {
147- return get_map_val ().checksum ;
148- }
149-
150- void adjust_mutable_indirect_attrs (
151- laddr_t new_key,
152- extent_len_t length,
153- laddr_t interkey = L_ADDR_NULL)
154- {
155- assert (indirect);
156- assert (value.is_paddr ());
157- intermediate_key = (interkey == L_ADDR_NULL ? key : interkey);
158- key = new_key;
159- len = length;
160- }
161-
162- uint64_t get_parent_modifications () const {
163- return parent_modifications;
164- }
165-
166- bool parent_modified () const final {
167- ceph_assert (parent);
168- ceph_assert (is_parent_viewable ());
169- auto &p = static_cast <LBALeafNode&>(*parent);
170- return p.modified_since (parent_modifications);
171- }
172-
173- void maybe_fix_pos () final {
174- assert (is_parent_viewable ());
175- if (!parent_modified ()) {
176- return ;
177- }
178- LOG_PREFIX (BtreeLBAMapping::maybe_fix_pos);
179- auto &p = static_cast <LBALeafNode&>(*parent);
180- p.maybe_fix_mapping_pos (*this );
181- SUBDEBUGT (seastore_lba, " fixed pin {}" ,
182- ctx.trans , static_cast <LBAMapping&>(*this ));
183- }
184-
185- LBAMappingRef refresh_with_pending_parent () final {
186- LOG_PREFIX (BtreeLBAMapping::refresh_with_pending_parent);
187- assert (is_parent_valid () && !is_parent_viewable ());
188- auto &p = static_cast <LBALeafNode&>(*parent);
189- auto &viewable_p = static_cast <LBALeafNode&>(
190- *p.find_pending_version (ctx.trans , get_key ()));
191- auto new_pin = viewable_p.get_mapping (ctx, get_key ());
192- SUBDEBUGT (seastore_lba, " new pin {}" , ctx.trans , static_cast <LBAMapping&>(*new_pin));
193- return new_pin;
194- }
195- bool is_stable () const final ;
196- bool is_data_stable () const final ;
197- get_child_ret_t <lba_manager::btree::LBALeafNode, LogicalChildNode>
198- get_logical_extent (Transaction &t);
199-
200- protected:
201- LBAMappingRef _duplicate (
202- op_context_t ctx) const final {
203- auto pin = std::unique_ptr<BtreeLBAMapping>(new BtreeLBAMapping (ctx));
204- pin->key = key;
205- pin->intermediate_base = intermediate_base;
206- pin->intermediate_key = intermediate_key;
207- pin->intermediate_length = intermediate_length;
208- pin->indirect = indirect;
209- pin->raw_val = raw_val;
210- pin->map_val = map_val;
211- pin->parent_modifications = parent_modifications;
212- return pin;
213- }
214- private:
215- void _new_pos (uint16_t pos) {
216- this ->pos = pos;
217- }
218-
219- laddr_t key = L_ADDR_NULL;
220- bool indirect = false ;
221- laddr_t intermediate_key = L_ADDR_NULL;
222- laddr_t intermediate_base = L_ADDR_NULL;
223- extent_len_t intermediate_length = 0 ;
224- pladdr_t raw_val;
225- lba_map_val_t map_val;
226- uint64_t parent_modifications = 0 ;
227- friend struct LBALeafNode ;
228- };
229-
230- using BtreeLBAMappingRef = std::unique_ptr<BtreeLBAMapping>;
231-
23232using LBABtree = FixedKVBtree<
23333 laddr_t , lba_map_val_t , LBAInternalNode,
23434 LBALeafNode, LBACursor, LBA_BLOCK_SIZE>;
0 commit comments