From: Christoph Hellwig Date: Fri, 17 Nov 2017 04:11:35 +0000 (-0600) Subject: xfs: handle zero entries case in xfs_iext_rebalance_leaf X-Git-Tag: v4.15.0-rc1~143^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=546f38321d86b92d20e204d65ade99779b3d897b;p=thirdparty%2Fxfsprogs-dev.git xfs: handle zero entries case in xfs_iext_rebalance_leaf Source kernel commit: ae82968ee9b404b9fc101f9d75e171c78797a4d1 And also rename fill to nr_entries to match the rest of the code. Reported-by: Brian Foster Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Eric Sandeen --- diff --git a/libxfs/xfs_iext_tree.c b/libxfs/xfs_iext_tree.c index 31e907bf9..3954341af 100644 --- a/libxfs/xfs_iext_tree.c +++ b/libxfs/xfs_iext_tree.c @@ -787,13 +787,21 @@ xfs_iext_rebalance_leaf( struct xfs_iext_cursor *cur, struct xfs_iext_leaf *leaf, xfs_fileoff_t offset, - int fill) + int nr_entries) { + /* + * If the neighbouring nodes are completely full we might never be able + * to merge our node, and will only delete it once the number of + * entries hits zero. + */ + if (nr_entries == 0) + goto remove_node; + if (leaf->prev) { int nr_prev = xfs_iext_leaf_nr_entries(ifp, leaf->prev, 0), i; - if (nr_prev + fill <= RECS_PER_LEAF) { - for (i = 0; i < fill; i++) + if (nr_prev + nr_entries <= RECS_PER_LEAF) { + for (i = 0; i < nr_entries; i++) leaf->prev->recs[nr_prev + i] = leaf->recs[i]; if (cur->leaf == leaf) { @@ -807,18 +815,20 @@ xfs_iext_rebalance_leaf( if (leaf->next) { int nr_next = xfs_iext_leaf_nr_entries(ifp, leaf->next, 0), i; - if (fill + nr_next <= RECS_PER_LEAF) { + if (nr_entries + nr_next <= RECS_PER_LEAF) { /* * Merge the next node into this node so that we don't * have to do an additional update of the keys in the * higher levels. */ - for (i = 0; i < nr_next; i++) - leaf->recs[fill + i] = leaf->next->recs[i]; + for (i = 0; i < nr_next; i++) { + leaf->recs[nr_entries + i] = + leaf->next->recs[i]; + } if (cur->leaf == leaf->next) { cur->leaf = leaf; - cur->pos += fill; + cur->pos += nr_entries; } offset = xfs_iext_leaf_key(leaf->next, 0);