]) # LC_HAVE_DIR_CONTEXT
#
+# LC_D_COMPARE_5ARGS
+#
+# 3.11 dentry_operations.d_compare() taken 5 arguments.
+#
+AC_DEFUN([LC_D_COMPARE_5ARGS], [
+LB_CHECK_COMPILE([if 'd_compare' taken 5 arguments],
+d_compare_5args, [
+ #include <linux/dcache.h>
+],[
+ ((struct dentry_operations*)0)->d_compare(NULL,NULL,0,NULL,NULL);
+],[
+ AC_DEFINE(HAVE_D_COMPARE_5ARGS, 1,
+ [d_compare need 5 arguments])
+])
+]) # LC_D_COMPARE_5ARGS
+
+#
# LC_HAVE_DCOUNT
#
# 3.11 need to access d_count to get dentry reference count
]) # LC_HAVE_POSIX_ACL_VALID_USER_NS
#
+# LC_D_COMPARE_4ARGS
+#
+# Kernel version 4.8 commit 6fa67e707559303e086303aeecc9e8b91ef497d5
+# get rid of 'parent' argument of ->d_compare()
+#
+AC_DEFUN([LC_D_COMPARE_4ARGS], [
+LB_CHECK_COMPILE([if 'd_compare' taken 4 arguments],
+d_compare_4args, [
+ #include <linux/dcache.h>
+],[
+ ((struct dentry_operations*)0)->d_compare(NULL,0,NULL,NULL);
+],[
+ AC_DEFINE(HAVE_D_COMPARE_4ARGS, 1,
+ [d_compare need 4 arguments])
+])
+]) # LC_D_COMPARE_4ARGS
+
+#
# LC_FULL_NAME_HASH_3ARGS
#
# Kernel version 4.8 commit 8387ff2577eb9ed245df9a39947f66976c6bcd02
# 3.11
LC_INVALIDATE_RANGE
LC_HAVE_DIR_CONTEXT
+ LC_D_COMPARE_5ARGS
LC_HAVE_DCOUNT
LC_HAVE_DENTRY_D_U_D_ALIAS
LC_HAVE_DENTRY_D_CHILD
# 4.8
LC_HAVE_POSIX_ACL_VALID_USER_NS
+ LC_D_COMPARE_4ARGS
LC_FULL_NAME_HASH_3ARGS
LC_STRUCT_POSIX_ACL_XATTR
LC_IOP_XATTR
EXIT;
}
+/* Compare if two dentries are the same. Don't match if the existing dentry
+ * is marked invalid. Returns 1 if different, 0 if the same.
+ *
+ * This avoids a race where ll_lookup_it() instantiates a dentry, but we get
+ * 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.
+ */
+#if defined(HAVE_D_COMPARE_5ARGS)
+static int ll_dcompare(const struct dentry *parent, const struct dentry *dentry,
+ unsigned int len, const char *str,
+ const struct qstr *name)
+#elif defined(HAVE_D_COMPARE_4ARGS)
+static int ll_dcompare(const struct dentry *dentry, unsigned int len,
+ const char *str, const struct qstr *name)
+#endif
+{
+ ENTRY;
+
+ if (len != name->len)
+ RETURN(1);
+
+ if (memcmp(str, name->name, len))
+ RETURN(1);
+
+ CDEBUG(D_DENTRY, "found name %.*s(%p) flags %#x refc %d\n",
+ name->len, name->name, dentry, dentry->d_flags,
+ ll_d_count(dentry));
+
+ /* mountpoint is always valid */
+ if (d_mountpoint((struct dentry *)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))
+ RETURN(1);
+
+ RETURN(0);
+}
+
/**
* Called when last reference to a dentry is dropped and dcache wants to know
* whether or not it should cache it:
CDEBUG(D_VFSTRACE, "VFS Op:name=%s, flags=%u\n",
dentry->d_name.name, lookup_flags);
- /* mountpoint is always valid */
- if (d_mountpoint((struct dentry *)dentry))
- return 1;
-
- /* No lock -> invalid dentry */
- if (d_lustre_invalid(dentry))
- return 0;
-
/* If this is intermediate component path lookup and we were able to get
* to this dentry, then its lock has not been revoked and the
* path component is valid. */
.d_revalidate = ll_revalidate_dentry,
.d_release = ll_release,
.d_delete = ll_ddelete,
+ .d_compare = ll_dcompare,
};