Re: [PATCH v2] btrfs: send: fix is_current_inode_path() to avoid path resets for common prefixes
Qu Wenruo <[email protected]>
| Newsgroups | org.kernel.vger.linux-btrfs |
|---|---|
| Message-ID | <[email protected]> |
在 2026/6/16 02:44, [email protected] 写道: > 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]> > --- > > 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); Can we just use strcmp without string length check? It looks like fs_path is always NUL terminated. E.g. fs_path_prepare_for_add() always reset *p->end to 0. So we can just use strcmp() to compare two NUL terminated paths. Thanks, Qu > } > > static struct btrfs_path *alloc_path_for_send(void)