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: linux-btrfs@vger.kernel.org
Subject: [PATCH 08/21] btrfs: return the new ordered_extent from btrfs_split_ordered_extent
Date: Mon,  8 May 2023 09:08:30 -0700	[thread overview]
Message-ID: <20230508160843.133013-9-hch@lst.de> (raw)
In-Reply-To: <20230508160843.133013-1-hch@lst.de>

Return the ordered_extent split from the passed in one.  This will be
needed to be able to store an ordered_extent in the btrfs_bio.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/inode.c        |  7 ++++++-
 fs/btrfs/ordered-data.c | 19 ++++++++++---------
 fs/btrfs/ordered-data.h |  3 ++-
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 711f0e2081148c..3dceedf612d4ba 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2799,6 +2799,7 @@ 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_ordered_extent *new;
 	int ret;
 
 	/* Must always be called for the beginning of an ordered extent. */
@@ -2820,7 +2821,11 @@ int btrfs_extract_ordered_extent(struct btrfs_bio *bbio,
 			return ret;
 	}
 
-	return btrfs_split_ordered_extent(ordered, len);
+	new = btrfs_split_ordered_extent(ordered, len);
+	if (IS_ERR(new))
+		return PTR_ERR(new);
+	btrfs_put_ordered_extent(new);
+	return 0;
 }
 
 /*
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index a9778a91511e19..f6855e37e7f94d 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -1117,7 +1117,8 @@ bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end,
 }
 
 /* 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 btrfs_ordered_extent *
+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;
@@ -1136,16 +1137,16 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len)
 	 * reduce the original extent to a zero length either.
 	 */
 	if (WARN_ON_ONCE(len >= ordered->num_bytes))
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 	/* We cannot split once ordered extent is past end_bio. */
 	if (WARN_ON_ONCE(ordered->bytes_left != ordered->disk_num_bytes))
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 	/* We cannot split a compressed ordered extent. */
 	if (WARN_ON_ONCE(ordered->disk_num_bytes != ordered->num_bytes))
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 	/* Checksum list should be empty. */
 	if (WARN_ON_ONCE(!list_empty(&ordered->list)))
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	spin_lock_irq(&tree->lock);
 	/* Remove from tree once */
@@ -1172,13 +1173,13 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len)
 
 	/*
 	 * The splitting extent is already counted and will be added again in
-	 * btrfs_add_ordered_extent(). Subtract len to avoid double counting.
+	 * btrfs_alloc_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);
+	return btrfs_alloc_ordered_extent(BTRFS_I(inode), file_offset, len, len,
+					  disk_bytenr, len, 0, flags,
+					  ordered->compress_type);
 }
 
 int __init ordered_data_init(void)
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index f0f1138d23c331..150f75a155ca0c 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -212,7 +212,8 @@ 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 len);
+struct btrfs_ordered_extent *
+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


  parent reply	other threads:[~2023-05-08 16:09 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 16:08 add an ordered_extent pointer to struct btrfs_bio Christoph Hellwig
2023-05-08 16:08 ` [PATCH 01/21] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio Christoph Hellwig
2023-05-08 16:08 ` [PATCH 02/21] btrfs: fix file_offset for REQ_BTRFS_ONE_ORDERED bios that get split Christoph Hellwig
2023-05-08 22:17   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 03/21] btrfs: limit write bios to a single ordered extent Christoph Hellwig
2023-05-08 22:40   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 04/21] btrfs: merge the two calls to btrfs_add_ordered_extent in run_delalloc_nocow Christoph Hellwig
2023-05-08 16:08 ` [PATCH 05/21] btrfs: pass an ordered_extent to btrfs_reloc_clone_csums Christoph Hellwig
2023-05-08 23:30   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 06/21] btrfs: pass an ordered_extent to btrfs_submit_compressed_write Christoph Hellwig
2023-05-08 23:39   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 07/21] btrfs: reorder btrfs_extract_ordered_extent Christoph Hellwig
2023-05-08 23:45   ` Johannes Thumshirn
2023-05-09  0:04   ` Naohiro Aota
2023-05-08 16:08 ` Christoph Hellwig [this message]
2023-05-08 23:51   ` [PATCH 08/21] btrfs: return the new ordered_extent from btrfs_split_ordered_extent Johannes Thumshirn
2023-05-09  0:11   ` Naohiro Aota
2023-05-08 16:08 ` [PATCH 09/21] btrfs: remove btrfs_add_ordered_extent Christoph Hellwig
2023-05-08 23:55   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 10/21] btrfs: add a is_data_bio helper Christoph Hellwig
2023-05-09  0:00   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 11/21] btrfs: open code btrfs_bio_end_io in btrfs_dio_submit_io Christoph Hellwig
2023-05-09  0:03   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 12/21] btrfs: add an ordered_extent pointer to struct btrfs_bio Christoph Hellwig
2023-05-09  0:12   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 13/21] btrfs: use bbio->ordered in btrfs_csum_one_bio Christoph Hellwig
2023-05-09  0:14   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 14/21] btrfs: use bbio->ordered for zone append completions Christoph Hellwig
2023-05-09  0:16   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 15/21] btrfs: factor out a can_finish_ordered_extent helper Christoph Hellwig
2023-05-09  0:17   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 16/21] btrfs: factor out a btrfs_queue_ordered_fn helper Christoph Hellwig
2023-05-09  0:19   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 17/21] btrfs: add a btrfs_finish_ordered_extent helper Christoph Hellwig
2023-05-09  0:22   ` Johannes Thumshirn
2023-05-09 13:12     ` Christoph Hellwig
2023-05-10 13:16       ` David Sterba
2023-05-08 16:08 ` [PATCH 18/21] btrfs: use btrfs_finish_ordered_extent to complete compressed writes Christoph Hellwig
2023-05-09 15:48   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 19/21] btrfs: use btrfs_finish_ordered_extent to complete direct writes Christoph Hellwig
2023-05-09 15:50   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 20/21] btrfs: open code end_extent_writepage in end_bio_extent_writepage Christoph Hellwig
2023-05-09 15:55   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 21/21] btrfs: use btrfs_finish_ordered_extent to complete buffered writes Christoph Hellwig
2023-05-09 15:56   ` Johannes Thumshirn
2023-05-10 16:32 ` add an ordered_extent pointer to struct btrfs_bio David Sterba
2023-05-11 17:56   ` David Sterba
2023-05-12 13:32     ` Christoph Hellwig
2023-05-15  6:40 ` Christoph Hellwig
2023-05-15 11:12   ` 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=20230508160843.133013-9-hch@lst.de \
    --to=hch@lst.de \
    --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 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.