ubifs: Check link count of inodes when killing orphans.
[linux-2.6-block.git] / fs / ocfs2 / dcache.c
index 2d016937fddab856b402c12c686c422a4d7e9ff5..42a61eecdacdd68993a83ceebca5d19939d2d651 100644 (file)
@@ -296,6 +296,18 @@ int ocfs2_dentry_attach_lock(struct dentry *dentry,
 
 out_attach:
        spin_lock(&dentry_attach_lock);
+       if (unlikely(dentry->d_fsdata && !alias)) {
+               /* d_fsdata is set by a racing thread which is doing
+                * the same thing as this thread is doing. Leave the racing
+                * thread going ahead and we return here.
+                */
+               spin_unlock(&dentry_attach_lock);
+               iput(dl->dl_inode);
+               ocfs2_lock_res_free(&dl->dl_lockres);
+               kfree(dl);
+               return 0;
+       }
+
        dentry->d_fsdata = dl;
        dl->dl_count++;
        spin_unlock(&dentry_attach_lock);