diff mbox series

[v7,24/39] btrfs: enable zone append writing for direct IO

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

Commit Message

Naohiro Aota Sept. 11, 2020, 12:32 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 7fe28a77f9b8..422940d7bb4b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7351,6 +7351,11 @@  static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
 	u64 len = length;
 	bool unlock_extents = false;
 
+	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);
 
@@ -7692,6 +7697,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);
 }
@@ -7701,7 +7708,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. */
@@ -7846,6 +7854,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;