commit 6cc18072d543cf8671739f7eec04938221f49f77
Author: Erez Zadok <[EMAIL PROTECTED](none)>
Date: Fri May 18 01:31:14 2007 -0400
Post-copyup helper functions
Two functions which are very useful to execute common actions needed after a
copy-up had taken place.
diff --git a/fs/unionfs/copyup.c b/fs/unionfs/copyup.c
index e0f637e..02aa62a 100644
--- a/fs/unionfs/copyup.c
+++ b/fs/unionfs/copyup.c
@@ -813,3 +813,51 @@ out:
kfree(path);
return hidden_dentry;
}
+
+/* set lower mnt of dentry+parents to the first parent node that has an mnt */
+void unionfs_inherit_mnt(struct dentry *dentry)
+{
+ struct dentry *parent, *hasone;
+ int bindex = dbstart(dentry);
+
+ if (unionfs_lower_mnt_idx(dentry, bindex))
+ return;
+ hasone = dentry->d_parent;
+ /* this loop should stop at root dentry */
+ while (!unionfs_lower_mnt_idx(hasone, bindex)) {
+ hasone = hasone->d_parent;
+ }
+ parent = dentry;
+ while (!unionfs_lower_mnt_idx(parent, bindex)) {
+ unionfs_set_lower_mnt_idx(parent, bindex,
+ unionfs_mntget(hasone, bindex));
+ parent = parent->d_parent;
+ }
+}
+
+/*
+ * Regular files should have only one lower object(s). On copyup, we may
+ * have leftover objects from previous branches. So purge all such extra
+ * objects and keep only the most recent, leftmost, copied-up one.
+ */
+void unionfs_purge_extras(struct dentry *dentry)
+{
+ int bindex;
+
+ BUG_ON(S_ISDIR(dentry->d_inode->i_mode));
+ for (bindex=dbstart(dentry)+1; bindex<=dbend(dentry); bindex++) {
+ if (unionfs_lower_mnt_idx(dentry, bindex)) {
+ unionfs_mntput(dentry, bindex);
+ unionfs_set_lower_mnt_idx(dentry, bindex, NULL);
+ }
+ if (unionfs_lower_dentry_idx(dentry, bindex)) {
+ dput(unionfs_lower_dentry_idx(dentry, bindex));
+ unionfs_set_lower_dentry_idx(dentry, bindex, NULL);
+ iput(unionfs_lower_inode_idx(dentry->d_inode, bindex));
+ unionfs_set_lower_inode_idx(dentry->d_inode, bindex,
NULL);
+ }
+ }
+ bindex = dbstart(dentry);
+ set_dbend(dentry, bindex);
+ ibend(dentry->d_inode) = ibstart(dentry->d_inode) = bindex;
+}
diff --git a/fs/unionfs/union.h b/fs/unionfs/union.h
index 62eaf39..b35dd84 100644
--- a/fs/unionfs/union.h
+++ b/fs/unionfs/union.h
@@ -280,6 +280,9 @@ extern int copyup_named_file(struct inode *dir, struct file
*file,
extern int copyup_dentry(struct inode *dir, struct dentry *dentry, int bstart,
int new_bindex, struct file **copyup_file,
loff_t len);
+/* helper functions for post-copyup cleanup */
+extern void unionfs_inherit_mnt(struct dentry *dentry);
+extern void unionfs_purge_extras(struct dentry *dentry);
extern int unionfs_get_nlinks(struct inode *inode);
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs