Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752932AbZK3GOH (ORCPT ); Mon, 30 Nov 2009 01:14:07 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752433AbZK3GOG (ORCPT ); Mon, 30 Nov 2009 01:14:06 -0500 Received: from filer.fsl.cs.sunysb.edu ([130.245.126.2]:51199 "EHLO filer.fsl.cs.sunysb.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752082AbZK3GOF (ORCPT ); Mon, 30 Nov 2009 01:14:05 -0500 Date: Mon, 30 Nov 2009 01:13:36 -0500 Message-Id: <200911300613.nAU6Da0Z022008@agora.fsl.cs.sunysb.edu> From: Erez Zadok To: Valerie Aurora Cc: Jan Blunck , Alexander Viro , Christoph Hellwig , Andy Whitcroft , Scott James Remnant , Sandu Popa Marius , Jan Rekorajski , "J. R. Okajima" , Arnd Bergmann , Vladimir Dronnikov , Felix Fietkau , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 12/41] union-mount: Allow removal of a directory In-reply-to: Your message of "Wed, 21 Oct 2009 12:19:10 PDT." <1256152779-10054-13-git-send-email-vaurora@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2960 Lines: 80 In message <1256152779-10054-13-git-send-email-vaurora@redhat.com>, Valerie Aurora writes: > From: Jan Blunck > > do_whiteout() allows removal of a directory when it has whiteouts but > is logically empty. > > XXX - This patch abuses readdir() to check if the union directory is > logically empty - that is, all the entries are whiteouts (or "." or > ".."). Currently, we have no clean VFS interface to ask the lower > file system if a directory is empty. > > Fixes: > - Add ->is_directory_empty() op > - Add is_directory_empty flag to dentry (ugly dcache populate) > - Ask underlying fs to remove it and look for an error return > - (your idea here) Yeah, this is a difficult issue. I think the best way would be to 1. add an OPTIONAL ->is_directory_empty() inode op. 2. have the VFS use some default/generic behavior ala filldir_is_empty() below if inode->i_op->is_directory_empty is NULL. I assume this behavior will only need to be checked for file systems that support whiteouts in the first place. This'll provide some working behavior for all whiteout-supporting file systems, but allow anyone who wants to develop a more efficient method to provide one. > Signed-off-by: Jan Blunck > Signed-off-by: Valerie Aurora > --- > fs/namei.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 85 insertions(+), 0 deletions(-) > > diff --git a/fs/namei.c b/fs/namei.c > index 5da1635..9a62c75 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2284,6 +2284,91 @@ int vfs_whiteout(struct inode *dir, struct dentry *dentry, int isdir) > } > > /* > + * This is abusing readdir to check if a union directory is logically empty. > + * Al Viro barfed when he saw this, but Val said: "Well, at this point I'm > + * aiming for working, pretty can come later" > + */ > +static int filldir_is_empty(void *__buf, const char *name, int namlen, > + loff_t offset, u64 ino, unsigned int d_type) > +{ Why not make filldir_is_empty() return a bool? That explains more clearly the function's return code. > +static int directory_is_empty(struct dentry *dentry, struct vfsmount *mnt) > +{ This can also return a bool. > +static int do_whiteout(struct nameidata *nd, struct path *path, int isdir) > +{ 'isdir' can be bool. > + struct path safe = { .dentry = dget(nd->path.dentry), > + .mnt = mntget(nd->path.mnt) }; > + struct dentry *dentry = path->dentry; > + int err; You might want to move the initialization of 'struct path safe' down below, and add a BUG_ON(!nd) before that. I think during the development phases of UM, it's a good idea to have a few more debugging BUG_ON's. Erez. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/