Skip to content

Commit a45ee87

Browse files
neilbrownbrauner
authored andcommitted
ovl: narrow locking in ovl_workdir_cleanup_recurse()
Only take the dir lock when needed, rather than for the whole loop. Signed-off-by: NeilBrown <neil@brown.name> Link: https://lore.kernel.org/20250716004725.1206467-15-neil@brown.name Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent d56c6fe commit a45ee87

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

fs/overlayfs/readdir.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ static int ovl_workdir_cleanup_recurse(struct ovl_fs *ofs, const struct path *pa
11221122
if (err)
11231123
goto out;
11241124

1125-
inode_lock_nested(dir, I_MUTEX_PARENT);
11261125
list_for_each_entry(p, &list, l_node) {
11271126
struct dentry *dentry;
11281127

@@ -1137,16 +1136,21 @@ static int ovl_workdir_cleanup_recurse(struct ovl_fs *ofs, const struct path *pa
11371136
err = -EINVAL;
11381137
break;
11391138
}
1140-
dentry = ovl_lookup_upper(ofs, p->name, path->dentry, p->len);
1139+
dentry = ovl_lookup_upper_unlocked(ofs, p->name, path->dentry, p->len);
11411140
if (IS_ERR(dentry))
11421141
continue;
1143-
if (dentry->d_inode)
1144-
err = ovl_workdir_cleanup(ofs, dir, path->mnt, dentry, level);
1142+
if (dentry->d_inode) {
1143+
err = ovl_parent_lock(path->dentry, dentry);
1144+
if (!err) {
1145+
err = ovl_workdir_cleanup(ofs, dir, path->mnt,
1146+
dentry, level);
1147+
ovl_parent_unlock(path->dentry);
1148+
}
1149+
}
11451150
dput(dentry);
11461151
if (err)
11471152
break;
11481153
}
1149-
inode_unlock(dir);
11501154
out:
11511155
ovl_cache_free(&list);
11521156
return err;

0 commit comments

Comments
 (0)