[PATCH 36/40] btrfs: implement ->iomap_iter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Switch from the separate ->iomap_begin and ->iomap_end methods to
->iomap_iter to allow or greater control over the iteration in subsequent
patches.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
 fs/btrfs/inode.c | 69 ++++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 25 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index adcd392caa78e..d4faed31d36a4 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7507,17 +7507,18 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
 	return ret;
 }
 
-static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
-		loff_t length, unsigned int flags, struct iomap *iomap,
-		struct iomap *srcmap)
+static int btrfs_dio_iomap_begin(struct iomap_iter *iter)
 {
-	struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
+	struct inode *inode = iter->inode;
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+	loff_t start = iter->pos;
+	loff_t length = iter->len;
+	struct iomap *iomap = &iter->iomap;
 	struct extent_map *em;
 	struct extent_state *cached_state = NULL;
 	struct btrfs_dio_data *dio_data = iter->private;
 	u64 lockstart, lockend;
-	const bool write = !!(flags & IOMAP_WRITE);
+	bool write = (iter->flags & IOMAP_WRITE);
 	int ret = 0;
 	u64 len = length;
 	bool unlock_extents = false;
@@ -7602,7 +7603,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
 	 * which we return back to our caller - we should only return EIOCBQUEUED
 	 * after we have submitted bios for all the extents in the range.
 	 */
-	if ((flags & IOMAP_NOWAIT) && len < length) {
+	if ((iter->flags & IOMAP_NOWAIT) && len < length) {
 		free_extent_map(em);
 		ret = -EAGAIN;
 		goto unlock_err;
@@ -7662,30 +7663,28 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
 	return ret;
 }
 
-static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length,
-		ssize_t written, unsigned int flags, struct iomap *iomap)
+static int btrfs_dio_iomap_end(struct iomap_iter *iter)
 {
-	struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
 	struct btrfs_dio_data *dio_data = iter->private;
-	size_t submitted = dio_data->submitted;
-	const bool write = !!(flags & IOMAP_WRITE);
+	struct btrfs_inode *bi = BTRFS_I(iter->inode);
+	bool write = (iter->flags & IOMAP_WRITE);
+	loff_t length = iomap_length(iter);
+	loff_t pos = iter->pos;
 	int ret = 0;
 
-	if (!write && (iomap->type == IOMAP_HOLE)) {
+	if (!write && iter->iomap.type == IOMAP_HOLE) {
 		/* If reading from a hole, unlock and return */
-		unlock_extent(&BTRFS_I(inode)->io_tree, pos, pos + length - 1);
+		unlock_extent(&bi->io_tree, pos, pos + length - 1);
 		return 0;
 	}
 
-	if (submitted < length) {
-		pos += submitted;
-		length -= submitted;
+	if (dio_data->submitted < length) {
+		pos += dio_data->submitted;
+		length -= dio_data->submitted;
 		if (write)
-			__endio_write_update_ordered(BTRFS_I(inode), pos,
-					length, false);
+			__endio_write_update_ordered(bi, pos, length, false);
 		else
-			unlock_extent(&BTRFS_I(inode)->io_tree, pos,
-				      pos + length - 1);
+			unlock_extent(&bi->io_tree, pos, pos + length - 1);
 		ret = -ENOTBLK;
 	}
 
@@ -7694,6 +7693,31 @@ static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length,
 	return ret;
 }
 
+static int btrfs_dio_iomap_iter(struct iomap_iter *iter)
+{
+	int ret;
+
+	if (iter->iomap.length) {
+		ret = btrfs_dio_iomap_end(iter);
+		if (ret < 0 && !iter->processed)
+			return ret;
+	}
+
+	ret = iomap_iter_advance(iter);
+	if (ret <= 0)
+		return ret;
+
+	ret = btrfs_dio_iomap_begin(iter);
+	if (ret < 0)
+		return ret;
+	iomap_iter_done(iter);
+	return 1;
+}
+
+static const struct iomap_ops btrfs_dio_iomap_ops = {
+	.iomap_iter		= btrfs_dio_iomap_iter,
+};
+
 static void btrfs_dio_private_put(struct btrfs_dio_private *dip)
 {
 	/*
@@ -8039,11 +8063,6 @@ static void btrfs_submit_direct(const struct iomap_iter *iter,
 	btrfs_dio_private_put(dip);
 }
 
-static const struct iomap_ops btrfs_dio_iomap_ops = {
-	.iomap_begin            = btrfs_dio_iomap_begin,
-	.iomap_end              = btrfs_dio_iomap_end,
-};
-
 static const struct iomap_dio_ops btrfs_dio_ops = {
 	.submit_io		= btrfs_submit_direct,
 };
-- 
2.30.2




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux