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>
11 #include <seastar/core/future.hh>
13 #include "include/ceph_assert.h"
14 #include "include/buffer_fwd.h"
15 #include "include/interval_set.h"
16 #include "common/interval_map.h"
18 #include "crimson/osd/exceptions.h"
20 #include "crimson/os/seastore/cache.h"
21 #include "crimson/os/seastore/seastore_types.h"
23 namespace crimson::os::seastore
{
26 * Abstract interface for managing the logical to physical mapping
30 using base_iertr
= Cache::base_iertr
;
32 using mkfs_iertr
= base_iertr
;
33 using mkfs_ret
= mkfs_iertr::future
<>;
34 virtual mkfs_ret
mkfs(
39 * Fetches mappings for laddr_t in range [offset, offset + len)
41 * Future will not resolve until all pins have resolved (set_paddr called)
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(
47 laddr_t offset
, extent_len_t length
) = 0;
50 * Fetches mappings for a list of laddr_t in range [offset, offset + len)
52 * Future will not resolve until all pins have resolved (set_paddr called)
54 virtual get_mappings_ret
get_mappings(
56 laddr_list_t
&&extent_lisk
) = 0;
59 * Fetches the mapping for laddr_t
61 * Future will not resolve until the pin has resolved (set_paddr called)
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(
71 * Allocates a new mapping referenced by LBARef
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.
77 using alloc_extent_iertr
= base_iertr
;
78 using alloc_extent_ret
= alloc_extent_iertr::future
<LBAMappingRef
>;
79 virtual alloc_extent_ret
alloc_extent(
84 LogicalCachedExtent
*nextent
) = 0;
86 struct ref_update_result_t
{
87 unsigned refcount
= 0;
89 extent_len_t length
= 0;
91 using ref_iertr
= base_iertr::extend
<
92 crimson::ct_error::enoent
>;
93 using ref_ret
= ref_iertr::future
<ref_update_result_t
>;
96 * Decrements ref count on extent
98 * @return returns resulting refcount
100 virtual ref_ret
decref_extent(
105 * Increments ref count on extent
107 * @return returns resulting refcount
109 virtual ref_ret
incref_extent(
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
119 * @return returns whether the extent is alive
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(
125 CachedExtentRef e
) = 0;
127 using check_child_trackers_ret
= base_iertr::future
<>;
128 virtual check_child_trackers_ret
check_child_trackers(Transaction
&t
) = 0;
131 * Calls f for each mapping in [begin, end)
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(
141 scan_mappings_func_t
&&f
) = 0;
146 * rewrite extent into passed transaction
148 using rewrite_extent_iertr
= base_iertr
;
149 using rewrite_extent_ret
= rewrite_extent_iertr::future
<>;
150 virtual rewrite_extent_ret
rewrite_extent(
152 CachedExtentRef extent
) = 0;
157 * update lba mapping for a delayed allocated extent
159 using update_mapping_iertr
= base_iertr
;
160 using update_mapping_ret
= base_iertr::future
<>;
161 virtual update_mapping_ret
update_mapping(
166 LogicalCachedExtent
*nextent
) = 0;
171 * update lba mappings for delayed allocated extents
173 using update_mappings_iertr
= update_mapping_iertr
;
174 using update_mappings_ret
= update_mapping_ret
;
175 update_mappings_ret
update_mappings(
177 const std::list
<LogicalCachedExtentRef
>& extents
);
180 * get_physical_extent_if_live
182 * Returns extent at addr/laddr if still live (if laddr
183 * still points at addr). Extent must be an internal, physical
186 * Returns a null CachedExtentRef if extent is not live.
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(
196 extent_len_t len
) = 0;
198 virtual ~LBAManager() {}
200 using LBAManagerRef
= std::unique_ptr
<LBAManager
>;
203 namespace lba_manager
{
204 LBAManagerRef
create_lba_manager(Cache
&cache
);