All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC 8/8] btrfs: reorder disk_bytenr/disk_num_bytes/ram_bytes/offset parameters
Date: Tue,  9 Apr 2024 08:03:47 +0930	[thread overview]
Message-ID: <526aa9bf5492f74c1c848357b90d7ceff93d0f1f.1712614770.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1712614770.git.wqu@suse.com>

Since we have cleaned up the old
block_start/block_len/orig_start/orig_block_len members, we can re-order
above parameters to a more common order.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/btrfs_inode.h |  6 +--
 fs/btrfs/file.c        |  2 +-
 fs/btrfs/inode.c       | 95 ++++++++++++++++++++++++------------------
 3 files changed, 58 insertions(+), 45 deletions(-)

diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index f4514ee273ce..696e095e7111 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -443,9 +443,9 @@ int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page,
 bool btrfs_data_csum_ok(struct btrfs_bio *bbio, struct btrfs_device *dev,
 			u32 bio_offset, struct bio_vec *bv);
 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
-			      u64 *orig_block_len,
-			      u64 *ram_bytes, bool nowait, bool strict,
-			      u64 *disk_bytenr_ret, u64 *extent_offset_ret);
+			      u64 *disk_bytenr, u64 *disk_num_bytes,
+			      u64 *ram_bytes, u64 *new_offset_ret,
+			      bool nowait, bool strict);
 
 void btrfs_del_delalloc_inode(struct btrfs_inode *inode);
 struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 965d2ba34aeb..b3ba2d4f2b8b 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1094,7 +1094,7 @@ int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
 						   &cached_state);
 	}
 	ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
-			NULL, NULL, nowait, false, NULL, NULL);
+			NULL, NULL, NULL, NULL, nowait, false);
 	if (ret <= 0)
 		btrfs_drew_write_unlock(&root->snapshot_lock);
 	else
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index cbc40d291d76..0d9d743719e9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -139,9 +139,10 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
 				     bool pages_dirty);
 static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
 				       u64 len,
+				       u64 disk_bytenr,
 				       u64 disk_num_bytes,
-				       u64 ram_bytes, int compress_type,
-				       int type, u64 disk_bytenr, u64 offset);
+				       u64 ram_bytes, u64 offset, int compress_type,
+				       int type);
 
 static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
 					  u64 root, void *warn_ctx)
@@ -1160,11 +1161,12 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
 	/* Here we're doing allocation and writeback of the compressed pages */
 	em = create_io_em(inode, start,
 			  async_extent->ram_size,	/* len */
-			  ins.offset,			/* orig_block_len */
+			  ins.objectid,			/* disk_bytenr */
+			  ins.offset,			/* disk_num_bytes */
 			  async_extent->ram_size,	/* ram_bytes */
+			  0,				/* offset */
 			  async_extent->compress_type,
-			  BTRFS_ORDERED_COMPRESSED,
-			  ins.objectid, 0);
+			  BTRFS_ORDERED_COMPRESSED);
 	if (IS_ERR(em)) {
 		ret = PTR_ERR(em);
 		goto out_free_reserve;
@@ -1421,11 +1423,12 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
 
 		ram_size = ins.offset;
 		em = create_io_em(inode, start, ins.offset, /* len */
+				  ins.objectid, /* disk_bytenr */
 				  ins.offset, /* orig_block_len */
 				  ram_size, /* ram_bytes */
+				  0, /* offset */
 				  BTRFS_COMPRESS_NONE, /* compress_type */
-				  BTRFS_ORDERED_REGULAR /* type */,
-				  ins.objectid, 0);
+				  BTRFS_ORDERED_REGULAR /* type */);
 		if (IS_ERR(em)) {
 			ret = PTR_ERR(em);
 			goto out_reserve;
@@ -2161,12 +2164,13 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
 			struct extent_map *em;
 
 			em = create_io_em(inode, cur_offset, nocow_args.num_bytes,
-					  nocow_args.orig_disk_num_bytes, /* orig_block_len */
-					  ram_bytes, BTRFS_COMPRESS_NONE,
-					  BTRFS_ORDERED_PREALLOC,
-					  nocow_args.orig_disk_bytenr,
+					  nocow_args.orig_disk_bytenr, /* disk_bytenr */
+					  nocow_args.orig_disk_num_bytes, /* disk_num_bytes */
+					  ram_bytes,
 					  cur_offset - found_key.offset +
-					  nocow_args.orig_offset);
+					  nocow_args.orig_offset, /* offset */
+					  BTRFS_COMPRESS_NONE,
+					  BTRFS_ORDERED_PREALLOC);
 			if (IS_ERR(em)) {
 				btrfs_dec_nocow_writers(nocow_bg);
 				ret = PTR_ERR(em);
@@ -7012,20 +7016,20 @@ static struct extent_map *btrfs_create_dio_extent(struct btrfs_inode *inode,
 						  struct btrfs_dio_data *dio_data,
 						  const u64 start,
 						  const u64 len,
-						  const u64 orig_block_len,
-						  const u64 ram_bytes,
-						  const int type,
 						  const u64 disk_bytenr,
-						  const u64 offset)
+						  const u64 disk_num_bytes,
+						  const u64 ram_bytes,
+						  const u64 offset,
+						  const int type)
 {
 	struct extent_map *em = NULL;
 	struct btrfs_ordered_extent *ordered;
 
 	if (type != BTRFS_ORDERED_NOCOW) {
 		em = create_io_em(inode, start, len,
-				  orig_block_len, ram_bytes,
+				  disk_bytenr, disk_num_bytes, ram_bytes, offset,
 				  BTRFS_COMPRESS_NONE, /* compress_type */
-				  type, disk_bytenr, offset);
+				  type);
 		if (IS_ERR(em))
 			goto out;
 	}
