aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/persistent-data
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-12-21 20:08:06 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-21 20:08:06 -0500
commitb49249d10324d0fd6fb29725c2807dfd80d0edbc (patch)
tree9a8fa724e6c9f9283530979c6e32a311c74999d5 /drivers/md/persistent-data
parent10532b560bacf23766f9c7dc09778b31b198ff45 (diff)
parent45e621d45e24ffc4cb2b2935e8438987b860063a (diff)
Merge tag 'dm-3.8-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/agk/linux-dm
Pull dm update from Alasdair G Kergon: "Miscellaneous device-mapper fixes, cleanups and performance improvements. Of particular note: - Disable broken WRITE SAME support in all targets except linear and striped. Use it when kcopyd is zeroing blocks. - Remove several mempools from targets by moving the data into the bio's new front_pad area(which dm calls 'per_bio_data'). - Fix a race in thin provisioning if discards are misused. - Prevent userspace from interfering with the ioctl parameters and use kmalloc for the data buffer if it's small instead of vmalloc. - Throttle some annoying error messages when I/O fails." * tag 'dm-3.8-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/agk/linux-dm: (36 commits) dm stripe: add WRITE SAME support dm: remove map_info dm snapshot: do not use map_context dm thin: dont use map_context dm raid1: dont use map_context dm flakey: dont use map_context dm raid1: rename read_record to bio_record dm: move target request nr to dm_target_io dm snapshot: use per_bio_data dm verity: use per_bio_data dm raid1: use per_bio_data dm: introduce per_bio_data dm kcopyd: add WRITE SAME support to dm_kcopyd_zero dm linear: add WRITE SAME support dm: add WRITE SAME support dm: prepare to support WRITE SAME dm ioctl: use kmalloc if possible dm ioctl: remove PF_MEMALLOC dm persistent data: improve improve space map block alloc failure message dm thin: use DMERR_LIMIT for errors ...
Diffstat (limited to 'drivers/md/persistent-data')
-rw-r--r--drivers/md/persistent-data/dm-block-manager.c12
-rw-r--r--drivers/md/persistent-data/dm-btree-internal.h16
-rw-r--r--drivers/md/persistent-data/dm-btree-remove.c50
-rw-r--r--drivers/md/persistent-data/dm-btree-spine.c20
-rw-r--r--drivers/md/persistent-data/dm-btree.c31
-rw-r--r--drivers/md/persistent-data/dm-space-map-common.c16
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.c2
7 files changed, 77 insertions, 70 deletions
diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c
index a3ae09124a67..28c3ed072a79 100644
--- a/drivers/md/persistent-data/dm-block-manager.c
+++ b/drivers/md/persistent-data/dm-block-manager.c
@@ -428,15 +428,17 @@ static int dm_bm_validate_buffer(struct dm_block_manager *bm,
428 if (!v) 428 if (!v)
429 return 0; 429 return 0;
430 r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(bm->bufio)); 430 r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(bm->bufio));
431 if (unlikely(r)) 431 if (unlikely(r)) {
432 DMERR_LIMIT("%s validator check failed for block %llu", v->name,
433 (unsigned long long) dm_bufio_get_block_number(buf));
432 return r; 434 return r;
435 }
433 aux->validator = v; 436 aux->validator = v;
434 } else { 437 } else {
435 if (unlikely(aux->validator != v)) { 438 if (unlikely(aux->validator != v)) {
436 DMERR("validator mismatch (old=%s vs new=%s) for block %llu", 439 DMERR_LIMIT("validator mismatch (old=%s vs new=%s) for block %llu",
437 aux->validator->name, v ? v->name : "NULL", 440 aux->validator->name, v ? v->name : "NULL",
438 (unsigned long long) 441 (unsigned long long) dm_bufio_get_block_number(buf));
439 dm_bufio_get_block_number(buf));
440 return -EINVAL; 442 return -EINVAL;
441 } 443 }
442 } 444 }
diff --git a/drivers/md/persistent-data/dm-btree-internal.h b/drivers/md/persistent-data/dm-btree-internal.h
index 5709bfeab1e8..accbb05f17b6 100644
--- a/drivers/md/persistent-data/dm-btree-internal.h
+++ b/drivers/md/persistent-data/dm-btree-internal.h
@@ -36,13 +36,13 @@ struct node_header {
36 __le32 padding; 36 __le32 padding;
37} __packed; 37} __packed;
38 38
39struct node { 39struct btree_node {
40 struct node_header header; 40 struct node_header header;
41 __le64 keys[0]; 41 __le64 keys[0];
42} __packed; 42} __packed;
43 43
44 44
45void inc_children(struct dm_transaction_manager *tm, struct node *n, 45void inc_children(struct dm_transaction_manager *tm, struct btree_node *n,
46 struct dm_btree_value_type *vt); 46 struct dm_btree_value_type *vt);
47 47
48int new_block(struct dm_btree_info *info, struct dm_block **result); 48int new_block(struct dm_btree_info *info, struct dm_block **result);
@@ -64,7 +64,7 @@ struct ro_spine {
64void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info); 64void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info);
65int exit_ro_spine(struct ro_spine *s); 65int exit_ro_spine(struct ro_spine *s);
66int ro_step(struct ro_spine *s, dm_block_t new_child); 66int ro_step(struct ro_spine *s, dm_block_t new_child);
67struct node *ro_node(struct ro_spine *s); 67struct btree_node *ro_node(struct ro_spine *s);
68 68
69struct shadow_spine { 69struct shadow_spine {
70 struct dm_btree_info *info; 70 struct dm_btree_info *info;
@@ -98,17 +98,17 @@ int shadow_root(struct shadow_spine *s);
98/* 98/*
99 * Some inlines. 99 * Some inlines.
100 */ 100 */
101static inline __le64 *key_ptr(struct node *n, uint32_t index) 101static inline __le64 *key_ptr(struct btree_node *n, uint32_t index)
102{ 102{
103 return n->keys + index; 103 return n->keys + index;
104} 104}
105 105
106static inline void *value_base(struct node *n) 106static inline void *value_base(struct btree_node *n)
107{ 107{
108 return &n->keys[le32_to_cpu(n->header.max_entries)]; 108 return &n->keys[le32_to_cpu(n->header.max_entries)];
109} 109}
110 110
111static inline void *value_ptr(struct node *n, uint32_t index) 111static inline void *value_ptr(struct btree_node *n, uint32_t index)
112{ 112{
113 uint32_t value_size = le32_to_cpu(n->header.value_size); 113 uint32_t value_size = le32_to_cpu(n->header.value_size);
114 return value_base(n) + (value_size * index); 114 return value_base(n) + (value_size * index);
@@ -117,7 +117,7 @@ static inline void *value_ptr(struct node *n, uint32_t index)
117/* 117/*
118 * Assumes the values are suitably-aligned and converts to core format. 118 * Assumes the values are suitably-aligned and converts to core format.
119 */ 119 */
120static inline uint64_t value64(struct node *n, uint32_t index) 120static inline uint64_t value64(struct btree_node *n, uint32_t index)
121{ 121{
122 __le64 *values_le = value_base(n); 122 __le64 *values_le = value_base(n);
123 123
@@ -127,7 +127,7 @@ static inline uint64_t value64(struct node *n, uint32_t index)
127/* 127/*
128 * Searching for a key within a single node. 128 * Searching for a key within a single node.
129 */ 129 */
130int lower_bound(struct node *n, uint64_t key); 130int lower_bound(struct btree_node *n, uint64_t key);
131 131
132extern struct dm_block_validator btree_node_validator; 132extern struct dm_block_validator btree_node_validator;
133 133
diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c
index aa71e2359a07..c4f28133ef82 100644
--- a/drivers/md/persistent-data/dm-btree-remove.c
+++ b/drivers/md/persistent-data/dm-btree-remove.c
@@ -53,7 +53,7 @@
53/* 53/*
54 * Some little utilities for moving node data around. 54 * Some little utilities for moving node data around.
55 */ 55 */
56static void node_shift(struct node *n, int shift) 56static void node_shift(struct btree_node *n, int shift)
57{ 57{
58 uint32_t nr_entries = le32_to_cpu(n->header.nr_entries); 58 uint32_t nr_entries = le32_to_cpu(n->header.nr_entries);
59 uint32_t value_size = le32_to_cpu(n->header.value_size); 59 uint32_t value_size = le32_to_cpu(n->header.value_size);
@@ -79,7 +79,7 @@ static void node_shift(struct node *n, int shift)
79 } 79 }
80} 80}
81 81
82static void node_copy(struct node *left, struct node *right, int shift) 82static void node_copy(struct btree_node *left, struct btree_node *right, int shift)
83{ 83{
84 uint32_t nr_left = le32_to_cpu(left->header.nr_entries); 84 uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
85 uint32_t value_size = le32_to_cpu(left->header.value_size); 85 uint32_t value_size = le32_to_cpu(left->header.value_size);
@@ -108,7 +108,7 @@ static void node_copy(struct node *left, struct node *right, int shift)
108/* 108/*
109 * Delete a specific entry from a leaf node. 109 * Delete a specific entry from a leaf node.
110 */ 110 */
111static void delete_at(struct node *n, unsigned index) 111static void delete_at(struct btree_node *n, unsigned index)
112{ 112{
113 unsigned nr_entries = le32_to_cpu(n->header.nr_entries); 113 unsigned nr_entries = le32_to_cpu(n->header.nr_entries);
114 unsigned nr_to_copy = nr_entries - (index + 1); 114 unsigned nr_to_copy = nr_entries - (index + 1);
@@ -128,7 +128,7 @@ static void delete_at(struct node *n, unsigned index)
128 n->header.nr_entries = cpu_to_le32(nr_entries - 1); 128 n->header.nr_entries = cpu_to_le32(nr_entries - 1);
129} 129}
130 130
131static unsigned merge_threshold(struct node *n) 131static unsigned merge_threshold(struct btree_node *n)
132{ 132{
133 return le32_to_cpu(n->header.max_entries) / 3; 133 return le32_to_cpu(n->header.max_entries) / 3;
134} 134}
@@ -136,7 +136,7 @@ static unsigned merge_threshold(struct node *n)
136struct child { 136struct child {
137 unsigned index; 137 unsigned index;
138 struct dm_block *block; 138 struct dm_block *block;
139 struct node *n; 139 struct btree_node *n;
140}; 140};
141 141
142static struct dm_btree_value_type le64_type = { 142static struct dm_btree_value_type le64_type = {
@@ -147,7 +147,7 @@ static struct dm_btree_value_type le64_type = {
147 .equal = NULL 147 .equal = NULL
148}; 148};
149 149
150static int init_child(struct dm_btree_info *info, struct node *parent, 150static int init_child(struct dm_btree_info *info, struct btree_node *parent,
151 unsigned index, struct child *result) 151 unsigned index, struct child *result)
152{ 152{
153 int r, inc; 153 int r, inc;
@@ -177,7 +177,7 @@ static int exit_child(struct dm_btree_info *info, struct child *c)
177 return dm_tm_unlock(info->tm, c->block); 177 return dm_tm_unlock(info->tm, c->block);
178} 178}
179 179
180static void shift(struct node *left, struct node *right, int count) 180static void shift(struct btree_node *left, struct btree_node *right, int count)
181{ 181{
182 uint32_t nr_left = le32_to_cpu(left->header.nr_entries); 182 uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
183 uint32_t nr_right = le32_to_cpu(right->header.nr_entries); 183 uint32_t nr_right = le32_to_cpu(right->header.nr_entries);
@@ -203,11 +203,11 @@ static void shift(struct node *left, struct node *right, int count)
203 right->header.nr_entries = cpu_to_le32(nr_right + count); 203 right->header.nr_entries = cpu_to_le32(nr_right + count);
204} 204}
205 205
206static void __rebalance2(struct dm_btree_info *info, struct node *parent, 206static void __rebalance2(struct dm_btree_info *info, struct btree_node *parent,
207 struct child *l, struct child *r) 207 struct child *l, struct child *r)
208{ 208{
209 struct node *left = l->n; 209 struct btree_node *left = l->n;
210 struct node *right = r->n; 210 struct btree_node *right = r->n;
211 uint32_t nr_left = le32_to_cpu(left->header.nr_entries); 211 uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
212 uint32_t nr_right = le32_to_cpu(right->header.nr_entries); 212 uint32_t nr_right = le32_to_cpu(right->header.nr_entries);
213 unsigned threshold = 2 * merge_threshold(left) + 1; 213 unsigned threshold = 2 * merge_threshold(left) + 1;
@@ -239,7 +239,7 @@ static int rebalance2(struct shadow_spine *s, struct dm_btree_info *info,
239 unsigned left_index) 239 unsigned left_index)
240{ 240{
241 int r; 241 int r;
242 struct node *parent; 242 struct btree_node *parent;
243 struct child left, right; 243 struct child left, right;
244 244
245 parent = dm_block_data(shadow_current(s)); 245 parent = dm_block_data(shadow_current(s));
@@ -270,9 +270,9 @@ static int rebalance2(struct shadow_spine *s, struct dm_btree_info *info,
270 * in right, then rebalance2. This wastes some cpu, but I want something 270 * in right, then rebalance2. This wastes some cpu, but I want something
271 * simple atm. 271 * simple atm.
272 */ 272 */
273static void delete_center_node(struct dm_btree_info *info, struct node *parent, 273static void delete_center_node(struct dm_btree_info *info, struct btree_node *parent,
274 struct child *l, struct child *c, struct child *r, 274 struct child *l, struct child *c, struct child *r,
275 struct node *left, struct node *center, struct node *right, 275 struct btree_node *left, struct btree_node *center, struct btree_node *right,
276 uint32_t nr_left, uint32_t nr_center, uint32_t nr_right) 276 uint32_t nr_left, uint32_t nr_center, uint32_t nr_right)
277{ 277{
278 uint32_t max_entries = le32_to_cpu(left->header.max_entries); 278 uint32_t max_entries = le32_to_cpu(left->header.max_entries);
@@ -301,9 +301,9 @@ static void delete_center_node(struct dm_btree_info *info, struct node *parent,
301/* 301/*
302 * Redistributes entries among 3 sibling nodes. 302 * Redistributes entries among 3 sibling nodes.
303 */ 303 */
304static void redistribute3(struct dm_btree_info *info, struct node *parent, 304static void redistribute3(struct dm_btree_info *info, struct btree_node *parent,
305 struct child *l, struct child *c, struct child *r, 305 struct child *l, struct child *c, struct child *r,
306 struct node *left, struct node *center, struct node *right, 306 struct btree_node *left, struct btree_node *center, struct btree_node *right,
307 uint32_t nr_left, uint32_t nr_center, uint32_t nr_right) 307 uint32_t nr_left, uint32_t nr_center, uint32_t nr_right)
308{ 308{
309 int s; 309 int s;
@@ -343,12 +343,12 @@ static void redistribute3(struct dm_btree_info *info, struct node *parent,
343 *key_ptr(parent, r->index) = right->keys[0]; 343 *key_ptr(parent, r->index) = right->keys[0];
344} 344}
345 345
346static void __rebalance3(struct dm_btree_info *info, struct node *parent, 346static void __rebalance3(struct dm_btree_info *info, struct btree_node *parent,
347 struct child *l, struct child *c, struct child *r) 347 struct child *l, struct child *c, struct child *r)
348{ 348{
349 struct node *left = l->n; 349 struct btree_node *left = l->n;
350 struct node *center = c->n; 350 struct btree_node *center = c->n;
351 struct node *right = r->n; 351 struct btree_node *right = r->n;
352 352
353 uint32_t nr_left = le32_to_cpu(left->header.nr_entries); 353 uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
354 uint32_t nr_center = le32_to_cpu(center->header.nr_entries); 354 uint32_t nr_center = le32_to_cpu(center->header.nr_entries);
@@ -371,7 +371,7 @@ static int rebalance3(struct shadow_spine *s, struct dm_btree_info *info,
371 unsigned left_index) 371 unsigned left_index)
372{ 372{
373 int r; 373 int r;
374 struct node *parent = dm_block_data(shadow_current(s)); 374 struct btree_node *parent = dm_block_data(shadow_current(s));
375 struct child left, center, right; 375 struct child left, center, right;
376 376
377 /* 377 /*
@@ -421,7 +421,7 @@ static int get_nr_entries(struct dm_transaction_manager *tm,
421{ 421{
422 int r; 422 int r;
423 struct dm_block *block; 423 struct dm_block *block;
424 struct node *n; 424 struct btree_node *n;
425 425
426 r = dm_tm_read_lock(tm, b, &btree_node_validator, &block); 426 r = dm_tm_read_lock(tm, b, &btree_node_validator, &block);
427 if (r) 427 if (r)
@@ -438,7 +438,7 @@ static int rebalance_children(struct shadow_spine *s,
438{ 438{
439 int i, r, has_left_sibling, has_right_sibling; 439 int i, r, has_left_sibling, has_right_sibling;
440 uint32_t child_entries; 440 uint32_t child_entries;
441 struct node *n; 441 struct btree_node *n;
442 442
443 n = dm_block_data(shadow_current(s)); 443 n = dm_block_data(shadow_current(s));
444 444
@@ -483,7 +483,7 @@ static int rebalance_children(struct shadow_spine *s,
483 return r; 483 return r;
484} 484}
485 485
486static int do_leaf(struct node *n, uint64_t key, unsigned *index) 486static int do_leaf(struct btree_node *n, uint64_t key, unsigned *index)
487{ 487{
488 int i = lower_bound(n, key); 488 int i = lower_bound(n, key);
489 489
@@ -506,7 +506,7 @@ static int remove_raw(struct shadow_spine *s, struct dm_btree_info *info,
506 uint64_t key, unsigned *index) 506 uint64_t key, unsigned *index)
507{ 507{
508 int i = *index, r; 508 int i = *index, r;
509 struct node *n; 509 struct btree_node *n;
510 510
511 for (;;) { 511 for (;;) {
512 r = shadow_step(s, root, vt); 512 r = shadow_step(s, root, vt);
@@ -556,7 +556,7 @@ int dm_btree_remove(struct dm_btree_info *info, dm_block_t root,
556 unsigned level, last_level = info->levels - 1; 556 unsigned level, last_level = info->levels - 1;
557 int index = 0, r = 0; 557 int index = 0, r = 0;
558 struct shadow_spine spine; 558 struct shadow_spine spine;
559 struct node *n; 559 struct btree_node *n;
560 560
561 init_shadow_spine(&spine, info); 561 init_shadow_spine(&spine, info);
562 for (level = 0; level < info->levels; level++) { 562 for (level = 0; level < info->levels; level++) {
diff --git a/drivers/md/persistent-data/dm-btree-spine.c b/drivers/md/persistent-data/dm-btree-spine.c
index d9a7912ee8ee..f199a0c4ed04 100644
--- a/drivers/md/persistent-data/dm-btree-spine.c
+++ b/drivers/md/persistent-data/dm-btree-spine.c
@@ -23,7 +23,7 @@ static void node_prepare_for_write(struct dm_block_validator *v,
23 struct dm_block *b, 23 struct dm_block *b,
24 size_t block_size) 24 size_t block_size)
25{ 25{
26 struct node *n = dm_block_data(b); 26 struct btree_node *n = dm_block_data(b);
27 struct node_header *h = &n->header; 27 struct node_header *h = &n->header;
28 28
29 h->blocknr = cpu_to_le64(dm_block_location(b)); 29 h->blocknr = cpu_to_le64(dm_block_location(b));
@@ -38,15 +38,15 @@ static int node_check(struct dm_block_validator *v,
38 struct dm_block *b, 38 struct dm_block *b,
39 size_t block_size) 39 size_t block_size)
40{ 40{
41 struct node *n = dm_block_data(b); 41 struct btree_node *n = dm_block_data(b);
42 struct node_header *h = &n->header; 42 struct node_header *h = &n->header;
43 size_t value_size; 43 size_t value_size;
44 __le32 csum_disk; 44 __le32 csum_disk;
45 uint32_t flags; 45 uint32_t flags;
46 46
47 if (dm_block_location(b) != le64_to_cpu(h->blocknr)) { 47 if (dm_block_location(b) != le64_to_cpu(h->blocknr)) {
48 DMERR("node_check failed blocknr %llu wanted %llu", 48 DMERR_LIMIT("node_check failed: blocknr %llu != wanted %llu",
49 le64_to_cpu(h->blocknr), dm_block_location(b)); 49 le64_to_cpu(h->blocknr), dm_block_location(b));
50 return -ENOTBLK; 50 return -ENOTBLK;
51 } 51 }
52 52
@@ -54,8 +54,8 @@ static int node_check(struct dm_block_validator *v,
54 block_size - sizeof(__le32), 54 block_size - sizeof(__le32),
55 BTREE_CSUM_XOR)); 55 BTREE_CSUM_XOR));
56 if (csum_disk != h->csum) { 56 if (csum_disk != h->csum) {
57 DMERR("node_check failed csum %u wanted %u", 57 DMERR_LIMIT("node_check failed: csum %u != wanted %u",
58 le32_to_cpu(csum_disk), le32_to_cpu(h->csum)); 58 le32_to_cpu(csum_disk), le32_to_cpu(h->csum));
59 return -EILSEQ; 59 return -EILSEQ;
60 } 60 }
61 61
@@ -63,12 +63,12 @@ static int node_check(struct dm_block_validator *v,
63 63
64 if (sizeof(struct node_header) + 64 if (sizeof(struct node_header) +
65 (sizeof(__le64) + value_size) * le32_to_cpu(h->max_entries) > block_size) { 65 (sizeof(__le64) + value_size) * le32_to_cpu(h->max_entries) > block_size) {
66 DMERR("node_check failed: max_entries too large"); 66 DMERR_LIMIT("node_check failed: max_entries too large");
67 return -EILSEQ; 67 return -EILSEQ;
68 } 68 }
69 69
70 if (le32_to_cpu(h->nr_entries) > le32_to_cpu(h->max_entries)) { 70 if (le32_to_cpu(h->nr_entries) > le32_to_cpu(h->max_entries)) {
71 DMERR("node_check failed, too many entries"); 71 DMERR_LIMIT("node_check failed: too many entries");
72 return -EILSEQ; 72 return -EILSEQ;
73 } 73 }
74 74
@@ -77,7 +77,7 @@ static int node_check(struct dm_block_validator *v,
77 */ 77 */
78 flags = le32_to_cpu(h->flags); 78 flags = le32_to_cpu(h->flags);
79 if (!(flags & INTERNAL_NODE) && !(flags & LEAF_NODE)) { 79 if (!(flags & INTERNAL_NODE) && !(flags & LEAF_NODE)) {
80 DMERR("node_check failed, node is neither INTERNAL or LEAF"); 80 DMERR_LIMIT("node_check failed: node is neither INTERNAL or LEAF");
81 return -EILSEQ; 81 return -EILSEQ;
82 } 82 }
83 83
@@ -164,7 +164,7 @@ int ro_step(struct ro_spine *s, dm_block_t new_child)
164 return r; 164 return r;
165} 165}
166 166
167struct node *ro_node(struct ro_spine *s) 167struct btree_node *ro_node(struct ro_spine *s)
168{ 168{
169 struct dm_block *block; 169 struct dm_block *block;
170 170
diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c
index d12b2cc51f1a..4caf66918cdb 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -38,7 +38,7 @@ static void array_insert(void *base, size_t elt_size, unsigned nr_elts,
38/*----------------------------------------------------------------*/ 38/*----------------------------------------------------------------*/
39 39
40/* makes the assumption that no two keys are the same. */ 40/* makes the assumption that no two keys are the same. */
41static int bsearch(struct node *n, uint64_t key, int want_hi) 41static int bsearch(struct btree_node *n, uint64_t key, int want_hi)
42{ 42{
43 int lo = -1, hi = le32_to_cpu(n->header.nr_entries); 43 int lo = -1, hi = le32_to_cpu(n->header.nr_entries);
44 44
@@ -58,12 +58,12 @@ static int bsearch(struct node *n, uint64_t key, int want_hi)
58 return want_hi ? hi : lo; 58 return want_hi ? hi : lo;
59} 59}
60 60
61int lower_bound(struct node *n, uint64_t key) 61int lower_bound(struct btree_node *n, uint64_t key)
62{ 62{
63 return bsearch(n, key, 0); 63 return bsearch(n, key, 0);
64} 64}
65 65
66void inc_children(struct dm_transaction_manager *tm, struct node *n, 66void inc_children(struct dm_transaction_manager *tm, struct btree_node *n,
67 struct dm_btree_value_type *vt) 67 struct dm_btree_value_type *vt)
68{ 68{
69 unsigned i; 69 unsigned i;
@@ -77,7 +77,7 @@ void inc_children(struct dm_transaction_manager *tm, struct node *n,
77 vt->inc(vt->context, value_ptr(n, i)); 77 vt->inc(vt->context, value_ptr(n, i));
78} 78}
79 79
80static int insert_at(size_t value_size, struct node *node, unsigned index, 80static int insert_at(size_t value_size, struct btree_node *node, unsigned index,
81 uint64_t key, void *value) 81 uint64_t key, void *value)
82 __dm_written_to_disk(value) 82 __dm_written_to_disk(value)
83{ 83{
@@ -122,7 +122,7 @@ int dm_btree_empty(struct dm_btree_info *info, dm_block_t *root)
122{ 122{
123 int r; 123 int r;
124 struct dm_block *b; 124 struct dm_block *b;
125 struct node *n; 125 struct btree_node *n;
126 size_t block_size; 126 size_t block_size;
127 uint32_t max_entries; 127 uint32_t max_entries;
128 128
@@ -154,7 +154,7 @@ EXPORT_SYMBOL_GPL(dm_btree_empty);
154#define MAX_SPINE_DEPTH 64 154#define MAX_SPINE_DEPTH 64
155struct frame { 155struct frame {
156 struct dm_block *b; 156 struct dm_block *b;
157 struct node *n; 157 struct btree_node *n;
158 unsigned level; 158 unsigned level;
159 unsigned nr_children; 159 unsigned nr_children;
160 unsigned current_child; 160 unsigned current_child;
@@ -230,6 +230,11 @@ static void pop_frame(struct del_stack *s)
230 dm_tm_unlock(s->tm, f->b); 230 dm_tm_unlock(s->tm, f->b);
231} 231}
232 232
233static bool is_internal_level(struct dm_btree_info *info, struct frame *f)
234{
235 return f->level < (info->levels - 1);
236}
237
233int dm_btree_del(struct dm_btree_info *info, dm_block_t root) 238int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
234{ 239{
235 int r; 240 int r;
@@ -241,7 +246,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
241 s->tm = info->tm; 246 s->tm = info->tm;
242 s->top = -1; 247 s->top = -1;
243 248
244 r = push_frame(s, root, 1); 249 r = push_frame(s, root, 0);
245 if (r) 250 if (r)
246 goto out; 251 goto out;
247 252
@@ -267,7 +272,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
267 if (r) 272 if (r)
268 goto out; 273 goto out;
269 274
270 } else if (f->level != (info->levels - 1)) { 275 } else if (is_internal_level(info, f)) {
271 b = value64(f->n, f->current_child); 276 b = value64(f->n, f->current_child);
272 f->current_child++; 277 f->current_child++;
273 r = push_frame(s, b, f->level + 1); 278 r = push_frame(s, b, f->level + 1);
@@ -295,7 +300,7 @@ EXPORT_SYMBOL_GPL(dm_btree_del);
295/*----------------------------------------------------------------*/ 300/*----------------------------------------------------------------*/
296 301
297static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key, 302static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key,
298 int (*search_fn)(struct node *, uint64_t), 303 int (*search_fn)(struct btree_node *, uint64_t),
299 uint64_t *result_key, void *v, size_t value_size) 304 uint64_t *result_key, void *v, size_t value_size)
300{ 305{
301 int i, r; 306 int i, r;
@@ -406,7 +411,7 @@ static int btree_split_sibling(struct shadow_spine *s, dm_block_t root,
406 size_t size; 411 size_t size;
407 unsigned nr_left, nr_right; 412 unsigned nr_left, nr_right;
408 struct dm_block *left, *right, *parent; 413 struct dm_block *left, *right, *parent;
409 struct node *ln, *rn, *pn; 414 struct btree_node *ln, *rn, *pn;
410 __le64 location; 415 __le64 location;
411 416
412 left = shadow_current(s); 417 left = shadow_current(s);
@@ -491,7 +496,7 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
491 size_t size; 496 size_t size;
492 unsigned nr_left, nr_right; 497 unsigned nr_left, nr_right;
493 struct dm_block *left, *right, *new_parent; 498 struct dm_block *left, *right, *new_parent;
494 struct node *pn, *ln, *rn; 499 struct btree_node *pn, *ln, *rn;
495 __le64 val; 500 __le64 val;
496 501
497 new_parent = shadow_current(s); 502 new_parent = shadow_current(s);
@@ -576,7 +581,7 @@ static int btree_insert_raw(struct shadow_spine *s, dm_block_t root,
576 uint64_t key, unsigned *index) 581 uint64_t key, unsigned *index)
577{ 582{
578 int r, i = *index, top = 1; 583 int r, i = *index, top = 1;
579 struct node *node; 584 struct btree_node *node;
580 585
581 for (;;) { 586 for (;;) {
582 r = shadow_step(s, root, vt); 587 r = shadow_step(s, root, vt);
@@ -643,7 +648,7 @@ static int insert(struct dm_btree_info *info, dm_block_t root,
643 unsigned level, index = -1, last_level = info->levels - 1; 648 unsigned level, index = -1, last_level = info->levels - 1;
644 dm_block_t block = root; 649 dm_block_t block = root;
645 struct shadow_spine spine; 650 struct shadow_spine spine;
646 struct node *n; 651 struct btree_node *n;
647 struct dm_btree_value_type le64_type; 652 struct dm_btree_value_type le64_type;
648 653
649 le64_type.context = NULL; 654 le64_type.context = NULL;
diff --git a/drivers/md/persistent-data/dm-space-map-common.c b/drivers/md/persistent-data/dm-space-map-common.c
index f3a9af8cdec3..3e7a88d99eb0 100644
--- a/drivers/md/persistent-data/dm-space-map-common.c
+++ b/drivers/md/persistent-data/dm-space-map-common.c
@@ -39,8 +39,8 @@ static int index_check(struct dm_block_validator *v,
39 __le32 csum_disk; 39 __le32 csum_disk;
40 40
41 if (dm_block_location(b) != le64_to_cpu(mi_le->blocknr)) { 41 if (dm_block_location(b) != le64_to_cpu(mi_le->blocknr)) {
42 DMERR("index_check failed blocknr %llu wanted %llu", 42 DMERR_LIMIT("index_check failed: blocknr %llu != wanted %llu",
43 le64_to_cpu(mi_le->blocknr), dm_block_location(b)); 43 le64_to_cpu(mi_le->blocknr), dm_block_location(b));
44 return -ENOTBLK; 44 return -ENOTBLK;
45 } 45 }
46 46
@@ -48,8 +48,8 @@ static int index_check(struct dm_block_validator *v,
48 block_size - sizeof(__le32), 48 block_size - sizeof(__le32),
49 INDEX_CSUM_XOR)); 49 INDEX_CSUM_XOR));
50 if (csum_disk != mi_le->csum) { 50 if (csum_disk != mi_le->csum) {
51 DMERR("index_check failed csum %u wanted %u", 51 DMERR_LIMIT("index_check failed: csum %u != wanted %u",
52 le32_to_cpu(csum_disk), le32_to_cpu(mi_le->csum)); 52 le32_to_cpu(csum_disk), le32_to_cpu(mi_le->csum));
53 return -EILSEQ; 53 return -EILSEQ;
54 } 54 }
55 55
@@ -89,8 +89,8 @@ static int bitmap_check(struct dm_block_validator *v,
89 __le32 csum_disk; 89 __le32 csum_disk;
90 90
91 if (dm_block_location(b) != le64_to_cpu(disk_header->blocknr)) { 91 if (dm_block_location(b) != le64_to_cpu(disk_header->blocknr)) {
92 DMERR("bitmap check failed blocknr %llu wanted %llu", 92 DMERR_LIMIT("bitmap check failed: blocknr %llu != wanted %llu",
93 le64_to_cpu(disk_header->blocknr), dm_block_location(b)); 93 le64_to_cpu(disk_header->blocknr), dm_block_location(b));
94 return -ENOTBLK; 94 return -ENOTBLK;
95 } 95 }
96 96
@@ -98,8 +98,8 @@ static int bitmap_check(struct dm_block_validator *v,
98 block_size - sizeof(__le32), 98 block_size - sizeof(__le32),
99 BITMAP_CSUM_XOR)); 99 BITMAP_CSUM_XOR));
100 if (csum_disk != disk_header->csum) { 100 if (csum_disk != disk_header->csum) {
101 DMERR("bitmap check failed csum %u wanted %u", 101 DMERR_LIMIT("bitmap check failed: csum %u != wanted %u",
102 le32_to_cpu(csum_disk), le32_to_cpu(disk_header->csum)); 102 le32_to_cpu(csum_disk), le32_to_cpu(disk_header->csum));
103 return -EILSEQ; 103 return -EILSEQ;
104 } 104 }
105 105
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
index e89ae5e7a519..906cf3df71af 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -337,7 +337,7 @@ static int sm_metadata_new_block(struct dm_space_map *sm, dm_block_t *b)
337{ 337{
338 int r = sm_metadata_new_block_(sm, b); 338 int r = sm_metadata_new_block_(sm, b);
339 if (r) 339 if (r)
340 DMERR("out of metadata space"); 340 DMERR("unable to allocate new metadata block");
341 return r; 341 return r;
342} 342}
343 343