diff mbox series

[v2,10/11] btrfs: cleanup duplicated parameters related to create_io_em()

Message ID ee8e2727bfb0607f2e3b091364c131864e120439.1714707707.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: extent-map: unify the members with btrfs_ordered_extent | expand

Commit Message

Qu Wenruo May 3, 2024, 6:01 a.m. UTC
Most parameters of create_io_em() can be replaced by the members with
the same name inside btrfs_file_extent.

Do a straight parameters cleanup here.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/inode.c | 50 +++++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 37 deletions(-)

Comments

Filipe Manana May 20, 2024, 4:46 p.m. UTC | #1
On Fri, May 3, 2024 at 7:03 AM Qu Wenruo <wqu@suse.com> wrote:
>
> Most parameters of create_io_em() can be replaced by the members with
> the same name inside btrfs_file_extent.
>
> Do a straight parameters cleanup here.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/inode.c | 50 +++++++++++++-----------------------------------
>  1 file changed, 13 insertions(+), 37 deletions(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index eec5ecb917d8..a95dc2333972 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -138,9 +138,6 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
>                                      u64 end, struct writeback_control *wbc,
>                                      bool pages_dirty);
>  static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
> -                                      u64 len,
> -                                      u64 disk_num_bytes,
> -                                      u64 ram_bytes, int compress_type,
>                                        struct btrfs_file_extent *file_extent,
>                                        int type);
>
> @@ -1207,12 +1204,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
>         file_extent.offset = 0;
>         file_extent.compression = async_extent->compress_type;
>
> -       em = create_io_em(inode, start,
> -                         async_extent->ram_size,       /* len */
> -                         ins.offset,                   /* orig_block_len */
> -                         async_extent->ram_size,       /* ram_bytes */
> -                         async_extent->compress_type,
> -                         &file_extent,
> +       em = create_io_em(inode, start, &file_extent,
>                           BTRFS_ORDERED_COMPRESSED);

Btw, as we're changing this, we can take the chance to make everything
in a single line since it fits and gets more readable.

>         if (IS_ERR(em)) {
>                 ret = PTR_ERR(em);
> @@ -1443,11 +1435,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
>                 lock_extent(&inode->io_tree, start, start + ram_size - 1,
>                             &cached);
>
> -               em = create_io_em(inode, start, ins.offset, /* len */
> -                                 ins.offset, /* orig_block_len */
> -                                 ram_size, /* ram_bytes */
> -                                 BTRFS_COMPRESS_NONE, /* compress_type */
> -                                 &file_extent,
> +               em = create_io_em(inode, start, &file_extent,
>                                   BTRFS_ORDERED_REGULAR /* type */);

Same here, and remove the /* type */ comment there which is superfluous anyway.

>                 if (IS_ERR(em)) {
>                         unlock_extent(&inode->io_tree, start,
> @@ -2168,10 +2156,6 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
>                         struct extent_map *em;
>
>                         em = create_io_em(inode, cur_offset,
> -                                         nocow_args.file_extent.num_bytes,
> -                                         nocow_args.file_extent.disk_num_bytes,
> -                                         nocow_args.file_extent.ram_bytes,
> -                                         BTRFS_COMPRESS_NONE,
>                                           &nocow_args.file_extent,
>                                           BTRFS_ORDERED_PREALLOC);

Same here.

The rest looks good, simple patch.
Thanks.

>                         if (IS_ERR(em)) {
> @@ -6995,10 +6979,7 @@ static struct extent_map *btrfs_create_dio_extent(struct btrfs_inode *inode,
>         struct btrfs_ordered_extent *ordered;
>
>         if (type != BTRFS_ORDERED_NOCOW) {
> -               em = create_io_em(inode, start, len,
> -                                 orig_block_len, ram_bytes,
> -                                 BTRFS_COMPRESS_NONE, /* compress_type */
> -                                 file_extent, type);
> +               em = create_io_em(inode, start, file_extent, type);
>                 if (IS_ERR(em))
>                         goto out;
>         }
> @@ -7290,9 +7271,6 @@ 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_num_bytes,
> -                                      u64 ram_bytes, int compress_type,
>                                        struct btrfs_file_extent *file_extent,
>                                        int type)
>  {
> @@ -7314,25 +7292,25 @@ static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
>         switch (type) {
>         case BTRFS_ORDERED_PREALLOC:
>                 /* We're only referring part of a larger preallocated extent. */
> -               ASSERT(len <= ram_bytes);
> +               ASSERT(file_extent->num_bytes <= file_extent->ram_bytes);
>                 break;
>         case BTRFS_ORDERED_REGULAR:
>                 /* COW results a new extent matching our file extent size. */
> -               ASSERT(disk_num_bytes == len);
> -               ASSERT(ram_bytes == len);
> +               ASSERT(file_extent->disk_num_bytes == file_extent->num_bytes);
> +               ASSERT(file_extent->ram_bytes == file_extent->num_bytes);
>
>                 /* Since it's a new extent, we should not have any offset. */
>                 ASSERT(file_extent->offset == 0);
>                 break;
>         case BTRFS_ORDERED_COMPRESSED:
>                 /* Must be compressed. */
> -               ASSERT(compress_type != BTRFS_COMPRESS_NONE);
> +               ASSERT(file_extent->compression != BTRFS_COMPRESS_NONE);
>
>                 /*
>                  * Encoded write can make us to refer to part of the
>                  * uncompressed extent.
>                  */
> -               ASSERT(len <= ram_bytes);
> +               ASSERT(file_extent->num_bytes <= file_extent->ram_bytes);
>                 break;
>         }
>
> @@ -7341,15 +7319,15 @@ static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
>                 return ERR_PTR(-ENOMEM);
>
>         em->start = start;
> -       em->len = len;
> +       em->len = file_extent->num_bytes;
>         em->disk_bytenr = file_extent->disk_bytenr;
> -       em->disk_num_bytes = disk_num_bytes;
> -       em->ram_bytes = ram_bytes;
> +       em->disk_num_bytes = file_extent->disk_num_bytes;
> +       em->ram_bytes = file_extent->ram_bytes;
>         em->generation = -1;
>         em->offset = file_extent->offset;
>         em->flags |= EXTENT_FLAG_PINNED;
>         if (type == BTRFS_ORDERED_COMPRESSED)
> -               extent_map_set_compression(em, compress_type);
> +               extent_map_set_compression(em, file_extent->compression);
>
>         ret = btrfs_replace_extent_map_range(inode, em, true);
>         if (ret) {
> @@ -10327,9 +10305,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
>         file_extent.ram_bytes = ram_bytes;
>         file_extent.offset = encoded->unencoded_offset;
>         file_extent.compression = compression;
> -       em = create_io_em(inode, start, num_bytes,
> -                         ins.offset, ram_bytes, compression,
> -                         &file_extent, BTRFS_ORDERED_COMPRESSED);
> +       em = create_io_em(inode, start, &file_extent, BTRFS_ORDERED_COMPRESSED);
>         if (IS_ERR(em)) {
>                 ret = PTR_ERR(em);
>                 goto out_free_reserved;
> --
> 2.45.0
>
>
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index eec5ecb917d8..a95dc2333972 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -138,9 +138,6 @@  static noinline int run_delalloc_cow(struct btrfs_inode *inode,
 				     u64 end, struct writeback_control *wbc,
 				     bool pages_dirty);
 static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
-				       u64 len,
-				       u64 disk_num_bytes,
-				       u64 ram_bytes, int compress_type,
 				       struct btrfs_file_extent *file_extent,
 				       int type);
 
@@ -1207,12 +1204,7 @@  static void submit_one_async_extent(struct async_chunk *async_chunk,
 	file_extent.offset = 0;
 	file_extent.compression = async_extent->compress_type;
 
-	em = create_io_em(inode, start,
-			  async_extent->ram_size,	/* len */
-			  ins.offset,			/* orig_block_len */
-			  async_extent->ram_size,	/* ram_bytes */
-			  async_extent->compress_type,
-			  &file_extent,
+	em = create_io_em(inode, start, &file_extent,
 			  BTRFS_ORDERED_COMPRESSED);
 	if (IS_ERR(em)) {
 		ret = PTR_ERR(em);
@@ -1443,11 +1435,7 @@  static noinline int cow_file_range(struct btrfs_inode *inode,
 		lock_extent(&inode->io_tree, start, start + ram_size - 1,
 			    &cached);
 
-		em = create_io_em(inode, start, ins.offset, /* len */
-				  ins.offset, /* orig_block_len */
-				  ram_size, /* ram_bytes */
-				  BTRFS_COMPRESS_NONE, /* compress_type */
-				  &file_extent,
+		em = create_io_em(inode, start, &file_extent,
 				  BTRFS_ORDERED_REGULAR /* type */);
 		if (IS_ERR(em)) {
 			unlock_extent(&inode->io_tree, start,
@@ -2168,10 +2156,6 @@  static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
 			struct extent_map *em;
 
 			em = create_io_em(inode, cur_offset,
-					  nocow_args.file_extent.num_bytes,
-					  nocow_args.file_extent.disk_num_bytes,
-					  nocow_args.file_extent.ram_bytes,
-					  BTRFS_COMPRESS_NONE,
 					  &nocow_args.file_extent,
 					  BTRFS_ORDERED_PREALLOC);
 			if (IS_ERR(em)) {
@@ -6995,10 +6979,7 @@  static struct extent_map *btrfs_create_dio_extent(struct btrfs_inode *inode,
 	struct btrfs_ordered_extent *ordered;
 
 	if (type != BTRFS_ORDERED_NOCOW) {
-		em = create_io_em(inode, start, len,
-				  orig_block_len, ram_bytes,
-				  BTRFS_COMPRESS_NONE, /* compress_type */
-				  file_extent, type);
+		em = create_io_em(inode, start, file_extent, type);
 		if (IS_ERR(em))
 			goto out;
 	}
@@ -7290,9 +7271,6 @@  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_num_bytes,
-				       u64 ram_bytes, int compress_type,
 				       struct btrfs_file_extent *file_extent,
 				       int type)
 {
@@ -7314,25 +7292,25 @@  static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
 	switch (type) {
 	case BTRFS_ORDERED_PREALLOC:
 		/* We're only referring part of a larger preallocated extent. */
-		ASSERT(len <= ram_bytes);
+		ASSERT(file_extent->num_bytes <= file_extent->ram_bytes);
 		break;
 	case BTRFS_ORDERED_REGULAR:
 		/* COW results a new extent matching our file extent size. */
-		ASSERT(disk_num_bytes == len);
-		ASSERT(ram_bytes == len);
+		ASSERT(file_extent->disk_num_bytes == file_extent->num_bytes);
+		ASSERT(file_extent->ram_bytes == file_extent->num_bytes);
 
 		/* Since it's a new extent, we should not have any offset. */
 		ASSERT(file_extent->offset == 0);
 		break;
 	case BTRFS_ORDERED_COMPRESSED:
 		/* Must be compressed. */
-		ASSERT(compress_type != BTRFS_COMPRESS_NONE);
+		ASSERT(file_extent->compression != BTRFS_COMPRESS_NONE);
 
 		/*
 		 * Encoded write can make us to refer to part of the
 		 * uncompressed extent.
 		 */
-		ASSERT(len <= ram_bytes);
+		ASSERT(file_extent->num_bytes <= file_extent->ram_bytes);
 		break;
 	}
 
@@ -7341,15 +7319,15 @@  static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
 		return ERR_PTR(-ENOMEM);
 
 	em->start = start;
-	em->len = len;
+	em->len = file_extent->num_bytes;
 	em->disk_bytenr = file_extent->disk_bytenr;
-	em->disk_num_bytes = disk_num_bytes;
-	em->ram_bytes = ram_bytes;
+	em->disk_num_bytes = file_extent->disk_num_bytes;
+	em->ram_bytes = file_extent->ram_bytes;
 	em->generation = -1;
 	em->offset = file_extent->offset;
 	em->flags |= EXTENT_FLAG_PINNED;
 	if (type == BTRFS_ORDERED_COMPRESSED)
-		extent_map_set_compression(em, compress_type);
+		extent_map_set_compression(em, file_extent->compression);
 
 	ret = btrfs_replace_extent_map_range(inode, em, true);
 	if (ret) {
@@ -10327,9 +10305,7 @@  ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
 	file_extent.ram_bytes = ram_bytes;
 	file_extent.offset = encoded->unencoded_offset;
 	file_extent.compression = compression;
-	em = create_io_em(inode, start, num_bytes,
-			  ins.offset, ram_bytes, compression,
-			  &file_extent, BTRFS_ORDERED_COMPRESSED);
+	em = create_io_em(inode, start, &file_extent, BTRFS_ORDERED_COMPRESSED);
 	if (IS_ERR(em)) {
 		ret = PTR_ERR(em);
 		goto out_free_reserved;