[Top] [All Lists]

[PATCH] xfs: recalculate leaf entry pointer after compacting a dir2 bloc

To: xfs-oss <xfs@xxxxxxxxxxx>
Subject: [PATCH] xfs: recalculate leaf entry pointer after compacting a dir2 block
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Thu, 10 Jan 2013 10:41:48 -0600
Cc: Dave Chinner <dchinner@xxxxxxxxxx>, Dave Jones <davej@xxxxxxxxxx>
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/17.0 Thunderbird/17.0
Dave Jones hit this assert when doing a compile on recent git, with

XFS: Assertion failed: (char *)dup - (char *)hdr == 
be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)), file: fs/xfs/xfs_dir2_data.c, 
line: 828

Upon further digging, the tag found by xfs_dir2_data_unused_tag_p(dup)
contained "2" and not the proper offset, and I found that this value was
changed after the memmoves under "Use a stale leaf for our new entry."
in xfs_dir2_block_addname(), i.e.

                        memmove(&blp[mid + 1], &blp[mid],
                                (highstale - mid) * sizeof(*blp));

overwrote it.

What has happened is that the previous call to xfs_dir2_block_compact()
has rearranged things; it changes btp->count as well as the
blp array.  So after we make that call, we must recalculate the
proper pointer to the leaf entries by making another call to

Dave provided a metadump image which led to a simple reproducer
(create a particular filename in the affected directory) and this
resolves the testcase as well as the bug on his live system.

Thanks also to dchinner for looking at this one with me.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
Tested-by: Dave Jones <davej@xxxxxxxxxx>

diff --git a/fs/xfs/xfs_dir2_block.c b/fs/xfs/xfs_dir2_block.c
index 7536faa..12afe07 100644
--- a/fs/xfs/xfs_dir2_block.c
+++ b/fs/xfs/xfs_dir2_block.c
@@ -355,10 +355,12 @@ xfs_dir2_block_addname(
         * If need to compact the leaf entries, do it now.
-       if (compact)
+       if (compact) {
                xfs_dir2_block_compact(tp, bp, hdr, btp, blp, &needlog,
                                      &lfloghigh, &lfloglow);
-       else if (btp->stale) {
+               /* recalculate blp post-compaction */
+               blp = xfs_dir2_block_leaf_p(btp);
+       } else if (btp->stale) {
                 * Set leaf logging boundaries to impossible state.
                 * For the no-stale case they're set explicitly.

<Prev in Thread] Current Thread [Next in Thread>