commit 2db45256ac1587a072a1b7fe47b47952e48f7094
Author: Erez_Zadok <[EMAIL PROTECTED]>
Date:   Fri Nov 16 13:47:04 2007 -0500

    Unionfs: branch-management bug-fix to lower mnt counts
    
    When we revalidate opened files, the files may point to a different set of
    files on the lower branches: this could happen especially if we insert a new
    leftmost branch which happens to have duplicate file names of already-open
    files in lower-priority branches.  In this case, update the mnt counts of
    the old and new branches which hold the file accordingly.  Without this fix,
    the mntcnt of one branch is going to be one too high; and another will be
    one too low.
    
    Signed-off-by: Erez Zadok <[EMAIL PROTECTED]>

diff --git a/fs/unionfs/commonfops.c b/fs/unionfs/commonfops.c
index 9f6b2da..247c89b 100644
--- a/fs/unionfs/commonfops.c
+++ b/fs/unionfs/commonfops.c
@@ -401,6 +401,9 @@ int unionfs_file_revalidate(struct file *file, int 
willwrite)
         */
        if (!d_deleted(dentry) &&
            (sbgen > fgen || dbstart(dentry) != fbstart(file))) {
+               int orig_brid = /* save orig branch ID */
+                       UNIONFS_F(file)->saved_branch_ids[fbstart(file)];
+
                /* First we throw out the existing files. */
                cleanup_file(file);
 
@@ -427,10 +430,23 @@ int unionfs_file_revalidate(struct file *file, int 
willwrite)
                        if (err)
                                goto out;
                } else {
+                       int new_brid;
                        /* We only open the highest priority branch. */
                        err = open_highest_file(file, willwrite);
                        if (err)
                                goto out;
+                       new_brid = 
UNIONFS_F(file)->saved_branch_ids[fbstart(file)];
+                       if (new_brid != orig_brid) {
+                               /*
+                                * If we re-opened the file on a different
+                                * branch than the original one, then update
+                                * the mnt counts of the old and new
+                                * branches accordingly.
+                                */
+                               unionfs_mntget(dentry, bstart); /* new branch */
+                               unionfs_mntput(sb->s_root, /* orig branch */
+                                              branch_id_to_idx(sb, orig_brid));
+                       }
                }
                atomic_set(&UNIONFS_F(file)->generation,
                           atomic_read(&UNIONFS_I(dentry->d_inode)->
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs

Reply via email to