[PATCH v7 5/6] btrfs: move inode_to_path higher in backref.c

Daniel Vacek posted 6 patches 1 week, 6 days ago
[PATCH v7 5/6] btrfs: move inode_to_path higher in backref.c
Posted by Daniel Vacek 1 week, 6 days ago
From: Josef Bacik <josef@toxicpanda.com>

We have a prototype and then the definition lower below, we don't need
to do this, simply move the function to where the prototype is.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/backref.c | 68 ++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 36 deletions(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 78da47a3d00e..bd913e3c356f 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2574,8 +2574,39 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
 	return iterate_extent_inodes(&walk_ctx, false, build_ino_list, ctx);
 }
 
+/*
+ * returns 0 if the path could be dumped (probably truncated)
+ * returns <0 in case of an error
+ */
 static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
-			 struct extent_buffer *eb, struct inode_fs_paths *ipath);
+			 struct extent_buffer *eb, struct inode_fs_paths *ipath)
+{
+	char *fspath;
+	char *fspath_min;
+	int i = ipath->fspath->elem_cnt;
+	const int s_ptr = sizeof(char *);
+	u32 bytes_left;
+
+	bytes_left = ipath->fspath->bytes_left > s_ptr ? ipath->fspath->bytes_left - s_ptr : 0;
+
+	fspath_min = (char *)ipath->fspath->val + (i + 1) * s_ptr;
+	fspath = btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len,
+				   name_off, eb, inum, fspath_min, bytes_left);
+	if (IS_ERR(fspath))
+		return PTR_ERR(fspath);
+
+	if (fspath > fspath_min) {
+		ipath->fspath->val[i] = (u64)(unsigned long)fspath;
+		++ipath->fspath->elem_cnt;
+		ipath->fspath->bytes_left = fspath - fspath_min;
+	} else {
+		++ipath->fspath->elem_missed;
+		ipath->fspath->bytes_missing += fspath_min - fspath;
+		ipath->fspath->bytes_left = 0;
+	}
+
+	return 0;
+}
 
 static int iterate_inode_refs(u64 inum, struct inode_fs_paths *ipath)
 {
@@ -2700,41 +2731,6 @@ static int iterate_inode_extrefs(u64 inum, struct inode_fs_paths *ipath)
 	return ret;
 }
 
