]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/backref_manager.h
3feedb997b4c39c674993a5751fb8d3a33b529b8
[ceph.git] / ceph / src / crimson / os / seastore / backref_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 "crimson/os/seastore/cache.h"
7 #include "crimson/os/seastore/cached_extent.h"
8 #include "crimson/os/seastore/transaction.h"
9
10 namespace crimson::os::seastore {
11
12 /**
13 * Abstract interface for managing back references that map paddr_t to laddr_t
14 */
15 class BackrefManager {
16 public:
17 using base_ertr = crimson::errorator<
18 crimson::ct_error::input_output_error>;
19 using base_iertr = trans_iertr<base_ertr>;
20
21 using mkfs_iertr = base_iertr;
22 using mkfs_ret = mkfs_iertr::future<>;
23 virtual mkfs_ret mkfs(
24 Transaction &t) = 0;
25
26 /**
27 * Fetches mappings for paddr_t in range [offset, offset + len)
28 *
29 * Future will not resolve until all pins have resolved
30 */
31 using get_mappings_iertr = base_iertr;
32 using get_mappings_ret = get_mappings_iertr::future<backref_pin_list_t>;
33 virtual get_mappings_ret get_mappings(
34 Transaction &t,
35 paddr_t offset,
36 paddr_t end) = 0;
37
38 /**
39 * Fetches the mapping for paddr_t
40 *
41 * Future will not resolve until the pin has resolved
42 */
43 using get_mapping_iertr = base_iertr::extend<
44 crimson::ct_error::enoent>;
45 using get_mapping_ret = get_mapping_iertr::future<BackrefMappingRef>;
46 virtual get_mapping_ret get_mapping(
47 Transaction &t,
48 paddr_t offset) = 0;
49
50 /**
51 * rewrite_extent
52 *
53 * rewrite extent into passed transaction
54 */
55 using rewrite_extent_iertr = base_iertr;
56 using rewrite_extent_ret = rewrite_extent_iertr::future<>;
57 virtual rewrite_extent_ret rewrite_extent(
58 Transaction &t,
59 CachedExtentRef extent) = 0;
60
61 /**
62 * Insert new paddr_t -> laddr_t mapping
63 */
64 using new_mapping_iertr = base_iertr;
65 using new_mapping_ret = new_mapping_iertr::future<BackrefMappingRef>;
66 virtual new_mapping_ret new_mapping(
67 Transaction &t,
68 paddr_t key,
69 extent_len_t len,
70 laddr_t val,
71 extent_types_t type) = 0;
72
73 /**
74 * Check if a CachedExtent is alive, should be called
75 * after replay on each cached extent.
76 *
77 * @return returns whether the extent is alive
78 */
79 using init_cached_extent_iertr = base_iertr;
80 using init_cached_extent_ret = init_cached_extent_iertr::future<bool>;
81 virtual init_cached_extent_ret init_cached_extent(
82 Transaction &t,
83 CachedExtentRef e) = 0;
84
85 virtual Cache::backref_entry_query_mset_t
86 get_cached_backref_entries_in_range(
87 paddr_t start,
88 paddr_t end) = 0;
89
90 using retrieve_backref_extents_in_range_iertr = base_iertr;
91 using retrieve_backref_extents_in_range_ret =
92 retrieve_backref_extents_in_range_iertr::future<std::vector<CachedExtentRef>>;
93 virtual retrieve_backref_extents_in_range_ret
94 retrieve_backref_extents_in_range(
95 Transaction &t,
96 paddr_t start,
97 paddr_t end) = 0;
98
99 virtual void cache_new_backref_extent(
100 paddr_t paddr,
101 paddr_t key,
102 extent_types_t type) = 0;
103
104 /**
105 * merge in-cache paddr_t -> laddr_t mappings to the on-disk backref tree
106 */
107 using merge_cached_backrefs_iertr = base_iertr;
108 using merge_cached_backrefs_ret = merge_cached_backrefs_iertr::future<journal_seq_t>;
109 virtual merge_cached_backrefs_ret merge_cached_backrefs(
110 Transaction &t,
111 const journal_seq_t &limit,
112 const uint64_t max) = 0;
113
114 struct remove_mapping_result_t {
115 paddr_t offset = P_ADDR_NULL;
116 extent_len_t len = 0;
117 laddr_t laddr = L_ADDR_NULL;
118 };
119
120 /**
121 * delete the mapping for paddr_t offset
122 */
123 using remove_mapping_iertr = base_iertr::extend<
124 crimson::ct_error::enoent>;
125 using remove_mapping_ret = remove_mapping_iertr::future<remove_mapping_result_t>;
126 virtual remove_mapping_ret remove_mapping(
127 Transaction &t,
128 paddr_t offset) = 0;
129
130 /**
131 * scan all extents in both tree and cache,
132 * including backref extents, logical extents and lba extents,
133 * visit them with scan_mapped_space_func_t
134 */
135 using scan_mapped_space_iertr = base_iertr;
136 using scan_mapped_space_ret = scan_mapped_space_iertr::future<>;
137 using scan_mapped_space_func_t = std::function<
138 void(paddr_t, paddr_t, extent_len_t, extent_types_t, laddr_t)>;
139 virtual scan_mapped_space_ret scan_mapped_space(
140 Transaction &t,
141 scan_mapped_space_func_t &&f) = 0;
142
143 virtual ~BackrefManager() {}
144 };
145
146 using BackrefManagerRef =
147 std::unique_ptr<BackrefManager>;
148
149 BackrefManagerRef create_backref_manager(
150 Cache &cache);
151
152 } // namespace crimson::os::seastore::backref