• Brian Foster's avatar
    bcachefs: clean up post-eof folios on -ENOSPC · 335f7d4f
    Brian Foster authored
    The buffered write path batches folio creations in the file mapping
    based on the requested size of the write. Under low free space
    conditions, it is possible to add a bunch of folios to the mapping
    and then return a short write or -ENOSPC due to lack of space. If
    this occurs on an extending write, the file size is updated based on
    the amount of data successfully written to the file. If folios were
    added beyond the final i_size, they may hang around until reclaimed,
    truncated or encountered unexpectedly by another operation.
    
    For example, generic/083 reproduces a sequence of events where a
    short write leaves around one or more post-EOF folios on an inode, a
    subsequent zero range request extends beyond i_size and overlaps
    with an aforementioned folio, and __bch2_truncate_folio() happens
    across it and complains.
    
    Update __bch2_buffered_write() to keep track of the start offset of
    the last folio added to the mapping for a prospective write. After
    i_size is updated, check whether this offset starts beyond EOF. If
    so, truncate pagecache beyond the latest EOF to clean up any folios
    that don't reside at least partially within EOF upon completion of
    the write.
    Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
    Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
    335f7d4f
fs-io.c 93.8 KB