Unionfs: create and consolidate helpers to path-put lower objects
authorErez Zadok <ezk@cs.sunysb.edu>
Mon, 28 Jul 2008 04:25:46 +0000 (00:25 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Wed, 30 Mar 2011 23:31:37 +0000 (19:31 -0400)
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/commonfops.c
fs/unionfs/copyup.c
fs/unionfs/dentry.c
fs/unionfs/fanout.h
fs/unionfs/lookup.c

index 585c5c9fb2cb1e9b09e01e4142c7c4251d123021..5816d41be3ea09c9975e2a42a2cd88c0a5e576da 100644 (file)
@@ -275,15 +275,8 @@ static int do_delayed_copyup(struct file *file)
                        fput(unionfs_lower_file_idx(file, bindex));
                        unionfs_set_lower_file_idx(file, bindex, NULL);
                }
-               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);
-               }
        }
+       path_put_lowers(dentry, bstart, bend, false);
        iput_lowers(dentry->d_inode, bstart, bend, false);
        /* for reg file, we only open it "once" */
        fbend(file) = fbstart(file);
index f20b9845eea747d5d86f5f2c75d75726bd860592..55d48aa9b924c45c1c182ef791a6ff872805f19c 100644 (file)
@@ -866,22 +866,15 @@ void unionfs_postcopyup_setmnt(struct dentry *dentry)
  */
 void unionfs_postcopyup_release(struct dentry *dentry)
 {
-       int bindex;
+       int bstart, bend;
 
        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_lowers(dentry->d_inode, dbstart(dentry)+1, dbend(dentry), false);
+       bstart = dbstart(dentry);
+       bend = dbend(dentry);
+
+       path_put_lowers(dentry, bstart + 1, bend, false);
+       iput_lowers(dentry->d_inode, bstart + 1, bend, false);
 
-       bindex = dbstart(dentry);
-       dbend(dentry) = bindex;
-       ibend(dentry->d_inode) = ibstart(dentry->d_inode) = bindex;
+       dbend(dentry) = bstart;
+       ibend(dentry->d_inode) = ibstart(dentry->d_inode) = bstart;
 }
index a7960ac0829201aaf6468a9d593d834a200dd023..51c0baf47810512e48b4aaee8939843065bcfd89 100644 (file)
@@ -455,8 +455,6 @@ static int unionfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 
 static void unionfs_d_release(struct dentry *dentry)
 {
-       int bindex, bstart, bend;
-
        unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_CHILD);
        if (unlikely(!UNIONFS_D(dentry)))
                goto out;       /* skip if no lower branches */
@@ -471,20 +469,7 @@ static void unionfs_d_release(struct dentry *dentry)
        }
 
        /* Release all the lower dentries */
-       bstart = dbstart(dentry);
-       bend = dbend(dentry);
-       for (bindex = bstart; bindex <= bend; bindex++) {
-               dput(unionfs_lower_dentry_idx(dentry, bindex));
-               unionfs_set_lower_dentry_idx(dentry, bindex, NULL);
-               /* NULL lower mnt is ok if this is a negative dentry */
-               if (!dentry->d_inode && !unionfs_lower_mnt_idx(dentry, bindex))
-                       continue;
-               unionfs_mntput(dentry, bindex);
-               unionfs_set_lower_mnt_idx(dentry, bindex, NULL);
-       }
-       /* free private data (unionfs_dentry_info) here */
-       kfree(UNIONFS_D(dentry)->lower_paths);
-       UNIONFS_D(dentry)->lower_paths = NULL;
+       path_put_lowers_all(dentry, true);
 
        unionfs_unlock_dentry(dentry);
 
@@ -500,7 +485,7 @@ out:
  */
 static void unionfs_d_iput(struct dentry *dentry, struct inode *inode)
 {
-       int bindex, rc;
+       int rc;
 
        BUG_ON(!dentry);
        unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_CHILD);
