Skip to content

Commit 7f79d85

Browse files
committed
iomap: Refactor iomap_write_delalloc_punch() function out
This patch factors iomap_write_delalloc_punch() function out. This function is resposible for actual punch out operation. The reason for doing this is, to avoid deep indentation when we bring punch-out of individual non-dirty blocks within a dirty folio in a later patch (which adds per-block dirty status handling to iomap) to avoid delalloc block leak. Signed-off-by: Ritesh Harjani (IBM) <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 0af2b37 commit 7f79d85

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

fs/iomap/buffered-io.c

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,33 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
883883
}
884884
EXPORT_SYMBOL_GPL(iomap_file_buffered_write);
885885

886+
static int iomap_write_delalloc_punch(struct inode *inode, struct folio *folio,
887+
loff_t *punch_start_byte, loff_t start_byte, loff_t end_byte,
888+
iomap_punch_t punch)
889+
{
890+
int ret = 0;
891+
892+
if (!folio_test_dirty(folio))
893+
return ret;
894+
895+
/* if dirty, punch up to offset */
896+
if (start_byte > *punch_start_byte) {
897+
ret = punch(inode, *punch_start_byte,
898+
start_byte - *punch_start_byte);
899+
if (ret)
900+
return ret;
901+
}
902+
903+
/*
904+
* Make sure the next punch start is correctly bound to
905+
* the end of this data range, not the end of the folio.
906+
*/
907+
*punch_start_byte = min_t(loff_t, end_byte,
908+
folio_pos(folio) + folio_size(folio));
909+
910+
return ret;
911+
}
912+
886913
/*
887914
* Scan the data range passed to us for dirty page cache folios. If we find a
888915
* dirty folio, punch out the preceeding range and update the offset from which
@@ -906,6 +933,7 @@ static int iomap_write_delalloc_scan(struct inode *inode,
906933
{
907934
while (start_byte < end_byte) {
908935
struct folio *folio;
936+
int ret;
909937

910938
/* grab locked page */
911939
folio = filemap_lock_folio(inode->i_mapping,
@@ -916,26 +944,12 @@ static int iomap_write_delalloc_scan(struct inode *inode,
916944
continue;
917945
}
918946

919-
/* if dirty, punch up to offset */
920-
if (folio_test_dirty(folio)) {
921-
if (start_byte > *punch_start_byte) {
922-
int error;
923-
924-
error = punch(inode, *punch_start_byte,
925-
start_byte - *punch_start_byte);
926-
if (error) {
927-
folio_unlock(folio);
928-
folio_put(folio);
929-
return error;
930-
}
931-
}
932-
933-
/*
934-
* Make sure the next punch start is correctly bound to
935-
* the end of this data range, not the end of the folio.
936-
*/
937-
*punch_start_byte = min_t(loff_t, end_byte,
938-
folio_pos(folio) + folio_size(folio));
947+
ret = iomap_write_delalloc_punch(inode, folio, punch_start_byte,
948+
start_byte, end_byte, punch);
949+
if (ret) {
950+
folio_unlock(folio);
951+
folio_put(folio);
952+
return ret;
939953
}
940954

941955
/* move offset to start of next folio in range */

0 commit comments

Comments
 (0)