diff options
author | Christoph Hellwig <hch@lst.de> | 2017-11-09 12:11:43 -0500 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2017-11-09 17:08:54 -0500 |
commit | ae82968ee9b404b9fc101f9d75e171c78797a4d1 (patch) | |
tree | 1147b64b59035df1cf9f51031991ea92a68569b9 | |
parent | 3e27c418a7a13b8dbf33f6eb49b0e461f011bdcd (diff) |
xfs: handle zero entries case in xfs_iext_rebalance_leaf
And also rename fill to nr_entries to match the rest of the code.
Reported-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r-- | fs/xfs/libxfs/xfs_iext_tree.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/fs/xfs/libxfs/xfs_iext_tree.c b/fs/xfs/libxfs/xfs_iext_tree.c index 81e0480822d8..343a94246f5b 100644 --- a/fs/xfs/libxfs/xfs_iext_tree.c +++ b/fs/xfs/libxfs/xfs_iext_tree.c | |||
@@ -787,13 +787,21 @@ xfs_iext_rebalance_leaf( | |||
787 | struct xfs_iext_cursor *cur, | 787 | struct xfs_iext_cursor *cur, |
788 | struct xfs_iext_leaf *leaf, | 788 | struct xfs_iext_leaf *leaf, |
789 | xfs_fileoff_t offset, | 789 | xfs_fileoff_t offset, |
790 | int fill) | 790 | int nr_entries) |
791 | { | 791 | { |
792 | /* | ||
793 | * If the neighbouring nodes are completely full we might never be able | ||
794 | * to merge our node, and will only delete it once the number of | ||
795 | * entries hits zero. | ||
796 | */ | ||
797 | if (nr_entries == 0) | ||
798 | goto remove_node; | ||
799 | |||
792 | if (leaf->prev) { | 800 | if (leaf->prev) { |
793 | int nr_prev = xfs_iext_leaf_nr_entries(ifp, leaf->prev, 0), i; | 801 | int nr_prev = xfs_iext_leaf_nr_entries(ifp, leaf->prev, 0), i; |
794 | 802 | ||
795 | if (nr_prev + fill <= RECS_PER_LEAF) { | 803 | if (nr_prev + nr_entries <= RECS_PER_LEAF) { |
796 | for (i = 0; i < fill; i++) | 804 | for (i = 0; i < nr_entries; i++) |
797 | leaf->prev->recs[nr_prev + i] = leaf->recs[i]; | 805 | leaf->prev->recs[nr_prev + i] = leaf->recs[i]; |
798 | 806 | ||
799 | if (cur->leaf == leaf) { | 807 | if (cur->leaf == leaf) { |
@@ -807,18 +815,20 @@ xfs_iext_rebalance_leaf( | |||
807 | if (leaf->next) { | 815 | if (leaf->next) { |
808 | int nr_next = xfs_iext_leaf_nr_entries(ifp, leaf->next, 0), i; | 816 | int nr_next = xfs_iext_leaf_nr_entries(ifp, leaf->next, 0), i; |
809 | 817 | ||
810 | if (fill + nr_next <= RECS_PER_LEAF) { | 818 | if (nr_entries + nr_next <= RECS_PER_LEAF) { |
811 | /* | 819 | /* |
812 | * Merge the next node into this node so that we don't | 820 | * Merge the next node into this node so that we don't |
813 | * have to do an additional update of the keys in the | 821 | * have to do an additional update of the keys in the |
814 | * higher levels. | 822 | * higher levels. |
815 | */ | 823 | */ |
816 | for (i = 0; i < nr_next; i++) | 824 | for (i = 0; i < nr_next; i++) { |
817 | leaf->recs[fill + i] = leaf->next->recs[i]; | 825 | leaf->recs[nr_entries + i] = |
826 | leaf->next->recs[i]; | ||
827 | } | ||
818 | 828 | ||
819 | if (cur->leaf == leaf->next) { | 829 | if (cur->leaf == leaf->next) { |
820 | cur->leaf = leaf; | 830 | cur->leaf = leaf; |
821 | cur->pos += fill; | 831 | cur->pos += nr_entries; |
822 | } | 832 | } |
823 | 833 | ||
824 | offset = xfs_iext_leaf_key(leaf->next, 0); | 834 | offset = xfs_iext_leaf_key(leaf->next, 0); |