-#ifdef LUSTRE_KERNEL_VERSION
- ll_unhash_aliases(de->d_inode);
- /* done in ll_unhash_aliases()
- dentry->d_flags |= DCACHE_LUSTRE_INVALID; */
-#else
- /* We do not want d_invalidate to kill all child dentries too */
- d_drop(de);
-#endif
- } else {
- CDEBUG(D_DENTRY, "revalidated dentry %.*s (%p) parent %p "
- "inode %p refc %d\n", de->d_name.len,
- de->d_name.name, de, de->d_parent, de->d_inode,
- atomic_read(&de->d_count));
- ll_lookup_finish_locks(it, de);
-#ifdef LUSTRE_KERNEL_VERSION
- lock_dentry(de);
- de->d_flags &= ~DCACHE_LUSTRE_INVALID;
- unlock_dentry(de);
-#endif
- }
+ /* mdt may grant layout lock for the newly created file, so
+ * release the lock to avoid leaking */
+ ll_intent_drop_lock(it);
+ ll_invalidate_aliases(de->d_inode);
+ } else {
+ __u64 bits = 0;
+ __u64 matched_bits = 0;
+
+ CDEBUG(D_DENTRY, "revalidated dentry %.*s (%p) parent %p "
+ "inode %p refc %d\n", de->d_name.len,
+ de->d_name.name, de, de->d_parent, de->d_inode,
+ d_refcount(de));
+
+ ll_set_lock_data(exp, de->d_inode, it, &bits);
+
+ /* Note: We have to match both LOOKUP and PERM lock
+ * here to make sure the dentry is valid and no one
+ * changing the permission.
+ * But if the client connects < 2.4 server, which will
+ * only grant LOOKUP lock, so we can only Match LOOKUP
+ * lock for old server */
+ if (exp_connect_flags(ll_i2mdexp(de->d_inode)) &&
+ OBD_CONNECT_LVB_TYPE)
+ matched_bits =
+ MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
+ else
+ matched_bits = MDS_INODELOCK_LOOKUP;
+
+ if (((bits & matched_bits) == matched_bits) &&
+ d_lustre_invalid(de))
+ d_lustre_revalidate(de);
+ ll_lookup_finish_locks(it, de);
+ }
+
+mark:
+ if (it != NULL && it->it_op == IT_GETATTR && rc > 0)
+ ll_statahead_mark(parent, de);