linux-btrfs.vger.kernel.org archive mirror
 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: Boris Burkov <boris@bur.io>,
	Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	Naohiro Aota <Naohiro.Aota@wdc.com>,
	linux-btrfs@vger.kernel.org
Subject: [PATCH 07/11] btrfs: fold btrfs_clone_ordered_extent into btrfs_split_ordered_extent
Date: Fri, 24 Mar 2023 10:32:03 +0800	[thread overview]
Message-ID: <20230324023207.544800-8-hch@lst.de> (raw)
In-Reply-To: <20230324023207.544800-1-hch@lst.de>

btrfs_clone_ordered_extent is very specific to the usage in
btrfs_split_ordered_extent.  Now that only a single call to
btrfs_clone_ordered_extent is left, just fold it into
btrfs_split_ordered_extent to make the operation more clear.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/ordered-data.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 1d5971b6e68c66..b5a86bb13115db 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -1116,38 +1116,21 @@ bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end,
 	return false;
 }
 
-
-static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
-				u64 len)
-{
-	struct inode *inode = ordered->inode;
-	struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
-	u64 file_offset = ordered->file_offset + pos;
-	u64 disk_bytenr = ordered->disk_bytenr + pos;
-	unsigned long flags = ordered->flags & BTRFS_ORDERED_TYPE_FLAGS;
-
-	/*
-	 * The splitting extent is already counted and will be added again in
-	 * btrfs_add_ordered_extent_*(). Subtract len to avoid double counting.
-	 */
-	percpu_counter_add_batch(&fs_info->ordered_bytes, -len,
-				 fs_info->delalloc_batch);
-	WARN_ON_ONCE(flags & (1 << BTRFS_ORDERED_COMPRESSED));
-	return btrfs_add_ordered_extent(BTRFS_I(inode), file_offset, len, len,
-					disk_bytenr, len, 0, flags,
-					ordered->compress_type);
-}
-
 /* 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 btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+	u64 file_offset = ordered->file_offset;
+	u64 disk_bytenr = ordered->disk_bytenr;
+	unsigned long flags = ordered->flags & BTRFS_ORDERED_TYPE_FLAGS;
 	struct rb_node *node;
 
 	trace_btrfs_ordered_extent_split(BTRFS_I(inode), ordered);
 
+	ASSERT(!(flags & (1 << BTRFS_ORDERED_COMPRESSED)));
+
 	/* The bio must be entirely covered by the ordered extent */
 	if (WARN_ON_ONCE(len > ordered->num_bytes))
 		return -EINVAL;
@@ -1184,7 +1167,15 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len)
 
 	spin_unlock_irq(&tree->lock);
 
-	return clone_ordered_extent(ordered, 0, len);
+	/*
+	 * The splitting extent is already counted and will be added again in
+	 * btrfs_add_ordered_extent(). Subtract len to avoid double counting.
+	 */
+	percpu_counter_add_batch(&fs_info->ordered_bytes, -len,
+				 fs_info->delalloc_batch);
+	return btrfs_add_ordered_extent(BTRFS_I(inode), file_offset, len, len,
+					disk_bytenr, len, 0, flags,
+					ordered->compress_type);
 }
 
 int __init ordered_data_init(void)
-- 
2.39.2


  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 ` Christoph Hellwig [this message]
2023-03-24  2:32 ` [PATCH 08/11] btrfs: simplify split_zoned_em Christoph Hellwig
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 07/11] btrfs: fold btrfs_clone_ordered_extent into btrfs_split_ordered_extent 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-8-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).