Commit 37f13561de6039b3a916d1510086030d097dea0f

Authored by Eric Sandeen
Committed by Ben Myers
1 parent ab7eac2200

xfs: recalculate leaf entry pointer after compacting a dir2 block

Dave Jones hit this assert when doing a compile on recent git, with
CONFIG_XFS_DEBUG enabled:

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
xfs_dir2_block_leaf_p().

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@redhat.com>
Tested-by: Dave Jones <davej@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>

Showing 1 changed file with 4 additions and 2 deletions Side-by-side Diff

fs/xfs/xfs_dir2_block.c
... ... @@ -355,10 +355,12 @@
355 355 /*
356 356 * If need to compact the leaf entries, do it now.
357 357 */
358   - if (compact)
  358 + if (compact) {
359 359 xfs_dir2_block_compact(tp, bp, hdr, btp, blp, &needlog,
360 360 &lfloghigh, &lfloglow);
361   - else if (btp->stale) {
  361 + /* recalculate blp post-compaction */
  362 + blp = xfs_dir2_block_leaf_p(btp);
  363 + } else if (btp->stale) {
362 364 /*
363 365 * Set leaf logging boundaries to impossible state.
364 366 * For the no-stale case they're set explicitly.