All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>
Cc: Damien Le Moal <damien.lemoal@wdc.com>,
	Naohiro Aota <naohiro.aota@wdc.com>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	Qu Wenruo <wqu@suse.com>, Jens Axboe <axboe@kernel.dk>,
	"Darrick J. Wong" <djwong@kernel.org>,
	linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH 06/17] btrfs: handle recording of zoned writes in the storage layer
Date: Thu,  1 Sep 2022 10:42:05 +0300	[thread overview]
Message-ID: <20220901074216.1849941-7-hch@lst.de> (raw)
In-Reply-To: <20220901074216.1849941-1-hch@lst.de>

Move the code that splits the ordered extents and records the physical
location for them to the storage layer so that the higher level consumers
don't have to care about physical block numbers at all.  This will also
allow to eventually remove accounting for the zone append write sizes in
the upper layer with a little bit more block layer work.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/compression.c  |  1 -
 fs/btrfs/extent_io.c    |  6 ------
 fs/btrfs/inode.c        | 40 ++++++++--------------------------------
 fs/btrfs/ordered-data.h |  1 +
 fs/btrfs/volumes.c      |  8 ++++++++
 fs/btrfs/zoned.c        | 13 +++++--------
 fs/btrfs/zoned.h        |  6 ++----
 7 files changed, 24 insertions(+), 51 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 53f9e123712b0..1f10f86e70557 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -270,7 +270,6 @@ static void end_compressed_bio_write(struct btrfs_bio *bbio)
 	if (refcount_dec_and_test(&cb->pending_ios)) {
 		struct btrfs_fs_info *fs_info = btrfs_sb(cb->inode->i_sb);
 
-		btrfs_record_physical_zoned(cb->inode, cb->start, &bbio->bio);
 		queue_work(fs_info->compressed_write_workers, &cb->write_end_work);
 	}
 	bio_put(&bbio->bio);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index d8c43e2111a99..4c00bdefe5b45 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2285,7 +2285,6 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio)
 	u64 start;
 	u64 end;
 	struct bvec_iter_all iter_all;
-	bool first_bvec = true;
 
 	ASSERT(!bio_flagged(bio, BIO_CLONED));
 	bio_for_each_segment_all(bvec, bio, iter_all) {
@@ -2307,11 +2306,6 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio)
 		start = page_offset(page) + bvec->bv_offset;
 		end = start + bvec->bv_len - 1;
 
-		if (first_bvec) {
-			btrfs_record_physical_zoned(inode, start, bio);
-			first_bvec = false;
-		}
-
 		end_extent_writepage(page, error, start, end);
 
 		btrfs_page_clear_writeback(fs_info, page, start, bvec->bv_len);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 88dd99997631a..03953c1f176dd 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2615,21 +2615,21 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
 	return ret;
 }
 
-static blk_status_t extract_ordered_extent(struct btrfs_inode *inode,
-					   struct bio *bio, loff_t file_offset)
+int btrfs_extract_ordered_extent(struct btrfs_bio *bbio)
 {
+	u64 start = (u64)bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
+	u64 len = bbio->bio.bi_iter.bi_size;
+	struct btrfs_inode *bi = BTRFS_I(bbio->inode);
 	struct btrfs_ordered_extent *ordered;
-	u64 start = (u64)bio->bi_iter.bi_sector << SECTOR_SHIFT;
 	u64 file_len;
-	u64 len = bio->bi_iter.bi_size;
 	u64 end = start + len;
 	u64 ordered_end;
 	u64 pre, post;
 	int ret = 0;
 
-	ordered = btrfs_lookup_ordered_extent(inode, file_offset);
+	ordered = btrfs_lookup_ordered_extent(bi, bbio->file_offset);
 	if (WARN_ON_ONCE(!ordered))
-		return BLK_STS_IOERR;
+		return -EIO;
 
 	/* No need to split */
 	if (ordered->disk_num_bytes == len)
@@ -2667,28 +2667,16 @@ static blk_status_t extract_ordered_extent(struct btrfs_inode *inode,
 	ret = btrfs_split_ordered_extent(ordered, pre, post);
 	if (ret)
 		goto out;
-	ret = split_zoned_em(inode, file_offset, file_len, pre, post);
+	ret = split_zoned_em(bi, bbio->file_offset, file_len, pre, post);
 
 out:
 	btrfs_put_ordered_extent(ordered);
-
-	return errno_to_blk_status(ret);
+	return ret;
 }
 
 void btrfs_submit_data_write_bio(struct inode *inode, struct bio *bio, int mirror_num)
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
-	struct btrfs_inode *bi = BTRFS_I(inode);
-	blk_status_t ret;
-
-	if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
-		ret = extract_ordered_extent(bi, bio,
-				page_offset(bio_first_bvec_all(bio)->bv_page));
-		if (ret) {
-			btrfs_bio_end_io(btrfs_bio(bio), ret);
-			return;
-		}
-	}
 
 	btrfs_submit_bio(fs_info, bio, mirror_num);
 }