@@ -7074,10 +7078,13 @@ static struct extent_map *btrfs_new_extent_direct(struct btrfs_inode *inode,
 	if (ret)
 		return ERR_PTR(ret);
 
-	em = btrfs_create_dio_extent(inode, dio_data, start, ins.offset,
-				     ins.offset,
-				     ins.offset, BTRFS_ORDERED_REGULAR,
-				     ins.objectid, 0);
+	em = btrfs_create_dio_extent(inode, dio_data,
+				     start, ins.offset,
+				     ins.objectid, /* disk_bytenr */
+				     ins.offset, /* disk_num_bytes */
+				     ins.offset, /* ram_bytes */
+				     0, /* offset */
+				     BTRFS_ORDERED_REGULAR);
 	btrfs_dec_block_group_reservations(fs_info, ins.objectid);
 	if (IS_ERR(em))
 		btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset,
@@ -7120,9 +7127,9 @@ static bool btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
  *	 any ordered extents.
  */
 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
-			      u64 *orig_block_len,
-			      u64 *ram_bytes, bool nowait, bool strict,
-			      u64 *disk_bytenr_ret, u64 *new_offset_ret)
+			      u64 *disk_bytenr, u64 *disk_num_bytes,
+			      u64 *ram_bytes, u64 *new_offset_ret,
+			      bool nowait, bool strict)
 {
 	struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
 	struct can_nocow_file_extent_args nocow_args = { 0 };
@@ -7207,10 +7214,10 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
 		}
 	}
 
-	if (orig_block_len)
-		*orig_block_len = nocow_args.orig_disk_num_bytes;
-	if (disk_bytenr_ret)
-		*disk_bytenr_ret = nocow_args.orig_disk_bytenr;
+	if (disk_bytenr)
+		*disk_bytenr = nocow_args.orig_disk_bytenr;
+	if (disk_num_bytes)
+		*disk_num_bytes = nocow_args.orig_disk_num_bytes;
 	if (new_offset_ret)
 		*new_offset_ret = offset - key.offset +
 				  nocow_args.orig_offset;
