[Devel] [PATCH rh7 06/30] mm: Use iov_iter in __swap_writepage()

Kirill Tkhai ktkhai at virtuozzo.com
Wed May 20 19:03:37 MSK 2020


Pack argument into iov_iter. Move mapping_direct_IO()
to header to access it from more files.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 include/linux/fs.h |   15 +++++++++++++++
 mm/filemap.c       |   15 ---------------
 mm/page_io.c       |    7 ++++---
 3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index d86dfce69845..f3ae7b9373d5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3653,6 +3653,21 @@ static inline iop_dentry_open_t get_dentry_open_iop(struct inode *inode)
 	return wrapper ? wrapper->dentry_open : NULL;
 }
 
+static inline ssize_t mapping_direct_IO(struct address_space *mapping, int rw,
+			         struct kiocb *iocb, struct iov_iter *iter,
+			         loff_t pos)
+{
+	if (iov_iter_has_iovec(iter))
+		return mapping->a_ops->direct_IO(rw, iocb, iov_iter_iovec(iter),
+						 pos, iter->nr_segs);
+	else if (iov_iter_has_bvec(iter))
+		return mapping->a_ops->direct_IO_bvec(rw, iocb,
+						      iov_iter_bvec(iter), pos,
+						      iter->nr_segs);
+	else
+		BUG();
+}
+
 extern bool path_noexec(const struct path *path);
 
 #endif /* _LINUX_FS_H */
diff --git a/mm/filemap.c b/mm/filemap.c
index 3fe13fbb8576..0619290ecd97 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1987,21 +1987,6 @@ int file_read_actor(read_descriptor_t *desc, struct page *page,
 	return size;
 }
 
-static ssize_t mapping_direct_IO(struct address_space *mapping, int rw,
-			         struct kiocb *iocb, struct iov_iter *iter,
-			         loff_t pos)
-{
-	if (iov_iter_has_iovec(iter))
-		return mapping->a_ops->direct_IO(rw, iocb, iov_iter_iovec(iter),
-						 pos, iter->nr_segs);
-	else if (iov_iter_has_bvec(iter))
-		return mapping->a_ops->direct_IO_bvec(rw, iocb,
-						      iov_iter_bvec(iter), pos,
-						      iter->nr_segs);
-	else
-		BUG();
-}
-
 static int file_read_iter_actor(read_descriptor_t *desc, struct page *page,
 				unsigned long offset, unsigned long size)
 {
diff --git a/mm/page_io.c b/mm/page_io.c
index 0f29c247d64a..d2bd82848946 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -225,17 +225,18 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
 			.iov_base = kmap(page),
 			.iov_len  = PAGE_SIZE,
 		};
+		struct iov_iter iter;
 
 		init_sync_kiocb(&kiocb, swap_file);
 		kiocb.ki_pos = page_file_offset(page);
 		kiocb.ki_left = PAGE_SIZE;
 		kiocb.ki_nbytes = PAGE_SIZE;
+		iov_iter_init(&iter, &iov, 1, PAGE_SIZE, 0);
 
 		set_page_writeback(page);
 		unlock_page(page);
-		ret = mapping->a_ops->direct_IO(KERNEL_WRITE,
-						&kiocb, &iov,
-						kiocb.ki_pos, 1);
+		ret = mapping_direct_IO(mapping, KERNEL_WRITE,
+					&kiocb, &iter, kiocb.ki_pos);
 		kunmap(page);
 		if (ret == PAGE_SIZE) {
 			count_vm_event(PSWPOUT);




More information about the Devel mailing list