1
2
3
4
5
6
7 #ifndef DM_THIN_METADATA_H
8 #define DM_THIN_METADATA_H
9
10 #include "persistent-data/dm-block-manager.h"
11 #include "persistent-data/dm-space-map.h"
12 #include "persistent-data/dm-space-map-metadata.h"
13
14 #define THIN_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
15
16
17
18
19 #define THIN_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
20
21
22
23
24 #define THIN_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
25
26
27
28
29
30
31 #define THIN_METADATA_NEEDS_CHECK_FLAG (1 << 0)
32
33 struct dm_pool_metadata;
34 struct dm_thin_device;
35
36
37
38
39 typedef uint64_t dm_thin_id;
40
41
42
43
44 struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
45 sector_t data_block_size,
46 bool format_device);
47
48 int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
49
50
51
52
53
54 #define THIN_FEATURE_COMPAT_SUPP 0UL
55 #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
56 #define THIN_FEATURE_INCOMPAT_SUPP 0UL
57
58
59
60
61 int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
62
63
64
65
66
67
68
69 int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
70 dm_thin_id origin);
71
72
73
74
75
76
77 int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
78 dm_thin_id dev);
79
80
81
82
83
84 int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
85
86
87
88
89
90
91
92
93
94 int dm_pool_abort_metadata(struct dm_pool_metadata *pmd);
95
96
97
98
99 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
100 uint64_t current_id,
101 uint64_t new_id);
102
103 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
104 uint64_t *result);
105
106
107
108
109
110
111
112
113
114
115 int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd);
116 int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd);
117
118 int dm_pool_get_metadata_snap(struct dm_pool_metadata *pmd,
119 dm_block_t *result);
120
121
122
123
124
125
126
127
128 int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
129 struct dm_thin_device **td);
130
131 int dm_pool_close_thin_device(struct dm_thin_device *td);
132
133 dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
134
135 struct dm_thin_lookup_result {
136 dm_block_t block;
137 bool shared:1;
138 };
139
140
141
142
143
144
145
146 int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
147 int can_issue_io, struct dm_thin_lookup_result *result);
148
149
150
151
152
153 int dm_thin_find_mapped_range(struct dm_thin_device *td,
154 dm_block_t begin, dm_block_t end,
155 dm_block_t *thin_begin, dm_block_t *thin_end,
156 dm_block_t *pool_begin, bool *maybe_shared);
157
158
159
160
161 int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
162
163
164
165
166 int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
167 dm_block_t data_block);
168
169 int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
170 int dm_thin_remove_range(struct dm_thin_device *td,
171 dm_block_t begin, dm_block_t end);
172
173
174
175
176 bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
177
178 bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd);
179
180 bool dm_thin_aborted_changes(struct dm_thin_device *td);
181
182 int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
183 dm_block_t *highest_mapped);
184
185 int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
186
187 int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
188 dm_block_t *result);
189
190 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
191 dm_block_t *result);
192
193 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
194 dm_block_t *result);
195
196 int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
197
198 int dm_pool_block_is_shared(struct dm_pool_metadata *pmd, dm_block_t b, bool *result);
199
200 int dm_pool_inc_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_t e);
201 int dm_pool_dec_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_t e);
202
203
204
205
206
207 int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
208 int dm_pool_resize_metadata_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
209
210
211
212
213
214 void dm_pool_metadata_read_only(struct dm_pool_metadata *pmd);
215 void dm_pool_metadata_read_write(struct dm_pool_metadata *pmd);
216
217 int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
218 dm_block_t threshold,
219 dm_sm_threshold_fn fn,
220 void *context);
221
222
223
224
225 int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd);
226 bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd);
227
228
229
230
231 void dm_pool_issue_prefetches(struct dm_pool_metadata *pmd);
232
233
234 typedef int (*dm_pool_pre_commit_fn)(void *context);
235
236 void dm_pool_register_pre_commit_callback(struct dm_pool_metadata *pmd,
237 dm_pool_pre_commit_fn fn,
238 void *context);
239
240
241
242 #endif