@@ -7864,8 +7852,6 @@ static void btrfs_end_dio_bio(struct btrfs_bio *bbio)
 		dip->bio.bi_status = err;
 	}
 
-	btrfs_record_physical_zoned(dip->inode, bbio->file_offset, bio);
-
 	bio_put(bio);
 	btrfs_dio_private_put(dip);
 }
@@ -7923,15 +7909,6 @@ static void btrfs_submit_direct(const struct iomap_iter *iter,
 					      inode, btrfs_end_dio_bio, dip);
 		btrfs_bio(bio)->file_offset = file_offset;
 
-		if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
-			status = extract_ordered_extent(BTRFS_I(inode), bio,
-							file_offset);
-			if (status) {
-				bio_put(bio);
-				goto out_err;
-			}
-		}
-
 		ASSERT(submit_len >= clone_len);
 		submit_len -= clone_len;
 
@@ -7960,7 +7937,6 @@ static void btrfs_submit_direct(const struct iomap_iter *iter,
 
 out_err_em:
 	free_extent_map(em);
-out_err:
 	dio_bio->bi_status = status;
 	btrfs_dio_private_put(dip);
 }
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 87792f85e2c4a..0cef17f4b752f 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -220,6 +220,7 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
 					struct extent_state **cached_state);
 int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
 			       u64 post);
+int btrfs_extract_ordered_extent(struct btrfs_bio *bbio);
 int __init ordered_data_init(void);
 void __cold ordered_data_exit(void);
 
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 2d13e8b52c94f..5c6535e10085d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6906,6 +6906,8 @@ static void btrfs_simple_end_io(struct bio *bio)
 		INIT_WORK(&bbio->end_io_work, btrfs_end_bio_work);
 		queue_work(btrfs_end_io_wq(fs_info, bio), &bbio->end_io_work);
 	} else {
+		if (bio_op(bio) == REQ_OP_ZONE_APPEND)
+			btrfs_record_physical_zoned(bbio);
 		bbio->end_io(bbio);
 	}
 }
