Skip to content

Commit 8e1f065

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: refactor the tail of xfs_writepage_map
Rejuggle how we deal with the different error vs non-error and have ioends vs not have ioend cases to keep the fast path streamlined, and the duplicate code at a minimum. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 1b65d3d commit 8e1f065

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

fs/xfs/xfs_aops.c

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,14 @@ xfs_writepage_map(
854854
* submission of outstanding ioends on the writepage context so they are
855855
* treated correctly on error.
856856
*/
857-
if (count) {
857+
if (unlikely(error)) {
858+
if (!count) {
859+
xfs_aops_discard_page(page);
860+
ClearPageUptodate(page);
861+
unlock_page(page);
862+
goto done;
863+
}
864+
858865
/*
859866
* If the page was not fully cleaned, we need to ensure that the
860867
* higher layers come back to it correctly. That means we need
@@ -863,43 +870,35 @@ xfs_writepage_map(
863870
* so another attempt to write this page in this writeback sweep
864871
* will be made.
865872
*/
866-
if (error) {
867-
set_page_writeback_keepwrite(page);
868-
} else {
869-
clear_page_dirty_for_io(page);
870-
set_page_writeback(page);
871-
}
872-
unlock_page(page);
873-
874-
/*
875-
* Preserve the original error if there was one, otherwise catch
876-
* submission errors here and propagate into subsequent ioend
877-
* submissions.
878-
*/
879-
list_for_each_entry_safe(ioend, next, &submit_list, io_list) {
880-
int error2;
881-
882-
list_del_init(&ioend->io_list);
883-
error2 = xfs_submit_ioend(wbc, ioend, error);
884-
if (error2 && !error)
885-
error = error2;
886-
}
887-
} else if (error) {
888-
xfs_aops_discard_page(page);
889-
ClearPageUptodate(page);
890-
unlock_page(page);
873+
set_page_writeback_keepwrite(page);
891874
} else {
892-
/*
893-
* We can end up here with no error and nothing to write if we
894-
* race with a partial page truncate on a sub-page block sized
895-
* filesystem. In that case we need to mark the page clean.
896-
*/
897875
clear_page_dirty_for_io(page);
898876
set_page_writeback(page);
899-
unlock_page(page);
900-
end_page_writeback(page);
901877
}
902878

879+
unlock_page(page);
880+
881+
/*
882+
* Preserve the original error if there was one, otherwise catch
883+
* submission errors here and propagate into subsequent ioend
884+
* submissions.
885+
*/
886+
list_for_each_entry_safe(ioend, next, &submit_list, io_list) {
887+
int error2;
888+
889+
list_del_init(&ioend->io_list);
890+
error2 = xfs_submit_ioend(wbc, ioend, error);
891+
if (error2 && !error)
892+
error = error2;
893+
}
894+
895+
/*
896+
* We can end up here with no error and nothing to write if we race with
897+
* a partial page truncate on a sub-page block sized filesystem.
898+
*/
899+
if (!count)
900+
end_page_writeback(page);
901+
done:
903902
mapping_set_error(page->mapping, error);
904903
return error;
905904
}

0 commit comments

Comments
 (0)