Merge tag 'staging-4.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[linux-2.6-block.git] / drivers / staging / lustre / lustre / llite / dcache.c
index 549369739d805736e95c8115ca7cbf48dd098e05..11b82c639bfe07d5c71cd4300feea983938dcac2 100644 (file)
@@ -74,6 +74,12 @@ static void ll_release(struct dentry *de)
  * an AST before calling d_revalidate_it().  The dentry still exists (marked
  * INVALID) so d_lookup() matches it, but we have no lock on it (so
  * lock_match() fails) and we spin around real_lookup().
+ *
+ * This race doesn't apply to lookups in d_alloc_parallel(), and for
+ * those we want to ensure that only one dentry with a given name is
+ * in ll_lookup_nd() at a time.  So allow invalid dentries to match
+ * while d_in_lookup().  We will be called again when the lookup
+ * completes, and can give a different answer then.
  */
 static int ll_dcompare(const struct dentry *dentry,
                       unsigned int len, const char *str,
@@ -90,7 +96,11 @@ static int ll_dcompare(const struct dentry *dentry,
               d_count(dentry));
 
        /* mountpoint is always valid */
-       if (d_mountpoint((struct dentry *)dentry))
+       if (d_mountpoint(dentry))
+               return 0;
+
+       /* ensure exclusion against parallel lookup of the same name */
+       if (d_in_lookup((struct dentry *)dentry))
                return 0;
 
        if (d_lustre_invalid(dentry))
@@ -111,7 +121,7 @@ static int ll_ddelete(const struct dentry *de)
        LASSERT(de);
 
        CDEBUG(D_DENTRY, "%s dentry %pd (%p, parent %p, inode %p) %s%s\n",
-              d_lustre_invalid((struct dentry *)de) ? "deleting" : "keeping",
+              d_lustre_invalid(de) ? "deleting" : "keeping",
               de, de, de->d_parent, d_inode(de),
               d_unhashed(de) ? "" : "hashed,",
               list_empty(&de->d_subdirs) ? "" : "subdirs");
@@ -119,7 +129,7 @@ static int ll_ddelete(const struct dentry *de)
        /* kernel >= 2.6.38 last refcount is decreased after this function. */
        LASSERT(d_count(de) == 1);
 
-       if (d_lustre_invalid((struct dentry *)de))
+       if (d_lustre_invalid(de))
                return 1;
        return 0;
 }