Unionfs: locking fixes
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 10 Jan 2008 17:04:26 +0000 (12:04 -0500)
committerRachita Kothiyal <rachita@dewey.fsl.cs.sunysb.edu>
Thu, 1 May 2008 23:03:33 +0000 (19:03 -0400)
Lock parent dentries during revalidation.
Reduce total number of lockdep classes used.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/dentry.c
fs/unionfs/fanout.h

index b3120637d16b99c1f40df7f85d355ce3a402c5cd..f045b04ed7e10a93ba0ed50876dcb70abd69f73d 100644 (file)
@@ -55,6 +55,7 @@ static bool __unionfs_d_revalidate_one(struct dentry *dentry,
                memset(&lowernd, 0, sizeof(struct nameidata));
 
        verify_locked(dentry);
+       verify_locked(dentry->d_parent);
 
        /* if the dentry is unhashed, do NOT revalidate */
        if (d_deleted(dentry))
@@ -369,7 +370,10 @@ bool __unionfs_d_revalidate_chain(struct dentry *dentry, struct nameidata *nd,
         * to child order.
         */
        for (i = 0; i < chain_len; i++) {
-               unionfs_lock_dentry(chain[i], UNIONFS_DMUTEX_REVAL+i);
+               unionfs_lock_dentry(chain[i], UNIONFS_DMUTEX_REVAL_CHILD);
+               if (chain[i] != chain[i]->d_parent)
+                       unionfs_lock_dentry(chain[i]->d_parent,
+                                           UNIONFS_DMUTEX_REVAL_PARENT);
                saved_bstart = dbstart(chain[i]);
                saved_bend = dbend(chain[i]);
                sbgen = atomic_read(&UNIONFS_SB(dentry->d_sb)->generation);
@@ -384,6 +388,8 @@ bool __unionfs_d_revalidate_chain(struct dentry *dentry, struct nameidata *nd,
                             bindex++)
                                unionfs_mntput(chain[i], bindex);
                }
+               if (chain[i] != chain[i]->d_parent)
+                       unionfs_unlock_dentry(chain[i]->d_parent);
                unionfs_unlock_dentry(chain[i]);
 
                if (unlikely(!valid))
@@ -394,6 +400,9 @@ bool __unionfs_d_revalidate_chain(struct dentry *dentry, struct nameidata *nd,
 out_this:
        /* finally, lock this dentry and revalidate it */
        verify_locked(dentry);
+       if (dentry != dentry->d_parent)
+               unionfs_lock_dentry(dentry->d_parent,
+                                   UNIONFS_DMUTEX_REVAL_PARENT);
        dgen = atomic_read(&UNIONFS_D(dentry)->generation);
 
        if (unlikely(is_newer_lower(dentry))) {
@@ -412,6 +421,8 @@ out_this:
                        purge_inode_data(dentry->d_inode);
        }
        valid = __unionfs_d_revalidate_one(dentry, nd);
+       if (dentry != dentry->d_parent)
+               unionfs_unlock_dentry(dentry->d_parent);
 
        /*
         * If __unionfs_d_revalidate_one() succeeded above, then it will
index 590cd9ea4c3a8d56c05ed245653fb4be9fe40657..2ae30a34d4245c750062756dcc987b105aa1e295 100644 (file)
@@ -283,7 +283,8 @@ enum unionfs_dentry_lock_class {
        UNIONFS_DMUTEX_PARENT,
        UNIONFS_DMUTEX_CHILD,
        UNIONFS_DMUTEX_WHITEOUT,
-       UNIONFS_DMUTEX_REVAL,   /* for file/dentry revalidate */
+       UNIONFS_DMUTEX_REVAL_PARENT, /* for file/dentry revalidate */
+       UNIONFS_DMUTEX_REVAL_CHILD,   /* for file/dentry revalidate */
 };
 
 static inline void unionfs_lock_dentry(struct dentry *d,