@@ -508,17 +493,7 @@ static void unionfs_d_iput(struct dentry *dentry, struct inode *inode)
 
        if (!UNIONFS_D(dentry) || dbstart(dentry) < 0)
                goto drop_lower_inodes;
-       for (bindex = dbstart(dentry); 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);
-               }
-       }
-       dbstart(dentry) = dbend(dentry) = -1;
+       path_put_lowers_all(dentry, false);
 
 drop_lower_inodes:
        rc = atomic_read(&inode->i_count);
index 94421f88aab0346155bdd26653b7dc3e8a993c4a..d8977bdd01ad34298e8f6fb78964f966047eabdc 100644 (file)
@@ -326,4 +326,59 @@ static inline void iput_lowers_all(struct inode *inode, bool free_lower)
        ibstart(inode) = ibend(inode) = -1;
 }
 
+/*
+ * dput/mntput all lower dentries and vfsmounts of an unionfs dentry, from
+ * bstart to bend.  If @free_lower is true, then also kfree the memory used
+ * to hold the lower object pointers.
+ *
+ * XXX: implement using path_put VFS macros
+ */
+static inline void path_put_lowers(struct dentry *dentry,
+                                  int bstart, int bend, bool free_lower)
+{
+       struct dentry *lower_dentry;
+       struct vfsmount *lower_mnt;
+       int bindex;
+
+       BUG_ON(!dentry);
+       BUG_ON(!UNIONFS_D(dentry));
+       BUG_ON(bstart < 0);
+
+       for (bindex = bstart; bindex <= bend; bindex++) {
+               lower_dentry = unionfs_lower_dentry_idx(dentry, bindex);
+               if (lower_dentry) {
+                       unionfs_set_lower_dentry_idx(dentry, bindex, NULL);
+                       dput(lower_dentry);
+               }
+               lower_mnt = unionfs_lower_mnt_idx(dentry, bindex);
+               if (lower_mnt) {
+                       unionfs_set_lower_mnt_idx(dentry, bindex, NULL);
+                       mntput(lower_mnt);
+               }
+       }
+
+       if (free_lower) {
+               kfree(UNIONFS_D(dentry)->lower_paths);
+               UNIONFS_D(dentry)->lower_paths = NULL;
+       }
+}
+
+/*
+ * dput/mntput all lower dentries and vfsmounts, and reset start/end branch
+ * indices to -1.
+ */
+static inline void path_put_lowers_all(struct dentry *dentry, bool free_lower)
+{
+       int bstart, bend;
+
+       BUG_ON(!dentry);
+       BUG_ON(!UNIONFS_D(dentry));
+       bstart = dbstart(dentry);
+       bend = dbend(dentry);
+       BUG_ON(bstart < 0);
+
+       path_put_lowers(dentry, bstart, bend, free_lower);
+       dbstart(dentry) = dbend(dentry) = -1;
+}
+
 #endif /* not _FANOUT_H */
index 33be53c5e7b8d900ca5174fdc86e115631cdd096..f6bb7481eedcbed3776559c9d913c0418d70f7d1 100644 (file)
@@ -407,18 +407,12 @@ out_drop:
        d_drop(dentry);
 
 out_free:
-       /* should dput all the underlying dentries on error condition */
-       bstart = dbstart(dentry);
-       if (bstart >= 0) {
-               bend = dbend(dentry);
-               for (bindex = bstart; bindex <= bend; bindex++) {
-                       dput(unionfs_lower_dentry_idx(dentry, bindex));
-                       unionfs_mntput(dentry, bindex);
-               }
-       }
+       /* should dput/mntput all the underlying dentries on error condition */
+       if (dbstart(dentry) >= 0)
+               path_put_lowers_all(dentry, false);
+       /* free lower_paths unconditionally */
        kfree(UNIONFS_D(dentry)->lower_paths);
        UNIONFS_D(dentry)->lower_paths = NULL;
-       dbstart(dentry) = dbend(dentry) = -1;
 
 out:
        if (!err && UNIONFS_D(dentry)) {