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

From: Filipe Manana

Date: Wed Nov 19 2025 - 07:22:31 EST


On Tue, Nov 18, 2025 at 4:16 PM Daniel Vacek <neelx@xxxxxxxx> wrote:
>
> From: Josef Bacik <josef@xxxxxxxxxxxxxx>
>
> 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@xxxxxxxxxxxxxx>
> ---
> 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
>
>