From: NeilBrown Date: Wed, 16 Jul 2025 00:44:25 +0000 (+1000) Subject: ovl: narrow locking in ovl_workdir_cleanup_recurse() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a45ee87ded78876f8106a255f726b89aa69cd7a4;p=thirdparty%2Fkernel%2Flinux.git 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 Link: https://lore.kernel.org/20250716004725.1206467-15-neil@brown.name Reviewed-by: Amir Goldstein Signed-off-by: Christian Brauner --- diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c index 95d5284daf8d9..b0f9e5a00c1a5 100644 --- a/fs/overlayfs/readdir.c +++ b/fs/overlayfs/readdir.c @@ -1122,7 +1122,6 @@ static int ovl_workdir_cleanup_recurse(struct ovl_fs *ofs, const struct path *pa if (err) goto out; - inode_lock_nested(dir, I_MUTEX_PARENT); list_for_each_entry(p, &list, l_node) { struct dentry *dentry; @@ -1137,16 +1136,21 @@ static int ovl_workdir_cleanup_recurse(struct ovl_fs *ofs, const struct path *pa err = -EINVAL; break; } - dentry = ovl_lookup_upper(ofs, p->name, path->dentry, p->len); + dentry = ovl_lookup_upper_unlocked(ofs, p->name, path->dentry, p->len); if (IS_ERR(dentry)) continue; - if (dentry->d_inode) - err = ovl_workdir_cleanup(ofs, dir, path->mnt, dentry, level); + if (dentry->d_inode) { + err = ovl_parent_lock(path->dentry, dentry); + if (!err) { + err = ovl_workdir_cleanup(ofs, dir, path->mnt, + dentry, level); + ovl_parent_unlock(path->dentry); + } + } dput(dentry); if (err) break; } - inode_unlock(dir); out: ovl_cache_free(&list); return err;