diff mbox series

[1/2] btrfs: btrfs_has_ordered_extent() to check for ordered extent in range

Message ID c252c360e04767f25698f0c6b85031c380a8a31d.1724847323.git.rgoldwyn@suse.com (mailing list archive)
State New, archived
Headers show
Series Limit scope of extent locks in btrfs_buffered_write() | expand

Commit Message

Goldwyn Rodrigues Aug. 28, 2024, 12:45 p.m. UTC
From: Goldwyn Rodrigues <rgoldwyn@suse.com>

A simple function which checks if there are ordered extent in range
supplied.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/ordered-data.c | 11 +++++++++++
 fs/btrfs/ordered-data.h |  1 +
 2 files changed, 12 insertions(+)

Comments

Filipe Manana Aug. 28, 2024, 1:28 p.m. UTC | #1
On Wed, Aug 28, 2024 at 1:53 PM Goldwyn Rodrigues <rgoldwyn@suse.de> wrote:
>
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
>
> A simple function which checks if there are ordered extent in range
> supplied.
>
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> ---
>  fs/btrfs/ordered-data.c | 11 +++++++++++
>  fs/btrfs/ordered-data.h |  1 +
>  2 files changed, 12 insertions(+)
>
> diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
> index eb9b32ffbc0c..ea8b5fa42454 100644
> --- a/fs/btrfs/ordered-data.c
> +++ b/fs/btrfs/ordered-data.c
> @@ -1006,6 +1006,17 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range(
>         return entry;
>  }
>
> +bool btrfs_has_ordered_extent(struct btrfs_inode *inode, u64 file_offset, u64 len)
> +{
> +       struct btrfs_ordered_extent *oe = NULL;

There's no point in this assignment, as we don't ever use the variable
before assigning it below.
Stuff like this has resulted in warnings from tools (and therefore
reports and patches), see for example:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=966de47ff0c9e64d74e1719e4480b7c34f6190fa

Thanks.

> +
> +       oe = btrfs_lookup_ordered_range(inode, file_offset, len);
> +       if (!oe)
> +               return false;
> +       btrfs_put_ordered_extent(oe);
> +       return true;
> +}
> +
>  /*
>   * Adds all ordered extents to the given list. The list ends up sorted by the
>   * file_offset of the ordered extents.
> diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
> index 4e152736d06c..0c715c2a01ac 100644
> --- a/fs/btrfs/ordered-data.h
> +++ b/fs/btrfs/ordered-data.h
> @@ -201,6 +201,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range(
>                 struct btrfs_inode *inode,
>                 u64 file_offset,
>                 u64 len);
> +bool btrfs_has_ordered_extent(struct btrfs_inode *inode, u64 file_offset, u64 len);
>  void btrfs_get_ordered_extents_for_logging(struct btrfs_inode *inode,
>                                            struct list_head *list);
>  u64 btrfs_wait_ordered_extents(struct btrfs_root *root, u64 nr,
> --
> 2.46.0
>
>
diff mbox series

Patch

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index eb9b32ffbc0c..ea8b5fa42454 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -1006,6 +1006,17 @@  struct btrfs_ordered_extent *btrfs_lookup_ordered_range(
 	return entry;
 }
 
+bool btrfs_has_ordered_extent(struct btrfs_inode *inode, u64 file_offset, u64 len)
+{
+	struct btrfs_ordered_extent *oe = NULL;
+
+	oe = btrfs_lookup_ordered_range(inode, file_offset, len);
+	if (!oe)
+		return false;
+	btrfs_put_ordered_extent(oe);
+	return true;
+}
+
 /*
  * Adds all ordered extents to the given list. The list ends up sorted by the
  * file_offset of the ordered extents.
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 4e152736d06c..0c715c2a01ac 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -201,6 +201,7 @@  struct btrfs_ordered_extent *btrfs_lookup_ordered_range(
 		struct btrfs_inode *inode,
 		u64 file_offset,
 		u64 len);
+bool btrfs_has_ordered_extent(struct btrfs_inode *inode, u64 file_offset, u64 len);
 void btrfs_get_ordered_extents_for_logging(struct btrfs_inode *inode,
 					   struct list_head *list);
 u64 btrfs_wait_ordered_extents(struct btrfs_root *root, u64 nr,