@@ -7226,6 +7228,12 @@ void btrfs_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
 	if (btrfs_op(bio) == BTRFS_MAP_WRITE) {
 		struct btrfs_inode *bi = BTRFS_I(bbio->inode);
 
+		if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
+			ret = btrfs_extract_ordered_extent(btrfs_bio(bio));
+			if (ret)
+				goto fail;
+		}
+
 		/*
 		 * Csum items for reloc roots have already been cloned at this
 		 * point, so they are handled as part of the no-checksum case.
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index dc96b3331bfb7..2638f71eec4b6 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1633,21 +1633,18 @@ bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start)
 	return ret;
 }
 
-void btrfs_record_physical_zoned(struct inode *inode, u64 file_offset,
-				 struct bio *bio)
+void btrfs_record_physical_zoned(struct btrfs_bio *bbio)
 {
+	const u64 physical = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
+	struct btrfs_inode *bi = BTRFS_I(bbio->inode);
 	struct btrfs_ordered_extent *ordered;
-	const u64 physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
 
-	if (bio_op(bio) != REQ_OP_ZONE_APPEND)
-		return;
-
-	ordered = btrfs_lookup_ordered_extent(BTRFS_I(inode), file_offset);
+	ordered = btrfs_lookup_ordered_extent(bi, bbio->file_offset);
 	if (WARN_ON(!ordered))
 		return;
 
 	ordered->physical = physical;
-	ordered->bdev = bio->bi_bdev;
+	ordered->bdev = bbio->bio.bi_bdev;
 
 	btrfs_put_ordered_extent(ordered);
 }
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index e17462db3a842..cafa639927050 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -55,8 +55,7 @@ void btrfs_redirty_list_add(struct btrfs_transaction *trans,
 			    struct extent_buffer *eb);
 void btrfs_free_redirty_list(struct btrfs_transaction *trans);
 bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start);
-void btrfs_record_physical_zoned(struct inode *inode, u64 file_offset,
-				 struct bio *bio);
+void btrfs_record_physical_zoned(struct btrfs_bio *bbio);
 void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered);
 bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info,
 				    struct extent_buffer *eb,
@@ -178,8 +177,7 @@ static inline bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start)
 	return false;
 }
 
-static inline void btrfs_record_physical_zoned(struct inode *inode,
-					       u64 file_offset, struct bio *bio)
+static inline void btrfs_record_physical_zoned(struct btrfs_bio *bbio)
 {
 }
 
-- 
2.30.2


  parent reply	other threads:[~2022-09-01  7:43 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01  7:41 consolidate btrfs checksumming, repair and bio splitting Christoph Hellwig
2022-09-01  7:42 ` [PATCH 01/17] block: export bio_split_rw Christoph Hellwig
2022-09-01  8:02   ` Johannes Thumshirn
2022-09-01  8:54   ` Qu Wenruo
2022-09-05  6:44     ` Christoph Hellwig
2022-09-05  6:51       ` Qu Wenruo
2022-09-07 17:51   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 02/17] btrfs: stop tracking failed reads in the I/O tree Christoph Hellwig
2022-09-01  8:55   ` Qu Wenruo
2022-09-07 17:52   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 03/17] btrfs: move repair_io_failure to volumes.c Christoph Hellwig
2022-09-07 17:54   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 04/17] btrfs: handle checksum validation and repair at the storage layer Christoph Hellwig
2022-09-01  9:04   ` Qu Wenruo
2022-09-05  6:48     ` Christoph Hellwig
2022-09-05  6:59       ` Qu Wenruo
2022-09-05 14:31         ` Christoph Hellwig
2022-09-05 22:34           ` Qu Wenruo
2022-09-06  4:34             ` Christoph Hellwig
2022-09-07 18:15   ` Josef Bacik
2022-09-12 13:57     ` Christoph Hellwig
2022-09-01  7:42 ` [PATCH 05/17] btrfs: handle checksum generation in " Christoph Hellwig
2022-09-07 20:33   ` Josef Bacik
2022-09-01  7:42 ` Christoph Hellwig [this message]
2022-09-01  9:44   ` [PATCH 06/17] btrfs: handle recording of zoned writes " Johannes Thumshirn
2022-09-07 20:36   ` Josef Bacik
2022-09-12  6:11   ` Naohiro Aota
2022-09-01  7:42 ` [PATCH 07/17] btrfs: allow btrfs_submit_bio to split bios Christoph Hellwig
2022-09-01  9:47   ` Johannes Thumshirn
2022-09-07 20:55   ` Josef Bacik
2022-09-12 13:58     ` Christoph Hellwig
2022-09-12  0:20   ` Qu Wenruo
2022-09-12 13:55     ` Christoph Hellwig
2022-09-12 22:23       ` Qu Wenruo
2022-09-01  7:42 ` [PATCH 08/17] btrfs: pass the iomap bio to btrfs_submit_bio Christoph Hellwig
2022-09-07 21:00   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 09/17] btrfs: remove stripe boundary calculation for buffered I/O Christoph Hellwig
2022-09-07 21:04   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 10/17] btrfs: remove stripe boundary calculation for compressed I/O Christoph Hellwig
2022-09-01  9:56   ` Johannes Thumshirn
2022-09-05  6:49     ` Christoph Hellwig
2022-09-07 21:07   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 11/17] btrfs: remove stripe boundary calculation for encoded I/O Christoph Hellwig
2022-09-01  9:58   ` Johannes Thumshirn
2022-09-07 21:08   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 12/17] btrfs: remove struct btrfs_io_geometry Christoph Hellwig
2022-09-07 21:10   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 13/17] btrfs: remove submit_encoded_read_bio Christoph Hellwig
2022-09-01 10:02   ` Johannes Thumshirn
2022-09-07 21:11   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 14/17] btrfs: remove now spurious bio submission helpers Christoph Hellwig
2022-09-01 10:14   ` Johannes Thumshirn
2022-09-07 21:12   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 15/17] btrfs: calculate file system wide queue limit for zoned mode Christoph Hellwig
2022-09-01 11:28   ` Johannes Thumshirn
2022-09-05  6:50     ` Christoph Hellwig
2022-09-02  1:56   ` Damien Le Moal
2022-09-02  1:59     ` Damien Le Moal
2022-09-05  6:54     ` Christoph Hellwig
2022-09-01  7:42 ` [PATCH 16/17] btrfs: split zone append bios in btrfs_submit_bio Christoph Hellwig
2022-09-02  1:46   ` Damien Le Moal
2022-09-05  6:55     ` Christoph Hellwig
2022-09-05 13:15   ` Johannes Thumshirn
2022-09-05 14:25     ` Christoph Hellwig
2022-09-05 14:31       ` Johannes Thumshirn
2022-09-05 14:39         ` Christoph Hellwig
2022-09-05 14:43           ` Johannes Thumshirn
2022-09-05 15:30           ` Johannes Thumshirn
2022-09-07 21:17   ` Josef Bacik
2022-09-01  7:42 ` [PATCH 17/17] iomap: remove IOMAP_F_ZONE_APPEND Christoph Hellwig
2022-09-01 10:46   ` Johannes Thumshirn
2022-09-02  1:38   ` Damien Le Moal
2022-09-05  6:50     ` Christoph Hellwig
2022-09-05  6:57       ` Damien Le Moal
2022-09-07 21:18   ` Josef Bacik
2022-09-02 15:18 ` consolidate btrfs checksumming, repair and bio splitting Johannes Thumshirn
2022-09-07  9:10 ` code placement for bio / storage layer code Christoph Hellwig
2022-09-07  9:46   ` Johannes Thumshirn
2022-09-07 10:28   ` Qu Wenruo
2022-09-07 11:10     ` Christoph Hellwig
2022-09-07 11:27       ` Qu Wenruo
2022-09-07 11:35         ` Christoph Hellwig
2022-10-10  8:01   ` Johannes Thumshirn
2022-10-24  8:12 ` consolidate btrfs checksumming, repair and bio splitting Johannes Thumshirn
2022-10-24  8:20   ` Qu Wenruo
2022-10-24  9:07     ` Johannes Thumshirn
2022-10-24  9:18       ` Qu Wenruo
2022-10-24 10:21         ` Johannes Thumshirn
2022-10-24 14:44   ` Christoph Hellwig
2022-10-24 15:25     ` Chris Mason
2022-10-24 17:10       ` David Sterba
2022-10-24 17:34         ` Chris Mason
2022-10-24 22:18           ` Damien Le Moal
2022-10-26  7:36         ` Johannes Thumshirn
2022-10-26 11:41           ` Steven Rostedt
2022-10-27 13:54             ` Johannes Thumshirn
2022-10-31 12:19             ` David Sterba
2022-10-31 16:06               ` Chris Mason
2022-11-02  4:00               ` Steven Rostedt
2022-11-02  6:29                 ` Christoph Hellwig
2022-11-02 14:00                   ` Chris Mason
2022-11-02 14:05                   ` Josef Bacik
2022-11-02 14:06                     ` Christoph Hellwig
2022-11-02 20:20                   ` Andreas Dilger
2022-11-02 22:07                     ` Chris Mason
2022-11-03  8:49                       ` Christoph Hellwig
2022-11-03  2:54               ` Theodore Ts'o
2022-11-11 17:57             ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220901074216.1849941-7-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=clm@fb.com \
    --cc=damien.lemoal@wdc.com \
    --cc=djwong@kernel.org \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=naohiro.aota@wdc.com \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.