linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: hch@infradead.org
Subject: [PATCH 11/76] whiteout: Allow removal of a directory with whiteouts
Date: Fri, 17 Jun 2011 17:01:47 +0100	[thread overview]
Message-ID: <20110617160147.30314.11524.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20110617160008.30314.22757.stgit@warthog.procyon.org.uk>

From: Jan Blunck <jblunck@suse.de>

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)

Signed-off-by: Jan Blunck <jblunck@suse.de>
Signed-off-by: Valerie Aurora <vaurora@redhat.com>
---

 fs/namei.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 99ca663..0014052 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -32,6 +32,7 @@
 #include <linux/fcntl.h>
 #include <linux/device_cgroup.h>
 #include <linux/fs_struct.h>
+#include <linux/init_task.h>
 #include <asm/uaccess.h>
 
 #include "internal.h"
@@ -2645,6 +2646,95 @@ error_unlock:
  * dentry, and if that is true (possibly after pruning the dcache),
  * then we drop the dentry now.
  *
+ * XXX - We are abusing readdir to check if a union directory is
+ * logically empty.
+ */
+static int filldir_is_empty(void *__buf, const char *name, int namelen,
+			    loff_t offset, u64 ino, unsigned int d_type)
+{
+	int *is_empty = __buf;
+
+	switch (namelen) {
+	case 2:
+		if (name[1] != '.')
+			break;
+	case 1:
+		if (name[0] != '.')
+			break;
+		return 0;
+	}
+
+	if (d_type == DT_WHT)
+		return 0;
+
+	*is_empty = 0;
+	return 1; /* no point scanning further */
+}
+
+static int directory_is_empty(struct path *path)
+{
+	struct file *file;
+	int err;
+	int is_empty = 1;
+
+	BUG_ON(!S_ISDIR(path->dentry->d_inode->i_mode));
+
+	/* references for the file pointer */
+	path_get(path);
+
+	file = dentry_open(path->dentry, path->mnt, O_RDONLY, &init_cred);
+	if (IS_ERR(file))
+		return 0;
+
+	err = vfs_readdir(file, filldir_is_empty, &is_empty);
+
+	fput(file);
+	return is_empty;
+}
+
+static int do_whiteout(struct nameidata *nd, struct path *path, int isdir)
+{
+	struct path safe = nd->path;
+	struct dentry *dentry = path->dentry;
+	int err;
+
+	path_get(&safe);
+
+	err = may_delete(nd->path.dentry->d_inode, dentry, isdir);
+	if (err)
+		goto out;
+
+	err = -ENOTEMPTY;
+	if (isdir && !directory_is_empty(path))
+		goto out;
+
+	if (nd->path.dentry != dentry->d_parent) {
+		dentry = __lookup_hash(&path->dentry->d_name, nd->path.dentry,
+				       nd);
+		err = PTR_ERR(dentry);
+		if (IS_ERR(dentry))
+			goto out;
+
+		dput(path->dentry);
+		if (path->mnt != safe.mnt)
+			mntput(path->mnt);
+		path->mnt = nd->path.mnt;
+		path->dentry = dentry;
+	}
+
+	err = vfs_whiteout(nd->path.dentry->d_inode, dentry, isdir);
+
+out:
+	path_put(&safe);
+	return err;
+}
+
+/*
+ * We try to drop the dentry early: we should have
+ * a usage count of 2 if we're the only user of this
+ * dentry, and if that is true (possibly after pruning
+ * the dcache), then we drop the dentry now.
+ *
  * A low-level filesystem can, if it choses, legally
  * do a
  *


  parent reply	other threads:[~2011-06-17 16:01 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-17 16:00 [RFC][PATCH 00/76] Union Mount David Howells
2011-06-17 16:00 ` [PATCH 01/76] VFS: Make clone_mnt()/copy_tree()/collect_mounts() return errors David Howells
2011-06-17 16:00 ` [PATCH 02/76] VFS: Add hard read-only users count to superblock David Howells
2011-06-17 16:00 ` [PATCH 03/76] VFS: Add CL_NO_SHARED flag to clone_mnt()/copy_tree() David Howells
2011-06-17 16:00 ` [PATCH 04/76] VFS: Add CL_NO_SLAVE " David Howells
2011-06-17 16:00 ` [PATCH 05/76] VFS: Add CL_MAKE_HARD_READONLY " David Howells
2011-06-17 16:01 ` [PATCH 06/76] VFS: Comment follow_mount() and friends David Howells
2011-06-17 16:53   ` Christoph Hellwig
2011-06-17 16:01 ` [PATCH 07/76] VFS: Make lookup_hash() return a struct path David Howells
2011-06-17 16:01 ` [PATCH 08/76] whiteout/NFSD: Don't return information about whiteouts to userspace David Howells
2011-06-17 16:01 ` [PATCH 09/76] whiteout: Define flags and operations for opaque inodes David Howells
2011-06-17 16:01 ` [PATCH 10/76] whiteout: Add vfs_whiteout() and whiteout inode operation David Howells
2011-06-17 16:01 ` David Howells [this message]
2011-06-17 16:01 ` [PATCH 12/76] tmpfs: Add whiteout support David Howells
2011-06-17 16:02 ` [PATCH 13/76] ext2: Add ext2_dirent_in_use() David Howells
2011-06-17 16:02 ` [PATCH 14/76] ext2: Split ext2_add_entry() from ext2_add_link() David Howells
2011-06-17 16:02 ` [PATCH 15/76] ext2: Add whiteout support David Howells
2011-06-17 16:02 ` [PATCH 16/76] jffs2: " David Howells
2011-06-17 16:02 ` [PATCH 17/76] VFS: Basic fallthru definitions David Howells
2011-06-17 16:02 ` [PATCH 18/76] ext2: Add fallthru support David Howells
2011-06-17 16:03 ` [PATCH 19/76] tmpfs: " David Howells
2011-06-17 16:03 ` [PATCH 20/76] jffs2: " David Howells
2011-06-17 16:03 ` [PATCH 21/76] union-mount: Union mounts documentation David Howells
2011-06-17 16:03 ` [PATCH 22/76] union-mount: Introduce MNT_UNION and MS_UNION flags David Howells
2011-06-17 16:03 ` [PATCH 23/76] union-mount: Add CONFIG_UNION_MOUNT option David Howells
2011-06-17 16:03 ` [PATCH 24/76] union-mount: Create union_stack structure David Howells
2011-06-17 16:03 ` [PATCH 25/76] union-mount: Add two superblock fields for union mounts David Howells
2011-06-17 16:04 ` [PATCH 26/76] union-mount: Add union_alloc() David Howells
2011-06-17 16:04 ` [PATCH 27/76] union-mount: Add union_find_dir() David Howells
2011-06-17 16:04 ` [PATCH 28/76] union-mount: Create d_free_unions() David Howells
2011-06-17 16:04 ` [PATCH 29/76] union-mount: Free union stack on removal of topmost dentry from dcache David Howells
2011-06-17 16:04 ` [PATCH 30/76] union-mount: Create union_add_dir() David Howells
2011-06-17 16:04 ` [PATCH 31/76] union-mount: Add union_create_topmost_dir() David Howells
2011-06-17 16:04 ` [PATCH 32/76] union-mount: Create IS_MNT_UNION() David Howells
2011-06-17 16:05 ` [PATCH 33/76] union-mount: Create needs_lookup_union() David Howells
2011-06-17 16:05 ` [PATCH 34/76] union-mount: Create check_topmost_union_mnt() David Howells
2011-06-17 16:05 ` [PATCH 35/76] union-mount: Add clone_union_tree() and put_union_sb() David Howells
2011-06-17 16:05 ` [PATCH 36/76] union-mount: Create build_root_union() David Howells
2011-06-17 16:05 ` [PATCH 37/76] union-mount: Create prepare_mnt_union() and cleanup_mnt_union() David Howells
2011-06-17 16:05 ` [PATCH 38/76] union-mount: Prevent improper union-related remounts David Howells
2011-06-17 16:05 ` [PATCH 39/76] union-mount: Prevent topmost file system from being mounted elsewhere David Howells
2011-06-17 16:06 ` [PATCH 40/76] union-mount: Prevent bind mounts of union mounts David Howells
2011-06-17 16:06 ` [PATCH 41/76] union-mount: Implement union mount David Howells
2011-06-17 16:06 ` [PATCH 42/76] union-mount: Temporarily disable some syscalls David Howells
2011-06-17 16:06 ` [PATCH 43/76] union-mount: Basic infrastructure of __lookup_union() David Howells
2011-06-17 16:06 ` [PATCH 44/76] union-mount: Process negative dentries in __lookup_union() David Howells
2011-06-17 16:06 ` [PATCH 45/76] union-mount: Return files found in lower layers " David Howells
2011-06-17 16:06 ` [PATCH 46/76] union-mount: Build union stack " David Howells
2011-06-17 16:07 ` [PATCH 47/76] union-mount: Follow mount " David Howells
2011-06-17 16:07 ` [PATCH 48/76] union-mount: Add lookup_union() David Howells
2011-06-17 16:07 ` [PATCH 49/76] union-mount: Add do_lookup_union() wrapper for __lookup_union() David Howells
2011-06-17 16:07 ` [PATCH 50/76] union-mount: Call union lookup functions in lookup path David Howells
2011-06-17 16:07 ` [PATCH 51/76] union-mount: Create whiteout on unlink() David Howells
2011-06-17 16:07 ` [PATCH 52/76] union-mount: Create whiteout on rmdir() David Howells
2011-06-17 16:07 ` [PATCH 53/76] union-mount: Set opaque flag on new directories in unioned file systems David Howells
2011-06-17 16:08 ` [PATCH 54/76] union-mount: Copy up directory entries on first readdir() David Howells
2011-06-17 16:08 ` [PATCH 55/76] union-mount: Add generic_readdir_fallthru() helper David Howells
2011-06-17 16:08 ` [PATCH 56/76] fallthru: ext2 support for lookup of d_type/d_ino in fallthrus David Howells
2011-06-17 16:08 ` [PATCH 57/76] fallthru: tmpfs " David Howells
2011-06-17 16:08 ` [PATCH 58/76] fallthru: jffs2 " David Howells
2011-06-17 16:08 ` [PATCH 59/76] VFS: Split inode_permission() and create path_permission() David Howells
2011-06-17 16:09 ` [PATCH 60/76] VFS: Create user_path_nd() to lookup both parent and target David Howells
2011-06-17 16:09 ` [PATCH 61/76] union-mount: In-kernel file copyup routines David Howells
2011-06-17 16:09 ` [PATCH 62/76] union-mount: Implement union-aware access()/faccessat() David Howells
2011-06-17 16:09 ` [PATCH 63/76] union-mount: Implement union-aware link() David Howells
2011-06-17 16:09 ` [PATCH 64/76] union-mount: Implement union-aware rename() David Howells
2011-06-17 16:09 ` [PATCH 65/76] union-mount: Implement union-aware writable open() David Howells
2011-06-17 16:09 ` [PATCH 66/76] union-mount: Implement union-aware chown() David Howells
2011-06-17 16:10 ` [PATCH 67/76] union-mount: Implement union-aware truncate() David Howells
2011-06-17 16:10 ` [PATCH 68/76] union-mount: Implement union-aware chmod()/fchmodat() David Howells
2011-06-17 16:10 ` [PATCH 69/76] union-mount: Implement union-aware lchown() David Howells
2011-06-17 16:10 ` [PATCH 70/76] union-mount: Implement union-aware utimensat() David Howells
2011-06-17 16:10 ` [PATCH 71/76] union-mount: Implement union-aware setxattr() David Howells
2011-06-17 16:10 ` [PATCH 72/76] union-mount: Implement union-aware lsetxattr() David Howells
2011-06-17 16:10 ` [PATCH 73/76] union-mount: Pass mount flags to sget() David Howells
2011-06-17 16:11 ` [PATCH 74/76] union-mount: Duplicate the i_{, dir_}mutex lock classes and use for upper layer David Howells
2011-06-17 16:11 ` [PATCH 76/76] Temporary commit David Howells
2011-06-17 16:23 ` [PATCH 75/76] Ext2: Unionmount devel David Howells
2011-06-17 16:44 ` [RFC][PATCH 00/76] Union Mount Sedat Dilek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110617160147.30314.11524.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).