[2/2] iomap: Convert page_mkwrite to iter API
diff mbox series

Message ID 20200401152522.20737-3-willy@infradead.org
State New
Headers show
Series
  • Begin switching iomap from apply to iter
Related show

Commit Message

Matthew Wilcox April 1, 2020, 3:25 p.m. UTC
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/iomap/buffered-io.c | 51 ++++++++++++++++--------------------------
 1 file changed, 19 insertions(+), 32 deletions(-)

Patch
diff mbox series

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 7c84c4c027c4..d91d1d5a0f84 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -1051,50 +1051,37 @@  iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
 }
 EXPORT_SYMBOL_GPL(iomap_truncate_page);
 
-static loff_t
-iomap_page_mkwrite_actor(struct inode *inode, loff_t pos, loff_t length,
-		void *data, struct iomap *iomap, struct iomap *srcmap)
-{
-	struct page *page = data;
-	int ret;
-
-	if (iomap->flags & IOMAP_F_BUFFER_HEAD) {
-		ret = __block_write_begin_int(page, pos, length, NULL, iomap);
-		if (ret)
-			return ret;
-		block_commit_write(page, 0, length);
-	} else {
-		WARN_ON_ONCE(!PageUptodate(page));
-		iomap_page_create(inode, page);
-		set_page_dirty(page);
-	}
-
-	return length;
-}
-
 vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)
 {
 	struct page *page = vmf->page;
 	struct inode *inode = file_inode(vmf->vma->vm_file);
-	unsigned long length;
-	loff_t offset;
-	ssize_t ret;
+	DEFINE_IOMAP_ITER(iter, inode, page_offset(page), 0,
+			IOMAP_WRITE | IOMAP_FAULT, ops);
+	loff_t ret, len = IOMAP_FIRST_CALL;
 
 	lock_page(page);
 	ret = page_mkwrite_check_truncate(page, inode);
 	if (ret < 0)
 		goto out_unlock;
-	length = ret;
+	iter.len = ret;
 
-	offset = page_offset(page);
-	while (length > 0) {
-		ret = iomap_apply(inode, offset, length,
-				IOMAP_WRITE | IOMAP_FAULT, ops, page,
-				iomap_page_mkwrite_actor);
+	for (;;) {
+		ret = iomap_iter(&iter, len);
 		if (unlikely(ret <= 0))
 			goto out_unlock;
-		offset += ret;
-		length -= ret;
+		len = ret;
+
+		if (iter.iomap.flags & IOMAP_F_BUFFER_HEAD) {
+			ret = __block_write_begin_int(page, iter.pos, len,
+					NULL, &iter.iomap);
+			if (ret)
+				goto out_unlock;
+			block_commit_write(page, 0, len);
+		} else {
+			WARN_ON_ONCE(!PageUptodate(page));
+			iomap_page_create(inode, page);
+			set_page_dirty(page);
+		}
 	}
 
 	wait_for_stable_page(page);