-/*
- * returns 0 if the path could be dumped (probably truncated)
- * returns <0 in case of an error
- */
-static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
-			 struct extent_buffer *eb, struct inode_fs_paths *ipath)
-{
-	char *fspath;
-	char *fspath_min;
-	int i = ipath->fspath->elem_cnt;
-	const int s_ptr = sizeof(char *);
-	u32 bytes_left;
-
-	bytes_left = ipath->fspath->bytes_left > s_ptr ?
-					ipath->fspath->bytes_left - s_ptr : 0;
-
-	fspath_min = (char *)ipath->fspath->val + (i + 1) * s_ptr;
-	fspath = btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len,
-				   name_off, eb, inum, fspath_min, bytes_left);
-	if (IS_ERR(fspath))
-		return PTR_ERR(fspath);
-
-	if (fspath > fspath_min) {
-		ipath->fspath->val[i] = (u64)(unsigned long)fspath;
-		++ipath->fspath->elem_cnt;
-		ipath->fspath->bytes_left = fspath - fspath_min;
-	} else {
-		++ipath->fspath->elem_missed;
-		ipath->fspath->bytes_missing += fspath_min - fspath;
-		ipath->fspath->bytes_left = 0;
-	}
-
-	return 0;
-}
-
 /*
  * this dumps all file system paths to the inode into the ipath struct, provided
  * is has been created large enough. each path is zero-terminated and accessed
-- 
2.51.0
Re: [PATCH v7 5/6] btrfs: move inode_to_path higher in backref.c
Posted by Filipe Manana 1 week, 5 days ago
On Tue, Nov 18, 2025 at 4:16 PM Daniel Vacek <neelx@suse.com> wrote:
>
> From: Josef Bacik <josef@toxicpanda.com>
>
> We have a prototype and then the definition lower below, we don't need
> to do this, simply move the function to where the prototype is.

According to our development notes here:

https://btrfs.readthedocs.io/en/latest/dev/Development-notes.html

Under the "Function declarations" section we have:

"avoid prototypes for static functions, order them in new code in a
way that does not need it

but don’t move static functions just to get rid of the prototype"

So what's the motivation for moving the function?



>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/backref.c | 68 ++++++++++++++++++++++------------------------
>  1 file changed, 32 insertions(+), 36 deletions(-)
>
> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> index 78da47a3d00e..bd913e3c356f 100644
> --- a/fs/btrfs/backref.c
> +++ b/fs/btrfs/backref.c
> @@ -2574,8 +2574,39 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
>         return iterate_extent_inodes(&walk_ctx, false, build_ino_list, ctx);
>  }
>
> +/*
> + * returns 0 if the path could be dumped (probably truncated)
> + * returns <0 in case of an error
> + */
>  static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
> -                        struct extent_buffer *eb, struct inode_fs_paths *ipath);
> +                        struct extent_buffer *eb, struct inode_fs_paths *ipath)
> +{
> +       char *fspath;
> +       char *fspath_min;
> +       int i = ipath->fspath->elem_cnt;
> +       const int s_ptr = sizeof(char *);
> +       u32 bytes_left;
> +
> +       bytes_left = ipath->fspath->bytes_left > s_ptr ? ipath->fspath->bytes_left - s_ptr : 0;
> +
> +       fspath_min = (char *)ipath->fspath->val + (i + 1) * s_ptr;
> +       fspath = btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len,
> +                                  name_off, eb, inum, fspath_min, bytes_left);
> +       if (IS_ERR(fspath))
> +               return PTR_ERR(fspath);
> +
> +       if (fspath > fspath_min) {
> +               ipath->fspath->val[i] = (u64)(unsigned long)fspath;
> +               ++ipath->fspath->elem_cnt;
> +               ipath->fspath->bytes_left = fspath - fspath_min;
> +       } else {
> +               ++ipath->fspath->elem_missed;
> +               ipath->fspath->bytes_missing += fspath_min - fspath;
> +               ipath->fspath->bytes_left = 0;
> +       }
> +
> +       return 0;
> +}
>
>  static int iterate_inode_refs(u64 inum, struct inode_fs_paths *ipath)
>  {
> @@ -2700,41 +2731,6 @@ static int iterate_inode_extrefs(u64 inum, struct inode_fs_paths *ipath)
>         return ret;
>  }
>
> -/*
> - * returns 0 if the path could be dumped (probably truncated)
> - * returns <0 in case of an error
> - */
> -static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
> -                        struct extent_buffer *eb, struct inode_fs_paths *ipath)
> -{
> -       char *fspath;
> -       char *fspath_min;
> -       int i = ipath->fspath->elem_cnt;
> -       const int s_ptr = sizeof(char *);
> -       u32 bytes_left;
> -
> -       bytes_left = ipath->fspath->bytes_left > s_ptr ?
> -                                       ipath->fspath->bytes_left - s_ptr : 0;
> -
> -       fspath_min = (char *)ipath->fspath->val + (i + 1) * s_ptr;
> -       fspath = btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len,
> -                                  name_off, eb, inum, fspath_min, bytes_left);
> -       if (IS_ERR(fspath))
> -               return PTR_ERR(fspath);
> -
> -       if (fspath > fspath_min) {
> -               ipath->fspath->val[i] = (u64)(unsigned long)fspath;
> -               ++ipath->fspath->elem_cnt;
> -               ipath->fspath->bytes_left = fspath - fspath_min;
> -       } else {
> -               ++ipath->fspath->elem_missed;
> -               ipath->fspath->bytes_missing += fspath_min - fspath;
> -               ipath->fspath->bytes_left = 0;
> -       }
> -
> -       return 0;
> -}
> -
>  /*
>   * this dumps all file system paths to the inode into the ipath struct, provided
>   * is has been created large enough. each path is zero-terminated and accessed
> --
> 2.51.0
>
>
Re: [PATCH v7 5/6] btrfs: move inode_to_path higher in backref.c
Posted by David Sterba 1 week, 5 days ago
On Wed, Nov 19, 2025 at 12:21:52PM +0000, Filipe Manana wrote:
> On Tue, Nov 18, 2025 at 4:16 PM Daniel Vacek <neelx@suse.com> wrote:
> >
> > From: Josef Bacik <josef@toxicpanda.com>
> >
> > We have a prototype and then the definition lower below, we don't need
> > to do this, simply move the function to where the prototype is.
> 
> According to our development notes here:
> 
> https://btrfs.readthedocs.io/en/latest/dev/Development-notes.html
> 
> Under the "Function declarations" section we have:
> 
> "avoid prototypes for static functions, order them in new code in a
> way that does not need it
> 
> but don’t move static functions just to get rid of the prototype"
> 
> So what's the motivation for moving the function?

Right, I thought the other fscrypt patches needed that for some reason
but after checking again they don't, I'll drop the patch. Thanks.
Re: [PATCH v7 5/6] btrfs: move inode_to_path higher in backref.c
Posted by Johannes Thumshirn 1 week, 5 days ago
Looks good,

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>