diff mbox series

[RFC,08/31] btrfs: btrfs_em_to_iomap () to convert em to iomap

Message ID 87e85bcd1f50533b3a18c09cff5bd88cc3c6f923.1623567940.git.rgoldwyn@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs buffered iomap support | expand

Commit Message

Goldwyn Rodrigues June 13, 2021, 1:39 p.m. UTC
From: Goldwyn Rodrigues <rgoldwyn@suse.com>

btrfs_em_to_iomap() converts and extent map into passed argument struct
iomap. It makes sure the information is set close to sectorsize block.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/ctree.h |  2 ++
 fs/btrfs/file.c  | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Nikolay Borisov June 16, 2021, 6:49 a.m. UTC | #1
On 13.06.21 г. 16:39, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> btrfs_em_to_iomap() converts and extent map into passed argument struct
> iomap. It makes sure the information is set close to sectorsize block.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> ---
>  fs/btrfs/ctree.h |  2 ++
>  fs/btrfs/file.c  | 22 ++++++++++++++++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index c9256f862085..d4567c7a93cb 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3267,6 +3267,8 @@ int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
>  int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
>  			   size_t *write_bytes);
>  void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
> +void btrfs_em_to_iomap(struct inode *inode, struct extent_map *em,
> +		struct iomap *iomap, loff_t pos);
>  
>  /* tree-defrag.c */
>  int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index e7d33c8177a0..cb9471e7224a 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1570,6 +1570,28 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
>  	return 0;
>  }
>  
> +void btrfs_em_to_iomap(struct inode *inode,
> +		struct extent_map *em, struct iomap *iomap,
> +		loff_t sector_pos)
> +{
> +	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
> +	loff_t diff = sector_pos - em->start;

rename this variable to offset or em_offset or something like that. diff
is too generic and somewhat non-descriptive.
> +
> +	if (em->block_start == EXTENT_MAP_HOLE) {
> +		iomap->addr = IOMAP_NULL_ADDR;
> +		iomap->type = IOMAP_HOLE;
> +	} else if (em->block_start == EXTENT_MAP_INLINE) {
> +		iomap->addr = IOMAP_NULL_ADDR;
> +		iomap->type = IOMAP_INLINE;
> +	} else {
> +		iomap->addr = em->block_start + diff;
> +		iomap->type = IOMAP_MAPPED;
> +	}
> +	iomap->offset = em->start + diff;
> +	iomap->bdev = fs_info->fs_devices->latest_bdev;
> +	iomap->length = em->len - diff;
> +}
> +
>  static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
>  					       struct iov_iter *i)
>  {
>
Nikolay Borisov June 16, 2021, 6:51 a.m. UTC | #2
On 13.06.21 г. 16:39, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> btrfs_em_to_iomap() converts and extent map into passed argument struct
> iomap. It makes sure the information is set close to sectorsize block.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> ---
>  fs/btrfs/ctree.h |  2 ++
>  fs/btrfs/file.c  | 22 ++++++++++++++++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index c9256f862085..d4567c7a93cb 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3267,6 +3267,8 @@ int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
>  int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
>  			   size_t *write_bytes);
>  void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
> +void btrfs_em_to_iomap(struct inode *inode, struct extent_map *em,
> +		struct iomap *iomap, loff_t pos);
>  
>  /* tree-defrag.c */
>  int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index e7d33c8177a0..cb9471e7224a 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1570,6 +1570,28 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
>  	return 0;
>  }
>  
> +void btrfs_em_to_iomap(struct inode *inode,
> +		struct extent_map *em, struct iomap *iomap,
> +		loff_t sector_pos)
> +{
> +	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
> +	loff_t diff = sector_pos - em->start;
> +
> +	if (em->block_start == EXTENT_MAP_HOLE) {
> +		iomap->addr = IOMAP_NULL_ADDR;
> +		iomap->type = IOMAP_HOLE;
> +	} else if (em->block_start == EXTENT_MAP_INLINE) {
> +		iomap->addr = IOMAP_NULL_ADDR;
> +		iomap->type = IOMAP_INLINE;
> +	} else {
> +		iomap->addr = em->block_start + diff;
> +		iomap->type = IOMAP_MAPPED;
> +	}
> +	iomap->offset = em->start + diff;

This is really iomap->offset = sector_pos i.e no need to perform the
addition.

> +	iomap->bdev = fs_info->fs_devices->latest_bdev;
> +	iomap->length = em->len - diff;
> +}
> +
>  static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
>  					       struct iov_iter *i)
>  {
>
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index c9256f862085..d4567c7a93cb 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3267,6 +3267,8 @@  int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
 int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
 			   size_t *write_bytes);
 void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
+void btrfs_em_to_iomap(struct inode *inode, struct extent_map *em,
+		struct iomap *iomap, loff_t pos);
 
 /* tree-defrag.c */
 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e7d33c8177a0..cb9471e7224a 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1570,6 +1570,28 @@  static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
 	return 0;
 }
 
+void btrfs_em_to_iomap(struct inode *inode,
+		struct extent_map *em, struct iomap *iomap,
+		loff_t sector_pos)
+{
+	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+	loff_t diff = sector_pos - em->start;
+
+	if (em->block_start == EXTENT_MAP_HOLE) {
+		iomap->addr = IOMAP_NULL_ADDR;
+		iomap->type = IOMAP_HOLE;
+	} else if (em->block_start == EXTENT_MAP_INLINE) {
+		iomap->addr = IOMAP_NULL_ADDR;
+		iomap->type = IOMAP_INLINE;
+	} else {
+		iomap->addr = em->block_start + diff;
+		iomap->type = IOMAP_MAPPED;
+	}
+	iomap->offset = em->start + diff;
+	iomap->bdev = fs_info->fs_devices->latest_bdev;
+	iomap->length = em->len - diff;
+}
+
 static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
 					       struct iov_iter *i)
 {