VFS/autofs: try_lookup_one_len() does not need any locks
authorNeilBrown <neil@brown.name>
Thu, 13 Mar 2025 22:32:54 +0000 (09:32 +1100)
committerChristian Brauner <brauner@kernel.org>
Tue, 18 Mar 2025 14:34:27 +0000 (15:34 +0100)
try_lookup_one_len() is identical to lookup_one_unlocked() except that
it doesn't include the call to lookup_slow().  The latter doesn't need
the inode to be locked, so the former cannot either.

So fix the documentation, remove the WARN_ON and fix the only caller to
not take the lock.

Signed-off-by: NeilBrown <neilb@suse.de>
Link: https://lore.kernel.org/r/174190517441.9342.5956460781380903128@noble.neil.brown.name
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/autofs/dev-ioctl.c
fs/namei.c

index 6d57efbb81102edcfe86070d699eb0ceb833d2b1..c5a6aae12d2c5d3e3d10ee2e2d8e1acf23f7cbdf 100644 (file)
@@ -442,7 +442,6 @@ static int autofs_dev_ioctl_timeout(struct file *fp,
                sbi->exp_timeout = timeout * HZ;
        } else {
                struct dentry *base = fp->f_path.dentry;
-               struct inode *inode = base->d_inode;
                int path_len = param->size - AUTOFS_DEV_IOCTL_SIZE - 1;
                struct dentry *dentry;
                struct autofs_info *ino;
@@ -460,9 +459,7 @@ static int autofs_dev_ioctl_timeout(struct file *fp,
                                "the parent autofs mount timeout which could "
                                "prevent shutdown\n");
 
-               inode_lock_shared(inode);
                dentry = try_lookup_one_len(param->path, base, path_len);
-               inode_unlock_shared(inode);
                if (IS_ERR_OR_NULL(dentry))
                        return dentry ? PTR_ERR(dentry) : -ENOENT;
                ino = autofs_dentry_ino(dentry);
index 345e20143b5d20381f02fcb921a67eca1ab3d1c7..b6eca442ab7acc1dbf3d62a72ff4272f4d5b814a 100644 (file)
@@ -2864,15 +2864,14 @@ static int lookup_one_common(struct mnt_idmap *idmap,
  * Note that this routine is purely a helper for filesystem usage and should
  * not be called by generic code.
  *
- * The caller must hold base->i_mutex.
+ * No locks need be held - only a counted reference to @base is needed.
+ *
  */
 struct dentry *try_lookup_one_len(const char *name, struct dentry *base, int len)
 {
        struct qstr this;
        int err;
 
-       WARN_ON_ONCE(!inode_is_locked(base->d_inode));
-
        err = lookup_one_common(&nop_mnt_idmap, name, base, len, &this);
        if (err)
                return ERR_PTR(err);