Unionfs: delete whiteouts in sticky directories
authorErez Zadok <ezk@cs.sunysb.edu>
Tue, 27 Nov 2007 00:54:09 +0000 (19:54 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 27 Nov 2007 00:54:09 +0000 (19:54 -0500)
This is needed to maintain Unix semantics.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/inode.c

index b60a3569d1ea4ea97a8d564e04edaa489cb090d5..8df67f033a71f5d277f633dcfb941ec7e41eae77 100644 (file)
@@ -89,6 +89,23 @@ static int unionfs_create(struct inode *parent, struct dentry *dentry,
                        err = vfs_unlink(lower_dir_dentry->d_inode, wh_dentry);
                        unlock_dir(lower_dir_dentry);
 
+                       /*
+                        * Whiteouts are special files and should be deleted
+                        * no matter what (as if they never existed), in
+                        * order to allow this create operation to succeed.
+                        * This is especially important in sticky
+                        * directories: a whiteout may have been created by
+                        * one user, but the newly created file may be
+                        * created by another user.  Therefore, in order to
+                        * maintain Unix semantics, if the vfs_unlink above
+                        * ailed, then we have to try to directly unlink the
+                        * whiteout.  Note: in the ODF version of unionfs,
+                        * whiteout are handled much more cleanly.
+                        */
+                       if (err == -EPERM) {
+                               struct inode *inode = lower_dir_dentry->d_inode;
+                               err = inode->i_op->unlink(inode, wh_dentry);
+                       }
                        if (err) {
                                printk(KERN_ERR "unionfs: create: could not "
                                       "unlink whiteout, err = %d\n", err);