Skip to contentSkip to conversation

btrfs: switch to iomap_dio_rw() for dio

PATCH In review Goldwyn Rodrigues 3 participants 4 messages Aug 17, 2020 – Aug 18, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: switch to iomap_dio_rw() for dio

[Rebased against kdave/misc-next]

Switch from __blockdev_direct_IO() to iomap_dio_rw(). Rename btrfs_get_blocks_direct() to btrfs_dio_iomap_begin() and use it as iomap_begin() for iomap direct I/O functions. This function allocates and locks all the blocks required for the I/O. btrfs_submit_direct() is used as the submit_io() hook for direct I/O ops.

Since we need direct I/O reads to go through iomap_dio_rw(), we change file_operations.read_iter() to a btrfs_file_read_iter() which calls btrfs_direct_IO() for direct reads and falls back to generic_file_buffered_read() for incomplete reads and buffered reads.

We don't need address_space.direct_IO() anymore: set it to noop. Similarly, we don't need flags used in __blockdev_direct_IO(). iomap is capable of direct I/O reads from a hole, so we don't need to return -ENOENT.

BTRFS direct I/O is now done under i_rwsem, shared in case of reads and exclusive in case of writes. This guards against simultaneous truncates.

Use iomap->iomap_end() to check for failed or incomplete direct I/O:
- for writes, call __endio_write_update_ordered()
- for reads, unlock extents

btrfs_dio_data is now hooked in iomap->private and not current->journal_info. It carries the reservation variable and the amount of data submitted, so we can calculate the amount of data to call __endio_write_update_ordered in case of an error.

This patch removes last use of struct buffer_head from btrfs.

---
 fs/btrfs/Kconfig |   1 +
 fs/btrfs/ctree.h |   1 +
 fs/btrfs/file.c  |  21 +++-
 fs/btrfs/inode.c | 322 ++++++++++++++++++++++-------------------------
 4 files changed, 173 insertions(+), 172 deletions(-)
fs/btrfs/Kconfig +1 -0
index 575636f6491e..68b95ad82126 100644
@@ -14,6 +14,7 @@ config BTRFS_FS
 	select LZO_DECOMPRESS
 	select ZSTD_COMPRESS
 	select ZSTD_DECOMPRESS
+	select FS_IOMAP
 	select RAID6_PQ
 	select XOR_BLOCKS
 	select SRCU
fs/btrfs/ctree.h +1 -0
index a3b110ffbc93..69dd730de986 100644
@@ -3020,6 +3020,7 @@ int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);
 void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
 					  u64 end, int uptodate);
 extern const struct dentry_operations btrfs_dentry_operations;
+ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
 
 /* ioctl.c */
 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
fs/btrfs/file.c +19 -2
index 5177e076d6b9..86de4cda5979 100644
@@ -1870,7 +1870,7 @@ static ssize_t __btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)
 	loff_t endbyte;
 	int err;
 
-	written = generic_file_direct_write(iocb, from);
+	written = btrfs_direct_IO(iocb, from);
 
 	if (written < 0 || !iov_iter_count(from))
 		return written;
@@ -3539,9 +3539,26 @@ static int btrfs_file_open(struct inode *inode, struct file *filp)
 	return generic_file_open(inode, filp);
 }
 
