Lines Matching +full:- +full:s

1 // SPDX-License-Identifier: GPL-2.0-only
8 #include "dm-btree-internal.h"
9 #include "dm-transaction-manager.h"
11 #include <linux/device-mapper.h>
15 /*----------------------------------------------------------------*/
24 struct node_header *h = &n->header; in node_prepare_for_write()
26 h->blocknr = cpu_to_le64(dm_block_location(b)); in node_prepare_for_write()
27 h->csum = cpu_to_le32(dm_bm_checksum(&h->flags, in node_prepare_for_write()
28 block_size - sizeof(__le32), in node_prepare_for_write()
37 struct node_header *h = &n->header; in node_check()
42 if (dm_block_location(b) != le64_to_cpu(h->blocknr)) { in node_check()
43 DMERR_LIMIT("%s failed: blocknr %llu != wanted %llu", __func__, in node_check()
44 le64_to_cpu(h->blocknr), dm_block_location(b)); in node_check()
45 return -ENOTBLK; in node_check()
48 csum_disk = cpu_to_le32(dm_bm_checksum(&h->flags, in node_check()
49 block_size - sizeof(__le32), in node_check()
51 if (csum_disk != h->csum) { in node_check()
52 DMERR_LIMIT("%s failed: csum %u != wanted %u", __func__, in node_check()
53 le32_to_cpu(csum_disk), le32_to_cpu(h->csum)); in node_check()
54 return -EILSEQ; in node_check()
57 nr_entries = le32_to_cpu(h->nr_entries); in node_check()
58 max_entries = le32_to_cpu(h->max_entries); in node_check()
59 value_size = le32_to_cpu(h->value_size); in node_check()
63 DMERR_LIMIT("%s failed: max_entries too large", __func__); in node_check()
64 return -EILSEQ; in node_check()
68 DMERR_LIMIT("%s failed: too many entries", __func__); in node_check()
69 return -EILSEQ; in node_check()
75 flags = le32_to_cpu(h->flags); in node_check()
77 DMERR_LIMIT("%s failed: node is neither INTERNAL or LEAF", __func__); in node_check()
78 return -EILSEQ; in node_check()
90 /*----------------------------------------------------------------*/
95 return dm_tm_read_lock(info->tm, b, &btree_node_validator, result); in bn_read_lock()
104 r = dm_tm_shadow_block(info->tm, orig, &btree_node_validator, in bn_shadow()
107 inc_children(info->tm, dm_block_data(*result), vt); in bn_shadow()
114 return dm_tm_new_block(info->tm, &btree_node_validator, result); in new_block()
119 dm_tm_unlock(info->tm, b); in unlock_block()
122 /*----------------------------------------------------------------*/
124 void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info) in init_ro_spine() argument
126 s->info = info; in init_ro_spine()
127 s->count = 0; in init_ro_spine()
128 s->nodes[0] = NULL; in init_ro_spine()
129 s->nodes[1] = NULL; in init_ro_spine()
132 void exit_ro_spine(struct ro_spine *s) in exit_ro_spine() argument
136 for (i = 0; i < s->count; i++) in exit_ro_spine()
137 unlock_block(s->info, s->nodes[i]); in exit_ro_spine()
140 int ro_step(struct ro_spine *s, dm_block_t new_child) in ro_step() argument
144 if (s->count == 2) { in ro_step()
145 unlock_block(s->info, s->nodes[0]); in ro_step()
146 s->nodes[0] = s->nodes[1]; in ro_step()
147 s->count--; in ro_step()
150 r = bn_read_lock(s->info, new_child, s->nodes + s->count); in ro_step()
152 s->count++; in ro_step()
157 void ro_pop(struct ro_spine *s) in ro_pop() argument
159 BUG_ON(!s->count); in ro_pop()
160 --s->count; in ro_pop()
161 unlock_block(s->info, s->nodes[s->count]); in ro_pop()
164 struct btree_node *ro_node(struct ro_spine *s) in ro_node() argument
168 BUG_ON(!s->count); in ro_node()
169 block = s->nodes[s->count - 1]; in ro_node()
174 /*----------------------------------------------------------------*/
176 void init_shadow_spine(struct shadow_spine *s, struct dm_btree_info *info) in init_shadow_spine() argument
178 s->info = info; in init_shadow_spine()
179 s->count = 0; in init_shadow_spine()
182 void exit_shadow_spine(struct shadow_spine *s) in exit_shadow_spine() argument
186 for (i = 0; i < s->count; i++) in exit_shadow_spine()
187 unlock_block(s->info, s->nodes[i]); in exit_shadow_spine()
190 int shadow_step(struct shadow_spine *s, dm_block_t b, in shadow_step() argument
195 if (s->count == 2) { in shadow_step()
196 unlock_block(s->info, s->nodes[0]); in shadow_step()
197 s->nodes[0] = s->nodes[1]; in shadow_step()
198 s->count--; in shadow_step()
201 r = bn_shadow(s->info, b, vt, s->nodes + s->count); in shadow_step()
203 if (!s->count) in shadow_step()
204 s->root = dm_block_location(s->nodes[0]); in shadow_step()
206 s->count++; in shadow_step()
212 struct dm_block *shadow_current(struct shadow_spine *s) in shadow_current() argument
214 BUG_ON(!s->count); in shadow_current()
216 return s->nodes[s->count - 1]; in shadow_current()
219 struct dm_block *shadow_parent(struct shadow_spine *s) in shadow_parent() argument
221 BUG_ON(s->count != 2); in shadow_parent()
223 return s->count == 2 ? s->nodes[0] : NULL; in shadow_parent()
226 int shadow_has_parent(struct shadow_spine *s) in shadow_has_parent() argument
228 return s->count >= 2; in shadow_has_parent()
231 dm_block_t shadow_root(struct shadow_spine *s) in shadow_root() argument
233 return s->root; in shadow_root()
258 vt->context = tm; in init_le64_type()
259 vt->size = sizeof(__le64); in init_le64_type()
260 vt->inc = le64_inc; in init_le64_type()
261 vt->dec = le64_dec; in init_le64_type()
262 vt->equal = le64_equal; in init_le64_type()