From: Christoph Hellwig <hch@lst.de>
To: linux-xfs@vger.kernel.org
Cc: bfoster@redhat.com
Subject: [PATCH 6/6] xfs: handle zero entries case in xfs_iext_rebalance_leaf
Date: Thu, 9 Nov 2017 14:26:56 +0100 [thread overview]
Message-ID: <20171109132656.1649-7-hch@lst.de> (raw)
In-Reply-To: <20171109132656.1649-1-hch@lst.de>
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>
---
fs/xfs/libxfs/xfs_iext_tree.c | 24 +++++++++++++++++-------
1 file 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(
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);
--
2.14.2
next prev parent reply other threads:[~2017-11-09 13:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-09 13:26 incore extent b+tree fixups Christoph Hellwig
2017-11-09 13:26 ` [PATCH 1/6] xfs: fix number of records handling in xfs_iext_split_leaf Christoph Hellwig
2017-11-09 13:26 ` [PATCH 2/6] xfs: add some comments to xfs_iext_insert/xfs_iext_insert_node Christoph Hellwig
2017-11-09 13:26 ` [PATCH 3/6] xfs: remove a superflous assignment in xfs_iext_remove_node Christoph Hellwig
2017-11-09 13:26 ` [PATCH 4/6] xfs: trivial indentation fixup for xfs_iext_remove_node Christoph Hellwig
2017-11-09 13:26 ` [PATCH 5/6] xfs: add comments documenting the rebalance algorithm Christoph Hellwig
2017-11-09 13:26 ` Christoph Hellwig [this message]
2017-11-09 14:32 ` incore extent b+tree fixups Brian Foster
2017-11-10 1:11 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171109132656.1649-7-hch@lst.de \
--to=hch@lst.de \
--cc=bfoster@redhat.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).