Re: [PATCH v2] btrfs: send: fix is_current_inode_path() to avoid path resets for common prefixes
Daniel Vacek <[email protected]>
| Newsgroups | org.kernel.vger.linux-btrfs |
|---|---|
| Message-ID | <CAPjX3FfPYBHDS5vyOHfMQVKU-zkyG_hEcAeN6GRtT9eL_rJ_3Q@mail.gmail.com> |
On Mon, 15 Jun 2026 at 19:15, <[email protected]> wrote: > From: Filipe Manana <[email protected]> > > In case the current inode's path is a prefix of the given path, the helper > is_current_inode_path() will return true, which causes the single caller > to reset the current inode's path. While this is not a functional issue, > it makes the caller recompute the current inode's path later. It could > also become a problem in the future in case get new callers for > is_current_inode_path() in more sensitive contexts. > > Example: the current inode path is "/foo/bar" and the path we compare > against is "/foo/bar_xyz". > > Fix this by returning true only if we have exact matches. > > Signed-off-by: Filipe Manana <[email protected]> This version looks good. Reviewed-by: Daniel Vacek <[email protected]> > --- > > V2: Simplify and avoid false positives in case of something like > "/foo/bar" vs "foo/bar/xyz". > > fs/btrfs/send.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c > index a3c8f2d889bb..d664e470fd77 100644 > --- a/fs/btrfs/send.c > +++ b/fs/btrfs/send.c > @@ -627,7 +627,14 @@ static inline bool is_current_inode_path(const struct send_ctx *sctx, > { > const struct fs_path *cur = &sctx->cur_inode_path; > > - return (strncmp(path->start, cur->start, fs_path_len(cur)) == 0); > + /* > + * Path may be a prefix of the current inode's path, so return false if > + * the lengths are different. > + */ > + if (fs_path_len(path) != fs_path_len(cur)) > + return false; > + > + return (strcmp(path->start, cur->start) == 0); > } > > static struct btrfs_path *alloc_path_for_send(void) > -- > 2.47.2 > >