Skip to content

Commit d3b4043

Browse files
Christoph Hellwigdjwong
authored andcommitted
iomap: move the zeroing case out of iomap_read_page_sync
That keeps the function a little easier to understand, and easier to modify for pending enhancements. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 3590c4d commit d3b4043

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

fs/iomap/buffered-io.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,12 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
562562
}
563563

564564
static int
565-
iomap_read_page_sync(struct inode *inode, loff_t block_start, struct page *page,
566-
unsigned poff, unsigned plen, unsigned from, unsigned to,
567-
struct iomap *iomap)
565+
iomap_read_page_sync(loff_t block_start, struct page *page, unsigned poff,
566+
unsigned plen, struct iomap *iomap)
568567
{
569568
struct bio_vec bvec;
570569
struct bio bio;
571570

572-
if (iomap_block_needs_zeroing(inode, iomap, block_start)) {
573-
zero_user_segments(page, poff, from, to, poff + plen);
574-
iomap_set_range_uptodate(page, poff, plen);
575-
return 0;
576-
}
577-
578571
bio_init(&bio, &bvec, 1);
579572
bio.bi_opf = REQ_OP_READ;
580573
bio.bi_iter.bi_sector = iomap_sector(iomap, block_start);
@@ -592,7 +585,7 @@ __iomap_write_begin(struct inode *inode, loff_t pos, unsigned len,
592585
loff_t block_start = pos & ~(block_size - 1);
593586
loff_t block_end = (pos + len + block_size - 1) & ~(block_size - 1);
594587
unsigned from = offset_in_page(pos), to = from + len, poff, plen;
595-
int status = 0;
588+
int status;
596589

597590
if (PageUptodate(page))
598591
return 0;
@@ -603,17 +596,23 @@ __iomap_write_begin(struct inode *inode, loff_t pos, unsigned len,
603596
if (plen == 0)
604597
break;
605598

606-
if ((from > poff && from < poff + plen) ||
607-
(to > poff && to < poff + plen)) {
608-
status = iomap_read_page_sync(inode, block_start, page,
609-
poff, plen, from, to, iomap);
610-
if (status)
611-
break;
599+
if ((from <= poff || from >= poff + plen) &&
600+
(to <= poff || to >= poff + plen))
601+
continue;
602+
603+
if (iomap_block_needs_zeroing(inode, iomap, block_start)) {
604+
zero_user_segments(page, poff, from, to, poff + plen);
605+
iomap_set_range_uptodate(page, poff, plen);
606+
continue;
612607
}
613608

609+
status = iomap_read_page_sync(block_start, page, poff, plen,
610+
iomap);
611+
if (status)
612+
return status;
614613
} while ((block_start += plen) < block_end);
615614

616-
return status;
615+
return 0;
617616
}
618617

619618
static int

0 commit comments

Comments
 (0)