[PATCH 09/16] Unionfs: don't create whiteouts on rightmost branch

From: Erez Zadok
Date: Mon Nov 26 2007 - 11:50:58 EST


If we are unlinking/rmdir'ing an object on the rightmost branch, there's no
need to create a whiteout there: this saves on storage space and inodes.
Also, in the (degenerate) case of having only one branch, this really saves
on whiteouts.

CC: Hugh Dickins <hugh@xxxxxxxxxxx>

Signed-off-by: Erez Zadok <ezk@xxxxxxxxxxxxx>
---
fs/unionfs/unlink.c | 25 +++++++++++++++++++++----
1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/fs/unionfs/unlink.c b/fs/unionfs/unlink.c
index f65245d..423ff36 100644
--- a/fs/unionfs/unlink.c
+++ b/fs/unionfs/unlink.c
@@ -53,14 +53,23 @@ static int unionfs_unlink_whiteout(struct inode *dir, struct dentry *dentry)
if (err && !IS_COPYUP_ERR(err))
goto out;

+ /*
+ * We create whiteouts if (1) there was an error unlinking the main
+ * file; (2) there is a lower priority file with the same name
+ * (dbopaque); (3) the branch in which the file is not the last
+ * (rightmost0 branch. The last rule is an optimization to avoid
+ * creating all those whiteouts if there's no chance they'd be
+ * masking any lower-priority branch, as well as unionfs is used
+ * with only one branch (using only one branch, while odd, is still
+ * possible).
+ */
if (err) {
if (dbstart(dentry) == 0)
goto out;
err = create_whiteout(dentry, dbstart(dentry) - 1);
} else if (dbopaque(dentry) != -1) {
- /* There is a lower lower-priority file with the same name. */
err = create_whiteout(dentry, dbopaque(dentry));
- } else {
+ } else if (dbstart(dentry) < sbend(dentry->d_sb)) {
err = create_whiteout(dentry, dbstart(dentry));
}

@@ -167,9 +176,17 @@ int unionfs_rmdir(struct inode *dir, struct dentry *dentry)
err = unionfs_rmdir_first(dir, dentry, namelist);
dstart = dbstart(dentry);
dend = dbend(dentry);
- /* create whiteout */
+ /*
+ * We create a whiteout for the directory if there was an error to
+ * rmdir the first directory entry in the union. Otherwise, we
+ * create a whiteout only if there is no chance that a lower
+ * priority branch might also have the same named directory. IOW,
+ * if there is not another same-named directory at a lower priority
+ * branch, then we don't need to create a whiteout for it.
+ */
if (!err) {
- err = create_whiteout(dentry, dstart);
+ if (dstart < dend)
+ err = create_whiteout(dentry, dstart);
} else {
int new_err;

--
1.5.2.2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/