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, Naohiro Aota <naohiro.aota@wdc.com>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH 06/11] btrfs: simplify btrfs_split_ordered_extent
Date: Tue, 28 Mar 2023 14:19:52 +0900 [thread overview]
Message-ID: <20230328051957.1161316-7-hch@lst.de> (raw)
In-Reply-To: <20230328051957.1161316-1-hch@lst.de>
btrfs_split_ordered_extent is only ever asked to split out the beginning
of an ordered_extent. Change it to only take a len to split out, and
switch it to allocate the new extent for the beginning, as that helps
with callers that want to keep a pointer to the ordered_extent that
it is stealing from.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Tested-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/inode.c | 8 +-------
fs/btrfs/ordered-data.c | 31 +++++++++++++++----------------
fs/btrfs/ordered-data.h | 3 +--
3 files changed, 17 insertions(+), 25 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 428fa99711def1..5358187f37fe10 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2646,17 +2646,11 @@ blk_status_t btrfs_extract_ordered_extent(struct btrfs_bio *bbio)
goto out;
}
- /* The bio must be entirely covered by the ordered extent */
- if (WARN_ON_ONCE(len > ordered_len)) {
- ret = -EINVAL;
- goto out;
- }
-
/* No need to split if the ordered extent covers the entire bio */
if (ordered->disk_num_bytes == len)
goto out;
- ret = btrfs_split_ordered_extent(ordered, len, 0);
+ ret = btrfs_split_ordered_extent(ordered, len);
if (ret)
goto out;
ret = split_zoned_em(inode, bbio->file_offset, ordered_len, len, 0);
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 4b46406c0c8af5..561531ca4e9ef2 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -1138,17 +1138,22 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
ordered->compress_type);
}
-int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
- u64 post)
+/* split out a new ordered extent for this first @len bytes of @ordered */
+int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len)
{
struct inode *inode = ordered->inode;
struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree;
- struct rb_node *node;
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
- int ret = 0;
+ struct rb_node *node;
trace_btrfs_ordered_extent_split(BTRFS_I(inode), ordered);
+ /*
+ * The entire bio must be covered by the ordered extent, but we can't
+ * reduce the original extent to a zero length either.
+ */
+ if (WARN_ON_ONCE(len >= ordered->num_bytes))
+ return -EINVAL;
/* We cannot split once end_bio'd ordered extent */
if (WARN_ON_ONCE(ordered->bytes_left != ordered->disk_num_bytes))
return -EINVAL;
@@ -1167,11 +1172,11 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
if (tree->last == node)
tree->last = NULL;
- ordered->file_offset += pre;
- ordered->disk_bytenr += pre;
- ordered->num_bytes -= (pre + post);
- ordered->disk_num_bytes -= (pre + post);
- ordered->bytes_left -= (pre + post);
+ ordered->file_offset += len;
+ ordered->disk_bytenr += len;
+ ordered->num_bytes -= len;
+ ordered->disk_num_bytes -= len;
+ ordered->bytes_left -= len;
/* Re-insert the node */
node = tree_insert(&tree->tree, ordered->file_offset, &ordered->rb_node);
@@ -1182,13 +1187,7 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
spin_unlock_irq(&tree->lock);
- if (pre)
- ret = clone_ordered_extent(ordered, 0, pre);
- if (ret == 0 && post)
- ret = clone_ordered_extent(ordered, pre + ordered->disk_num_bytes,
- post);
-
- return ret;
+ return clone_ordered_extent(ordered, 0, len);
}
int __init ordered_data_init(void)
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 18007f9c00add8..f0f1138d23c331 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -212,8 +212,7 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
struct extent_state **cached_state);
bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end,
struct extent_state **cached_state);
-int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
- u64 post);
+int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len);
int __init ordered_data_init(void);
void __cold ordered_data_exit(void);
--
2.39.2
next prev parent reply other threads:[~2023-03-28 5:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 5:19 btrfs: fix corruption caused by partial dio writes v7 Christoph Hellwig
2023-03-28 5:19 ` [PATCH 01/11] btrfs: add function to create and return an ordered extent Christoph Hellwig
2023-03-28 5:19 ` [PATCH 02/11] btrfs: pass flags as unsigned long to btrfs_add_ordered_extent Christoph Hellwig
2023-03-28 5:19 ` [PATCH 03/11] btrfs: stash ordered extent in dio_data during iomap dio Christoph Hellwig
2023-03-28 5:19 ` [PATCH 04/11] btrfs: move ordered_extent internal sanity checks into btrfs_split_ordered_extent Christoph Hellwig
2023-03-28 5:19 ` [PATCH 05/11] btrfs: simplify btrfs_extract_ordered_extent Christoph Hellwig
2023-03-28 17:53 ` David Sterba
2023-03-28 5:19 ` Christoph Hellwig [this message]
2023-03-28 5:19 ` [PATCH 07/11] btrfs: fold btrfs_clone_ordered_extent into btrfs_split_ordered_extent Christoph Hellwig
2023-03-28 5:19 ` [PATCH 08/11] btrfs: simplify split_zoned_em Christoph Hellwig
2023-03-28 5:19 ` [PATCH 09/11] btrfs: pass an ordered_extent to btrfs_extract_ordered_extent Christoph Hellwig
2023-03-28 5:19 ` [PATCH 10/11] btrfs: don't split nocow extent_maps in btrfs_extract_ordered_extent Christoph Hellwig
2023-03-28 5:19 ` [PATCH 11/11] btrfs: split partial dio bios before submit Christoph Hellwig
2023-03-28 15:20 ` btrfs: fix corruption caused by partial dio writes v7 Josef Bacik
2023-03-28 18:24 ` David Sterba
-- strict thread matches above, loose matches on Subject: below --
2023-03-24 2:31 btrfs: fix corruption caused by partial dio writes v6 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
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=20230328051957.1161316-7-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).