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: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	Naohiro Aota <naohiro.aota@wdc.com>,
	linux-btrfs@vger.kernel.org
Subject: [PATCH 14/14] btrfs: pass the new logical address to split_extent_map
Date: Wed, 24 May 2023 17:03:17 +0200	[thread overview]
Message-ID: <20230524150317.1767981-15-hch@lst.de> (raw)
In-Reply-To: <20230524150317.1767981-1-hch@lst.de>

split_extent_map splits off the first chunk of an extent map into a new
one.  One of the two users is the zoned I/O completion code that wants to
rewrite the logical block start address right after this split.  Pass in
the logical address to be set in the split off first extent_map as an
argument to avoid an extra extent tree lookup for this case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/extent_map.c | 8 +++++---
 fs/btrfs/extent_map.h | 3 ++-
 fs/btrfs/inode.c      | 3 ++-
 fs/btrfs/zoned.c      | 6 ++----
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 21cc4991360221..b7373fb03898f2 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -961,11 +961,13 @@ int btrfs_replace_extent_map_range(struct btrfs_inode *inode,
 }
 
 /*
- * Split off the first pre bytes from the extent_map at [start, start + len]
+ * Split off the first pre bytes from the extent_map at [start, start + len],
+ * and set the block_addr for it to new_logical.
  *
  * This function is used when an ordered_extent needs to be split.
  */
-int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre)
+int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre,
+		     u64 new_logical)
 {
 	struct extent_map_tree *em_tree = &inode->extent_tree;
 	struct extent_map *em;
@@ -1008,7 +1010,7 @@ int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre)
 	split_pre->start = em->start;
 	split_pre->len = pre;
 	split_pre->orig_start = split_pre->start;
-	split_pre->block_start = em->block_start;
+	split_pre->block_start = new_logical;
 	split_pre->block_len = split_pre->len;
 	split_pre->orig_block_len = split_pre->block_len;
 	split_pre->ram_bytes = split_pre->len;
diff --git a/fs/btrfs/extent_map.h b/fs/btrfs/extent_map.h
index 7df39112388dde..35d27c756e0808 100644
--- a/fs/btrfs/extent_map.h
+++ b/fs/btrfs/extent_map.h
@@ -90,7 +90,8 @@ struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
 int add_extent_mapping(struct extent_map_tree *tree,
 		       struct extent_map *em, int modified);
 void remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
-int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre);
+int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre,
+		     u64 new_logical);
 
 struct extent_map *alloc_extent_map(void);
 void free_extent_map(struct extent_map *em);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index eee4eefb279780..5e2315d78ea0cc 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2736,7 +2736,8 @@ static int btrfs_extract_ordered_extent(struct btrfs_bio *bbio,
 	 */
 	if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) {
 		ret = split_extent_map(bbio->inode, bbio->file_offset,
-				       ordered->num_bytes, len);
+				       ordered->num_bytes, len,
+				       ordered->disk_bytenr);
 		if (ret)
 			return ret;
 	}
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 92363fafc3a648..bc437259d2a06a 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1689,15 +1689,13 @@ static bool btrfs_zoned_split_ordered(struct btrfs_ordered_extent *ordered,
 
 	if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags) &&
 	    split_extent_map(BTRFS_I(ordered->inode), ordered->file_offset,
-			     ordered->num_bytes, len))
+			     ordered->num_bytes, len, logical))
 		return false;
 
 	new = btrfs_split_ordered_extent(ordered, len);
 	if (IS_ERR(new))
 		return false;
-
-	if (new->disk_bytenr != logical)
-		btrfs_rewrite_logical_zoned(new, logical);
+	new->disk_bytenr = logical;
 	btrfs_finish_one_ordered(new);
 	return true;
 }
-- 
2.39.2


  parent reply	other threads:[~2023-05-24 15:04 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24 15:03 don't split ordered_extents for zoned writes at I/O submission time Christoph Hellwig
2023-05-24 15:03 ` [PATCH 01/14] btrfs: optimize out btrfs_is_zoned for !CONFIG_BLK_DEV_ZONED Christoph Hellwig
2023-05-25  8:33   ` Johannes Thumshirn
2023-05-24 15:03 ` [PATCH 02/14] btrfs: don't call btrfs_record_physical_zoned for failed append Christoph Hellwig
2023-05-25  8:33   ` Johannes Thumshirn
2023-05-24 15:03 ` [PATCH 03/14] btrfs: mark the len field in struct btrfs_ordered_sum as unsigned Christoph Hellwig
2023-05-25  8:33   ` Johannes Thumshirn
2023-05-30 16:45   ` David Sterba
2023-05-24 15:03 ` [PATCH 04/14] btrfs: rename the bytenr field in struct btrfs_ordered_sum to logical Christoph Hellwig
2023-05-25  8:33   ` Johannes Thumshirn
2023-05-24 15:03 ` [PATCH 05/14] btrfs: optimize the logical to physical mapping for zoned writes Christoph Hellwig
2023-05-25 10:56   ` Johannes Thumshirn
2023-08-18 14:03   ` Naohiro Aota
2023-05-24 15:03 ` [PATCH 06/14] btrfs: move split_extent_map to extent_map.c Christoph Hellwig
2023-05-25 10:58   ` Johannes Thumshirn
2023-05-24 15:03 ` [PATCH 07/14] btrfs: reorder btrfs_extract_ordered_extent Christoph Hellwig
2023-05-24 15:03 ` [PATCH 08/14] btrfs: return the new ordered_extent from btrfs_split_ordered_extent Christoph Hellwig
2023-05-24 15:03 ` [PATCH 09/14] btrfs: return void from btrfs_finish_ordered_io Christoph Hellwig
2023-05-25 11:02   ` Johannes Thumshirn
2023-05-30 15:44   ` David Sterba
2023-05-31  4:00     ` Christoph Hellwig
2023-05-24 15:03 ` [PATCH 10/14] btrfs: split btrfs_alloc_ordered_extent Christoph Hellwig
2023-05-25 12:09   ` Johannes Thumshirn
2023-05-24 15:03 ` [PATCH 11/14] btrfs: atomically insert the new extent in btrfs_split_ordered_extent Christoph Hellwig
2023-05-25 12:30   ` Johannes Thumshirn
2023-05-25 12:34     ` Christoph Hellwig
2023-05-25 16:23       ` Johannes Thumshirn
2023-05-24 15:03 ` [PATCH 12/14] btrfs: handle completed ordered extents " Christoph Hellwig
2023-05-25 13:06   ` Johannes Thumshirn
2023-05-24 15:03 ` [PATCH 13/14] btrfs: defer splitting of ordered extents until I/O completion Christoph Hellwig
2023-05-25 16:25   ` Johannes Thumshirn
2023-05-30 18:40   ` David Sterba
2023-05-24 15:03 ` Christoph Hellwig [this message]
2023-05-25 16:28   ` [PATCH 14/14] btrfs: pass the new logical address to split_extent_map Johannes Thumshirn
2023-05-30 13:21 ` don't split ordered_extents for zoned writes at I/O submission time Johannes Thumshirn
2023-05-30 14:20   ` Christoph Hellwig
2023-05-30 18:48 ` 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=20230524150317.1767981-15-hch@lst.de \
    --to=hch@lst.de \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=naohiro.aota@wdc.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.