[PATCH 2/4] libxfs: buffers aren't stale once written

Dave Chinner
2014-07-01T12:55:09Z

When rebuilding a bad directory, repair first truncates away all the
blocks in the directory. This removes blocks from the bmap btree,
and when those blocks are freed the bmap btree code invalidates
them. This marks the buffers LIBXFS_B_STALE so that we don't try to
write stale data from that buffer at a later time.

However, when rebuilding the directory, the block gets reallocated
and new metadata gets written into it. however, it is still marked
stale and hence the new, corrected metadata is never written. Hence
if we write new metadata to a stale buffer, we have to clear the
LIBXFS_B_STALE flag to ensure that the new data gets written.

Note that this can affect more than just bmap btree buffers - there
are several different places in the libxfs code that mark buffers
stale via xfs_trans_binval() during repair operations.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
libxfs/rdwr.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 981f2ba..28f8f36 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -928,6 +928,7 @@ libxfs_writebuf_int(xfs_buf_t *bp, int flags)
* subsequent reads after this write from seeing stale errors.
*/
bp->b_error = 0;
+ bp->b_flags &= ~LIBXFS_B_STALE;
bp->b_flags |= (LIBXFS_B_DIRTY | flags);
return 0;
}
@@ -946,6 +947,7 @@ libxfs_writebuf(xfs_buf_t *bp, int flags)
* subsequent reads after this write from seeing stale errors.
*/
bp->b_error = 0;
+ bp->b_flags &= ~LIBXFS_B_STALE;
bp->b_flags |= (LIBXFS_B_DIRTY | flags);
libxfs_putbuf(bp);
return 0;