+static ssize_t btrfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
+{
+	ssize_t ret = 0;
+
+	if (iocb->ki_flags & IOCB_DIRECT) {
+		struct inode *inode = file_inode(iocb->ki_filp);
+
+		inode_lock_shared(inode);
+		ret = btrfs_direct_IO(iocb, to);
+		inode_unlock_shared(inode);
+		if (ret < 0)
+			return ret;
+	}
+
+	return generic_file_buffered_read(iocb, to, ret);
+}
+
 const struct file_operations btrfs_file_operations = {
 	.llseek		= btrfs_file_llseek,
-	.read_iter      = generic_file_read_iter,
+	.read_iter      = btrfs_file_read_iter,
 	.splice_read	= generic_file_splice_read,
 	.write_iter	= btrfs_file_write_iter,
 	.splice_write	= iter_file_splice_write,
fs/btrfs/inode.c +152 -170

495 lines not on this page · raw message

Signature · 5 lines
2.26.2


-- 
Goldwyn
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Goldwyn Rodrigues

[Rebased against kdave/misc-next]

Switch from __blockdev_direct_IO() to iomap_dio_rw(). Rename btrfs_get_blocks_direct() to btrfs_dio_iomap_begin() and use it as iomap_begin() for iomap direct I/O functions. This function allocates and locks all the blocks required for the I/O. btrfs_submit_direct() is used as the submit_io() hook for direct I/O ops.

Since we need direct I/O reads to go through iomap_dio_rw(), we change file_operations.read_iter() to a btrfs_file_read_iter() which calls btrfs_direct_IO() for direct reads and falls back to generic_file_buffered_read() for incomplete reads and buffered reads.

We don't need address_space.direct_IO() anymore: set it to noop. Similarly, we don't need flags used in __blockdev_direct_IO(). iomap is capable of direct I/O reads from a hole, so we don't need to return -ENOENT.

BTRFS direct I/O is now done under i_rwsem, shared in case of reads and exclusive in case of writes. This guards against simultaneous truncates.

Use iomap->iomap_end() to check for failed or incomplete direct I/O:
- for writes, call __endio_write_update_ordered()
- for reads, unlock extents

Quoted 8 lines

btrfs_dio_data is now hooked in iomap->private and not current->journal_info. It carries the reservation variable and the amount of data submitted, so we can calculate the amount of data to call __endio_write_update_ordered in case of an error.

This patch removes last use of struct buffer_head from btrfs.

This thing is huge, but it builds and passes the dio tests, and I went through it twice. I imagine we'll still find things broken after the fact, but IDK how to break it up more since we're converting to a new style.

Thanks,

Josef

#2 lore raw
Quoted 32 lines · Josef Bacik
Quoted 31 lines · Goldwyn Rodrigues

[Rebased against kdave/misc-next]

Switch from __blockdev_direct_IO() to iomap_dio_rw(). Rename btrfs_get_blocks_direct() to btrfs_dio_iomap_begin() and use it as iomap_begin() for iomap direct I/O functions. This function allocates and locks all the blocks required for the I/O. btrfs_submit_direct() is used as the submit_io() hook for direct I/O ops.

Since we need direct I/O reads to go through iomap_dio_rw(), we change file_operations.read_iter() to a btrfs_file_read_iter() which calls btrfs_direct_IO() for direct reads and falls back to generic_file_buffered_read() for incomplete reads and buffered reads.

We don't need address_space.direct_IO() anymore: set it to noop. Similarly, we don't need flags used in __blockdev_direct_IO(). iomap is capable of direct I/O reads from a hole, so we don't need to return -ENOENT.

BTRFS direct I/O is now done under i_rwsem, shared in case of reads and exclusive in case of writes. This guards against simultaneous truncates.

Use iomap->iomap_end() to check for failed or incomplete direct I/O:
- for writes, call __endio_write_update_ordered()
- for reads, unlock extents

btrfs_dio_data is now hooked in iomap->private and not current->journal_info. It carries the reservation variable and the amount of data submitted, so we can calculate the amount of data to call __endio_write_update_ordered in case of an error.

Quoted 7 lines
Quoted 3 lines

This patch removes last use of struct buffer_head from btrfs.

This thing is huge, but it builds and passes the dio tests, and I went through it twice. I imagine we'll still find things broken after the fact, but IDK how to break it up more since we're converting to a new style.

Thanks, ack, I think this is a resonably small version we can get. There are 3 patches doing some post-cleanups but for now I'd like to get just the switch so any eventual fixups are easy.

Tests finish for me but I haven't scanned all results so there are potential failures. The plan is to push the patch out early for wider testing despite that. Functionality-wise the patch is complete so we're now going to just hunt the remaining bugs.

I'll add the patch to misc-next by the end of the week, it'll be in for-next until then, more reviews are welcome.

#3 lore raw
Quoted 45 lines · David Sterba
Quoted 32 lines · Josef Bacik
Quoted 31 lines · Goldwyn Rodrigues

[Rebased against kdave/misc-next]

Switch from __blockdev_direct_IO() to iomap_dio_rw(). Rename btrfs_get_blocks_direct() to btrfs_dio_iomap_begin() and use it as iomap_begin() for iomap direct I/O functions. This function allocates and locks all the blocks required for the I/O. btrfs_submit_direct() is used as the submit_io() hook for direct I/O ops.

Since we need direct I/O reads to go through iomap_dio_rw(), we change file_operations.read_iter() to a btrfs_file_read_iter() which calls btrfs_direct_IO() for direct reads and falls back to generic_file_buffered_read() for incomplete reads and buffered reads.

We don't need address_space.direct_IO() anymore: set it to noop. Similarly, we don't need flags used in __blockdev_direct_IO(). iomap is capable of direct I/O reads from a hole, so we don't need to return -ENOENT.

BTRFS direct I/O is now done under i_rwsem, shared in case of reads and exclusive in case of writes. This guards against simultaneous truncates.

Use iomap->iomap_end() to check for failed or incomplete direct I/O:
- for writes, call __endio_write_update_ordered()
- for reads, unlock extents

btrfs_dio_data is now hooked in iomap->private and not current->journal_info. It carries the reservation variable and the amount of data submitted, so we can calculate the amount of data to call __endio_write_update_ordered in case of an error.

Quoted 7 lines
Quoted 3 lines

This patch removes last use of struct buffer_head from btrfs.

This thing is huge, but it builds and passes the dio tests, and I went through it twice. I imagine we'll still find things broken after the fact, but IDK how to break it up more since we're converting to a new style.

Thanks, ack, I think this is a resonably small version we can get. There are 3 patches doing some post-cleanups but for now I'd like to get just the switch so any eventual fixups are easy.

Quoted 8 lines

Tests finish for me but I haven't scanned all results so there are potential failures. The plan is to push the patch out early for wider testing despite that. Functionality-wise the patch is complete so we're now going to just hunt the remaining bugs.

I'll add the patch to misc-next by the end of the week, it'll be in for-next until then, more reviews are welcome.

Agreed, it's going to be one of those things where if it does fail it only fails for some of us in a subset of our xfstests runs, so might as well get it in so we can all start hammering on it. Thanks,

Josef