From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Howells Subject: [PATCH 44/73] union-mount: Return files found in lower layers in __lookup_union() [ver #2] Date: Tue, 21 Feb 2012 18:03:00 +0000 Message-ID: <20120221180300.25235.63345.stgit@warthog.procyon.org.uk> References: <20120221175721.25235.8901.stgit@warthog.procyon.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: linux-kernel@vger.kernel.org, David Howells To: linux-fsdevel@vger.kernel.org, viro@ZenIV.linux.org.uk, valerie.aurora@gmail.com Return-path: In-Reply-To: <20120221175721.25235.8901.stgit@warthog.procyon.org.uk> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org From: Valerie Aurora If we find a file during union lookup, don't look in any lower layers and replace the topmost path with the file's path. Original-author: Valerie Aurora Signed-off-by: David Howells --- fs/namei.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 009d9b5..f81f24e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1179,11 +1179,31 @@ static int __lookup_union(struct nameidata *nd, struct qstr *name, continue; } + /* Files block everything below them. Special case: If we find + * a file below a directory (which makes no sense), just ignore + * the file and return the directory above it. + */ + if (!S_ISDIR(lower.dentry->d_inode->i_mode)) { + if (topmost->dentry->d_inode && + S_ISDIR(topmost->dentry->d_inode->i_mode)) + goto out_lookup_done; + goto out_found_file; + } + /* XXX - do nothing, more in later patches */ path_put(&lower); } return 0; +out_found_file: + /* Swap out the positive lower dentry with the negative upper + * dentry for this file. Note that the matching mntput() is done + * in link_path_walk(). + */ + dput(topmost->dentry); + *topmost = lower; + return 0; + out_lookup_done: path_put(&lower); return 0;