]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include <iostream> | |
7 | ||
8 | #include <boost/intrusive_ptr.hpp> | |
9 | #include <boost/smart_ptr/intrusive_ref_counter.hpp> | |
10 | ||
11 | #include <seastar/core/future.hh> | |
12 | ||
13 | #include "include/ceph_assert.h" | |
14 | #include "include/buffer_fwd.h" | |
15 | #include "include/interval_set.h" | |
16 | #include "common/interval_map.h" | |
17 | ||
18 | #include "crimson/osd/exceptions.h" | |
19 | ||
20 | #include "crimson/os/seastore/cache.h" | |
21 | #include "crimson/os/seastore/seastore_types.h" | |
f67539c2 TL |
22 | |
23 | namespace crimson::os::seastore { | |
24 | ||
25 | /** | |
26 | * Abstract interface for managing the logical to physical mapping | |
27 | */ | |
28 | class LBAManager { | |
29 | public: | |
20effc67 TL |
30 | using base_iertr = Cache::base_iertr; |
31 | ||
32 | using mkfs_iertr = base_iertr; | |
33 | using mkfs_ret = mkfs_iertr::future<>; | |
f67539c2 TL |
34 | virtual mkfs_ret mkfs( |
35 | Transaction &t | |
36 | ) = 0; | |
37 | ||
38 | /** | |
39 | * Fetches mappings for laddr_t in range [offset, offset + len) | |
40 | * | |
41 | * Future will not resolve until all pins have resolved (set_paddr called) | |
aee94f69 TL |
42 | * For indirect lba mappings, get_mappings will always retrieve the original |
43 | * lba value. | |
f67539c2 | 44 | */ |
20effc67 TL |
45 | using get_mappings_iertr = base_iertr; |
46 | using get_mappings_ret = get_mappings_iertr::future<lba_pin_list_t>; | |
47 | virtual get_mappings_ret get_mappings( | |
f67539c2 TL |
48 | Transaction &t, |
49 | laddr_t offset, extent_len_t length) = 0; | |
50 | ||
51 | /** | |
20effc67 | 52 | * Fetches mappings for a list of laddr_t in range [offset, offset + len) |
f67539c2 | 53 | * |
20effc67 | 54 | * Future will not resolve until all pins have resolved (set_paddr called) |
aee94f69 TL |
55 | * For indirect lba mappings, get_mappings will always retrieve the original |
56 | * lba value. | |
f67539c2 | 57 | */ |
f67539c2 TL |
58 | virtual get_mappings_ret get_mappings( |
59 | Transaction &t, | |
60 | laddr_list_t &&extent_lisk) = 0; | |
61 | ||
20effc67 TL |
62 | /** |
63 | * Fetches the mapping for laddr_t | |
64 | * | |
65 | * Future will not resolve until the pin has resolved (set_paddr called) | |
aee94f69 TL |
66 | * For indirect lba mappings, get_mapping will always retrieve the original |
67 | * lba value. | |
20effc67 TL |
68 | */ |
69 | using get_mapping_iertr = base_iertr::extend< | |
70 | crimson::ct_error::enoent>; | |
1e59de90 | 71 | using get_mapping_ret = get_mapping_iertr::future<LBAMappingRef>; |
20effc67 TL |
72 | virtual get_mapping_ret get_mapping( |
73 | Transaction &t, | |
74 | laddr_t offset) = 0; | |
75 | ||
f67539c2 TL |
76 | /** |
77 | * Allocates a new mapping referenced by LBARef | |
78 | * | |
79 | * Offset will be relative to the block offset of the record | |
80 | * This mapping will block from transaction submission until set_paddr | |
1e59de90 | 81 | * is called on the LBAMapping. |
f67539c2 | 82 | */ |
20effc67 | 83 | using alloc_extent_iertr = base_iertr; |
1e59de90 | 84 | using alloc_extent_ret = alloc_extent_iertr::future<LBAMappingRef>; |
f67539c2 TL |
85 | virtual alloc_extent_ret alloc_extent( |
86 | Transaction &t, | |
87 | laddr_t hint, | |
88 | extent_len_t len, | |
1e59de90 | 89 | paddr_t addr, |
aee94f69 TL |
90 | LogicalCachedExtent &nextent) = 0; |
91 | ||
92 | virtual alloc_extent_ret clone_extent( | |
93 | Transaction &t, | |
94 | laddr_t hint, | |
95 | extent_len_t len, | |
96 | laddr_t intermediate_key, | |
97 | paddr_t actual_addr, | |
98 | laddr_t intermediate_base) = 0; | |
99 | ||
100 | virtual alloc_extent_ret reserve_region( | |
101 | Transaction &t, | |
102 | laddr_t hint, | |
103 | extent_len_t len) = 0; | |
f67539c2 | 104 | |
f67539c2 TL |
105 | struct ref_update_result_t { |
106 | unsigned refcount = 0; | |
aee94f69 | 107 | pladdr_t addr; |
20effc67 | 108 | extent_len_t length = 0; |
f67539c2 | 109 | }; |
20effc67 TL |
110 | using ref_iertr = base_iertr::extend< |
111 | crimson::ct_error::enoent>; | |
112 | using ref_ret = ref_iertr::future<ref_update_result_t>; | |
f67539c2 TL |
113 | |
114 | /** | |
115 | * Decrements ref count on extent | |
116 | * | |
117 | * @return returns resulting refcount | |
118 | */ | |
119 | virtual ref_ret decref_extent( | |
120 | Transaction &t, | |
aee94f69 TL |
121 | laddr_t addr, |
122 | bool cascade_remove) = 0; | |
f67539c2 TL |
123 | |
124 | /** | |
125 | * Increments ref count on extent | |
126 | * | |
127 | * @return returns resulting refcount | |
128 | */ | |
129 | virtual ref_ret incref_extent( | |
130 | Transaction &t, | |
131 | laddr_t addr) = 0; | |
132 | ||
aee94f69 TL |
133 | /** |
134 | * Increments ref count on extent | |
135 | * | |
136 | * @return returns resulting refcount | |
137 | */ | |
138 | virtual ref_ret incref_extent( | |
139 | Transaction &t, | |
140 | laddr_t addr, | |
141 | int delta) = 0; | |
142 | ||
f67539c2 TL |
143 | /** |
144 | * Should be called after replay on each cached extent. | |
1e59de90 | 145 | * Implementation must initialize the LBAMapping on any |
f67539c2 TL |
146 | * LogicalCachedExtent's and may also read in any dependent |
147 | * structures, etc. | |
1e59de90 TL |
148 | * |
149 | * @return returns whether the extent is alive | |
f67539c2 | 150 | */ |
20effc67 | 151 | using init_cached_extent_iertr = base_iertr; |
1e59de90 | 152 | using init_cached_extent_ret = init_cached_extent_iertr::future<bool>; |
f67539c2 TL |
153 | virtual init_cached_extent_ret init_cached_extent( |
154 | Transaction &t, | |
155 | CachedExtentRef e) = 0; | |
156 | ||
1e59de90 TL |
157 | using check_child_trackers_ret = base_iertr::future<>; |
158 | virtual check_child_trackers_ret check_child_trackers(Transaction &t) = 0; | |
159 | ||
f67539c2 TL |
160 | /** |
161 | * Calls f for each mapping in [begin, end) | |
162 | */ | |
20effc67 TL |
163 | using scan_mappings_iertr = base_iertr; |
164 | using scan_mappings_ret = scan_mappings_iertr::future<>; | |
f67539c2 TL |
165 | using scan_mappings_func_t = std::function< |
166 | void(laddr_t, paddr_t, extent_len_t)>; | |
167 | virtual scan_mappings_ret scan_mappings( | |
168 | Transaction &t, | |
169 | laddr_t begin, | |
170 | laddr_t end, | |
171 | scan_mappings_func_t &&f) = 0; | |
172 | ||
f67539c2 TL |
173 | /** |
174 | * rewrite_extent | |
175 | * | |
176 | * rewrite extent into passed transaction | |
177 | */ | |
20effc67 TL |
178 | using rewrite_extent_iertr = base_iertr; |
179 | using rewrite_extent_ret = rewrite_extent_iertr::future<>; | |
f67539c2 TL |
180 | virtual rewrite_extent_ret rewrite_extent( |
181 | Transaction &t, | |
182 | CachedExtentRef extent) = 0; | |
183 | ||
20effc67 | 184 | /** |
1e59de90 | 185 | * update_mapping |
20effc67 | 186 | * |
1e59de90 | 187 | * update lba mapping for a delayed allocated extent |
20effc67 | 188 | */ |
1e59de90 TL |
189 | using update_mapping_iertr = base_iertr; |
190 | using update_mapping_ret = base_iertr::future<>; | |
191 | virtual update_mapping_ret update_mapping( | |
20effc67 TL |
192 | Transaction& t, |
193 | laddr_t laddr, | |
194 | paddr_t prev_addr, | |
1e59de90 TL |
195 | paddr_t paddr, |
196 | LogicalCachedExtent *nextent) = 0; | |
197 | ||
198 | /** | |
199 | * update_mappings | |
200 | * | |
201 | * update lba mappings for delayed allocated extents | |
202 | */ | |
203 | using update_mappings_iertr = update_mapping_iertr; | |
204 | using update_mappings_ret = update_mapping_ret; | |
205 | update_mappings_ret update_mappings( | |
206 | Transaction& t, | |
207 | const std::list<LogicalCachedExtentRef>& extents); | |
208 | ||
f67539c2 TL |
209 | /** |
210 | * get_physical_extent_if_live | |
211 | * | |
212 | * Returns extent at addr/laddr if still live (if laddr | |
213 | * still points at addr). Extent must be an internal, physical | |
214 | * extent. | |
215 | * | |
216 | * Returns a null CachedExtentRef if extent is not live. | |
217 | */ | |
20effc67 | 218 | using get_physical_extent_if_live_iertr = base_iertr; |
f67539c2 | 219 | using get_physical_extent_if_live_ret = |
20effc67 | 220 | get_physical_extent_if_live_iertr::future<CachedExtentRef>; |
f67539c2 TL |
221 | virtual get_physical_extent_if_live_ret get_physical_extent_if_live( |
222 | Transaction &t, | |
223 | extent_types_t type, | |
224 | paddr_t addr, | |
225 | laddr_t laddr, | |
1e59de90 | 226 | extent_len_t len) = 0; |
f67539c2 TL |
227 | |
228 | virtual ~LBAManager() {} | |
229 | }; | |
230 | using LBAManagerRef = std::unique_ptr<LBAManager>; | |
231 | ||
232 | class Cache; | |
233 | namespace lba_manager { | |
1e59de90 | 234 | LBAManagerRef create_lba_manager(Cache &cache); |
f67539c2 TL |
235 | } |
236 | ||
237 | } |