orangefs: do not keep a write range for bytes that were not copied
Subsystems (2)
PATCH 1/1 orangefs: do not keep a write range for bytes that were not copied
From: Mike Marshall <[email protected]>
write_begin records the whole request before the copy. generic_perform_write copies with page faults disabled, and if that copy moves nothing it still calls write_end. For an extending write the private range then starts at i_size. The retry is not an extension of that range, so write_begin launders it and orangefs_writepage_locked warns. generic/010 hit this while creating its ndbm database. The retry wrote the real bytes, so the file stayed coherent.
We'll shrink the range to the bytes that were copied. If nothing was copied and the range is only this write, drop it and do not mark the folio dirty. Do not move i_size when nothing was copied. The retry records a new range and does not launder. A range that still starts at i_size on a later launder or writeback is unchanged.
--- fs/orangefs/inode.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
fs/orangefs/inode.c +21 -1
@@ -384,13 +384,33 @@ static int orangefs_write_end(const struct kiocb *iocb, struct folio *folio, void *fsdata) { struct inode *inode = folio->mapping->host; +struct orangefs_write_range *wr =folio_get_private (folio);loff_t last_pos = pos + copied; +/* +* write_begin records the whole request before any byte is +* copied. Keep only the copied bytes. A copy that moves +* nothing on a new range leaves wr starting at i_size, and +* the retry launders it and warns. +*/ +if (wr && copied < len && + wr->pos <= pos && wr->pos + wr->len == pos + len) { + wr->len -= len - copied; +if (wr->len ==0 ) { +kfree (folio_detach_private (folio)); +folio_cancel_dirty (folio); +folio_unlock (folio); +folio_put (folio); +return 0 ; + } + } +/* * No need to use i_size_read() here, the i_size * cannot change under us because we hold the i_mutex. +* A copy that moved nothing must not move i_size either. */ -if (last_pos > inode->i_size) +if (copied >0 && last_pos > inode->i_size)i_size_write (inode, last_pos);/* zero the stale part of the folio if we did a short copy */
Signature · 1 line
2.56.1