Skip to content

Commit 81d4782

Browse files
author
Matthew Wilcox (Oracle)
committed
iomap: Simplify iomap_do_writepage()
Rename end_offset to end_pos and offset_into_page to poff to match the rest of the file. Simplify the handling of the last page straddling i_size by doing the EOF check based on the byte granularity i_size instead of converting to a pgoff prematurely. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]>
1 parent 9265503 commit 81d4782

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

fs/iomap/buffered-io.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,9 +1408,7 @@ iomap_do_writepage(struct page *page, struct writeback_control *wbc, void *data)
14081408
{
14091409
struct iomap_writepage_ctx *wpc = data;
14101410
struct inode *inode = page->mapping->host;
1411-
pgoff_t end_index;
1412-
u64 end_offset;
1413-
loff_t offset;
1411+
u64 end_pos, isize;
14141412

14151413
trace_iomap_writepage(inode, page_offset(page), PAGE_SIZE);
14161414

@@ -1441,11 +1439,9 @@ iomap_do_writepage(struct page *page, struct writeback_control *wbc, void *data)
14411439
* | desired writeback range | see else |
14421440
* ---------------------------------^------------------|
14431441
*/
1444-
offset = i_size_read(inode);
1445-
end_index = offset >> PAGE_SHIFT;
1446-
if (page->index < end_index)
1447-
end_offset = (loff_t)(page->index + 1) << PAGE_SHIFT;
1448-
else {
1442+
isize = i_size_read(inode);
1443+
end_pos = page_offset(page) + PAGE_SIZE;
1444+
if (end_pos > isize) {
14491445
/*
14501446
* Check whether the page to write out is beyond or straddles
14511447
* i_size or not.
@@ -1457,7 +1453,8 @@ iomap_do_writepage(struct page *page, struct writeback_control *wbc, void *data)
14571453
* | | Straddles |
14581454
* ---------------------------------^-----------|--------|
14591455
*/
1460-
unsigned offset_into_page = offset & (PAGE_SIZE - 1);
1456+
size_t poff = offset_in_page(isize);
1457+
pgoff_t end_index = isize >> PAGE_SHIFT;
14611458

14621459
/*
14631460
* Skip the page if it's fully outside i_size, e.g. due to a
@@ -1477,7 +1474,7 @@ iomap_do_writepage(struct page *page, struct writeback_control *wbc, void *data)
14771474
* offset is just equal to the EOF.
14781475
*/
14791476
if (page->index > end_index ||
1480-
(page->index == end_index && offset_into_page == 0))
1477+
(page->index == end_index && poff == 0))
14811478
goto redirty;
14821479

14831480
/*
@@ -1488,13 +1485,13 @@ iomap_do_writepage(struct page *page, struct writeback_control *wbc, void *data)
14881485
* memory is zeroed when mapped, and writes to that region are
14891486
* not written out to the file."
14901487
*/
1491-
zero_user_segment(page, offset_into_page, PAGE_SIZE);
1488+
zero_user_segment(page, poff, PAGE_SIZE);
14921489

14931490
/* Adjust the end_offset to the end of file */
1494-
end_offset = offset;
1491+
end_pos = isize;
14951492
}
14961493

1497-
return iomap_writepage_map(wpc, wbc, inode, page, end_offset);
1494+
return iomap_writepage_map(wpc, wbc, inode, page, end_pos);
14981495

14991496
redirty:
15001497
redirty_page_for_writepage(wbc, page);

0 commit comments

Comments
 (0)