Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1264344
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 3.10 14/24] dm btree remove: fix a bug when rebalancing nodes after removal |
| Date | 2015-11-06 20:50 +0100 |
| Message-ID | <qrVbm-k7-79@gated-at.bofh.it> (permalink) |
| References | <qrVbj-k7-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
3.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Thornber <ejt@redhat.com>
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/md/persistent-data/dm-btree-remove.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
--- a/drivers/md/persistent-data/dm-btree-remove.c
+++ b/drivers/md/persistent-data/dm-btree-remove.c
@@ -301,11 +301,16 @@ static void redistribute3(struct dm_btre
{
int s;
uint32_t max_entries = le32_to_cpu(left->header.max_entries);
- unsigned target = (nr_left + nr_center + nr_right) / 3;
- BUG_ON(target > max_entries);
+ unsigned total = nr_left + nr_center + nr_right;
+ unsigned target_right = total / 3;
+ unsigned remainder = (target_right * 3) != total;
+ unsigned target_left = target_right + remainder;
+
+ BUG_ON(target_left > max_entries);
+ BUG_ON(target_right > max_entries);
if (nr_left < nr_right) {
- s = nr_left - target;
+ s = nr_left - target_left;
if (s < 0 && nr_center < -s) {
/* not enough in central node */
@@ -316,10 +321,10 @@ static void redistribute3(struct dm_btre
} else
shift(left, center, s);
- shift(center, right, target - nr_right);
+ shift(center, right, target_right - nr_right);
} else {
- s = target - nr_right;
+ s = target_right - nr_right;
if (s > 0 && nr_center < s) {
/* not enough in central node */
shift(center, right, nr_center);
@@ -329,7 +334,7 @@ static void redistribute3(struct dm_btre
} else
shift(center, right, s);
- shift(left, center, nr_left - target);
+ shift(left, center, nr_left - target_left);
}
*key_ptr(parent, c->index) = center->keys[0];
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 3.10 00/24] 3.10.93-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 08/24] mm: make sendfile(2) killable Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 16/24] xhci: handle no ping response error properly Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 15/24] dm btree: fix leak of bufio-backed block in btree_split_beneath error path Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 11/24] rbd: dont leak parent_spec in rbd_dev_probe_parent() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 17/24] xen-blkfront: check for null drvdata in blkback_changed (XenbusStateClosing) Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 14/24] dm btree remove: fix a bug when rebalancing nodes after removal Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 20/24] md/raid1: submit_bio_wait() returns 0 on success Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 06/24] ASoC: wm8904: Correct number of EQ registers Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 05/24] powerpc/rtas: Validate rtas.entry before calling enter_rtas() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 07/24] x86/setup: Extend low identity map to cover whole kernel range Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 13/24] Revert "ARM64: unwind: Fix PC calculation" Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 09/24] drm/nouveau/gem: return only valid domain when theres only one Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 04/24] iommu/amd: Dont clear DTE flags when modifying it Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 20:50 +0100 [PATCH 3.10 01/24] ath9k: declare required extra tx headroom Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 21:00 +0100 [PATCH 3.10 10/24] rbd: require stable pages if message data CRCs are enabled Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-11-06 21:00 +0100 Re: [PATCH 3.10 00/24] 3.10.93-stable review Guenter Roeck <linux@roeck-us.net> - 2015-11-07 02:50 +0100 Re: [PATCH 3.10 00/24] 3.10.93-stable review Shuah Khan <shuahkh@osg.samsung.com> - 2015-11-07 04:00 +0100
csiph-web