dm btree remove: fix a bug when rebalancing nodes after removal
authorJoe Thornber <ejt@redhat.com>
Wed, 21 Oct 2015 17:36:49 +0000 (18:36 +0100)
committerZefan Li <lizefan@huawei.com>
Mon, 21 Mar 2016 01:17:58 +0000 (09:17 +0800)
commit24fa51bde52b3671afa476c96d63bcf8a4e8a307
tree2acc8e5418f67ee480294a983397eaea5a485160
parentf43d490b4ce93037cb7cb8524abfc9a6accbbb29
dm btree remove: fix a bug when rebalancing nodes after removal

commit 2871c69e025e8bc507651d5a9cf81a8a7da9d24b upstream.

Commit 4c7e309340ff ("dm btree remove: fix bug in redistribute3") wasn't
a complete fix for redistribute3().

The redistribute3 function takes 3 btree nodes and shares out the entries
evenly between them.  If the three nodes in total contained
(MAX_ENTRIES * 3) - 1 entries between them then this was erroneously getting
rebalanced as (MAX_ENTRIES - 1) on the left and right, and (MAX_ENTRIES + 1) in
the center.

Fix this issue by being more careful about calculating the target number
of entries for the left and right nodes.

Unit tested in userspace using this program:
https://github.com/jthornber/redistribute3-test/blob/master/redistribute3_t.c

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Zefan Li <lizefan@huawei.com>
drivers/md/persistent-data/dm-btree-remove.c