]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/lba_manager.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crimson / os / seastore / lba_manager.h
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
23 namespace crimson::os::seastore {
24
25 /**
26 * Abstract interface for managing the logical to physical mapping
27 */
28 class LBAManager {
29 public:
30 using base_iertr = Cache::base_iertr;
31
32 using mkfs_iertr = base_iertr;
33 using mkfs_ret = mkfs_iertr::future<>;
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)
42 */
43 using get_mappings_iertr = base_iertr;
44 using get_mappings_ret = get_mappings_iertr::future<lba_pin_list_t>;
45 virtual get_mappings_ret get_mappings(
46 Transaction &t,
47 laddr_t offset, extent_len_t length) = 0;
48
49 /**
50 * Fetches mappings for a list of laddr_t in range [offset, offset + len)
51 *
52 * Future will not resolve until all pins have resolved (set_paddr called)
53 */
54 virtual get_mappings_ret get_mappings(
55 Transaction &t,
56 laddr_list_t &&extent_lisk) = 0;
57
58 /**
59 * Fetches the mapping for laddr_t
60 *
61 * Future will not resolve until the pin has resolved (set_paddr called)
62 */
63 using get_mapping_iertr = base_iertr::extend<
64 crimson::ct_error::enoent>;
65 using get_mapping_ret = get_mapping_iertr::future<LBAMappingRef>;
66 virtual get_mapping_ret get_mapping(
67 Transaction &t,
68 laddr_t offset) = 0;
69
70 /**
71 * Allocates a new mapping referenced by LBARef
72 *
73 * Offset will be relative to the block offset of the record
74 * This mapping will block from transaction submission until set_paddr
75 * is called on the LBAMapping.
76 */
77 using alloc_extent_iertr = base_iertr;
78 using alloc_extent_ret = alloc_extent_iertr::future<LBAMappingRef>;
79 virtual alloc_extent_ret alloc_extent(
80 Transaction &t,
81 laddr_t hint,
82 extent_len_t len,
83 paddr_t addr,
84 LogicalCachedExtent *nextent) = 0;
85
86 struct ref_update_result_t {
87 unsigned refcount = 0;
88 paddr_t addr;
89 extent_len_t length = 0;
90 };
91 using ref_iertr = base_iertr::extend<
92 crimson::ct_error::enoent>;
93 using ref_ret = ref_iertr::future<ref_update_result_t>;
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
113 /**
114 * Should be called after replay on each cached extent.
115 * Implementation must initialize the LBAMapping on any
116 * LogicalCachedExtent's and may also read in any dependent
117 * structures, etc.
118 *
119 * @return returns whether the extent is alive
120 */
121 using init_cached_extent_iertr = base_iertr;
122 using init_cached_extent_ret = init_cached_extent_iertr::future<bool>;
123 virtual init_cached_extent_ret init_cached_extent(
124 Transaction &t,
125 CachedExtentRef e) = 0;
126
127 using check_child_trackers_ret = base_iertr::future<>;
128 virtual check_child_trackers_ret check_child_trackers(Transaction &t) = 0;
129
130 /**
131 * Calls f for each mapping in [begin, end)
132 */
133 using scan_mappings_iertr = base_iertr;
134 using scan_mappings_ret = scan_mappings_iertr::future<>;
135 using scan_mappings_func_t = std::function<
136 void(laddr_t, paddr_t, extent_len_t)>;
137 virtual scan_mappings_ret scan_mappings(
138 Transaction &t,
139 laddr_t begin,
140 laddr_t end,
141 scan_mappings_func_t &&f) = 0;
142
143 /**
144 * rewrite_extent
145 *
146 * rewrite extent into passed transaction
147 */
148 using rewrite_extent_iertr = base_iertr;
149 using rewrite_extent_ret = rewrite_extent_iertr::future<>;
150 virtual rewrite_extent_ret rewrite_extent(
151 Transaction &t,
152 CachedExtentRef extent) = 0;
153
154 /**
155 * update_mapping
156 *
157 * update lba mapping for a delayed allocated extent
158 */
159 using update_mapping_iertr = base_iertr;
160 using update_mapping_ret = base_iertr::future<>;
161 virtual update_mapping_ret update_mapping(
162 Transaction& t,
163 laddr_t laddr,
164 paddr_t prev_addr,
165 paddr_t paddr,
166 LogicalCachedExtent *nextent) = 0;
167
168 /**
169 * update_mappings
170 *
171 * update lba mappings for delayed allocated extents
172 */
173 using update_mappings_iertr = update_mapping_iertr;
174 using update_mappings_ret = update_mapping_ret;
175 update_mappings_ret update_mappings(
176 Transaction& t,
177 const std::list<LogicalCachedExtentRef>& extents);
178
179 /**
180 * get_physical_extent_if_live
181 *
182 * Returns extent at addr/laddr if still live (if laddr
183 * still points at addr). Extent must be an internal, physical
184 * extent.
185 *
186 * Returns a null CachedExtentRef if extent is not live.
187 */
188 using get_physical_extent_if_live_iertr = base_iertr;
189 using get_physical_extent_if_live_ret =
190 get_physical_extent_if_live_iertr::future<CachedExtentRef>;
191 virtual get_physical_extent_if_live_ret get_physical_extent_if_live(
192 Transaction &t,
193 extent_types_t type,
194 paddr_t addr,
195 laddr_t laddr,
196 extent_len_t len) = 0;
197
198 virtual ~LBAManager() {}
199 };
200 using LBAManagerRef = std::unique_ptr<LBAManager>;
201
202 class Cache;
203 namespace lba_manager {
204 LBAManagerRef create_lba_manager(Cache &cache);
205 }
206
207 }