]>
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" | |
22 | #include "crimson/os/seastore/segment_manager.h" | |
23 | ||
24 | namespace crimson::os::seastore { | |
25 | ||
26 | /** | |
27 | * Abstract interface for managing the logical to physical mapping | |
28 | */ | |
29 | class LBAManager { | |
30 | public: | |
20effc67 TL |
31 | using base_iertr = Cache::base_iertr; |
32 | ||
33 | using mkfs_iertr = base_iertr; | |
34 | using mkfs_ret = mkfs_iertr::future<>; | |
f67539c2 TL |
35 | virtual mkfs_ret mkfs( |
36 | Transaction &t | |
37 | ) = 0; | |
38 | ||
39 | /** | |
40 | * Fetches mappings for laddr_t in range [offset, offset + len) | |
41 | * | |
42 | * Future will not resolve until all pins have resolved (set_paddr called) | |
43 | */ | |
20effc67 TL |
44 | using get_mappings_iertr = base_iertr; |
45 | using get_mappings_ret = get_mappings_iertr::future<lba_pin_list_t>; | |
46 | virtual get_mappings_ret get_mappings( | |
f67539c2 TL |
47 | Transaction &t, |
48 | laddr_t offset, extent_len_t length) = 0; | |
49 | ||
50 | /** | |
20effc67 | 51 | * Fetches mappings for a list of laddr_t in range [offset, offset + len) |
f67539c2 | 52 | * |
20effc67 | 53 | * Future will not resolve until all pins have resolved (set_paddr called) |
f67539c2 | 54 | */ |
f67539c2 TL |
55 | virtual get_mappings_ret get_mappings( |
56 | Transaction &t, | |
57 | laddr_list_t &&extent_lisk) = 0; | |
58 | ||
20effc67 TL |
59 | /** |
60 | * Fetches the mapping for laddr_t | |
61 | * | |
62 | * Future will not resolve until the pin has resolved (set_paddr called) | |
63 | */ | |
64 | using get_mapping_iertr = base_iertr::extend< | |
65 | crimson::ct_error::enoent>; | |
66 | using get_mapping_ret = get_mapping_iertr::future<LBAPinRef>; | |
67 | virtual get_mapping_ret get_mapping( | |
68 | Transaction &t, | |
69 | laddr_t offset) = 0; | |
70 | ||
f67539c2 TL |
71 | /** |
72 | * Allocates a new mapping referenced by LBARef | |
73 | * | |
74 | * Offset will be relative to the block offset of the record | |
75 | * This mapping will block from transaction submission until set_paddr | |
76 | * is called on the LBAPin. | |
77 | */ | |
20effc67 TL |
78 | using alloc_extent_iertr = base_iertr; |
79 | using alloc_extent_ret = alloc_extent_iertr::future<LBAPinRef>; | |
f67539c2 TL |
80 | virtual alloc_extent_ret alloc_extent( |
81 | Transaction &t, | |
82 | laddr_t hint, | |
83 | extent_len_t len, | |
84 | paddr_t addr) = 0; | |
85 | ||
f67539c2 TL |
86 | struct ref_update_result_t { |
87 | unsigned refcount = 0; | |
88 | paddr_t addr; | |
20effc67 | 89 | extent_len_t length = 0; |
f67539c2 | 90 | }; |
20effc67 TL |
91 | using ref_iertr = base_iertr::extend< |
92 | crimson::ct_error::enoent>; | |
93 | using ref_ret = ref_iertr::future<ref_update_result_t>; | |
f67539c2 TL |
94 | |
95 | /** | |
96 | * Decrements ref count on extent | |
97 | * | |
98 | * @return returns resulting refcount | |
99 | */ | |
100 | virtual ref_ret decref_extent( | |
101 | Transaction &t, | |
102 | laddr_t addr) = 0; | |
103 | ||
104 | /** | |
105 | * Increments ref count on extent | |
106 | * | |
107 | * @return returns resulting refcount | |
108 | */ | |
109 | virtual ref_ret incref_extent( | |
110 | Transaction &t, | |
111 | laddr_t addr) = 0; | |
112 | ||
20effc67 | 113 | virtual void complete_transaction( |
f67539c2 TL |
114 | Transaction &t) = 0; |
115 | ||
116 | /** | |
117 | * Should be called after replay on each cached extent. | |
118 | * Implementation must initialize the LBAPin on any | |
119 | * LogicalCachedExtent's and may also read in any dependent | |
120 | * structures, etc. | |
121 | */ | |
20effc67 TL |
122 | using init_cached_extent_iertr = base_iertr; |
123 | using init_cached_extent_ret = init_cached_extent_iertr::future<>; | |
f67539c2 TL |
124 | virtual init_cached_extent_ret init_cached_extent( |
125 | Transaction &t, | |
126 | CachedExtentRef e) = 0; | |
127 | ||
128 | /** | |
129 | * Calls f for each mapping in [begin, end) | |
130 | */ | |
20effc67 TL |
131 | using scan_mappings_iertr = base_iertr; |
132 | using scan_mappings_ret = scan_mappings_iertr::future<>; | |
f67539c2 TL |
133 | using scan_mappings_func_t = std::function< |
134 | void(laddr_t, paddr_t, extent_len_t)>; | |
135 | virtual scan_mappings_ret scan_mappings( | |
136 | Transaction &t, | |
137 | laddr_t begin, | |
138 | laddr_t end, | |
139 | scan_mappings_func_t &&f) = 0; | |
140 | ||
141 | /** | |
20effc67 | 142 | * Calls f for each mapped space usage |
f67539c2 | 143 | */ |
20effc67 TL |
144 | using scan_mapped_space_iertr = base_iertr::extend_ertr< |
145 | SegmentManager::read_ertr>; | |
146 | using scan_mapped_space_ret = scan_mapped_space_iertr::future<>; | |
f67539c2 TL |
147 | using scan_mapped_space_func_t = std::function< |
148 | void(paddr_t, extent_len_t)>; | |
149 | virtual scan_mapped_space_ret scan_mapped_space( | |
150 | Transaction &t, | |
151 | scan_mapped_space_func_t &&f) = 0; | |
152 | ||
153 | /** | |
154 | * rewrite_extent | |
155 | * | |
156 | * rewrite extent into passed transaction | |
157 | */ | |
20effc67 TL |
158 | using rewrite_extent_iertr = base_iertr; |
159 | using rewrite_extent_ret = rewrite_extent_iertr::future<>; | |
f67539c2 TL |
160 | virtual rewrite_extent_ret rewrite_extent( |
161 | Transaction &t, | |
162 | CachedExtentRef extent) = 0; | |
163 | ||
20effc67 TL |
164 | /** |
165 | * delayed_update_mapping | |
166 | * | |
167 | * update lba mapping for delayed allocated extents | |
168 | */ | |
169 | using update_le_mapping_iertr = base_iertr; | |
170 | using update_le_mapping_ret = base_iertr::future<>; | |
171 | virtual update_le_mapping_ret update_mapping( | |
172 | Transaction& t, | |
173 | laddr_t laddr, | |
174 | paddr_t prev_addr, | |
175 | paddr_t paddr) = 0; | |
f67539c2 TL |
176 | /** |
177 | * get_physical_extent_if_live | |
178 | * | |
179 | * Returns extent at addr/laddr if still live (if laddr | |
180 | * still points at addr). Extent must be an internal, physical | |
181 | * extent. | |
182 | * | |
183 | * Returns a null CachedExtentRef if extent is not live. | |
184 | */ | |
20effc67 | 185 | using get_physical_extent_if_live_iertr = base_iertr; |
f67539c2 | 186 | using get_physical_extent_if_live_ret = |
20effc67 | 187 | get_physical_extent_if_live_iertr::future<CachedExtentRef>; |
f67539c2 TL |
188 | virtual get_physical_extent_if_live_ret get_physical_extent_if_live( |
189 | Transaction &t, | |
190 | extent_types_t type, | |
191 | paddr_t addr, | |
192 | laddr_t laddr, | |
193 | segment_off_t len) = 0; | |
194 | ||
195 | virtual void add_pin(LBAPin &pin) = 0; | |
196 | ||
197 | virtual ~LBAManager() {} | |
198 | }; | |
199 | using LBAManagerRef = std::unique_ptr<LBAManager>; | |
200 | ||
201 | class Cache; | |
202 | namespace lba_manager { | |
203 | LBAManagerRef create_lba_manager( | |
204 | SegmentManager &segment_manager, | |
205 | Cache &cache); | |
206 | } | |
207 | ||
208 | } |