diff mbox series

[v8,26/41] btrfs: enable zone append writing for direct IO

Message ID 6f42df516fd9a7a8fc5dddbe73a048749e12ebea.1601574234.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: zoned block device support | expand

Commit Message

Naohiro Aota Oct. 1, 2020, 6:36 p.m. UTC
This commit enables zone append writing as same as in buffered write.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/inode.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b5fdc93b319f..37d85c062f3a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7422,6 +7422,11 @@  static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
 	       current->journal_info == BTRFS_DIO_SYNC_STUB);
 	current->journal_info = NULL;
 
+	if (write && fs_info->max_zone_append_size) {
+		length = min_t(u64, length, fs_info->max_zone_append_size);
+		len = length;
+	}
+
 	if (!write)
 		len = min_t(u64, len, fs_info->sectorsize);
 
@@ -7777,6 +7782,8 @@  static void btrfs_end_dio_bio(struct bio *bio)
 	if (err)
 		dip->dio_bio->bi_status = err;
 
+	btrfs_record_physical_zoned(dip->inode, dip->logical_offset, bio);
+
 	bio_put(bio);
 	btrfs_dio_private_put(dip);
 }
@@ -7786,7 +7793,8 @@  static inline blk_status_t btrfs_submit_dio_bio(struct bio *bio,
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	struct btrfs_dio_private *dip = bio->bi_private;
-	bool write = bio_op(bio) == REQ_OP_WRITE;
+	bool write = bio_op(bio) == REQ_OP_WRITE ||
+		     bio_op(bio) == REQ_OP_ZONE_APPEND;
 	blk_status_t ret;
 
 	/* Check btrfs_submit_bio_hook() for rules about async submit. */
@@ -7931,6 +7939,12 @@  static blk_qc_t btrfs_submit_direct(struct inode *inode, struct iomap *iomap,
 		bio->bi_end_io = btrfs_end_dio_bio;
 		btrfs_io_bio(bio)->logical = file_offset;
 
+		if (write && btrfs_fs_incompat(fs_info, ZONED) &&
+		    fs_info->max_zone_append_size) {
+			bio->bi_opf &= ~REQ_OP_MASK;
+			bio->bi_opf |= REQ_OP_ZONE_APPEND;
+		}
+
 		ASSERT(submit_len >= clone_len);
 		submit_len -= clone_len;