]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ovl: narrow locking in ovl_cleanup_index()
authorNeilBrown <neil@brown.name>
Wed, 16 Jul 2025 00:44:22 +0000 (10:44 +1000)
committerChristian Brauner <brauner@kernel.org>
Fri, 18 Jul 2025 09:10:41 +0000 (11:10 +0200)
ovl_cleanup_index() takes a lock on the directory and then does a lookup
and possibly one of two different cleanups.
This patch narrows the locking to use the _unlocked() versions of the
lookup and one cleanup, and just takes the lock for the other cleanup.

A subsequent patch will take the lock into the cleanup.

Signed-off-by: NeilBrown <neil@brown.name>
Link: https://lore.kernel.org/20250716004725.1206467-12-neil@brown.name
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/overlayfs/util.c

index c25c86e0f4da8aa06d793c93e89e1dc684c53378..7a1ca9380601e78d7901531b3640b79e430928a4 100644 (file)
@@ -1078,7 +1078,6 @@ static void ovl_cleanup_index(struct dentry *dentry)
 {
        struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
        struct dentry *indexdir = ovl_indexdir(dentry->d_sb);
-       struct inode *dir = indexdir->d_inode;
        struct dentry *lowerdentry = ovl_dentry_lower(dentry);
        struct dentry *upperdentry = ovl_dentry_upper(dentry);
        struct dentry *index = NULL;
@@ -1114,21 +1113,22 @@ static void ovl_cleanup_index(struct dentry *dentry)
                goto out;
        }
 
-       inode_lock_nested(dir, I_MUTEX_PARENT);
-       index = ovl_lookup_upper(ofs, name.name, indexdir, name.len);
+       index = ovl_lookup_upper_unlocked(ofs, name.name, indexdir, name.len);
        err = PTR_ERR(index);
        if (IS_ERR(index)) {
                index = NULL;
        } else if (ovl_index_all(dentry->d_sb)) {
                /* Whiteout orphan index to block future open by handle */
-               err = ovl_cleanup_and_whiteout(OVL_FS(dentry->d_sb),
-                                              indexdir, index);
+               err = ovl_parent_lock(indexdir, index);
+               if (!err) {
+                       err = ovl_cleanup_and_whiteout(OVL_FS(dentry->d_sb),
+                                                      indexdir, index);
+                       ovl_parent_unlock(indexdir);
+               }
        } else {
                /* Cleanup orphan index entries */
-               err = ovl_cleanup(ofs, dir, index);
+               err = ovl_cleanup_unlocked(ofs, indexdir, index);
        }
-
-       inode_unlock(dir);
        if (err)
                goto fail;