From: Christoph Hellwig <hch@lst.de>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>
Cc: Boris Burkov <boris@bur.io>,
Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
Naohiro Aota <Naohiro.Aota@wdc.com>,
linux-btrfs@vger.kernel.org
Subject: [PATCH 08/11] btrfs: simplify split_zoned_em
Date: Fri, 24 Mar 2023 10:32:04 +0800 [thread overview]
Message-ID: <20230324023207.544800-9-hch@lst.de> (raw)
In-Reply-To: <20230324023207.544800-1-hch@lst.de>
split_zoned_em is only ever asked to split out the beginning of an extent
map. Change it to only take a len to split out instead of a pre and post
region.
Also rename the function to split_extent_map as there is nothing zoned
device specific about it.
Note: this function should probably move to extent_map.c.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/btrfs/inode.c | 78 +++++++++++++++++-------------------------------
1 file changed, 27 insertions(+), 51 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index bff23bac85f2ef..5b3d6403363814 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2512,37 +2512,32 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode,
}
/*
- * Split an extent_map at [start, start + len]
+ * Split off the first pre bytes from the extent_map at [start, start + len]
*
* This function is intended to be used only for extract_ordered_extent().
*/
-static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
- u64 pre, u64 post)
+static int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len,
+ u64 pre)
{
struct extent_map_tree *em_tree = &inode->extent_tree;
struct extent_map *em;
struct extent_map *split_pre = NULL;
struct extent_map *split_mid = NULL;
- struct extent_map *split_post = NULL;
int ret = 0;
unsigned long flags;
- /* Sanity check */
- if (pre == 0 && post == 0)
- return 0;
+ ASSERT(pre != 0);
+ ASSERT(pre < len);
split_pre = alloc_extent_map();
- if (pre)
- split_mid = alloc_extent_map();
- if (post)
- split_post = alloc_extent_map();
- if (!split_pre || (pre && !split_mid) || (post && !split_post)) {
+ if (!split_pre)
+ return -ENOMEM;
+ split_mid = alloc_extent_map();
+ if (!split_mid) {
ret = -ENOMEM;
- goto out;
+ goto out_free_pre;
}
- ASSERT(pre + post < len);
-
lock_extent(&inode->io_tree, start, start + len - 1, NULL);
write_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, start, len);
@@ -2563,7 +2558,7 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
/* First, replace the em with a new extent_map starting from * em->start */
split_pre->start = em->start;
- split_pre->len = (pre ? pre : em->len - post);
+ split_pre->len = pre;
split_pre->orig_start = split_pre->start;
split_pre->block_start = em->block_start;
split_pre->block_len = split_pre->len;
@@ -2577,38 +2572,21 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
/*
* Now we only have an extent_map at:
- * [em->start, em->start + pre] if pre != 0
- * [em->start, em->start + em->len - post] if pre == 0
+ * [em->start, em->start + pre]
*/
- if (pre) {
- /* Insert the middle extent_map */
- split_mid->start = em->start + pre;
- split_mid->len = em->len - pre - post;
- split_mid->orig_start = split_mid->start;
- split_mid->block_start = em->block_start + pre;
- split_mid->block_len = split_mid->len;
- split_mid->orig_block_len = split_mid->block_len;
- split_mid->ram_bytes = split_mid->len;
- split_mid->flags = flags;
- split_mid->compress_type = em->compress_type;
- split_mid->generation = em->generation;
- add_extent_mapping(em_tree, split_mid, 1);
- }
-
- if (post) {
- split_post->start = em->start + em->len - post;
- split_post->len = post;
- split_post->orig_start = split_post->start;
- split_post->block_start = em->block_start + em->len - post;
- split_post->block_len = split_post->len;
- split_post->orig_block_len = split_post->block_len;
- split_post->ram_bytes = split_post->len;
- split_post->flags = flags;
- split_post->compress_type = em->compress_type;
- split_post->generation = em->generation;
- add_extent_mapping(em_tree, split_post, 1);
- }
+ /* Insert the middle extent_map */
+ split_mid->start = em->start + pre;
+ split_mid->len = em->len - pre;
+ split_mid->orig_start = split_mid->start;
+ split_mid->block_start = em->block_start + pre;
+ split_mid->block_len = split_mid->len;
+ split_mid->orig_block_len = split_mid->block_len;
+ split_mid->ram_bytes = split_mid->len;
+ split_mid->flags = flags;
+ split_mid->compress_type = em->compress_type;
+ split_mid->generation = em->generation;
+ add_extent_mapping(em_tree, split_mid, 1);
/* Once for us */
free_extent_map(em);
@@ -2618,11 +2596,9 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
out_unlock:
write_unlock(&em_tree->lock);
unlock_extent(&inode->io_tree, start, start + len - 1, NULL);
-out:
- free_extent_map(split_pre);
free_extent_map(split_mid);
- free_extent_map(split_post);
-
+out_free_pre:
+ free_extent_map(split_pre);
return ret;
}
@@ -2653,7 +2629,7 @@ blk_status_t btrfs_extract_ordered_extent(struct btrfs_bio *bbio)
ret = btrfs_split_ordered_extent(ordered, len);
if (ret)
goto out;
- ret = split_zoned_em(inode, bbio->file_offset, ordered_len, len, 0);
+ ret = split_extent_map(inode, bbio->file_offset, ordered_len, len);
out:
btrfs_put_ordered_extent(ordered);
return errno_to_blk_status(ret);
--
2.39.2
next prev parent reply other threads:[~2023-03-24 2:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-24 2:31 btrfs: fix corruption caused by partial dio writes v6 Christoph Hellwig
2023-03-24 2:31 ` [PATCH 01/11] btrfs: add function to create and return an ordered extent Christoph Hellwig
2023-03-24 5:47 ` Naohiro Aota
2023-03-25 8:22 ` Christoph Hellwig
2023-03-24 2:31 ` [PATCH 02/11] btrfs: pass flags as unsigned long to btrfs_add_ordered_extent Christoph Hellwig
2023-03-24 4:53 ` Naohiro Aota
2023-03-24 2:31 ` [PATCH 03/11] btrfs: stash ordered extent in dio_data during iomap dio Christoph Hellwig
2023-03-24 7:41 ` Naohiro Aota
2023-03-24 2:32 ` [PATCH 04/11] btrfs: move ordered_extent internal sanity checks into btrfs_split_ordered_extent Christoph Hellwig
2023-03-24 2:32 ` [PATCH 05/11] btrfs: simplify btrfs_extract_ordered_extent Christoph Hellwig
2023-03-24 6:07 ` Naohiro Aota
2023-03-25 8:34 ` Christoph Hellwig
2023-03-24 2:32 ` [PATCH 06/11] btrfs: simplify btrfs_split_ordered_extent Christoph Hellwig
2023-03-24 7:52 ` Naohiro Aota
2023-03-25 8:37 ` Christoph Hellwig
2023-03-24 2:32 ` [PATCH 07/11] btrfs: fold btrfs_clone_ordered_extent into btrfs_split_ordered_extent Christoph Hellwig
2023-03-24 2:32 ` Christoph Hellwig [this message]
2023-03-24 2:32 ` [PATCH 09/11] btrfs: pass an ordered_extent to btrfs_extract_ordered_extent Christoph Hellwig
2023-03-24 2:32 ` [PATCH 10/11] btrfs: don't split nocow extent_maps in btrfs_extract_ordered_extent Christoph Hellwig
2023-03-24 2:32 ` [PATCH 11/11] btrfs: split partial dio bios before submit Christoph Hellwig
2023-03-24 13:10 ` btrfs: fix corruption caused by partial dio writes v6 Johannes Thumshirn
2023-03-24 16:36 ` Johannes Thumshirn
2023-03-28 5:19 btrfs: fix corruption caused by partial dio writes v7 Christoph Hellwig
2023-03-28 5:19 ` [PATCH 08/11] btrfs: simplify split_zoned_em Christoph Hellwig
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=20230324023207.544800-9-hch@lst.de \
--to=hch@lst.de \
--cc=Johannes.Thumshirn@wdc.com \
--cc=Naohiro.Aota@wdc.com \
--cc=boris@bur.io \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).