]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.h
update source to Ceph Pacific 16.2.2
[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/seastore_types.h"
19 #include "crimson/os/seastore/lba_manager.h"
20 #include "crimson/os/seastore/cache.h"
21 #include "crimson/os/seastore/segment_manager.h"
22
23 #include "crimson/os/seastore/lba_manager/btree/lba_btree_node.h"
24
25 namespace crimson::os::seastore::lba_manager::btree {
26
27 /**
28 * BtreeLBAManager
29 *
30 * Uses a wandering btree to track two things:
31 * 1) lba state including laddr_t -> paddr_t mapping
32 * 2) reverse paddr_t -> laddr_t mapping for gc (TODO)
33 *
34 * Generally, any transaction will involve
35 * 1) deltas against lba tree nodes
36 * 2) new lba tree nodes
37 * - Note, there must necessarily be a delta linking
38 * these new nodes into the tree -- might be a
39 * bootstrap_state_t delta if new root
40 *
41 * get_mappings, alloc_extent_*, etc populate a Transaction
42 * which then gets submitted
43 */
44 class BtreeLBAManager : public LBAManager {
45 public:
46 BtreeLBAManager(
47 SegmentManager &segment_manager,
48 Cache &cache);
49
50 mkfs_ret mkfs(
51 Transaction &t) final;
52
53 get_mapping_ret get_mapping(
54 Transaction &t,
55 laddr_t offset, extent_len_t length) final;
56
57 get_mappings_ret get_mappings(
58 Transaction &t,
59 laddr_list_t &&list) final;
60
61 alloc_extent_ret alloc_extent(
62 Transaction &t,
63 laddr_t hint,
64 extent_len_t len,
65 paddr_t addr) final;
66
67 set_extent_ret set_extent(
68 Transaction &t,
69 laddr_t off, extent_len_t len, paddr_t addr) final;
70
71 ref_ret decref_extent(
72 Transaction &t,
73 laddr_t addr) final {
74 return update_refcount(t, addr, -1);
75 }
76
77 ref_ret incref_extent(
78 Transaction &t,
79 laddr_t addr) final {
80 return update_refcount(t, addr, 1);
81 }
82
83 complete_transaction_ret complete_transaction(
84 Transaction &t) final;
85
86 init_cached_extent_ret init_cached_extent(
87 Transaction &t,
88 CachedExtentRef e) final;
89
90 scan_mappings_ret scan_mappings(
91 Transaction &t,
92 laddr_t begin,
93 laddr_t end,
94 scan_mappings_func_t &&f) final;
95
96 scan_mapped_space_ret scan_mapped_space(
97 Transaction &t,
98 scan_mapped_space_func_t &&f) final;
99
100 rewrite_extent_ret rewrite_extent(
101 Transaction &t,
102 CachedExtentRef extent);
103
104 get_physical_extent_if_live_ret get_physical_extent_if_live(
105 Transaction &t,
106 extent_types_t type,
107 paddr_t addr,
108 laddr_t laddr,
109 segment_off_t len) final;
110
111 void add_pin(LBAPin &pin) final {
112 auto *bpin = reinterpret_cast<BtreeLBAPin*>(&pin);
113 pin_set.add_pin(bpin->pin);
114 bpin->parent = nullptr;
115 }
116
117 private:
118 SegmentManager &segment_manager;
119 Cache &cache;
120
121 btree_pin_set_t pin_set;
122
123 op_context_t get_context(Transaction &t) {
124 return op_context_t{cache, pin_set, t};
125 }
126
127 static btree_range_pin_t &get_pin(CachedExtent &e);
128
129
130 /**
131 * get_root
132 *
133 * Get a reference to the root LBANode.
134 */
135 using get_root_ertr = Cache::get_extent_ertr;
136 using get_root_ret = get_root_ertr::future<LBANodeRef>;
137 get_root_ret get_root(Transaction &);
138
139 /**
140 * insert_mapping
141 *
142 * Insert a lba mapping into the tree
143 */
144 using insert_mapping_ertr = crimson::errorator<
145 crimson::ct_error::input_output_error>;
146 using insert_mapping_ret = insert_mapping_ertr::future<LBAPinRef>;
147 insert_mapping_ret insert_mapping(
148 Transaction &t, ///< [in,out] transaction
149 LBANodeRef root, ///< [in] root node
150 laddr_t laddr, ///< [in] logical addr to insert
151 lba_map_val_t val ///< [in] mapping to insert
152 );
153
154 /**
155 * update_refcount
156 *
157 * Updates refcount, returns resulting refcount
158 */
159 using update_refcount_ret = ref_ret;
160 update_refcount_ret update_refcount(
161 Transaction &t,
162 laddr_t addr,
163 int delta);
164
165 /**
166 * update_mapping
167 *
168 * Updates mapping, removes if f returns nullopt
169 */
170 using update_mapping_ertr = ref_ertr;
171 using update_mapping_ret = ref_ertr::future<lba_map_val_t>;
172 using update_func_t = LBANode::mutate_func_t;
173 update_mapping_ret update_mapping(
174 Transaction &t,
175 laddr_t addr,
176 update_func_t &&f);
177
178 using update_internal_mapping_ertr = LBANode::mutate_internal_address_ertr;
179 using update_internal_mapping_ret = LBANode::mutate_internal_address_ret;
180 update_internal_mapping_ret update_internal_mapping(
181 Transaction &t,
182 depth_t depth,
183 laddr_t laddr,
184 paddr_t paddr);
185 };
186 using BtreeLBAManagerRef = std::unique_ptr<BtreeLBAManager>;
187
188 }