From patchwork Tue Mar 22 13:21:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 8642481 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CE3709F36E for ; Tue, 22 Mar 2016 13:20:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E6D820155 for ; Tue, 22 Mar 2016 13:20:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4212F20259 for ; Tue, 22 Mar 2016 13:19:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758755AbcCVNTq (ORCPT ); Tue, 22 Mar 2016 09:19:46 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34424 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758449AbcCVNTp (ORCPT ); Tue, 22 Mar 2016 09:19:45 -0400 Received: by mail-wm0-f66.google.com with SMTP id p65so30078565wmp.1 for ; Tue, 22 Mar 2016 06:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=xGwiLUuH5GzPPjBP8JzEkNxadRKMUtQTYUXHAVCe+/k=; b=gGwetmk+0BSTkRKI4iajSsTCzGPQ9LC6tpvPK8+AengllgXoekS6Lmv3749unGkYe4 SF6MRBQao28cfkIJtvhyKE/ktgaJ0sIeBdwPt+8B6Fm3a12NPWwYJobANzMH/RSu22SN oqDhuw2AjoVHJquTuPs6iRtIzFWlsO9bUOujE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=xGwiLUuH5GzPPjBP8JzEkNxadRKMUtQTYUXHAVCe+/k=; b=S7ulU5I8c7oE9mG6srRUoXjm3s4Xp/oo7jczJNFUAntQKQX+HLSUvKWPChbCmXm6r8 XJPnGZcCFhE4WvOz4W6/aCLeyIfpRMc/JBoa27Ac0+dLfHWBcH+wzp/Ee+I6NqKTuVuO hb8Ytld7MTAbmYu8vOE1CQiTK8c1swuu3vstJDaEIqUWmfDgnQQHUTk5IhQXKOi6xvm0 gYWu2wRS/+zbyB+um2xDXJUSGPJWEGRKVGVWSLj5vZOWY/JQxM3ihM/yi6QubXviWRYO TC7F1Qnjcgx9Vlk7FGDAWWuiaiWxpiMJTcYAZLP6fEtc+jnh4LRRsSpr1dK1eFkcSea5 T/Bg== X-Gm-Message-State: AD7BkJJfmwAK/AMx5tMybMpAGCXVnR6YzywBxzDh9oA9DTHhjLG3+we3RZo6NatwzBz4Nw== X-Received: by 10.28.178.208 with SMTP id b199mr19050724wmf.51.1458652783595; Tue, 22 Mar 2016 06:19:43 -0700 (PDT) Received: from tucsk (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id pd1sm30253933wjb.19.2016.03.22.06.19.42 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 06:19:43 -0700 (PDT) Date: Tue, 22 Mar 2016 14:21:03 +0100 From: Miklos Szeredi To: Al Viro Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH 1/2] vfs: export lookup_hash() to modules Message-ID: <20160322132103.GD11906@tucsk> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Overlayfs needs lookup without inode_permission() and already has the name hash (in form of dentry->d_name on overlayfs dentry). It also doesn't support filesystems with d_op->d_hash() so basically it only needs __lookup_hash() from lookup_one_len(). Rename __lookup_hash() to lookup_hash() and export to modules. Signed-off-by: Miklos Szeredi --- fs/namei.c | 35 ++++++++++++++++++++++++++--------- include/linux/namei.h | 2 ++ 2 files changed, 28 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/fs/namei.c +++ b/fs/namei.c @@ -1492,8 +1492,24 @@ static struct dentry *lookup_real(struct return dentry; } -static struct dentry *__lookup_hash(const struct qstr *name, - struct dentry *base, unsigned int flags) +/** + * lookup_hash - lookup single pathname component on already hashed name + * @name: name and hash to lookup + * @base: base directory to lookup from + * @flags: lookup flags + * + * The name must have been verified and hashed (see lookup_one_len()). Using + * this after just full_name_hash() is unsafe. + * + * This function also doesn't check for search permission on base directory. + * + * Use lookup_one_len() or lookup_one_len_unlocked() instead, unless you really + * know what you are doing. + * + * The caller must hold base->i_mutex. + */ +struct dentry *lookup_hash(const struct qstr *name, + struct dentry *base, unsigned int flags) { struct dentry *dentry = lookup_dcache(name, base, flags); @@ -1506,6 +1522,7 @@ static struct dentry *__lookup_hash(cons return lookup_real(base->d_inode, dentry, flags); } +EXPORT_SYMBOL(lookup_hash); static int lookup_fast(struct nameidata *nd, struct path *path, struct inode **inode, @@ -2229,7 +2246,7 @@ struct dentry *kern_path_locked(const ch return ERR_PTR(-EINVAL); } inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT); - d = __lookup_hash(&last, path->dentry, 0); + d = lookup_hash(&last, path->dentry, 0); if (IS_ERR(d)) { inode_unlock(path->dentry->d_inode); path_put(path); @@ -2313,7 +2330,7 @@ struct dentry *lookup_one_len(const char if (err) return ERR_PTR(err); - return __lookup_hash(&this, base, 0); + return lookup_hash(&this, base, 0); } EXPORT_SYMBOL(lookup_one_len); @@ -3476,7 +3493,7 @@ static struct dentry *filename_create(in */ lookup_flags |= LOOKUP_CREATE | LOOKUP_EXCL; inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT); - dentry = __lookup_hash(&last, path->dentry, lookup_flags); + dentry = lookup_hash(&last, path->dentry, lookup_flags); if (IS_ERR(dentry)) goto unlock; @@ -3756,7 +3773,7 @@ static long do_rmdir(int dfd, const char goto exit1; inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT); - dentry = __lookup_hash(&last, path.dentry, lookup_flags); + dentry = lookup_hash(&last, path.dentry, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) goto exit2; @@ -3878,7 +3895,7 @@ static long do_unlinkat(int dfd, const c goto exit1; retry_deleg: inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT); - dentry = __lookup_hash(&last, path.dentry, lookup_flags); + dentry = lookup_hash(&last, path.dentry, lookup_flags); error = PTR_ERR(dentry); if (!IS_ERR(dentry)) { /* Why not before? Because we want correct error value */ @@ -4407,7 +4424,7 @@ SYSCALL_DEFINE5(renameat2, int, olddfd, retry_deleg: trap = lock_rename(new_path.dentry, old_path.dentry); - old_dentry = __lookup_hash(&old_last, old_path.dentry, lookup_flags); + old_dentry = lookup_hash(&old_last, old_path.dentry, lookup_flags); error = PTR_ERR(old_dentry); if (IS_ERR(old_dentry)) goto exit3; @@ -4415,7 +4432,7 @@ SYSCALL_DEFINE5(renameat2, int, olddfd, error = -ENOENT; if (d_is_negative(old_dentry)) goto exit4; - new_dentry = __lookup_hash(&new_last, new_path.dentry, lookup_flags | target_flags); + new_dentry = lookup_hash(&new_last, new_path.dentry, lookup_flags | target_flags); error = PTR_ERR(new_dentry); if (IS_ERR(new_dentry)) goto exit4; --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -79,6 +79,8 @@ extern int kern_path_mountpoint(int, con extern struct dentry *lookup_one_len(const char *, struct dentry *, int); extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, int); +struct qstr; +extern struct dentry *lookup_hash(const struct qstr *, struct dentry *, unsigned int); extern int follow_down_one(struct path *); extern int follow_down(struct path *);