Unionfs: create and consolidate helpers to path-put lower objects
authorErez Zadok <ezk@cs.sunysb.edu>
Mon, 28 Jul 2008 06:15:43 +0000 (02:15 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Mon, 28 Jul 2008 06:15:43 +0000 (02:15 -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 b499f13d6ee874ac201251def938b1915cdc740d..822646b65de30b668098d28799aca741142582f4 100644 (file)
@@ -274,15 +274,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 1c5b28febb5ba00534b72a5dbde2b280ce03a1bc..6dd14b4ccea4ff5cdb59ca122fe5832e8bfb8871 100644 (file)
@@ -863,22 +863,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 7780f3df3b9e132dc86f6c587318f58597cd09be..919cbdbec049f679b0463dcbb2427e018711cb7c 100644 (file)
@@ -447,8 +447,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 */
@@ -463,20 +461,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);
 
@@ -492,7 +477,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);
@@ -500,17 +485,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 7495da8ac76b7329427d5722fcced69a1277e72e..15baf6efd71f0882b81a4606e59fdc0da6b63d17 100644 (file)
@@ -327,4 +327,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 f1426158fdc5873e08d3bb3e7ed20901e7ca53dc..7dfacc5aee37af3d0cd356cd38abf8c4e0b2ea1f 100644 (file)
@@ -419,18 +419,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)) {