]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.h
add stop-gap to fix compat with CPUs not supporting SSE 4.1
[ceph.git] / ceph / src / crimson / os / seastore / lba_manager / btree / btree_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 #include <seastar/core/future.hh>
11
12 #include "include/ceph_assert.h"
13 #include "include/buffer_fwd.h"
14 #include "include/interval_set.h"
15 #include "common/interval_map.h"
16 #include "crimson/osd/exceptions.h"
17
18 #include "crimson/os/seastore/btree/fixed_kv_btree.h"
19 #include "crimson/os/seastore/seastore_types.h"
20 #include "crimson/os/seastore/lba_manager.h"
21 #include "crimson/os/seastore/cache.h"
22
23 #include "crimson/os/seastore/lba_manager/btree/lba_btree_node.h"
24 #include "crimson/os/seastore/btree/btree_range_pin.h"
25
26 namespace crimson::os::seastore::lba_manager::btree {
27
28 class BtreeLBAMapping : public BtreeNodeMapping<laddr_t, paddr_t> {
29 public:
30 BtreeLBAMapping(op_context_t<laddr_t> ctx)
31 : BtreeNodeMapping(ctx) {}
32 BtreeLBAMapping(
33 op_context_t<laddr_t> c,
34 CachedExtentRef parent,
35 uint16_t pos,
36 lba_map_val_t &val,
37 lba_node_meta_t &&meta)
38 : BtreeNodeMapping(
39 c,
40 parent,
41 pos,
42 val.paddr,
43 val.len,
44 std::forward<lba_node_meta_t>(meta))
45 {}
46 };
47
48 using LBABtree = FixedKVBtree<
49 laddr_t, lba_map_val_t, LBAInternalNode,
50 LBALeafNode, BtreeLBAMapping, LBA_BLOCK_SIZE, true>;
51
52 /**
53 * BtreeLBAManager
54 *
55 * Uses a wandering btree to track two things:
56 * 1) lba state including laddr_t -> paddr_t mapping
57 * 2) reverse paddr_t -> laddr_t mapping for gc (TODO)
58 *
59 * Generally, any transaction will involve
60 * 1) deltas against lba tree nodes
61 * 2) new lba tree nodes
62 * - Note, there must necessarily be a delta linking
63 * these new nodes into the tree -- might be a
64 * bootstrap_state_t delta if new root
65 *
66 * get_mappings, alloc_extent_*, etc populate a Transaction
67 * which then gets submitted
68 */
69 class BtreeLBAManager : public LBAManager {
70 public:
71 BtreeLBAManager(Cache &cache)
72 : cache(cache)
73 {
74 register_metrics();
75 }
76
77 mkfs_ret mkfs(
78 Transaction &t) final;
79
80 get_mappings_ret get_mappings(
81 Transaction &t,
82 laddr_t offset, extent_len_t length) final;
83
84 get_mappings_ret get_mappings(
85 Transaction &t,
86 laddr_list_t &&list) final;
87
88 get_mapping_ret get_mapping(
89 Transaction &t,
90 laddr_t offset) final;
91
92 alloc_extent_ret alloc_extent(
93 Transaction &t,
94 laddr_t hint,
95 extent_len_t len,
96 paddr_t addr,
97 LogicalCachedExtent*) final;
98
99 ref_ret decref_extent(
100 Transaction &t,
101 laddr_t addr) final {
102 return update_refcount(t, addr, -1);
103 }
104
105 ref_ret incref_extent(
106 Transaction &t,
107 laddr_t addr) final {
108 return update_refcount(t, addr, 1);
109 }
110
111 /**
112 * init_cached_extent
113 *
114 * Checks whether e is live (reachable from lba tree) and drops or initializes
115 * accordingly.
116 *
117 * Returns if e is live.
118 */
119 init_cached_extent_ret init_cached_extent(
120 Transaction &t,
121 CachedExtentRef e) final;
122
123 check_child_trackers_ret check_child_trackers(Transaction &t) final;
124
125 scan_mappings_ret scan_mappings(
126 Transaction &t,
127 laddr_t begin,
128 laddr_t end,
129 scan_mappings_func_t &&f) final;
130
131 rewrite_extent_ret rewrite_extent(
132 Transaction &t,
133 CachedExtentRef extent) final;
134
135 update_mapping_ret update_mapping(
136 Transaction& t,
137 laddr_t laddr,
138 paddr_t prev_addr,
139 paddr_t paddr,
140 LogicalCachedExtent*) final;
141
142 get_physical_extent_if_live_ret get_physical_extent_if_live(
143 Transaction &t,
144 extent_types_t type,
145 paddr_t addr,
146 laddr_t laddr,
147 extent_len_t len) final;
148 private:
149 Cache &cache;
150
151
152 struct {
153 uint64_t num_alloc_extents = 0;
154 uint64_t num_alloc_extents_iter_nexts = 0;
155 } stats;
156
157 op_context_t<laddr_t> get_context(Transaction &t) {
158 return op_context_t<laddr_t>{cache, t};
159 }
160
161 seastar::metrics::metric_group metrics;
162 void register_metrics();
163
164 /**
165 * update_refcount
166 *
167 * Updates refcount, returns resulting refcount
168 */
169 using update_refcount_ret = ref_ret;
170 update_refcount_ret update_refcount(
171 Transaction &t,
172 laddr_t addr,
173 int delta);
174
175 /**
176 * _update_mapping
177 *
178 * Updates mapping, removes if f returns nullopt
179 */
180 using _update_mapping_iertr = ref_iertr;
181 using _update_mapping_ret = ref_iertr::future<lba_map_val_t>;
182 using update_func_t = std::function<
183 lba_map_val_t(const lba_map_val_t &v)
184 >;
185 _update_mapping_ret _update_mapping(
186 Transaction &t,
187 laddr_t addr,
188 update_func_t &&f,
189 LogicalCachedExtent*);
190 };
191 using BtreeLBAManagerRef = std::unique_ptr<BtreeLBAManager>;
192
193 }