Skip to contentSkip to conversation

persistent-data: fix bug about btree of updating internal node's minima key in btree_split_beneath.

PATCH Joe Thornber 2 participants 4 messages Dec 18, 2017 – Dec 19, 2017 1 message not in the archive Device mapper

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20171218212758.GA12360@yyp.

#1 lore raw

Hi Monty,

Quoted 6 lines · monty

Subject: [PATCH] persistent-data: fix bug about btree of updating internal node's minima
key in btree_split_beneath.

fix bug about btree_split_beneath func, this bug may cause a key had been inserted to btree, but dm_btree_lookup can not find the key in btree later.

I think you've spotted a real issue, but I don't like where you've fixed up the btree_split_beneath() function. I'll post a patch in a bit.

How did you recreate this bug?

Thanks,

- Joe

Quoted 27 lines
---
 drivers/md/persistent-data/dm-btree.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/md/persistent-data/dm-btree.c +2 -0
index f21ce6a..25ce5ec 100644
@@ -694,6 +694,8 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
 	if (key < le64_to_cpu(rn->keys[0])) {
 		unlock_block(s->info, right);
 		s->nodes[1] = left;
+		if (key < le64_to_cpu(ln->keys[0]))
+			ln->keys[0] = cpu_to_le64(key);
 	} else {
 		unlock_block(s->info, left);
 		s->nodes[1] = right;
Signature · 7 lines
1.7.1


--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#2 lore raw
Quoted 6 lines · Joe Thornber

Hi Monty,

Quoted 3 lines · monty

Subject: [PATCH] persistent-data: fix bug about btree of updating internal node's minima
key in btree_split_beneath.

Quoted 7 lines
Quoted 3 lines

fix bug about btree_split_beneath func, this bug may cause a key had been inserted to btree, but dm_btree_lookup can not find the key in btree later.

I think you've spotted a real issue, but I don't like where you've fixed up the btree_split_beneath() function. I'll post a patch in a bit.

Patch below. This is completely untested. I'll test tomorrow and update.

Instead of fiddling with the spine we unlock both the new children and let the current spine entry (which now has just two entries) continue. That way the bounds on the lowest key is adjusted within the main loop of btree_insert_raw().

- Joe

drivers/md/persistent-data/dm-btree.c +0 -0
index 416060c2570..ee2c01685f5 100644
@@ -572,23 +572,8 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
        pn->keys[1] = rn->keys[0];
	        memcpy_disk(value_ptr(pn, 1), &val, sizeof(__le64));

- /*

-        * rejig the spine.  This is ugly, since it knows too
-        * much about the spine
-        */

- if (s->nodes[0] != new_parent) {
- unlock_block(s->info, s->nodes[0]);
- s->nodes[0] = new_parent;
- }
- if (key < le64_to_cpu(rn->keys[0])) {
- unlock_block(s->info, right);
- s->nodes[1] = left;
- } else {
- unlock_block(s->info, left);
- s->nodes[1] = right;
- }
- s->count = 2;
-
+ unlock_block(s->info, left);

+       unlock_block(s->info, right);
        return 0;
}
#3 lore raw

Look forward to your test result. The scene I found with problem as follows:
note:
1. key size: 8;
2. value size: 8;
3. max_entries=252;
4. one level btree's root is A.
operations:
1. A's info:

	nr_entries=252
	keys:127-378
2. insert 379 to btree
		A'(127,253)
			|
	-------- ---------
	|				  |
	B(127-252)        C(253-379)
3. insert 1-126 to btree
		A'(127,253)
			|
	-------- ----------
	|				  |
	B(1-252)        C(253-379)
3. insert 0 to btree
		A'(127,127,253)
			|
	-------- -----------------
	|				  |      |
	B(0-126)    B'(127-252)   C(253-379)

4.lookup(key=127), we can not find 127 in btree.

Quoted 60 lines · Joe Thornber
Quoted 6 lines · Joe Thornber

Hi Monty,

Quoted 3 lines · monty

Subject: [PATCH] persistent-data: fix bug about btree of updating internal node's minima
key in btree_split_beneath.

Quoted 7 lines
Quoted 3 lines

fix bug about btree_split_beneath func, this bug may cause a key had been inserted to btree, but dm_btree_lookup can not find the key in btree later.

I think you've spotted a real issue, but I don't like where you've fixed up the btree_split_beneath() function. I'll post a patch in a bit.

Patch below. This is completely untested. I'll test tomorrow and update.

Instead of fiddling with the spine we unlock both the new children and let the current spine entry (which now has just two entries) continue. That way the bounds on the lowest key is adjusted within the main loop of btree_insert_raw().

- Joe

drivers/md/persistent-data/dm-btree.c +2 -17
index 416060c2570..ee2c01685f5 100644
@@ -572,23 +572,8 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
        pn->keys[1] = rn->keys[0];
 	        memcpy_disk(value_ptr(pn, 1), &val, sizeof(__le64));
 
-       /*
-        * rejig the spine.  This is ugly, since it knows too
-        * much about the spine
-        */
-       if (s->nodes[0] != new_parent) {
-               unlock_block(s->info, s->nodes[0]);
-               s->nodes[0] = new_parent;
-       }
-       if (key < le64_to_cpu(rn->keys[0])) {
-               unlock_block(s->info, right);
-               s->nodes[1] = left;
-       } else {
-               unlock_block(s->info, left);
-               s->nodes[1] = right;
-       }
-       s->count = 2;
-
+       unlock_block(s->info, left);
+       unlock_block(s->info, right);
        return 0;
 }