commit 473b1d0c6d5f8477e001313c99b5cc56fbdaf5f1
Author: Erez Zadok <[EMAIL PROTECTED](none)>
Date:   Wed May 23 00:03:59 2007 -0400

    bug fix: set lower inodes correctly after branch management succeeds
    
    Signed-off-by: Erez Zadok <[EMAIL PROTECTED]>
    
    Conflicts:
    
        fs/unionfs/super.c

diff --git a/fs/unionfs/super.c b/fs/unionfs/super.c
index d9704bb..d1f9151 100644
--- a/fs/unionfs/super.c
+++ b/fs/unionfs/super.c
@@ -349,7 +349,13 @@ found_insertion_point:
                       new_branch, err);
                goto out;
        }
-       /* it's probably safe to check_mode the new branch to insert */
+       /*
+        * It's probably safe to check_mode the new branch to insert.  Note:
+        * we don't allow inserting branches which are unionfs's by
+        * themselves (check_branch returns EINVAL in that case).  This is
+        * because this code base doesn't support stacking unionfs: the ODF
+        * code base supports that correctly.
+        */
        if ((err = check_branch(&nd))) {
                printk(KERN_WARNING "unionfs: hidden directory "
                       "\"%s\" is not a valid branch\n", optarg);
@@ -414,13 +420,14 @@ static int unionfs_remount_fs(struct super_block *sb, int 
*flags,
        int i;
        char *optionstmp, *tmp_to_free; /* kstrdup'ed of "options" */
        char *optname;
-       int cur_branches;       /* no. of current branches */
-       int new_branches;       /* no. of branches actually left in the end */
+       int cur_branches = 0;   /* no. of current branches */
+       int new_branches = 0;   /* no. of branches actually left in the end */
        int add_branches;       /* est. no. of branches to add */
        int del_branches;       /* est. no. of branches to del */
        int max_branches;       /* max possible no. of branches */
        struct unionfs_data *new_data = NULL, *tmp_data = NULL;
        struct path *new_lower_paths = NULL, *tmp_lower_paths = NULL;
+       struct inode **new_lower_inodes = NULL;
        int new_high_branch_id; /* new high branch ID */
        struct odf_sb_info *odf = UNIONFS_SB(sb)->odf;
        int odfforce = 0 ;      /* whether the odfforce option was provided */
@@ -672,10 +679,7 @@ out_no_change:
                        err = -ENOMEM;
                        goto out_release;
                }
-               /*
-                * copy current info into new placeholders, incrementing
-                * refcounts.
-                */
+               /* copy current info into new placeholders */
                memcpy(new_data, tmp_data,
                       new_branches * sizeof(struct unionfs_data));
                memcpy(new_lower_paths, tmp_lower_paths,
@@ -687,12 +691,19 @@ out_no_change:
                 */
                kfree(tmp_data);
                kfree(tmp_lower_paths);
-               /* no need to nullify pointers here */
+               /* no need to nullify pointers here (they get reused below) */
        } else {
                /* number of branches didn't change, no need to re-alloc */
                new_data = tmp_data;
                new_lower_paths = tmp_lower_paths;
        }
+       /* allocate space for new pointers to lower inodes */
+       new_lower_inodes = kcalloc(new_branches,
+                                  sizeof(struct inode *), GFP_KERNEL);
+       if (!new_lower_inodes) {
+               err = -ENOMEM;
+               goto out_release;
+       }
 
 
 
@@ -740,7 +751,7 @@ out_no_change:
         * fsync_super() which would not have returned until all dirty pages
         * were flushed.
         *
-        * But do w have to worry about locked pages?  Is there any chance
+        * But do we have to worry about locked pages?  Is there any chance
         * that in here we'll get locked pages?
         *
         * XXX: what about pages mapped into pagetables?  Are these pages
@@ -767,8 +778,31 @@ out_no_change:
        i = sbmax(sb);          /* save no. of branches to release at end */
        sbend(sb) = new_branches - 1;
        set_dbend(sb->s_root, new_branches - 1);
+       old_ibstart = ibstart(sb->s_root->d_inode);
+       old_ibend = ibend(sb->s_root->d_inode);
+       ibend(sb->s_root->d_inode) = new_branches - 1;
        UNIONFS_D(sb->s_root)->bcount = new_branches;
-       new_branches = i;       /* no. of branches to release below */
+       new_branches = i; /* no. of branches to release below */
+
+       /*
+        * Update lower inodes: 3 steps
+        * 1. grab ref on all new lower inodes
+        */
+       for (i=dbstart(sb->s_root); i<=dbend(sb->s_root); i++) {
+               struct dentry *lower_dentry =
+                       unionfs_lower_dentry_idx(sb->s_root, i);
+               atomic_inc(&lower_dentry->d_inode->i_count);
+               new_lower_inodes[i] = lower_dentry->d_inode;
+       }
+       /* 2. release reference on all older lower inodes */
+       for (i=old_ibstart; i<=old_ibend; i++) {
+               iput(unionfs_lower_inode_idx(sb->s_root->d_inode, i));
+               unionfs_set_lower_inode_idx(sb->s_root->d_inode, i, NULL);
+       }
+       kfree(UNIONFS_I(sb->s_root->d_inode)->lower_inodes);
+       /* 3. update root dentry's inode to new lower_inodes array */
+       UNIONFS_I(sb->s_root->d_inode)->lower_inodes = new_lower_inodes;
+       new_lower_inodes = NULL;
 
        /* maxbytes may have changed */
        sb->s_maxbytes = unionfs_lower_super_idx(sb, 0)->s_maxbytes;
@@ -801,8 +835,10 @@ out_free:
        kfree(tmp_data);
        kfree(new_lower_paths);
        kfree(new_data);
+       kfree(new_lower_inodes);
 out_error:
        unionfs_write_unlock(sb);
+       unionfs_check_dentry(sb->s_root);
        return err;
 }
 
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs

Reply via email to