Btrfs: Fix split_leaf to avoid incorrect double splits
authorChris Mason <chris.mason@oracle.com>
Fri, 19 Oct 2007 18:01:21 +0000 (14:01 -0400)
committerChris Mason <chris.mason@oracle.com>
Thu, 25 Sep 2008 15:03:57 +0000 (11:03 -0400)
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ctree.c

index e8466940fa30cd83d831346b3959ccd829bc35e4..53e40b5c084d693f4d3f491c72657ba4076e6af9 100644 (file)
@@ -1865,7 +1865,11 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root
                                return ret;
                        }
                        mid = slot;
-                       double_split = 1;
+                       if (mid != nritems &&
+                           leaf_space_used(l, mid, nritems - mid) +
+                           space_needed > BTRFS_LEAF_DATA_SIZE(root)) {
+                               double_split = 1;
+                       }
                }
        }
        nritems = nritems - mid;