@@ -7318,9 +7325,12 @@ static int lock_extent_direct(struct inode *inode, u64 lockstart, u64 lockend,
 /* The callers of this must take lock_extent() */
 static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
 				       u64 len,
+				       u64 disk_bytenr,
 				       u64 disk_num_bytes,
-				       u64 ram_bytes, int compress_type,
-				       int type, u64 disk_bytenr, u64 offset)
+				       u64 ram_bytes,
+				       u64 offset,
+				       int compress_type,
+				       int type)
 {
 	struct extent_map *em;
 	int ret;
@@ -7428,8 +7438,9 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
 		block_start = extent_map_block_start(em) + (start - em->start);
 
 		if (can_nocow_extent(inode, start, &len,
-				     &orig_block_len, &ram_bytes, false, false,
-				     &disk_bytenr, &new_offset) == 1) {
+				     &disk_bytenr, &orig_block_len,
+				     &ram_bytes, &new_offset,
+				     false, false) == 1) {
 			bg = btrfs_inc_nocow_writers(fs_info, block_start);
 			if (bg)
 				can_nocow = true;
@@ -7455,9 +7466,11 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
 		space_reserved = true;
 
 		em2 = btrfs_create_dio_extent(BTRFS_I(inode), dio_data, start, len,
-					      orig_block_len,
-					      ram_bytes, type,
-					      disk_bytenr, new_offset);
+					      disk_bytenr, /* disk_bytenr. */
+					      orig_block_len, /* disk_num_bytes */
+					      ram_bytes, /* ram_bytes */
+					      new_offset, /* offset */
+					      type);
 		btrfs_dec_nocow_writers(bg);
 		if (type == BTRFS_ORDERED_PREALLOC) {
 			free_extent_map(em);
@@ -10515,9 +10528,9 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
 	extent_reserved = true;
 
 	em = create_io_em(inode, start, num_bytes,
-			  ins.offset, ram_bytes, compression,
-			  BTRFS_ORDERED_COMPRESSED, ins.objectid,
-			  encoded->unencoded_offset);
+			  ins.objectid, ins.offset, ram_bytes,
+			  encoded->unencoded_offset, compression,
+			  BTRFS_ORDERED_COMPRESSED);
 	if (IS_ERR(em)) {
 		ret = PTR_ERR(em);
 		goto out_free_reserved;
@@ -10847,8 +10860,8 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
 		free_extent_map(em);
 		em = NULL;
 
-		ret = can_nocow_extent(inode, start, &len, NULL, NULL,
-				       false, true, NULL, NULL);
+		ret = can_nocow_extent(inode, start, &len, NULL, NULL, NULL, NULL,
+				       false, true);
 		if (ret < 0) {
 			goto out;
 		} else if (ret) {
-- 
2.44.0


  parent reply	other threads:[~2024-04-08 22:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08 22:33 [PATCH 0/8] btrfs: extent-map: use disk_bytenr/offset to replace block_start/block_len/orig_start Qu Wenruo
2024-04-08 22:33 ` [PATCH RFC 1/8] btrfs: rename extent_map::orig_block_len to disk_num_bytes Qu Wenruo
2024-04-09 14:58   ` David Sterba
2024-04-09 21:38     ` Qu Wenruo
2024-04-08 22:33 ` [PATCH RFC 2/8] btrfs: rename members of can_nocow_file_extent_args Qu Wenruo
2024-04-11 14:46   ` Filipe Manana
2024-04-11 22:03     ` Qu Wenruo
2024-04-12 13:21       ` Filipe Manana
2024-04-12 22:00         ` Qu Wenruo
2024-04-12 22:12           ` Qu Wenruo
2024-04-08 22:33 ` [PATCH RFC 3/8] btrfs: introduce new members for extent_map Qu Wenruo
2024-04-11 14:56   ` Filipe Manana
2024-04-11 21:52     ` Qu Wenruo
2024-04-08 22:33 ` [PATCH RFC 4/8] btrfs: introduce extra sanity checks for extent maps Qu Wenruo
2024-04-08 22:33 ` [PATCH RFC 5/8] btrfs: remove extent_map::orig_start member Qu Wenruo
2024-04-09 14:59   ` David Sterba
2024-04-08 22:33 ` [PATCH RFC 6/8] btrfs: remove extent_map::block_len member Qu Wenruo
2024-04-08 22:33 ` [PATCH RFC 7/8] btrfs: remove extent_map::block_start member Qu Wenruo
2024-04-08 22:33 ` Qu Wenruo [this message]
2024-04-09 14:57 ` [PATCH 0/8] btrfs: extent-map: use disk_bytenr/offset to replace block_start/block_len/orig_start David Sterba
2024-04-09 21:40   ` Qu Wenruo
2024-04-09 22:18     ` 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=526aa9bf5492f74c1c848357b90d7ceff93d0f1f.1712614770.git.wqu@suse.com \
    --to=wqu@suse.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.