+ __u32 ino = 0;
+
+ /* If this is not the ".." entry, it might be a remote DNE
+ * entry and we need to check if the FID is for a remote
+ * MDT. If the FID is not in the directory entry (e.g.
+ * upgraded 1.8 filesystem without dirdata enabled) then
+ * we need to get the FID from the LMA. For a remote directory
+ * there HAS to be an LMA, it cannot be an IGIF inode in this
+ * case.
+ *
+ * Delete the entry before the agent inode in order to
+ * simplify error handling. At worst an error after deleting
+ * the entry first might leak the agent inode afterward. The
+ * reverse would need filesystem abort in case of error deleting
+ * the entry after the agent had been removed, or leave a
+ * dangling entry pointing at a random inode. */
+ if (strcmp((char *)key, dotdot) != 0) {
+ LASSERT(de != NULL);
+ rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
+ /* If Fid is not in dentry, try to get it from LMA */
+ if (rc == -ENODATA) {
+ struct osd_inode_id *id;
+ struct inode *inode;
+
+ /* Before trying to get fid from the inode,
+ * check whether the inode is valid.
+ *
+ * If the inode has been deleted, do not go
+ * ahead to do osd_ea_fid_get, which will set
+ * the inode to bad inode, which might cause
+ * the inode to be deleted uncorrectly */
+ inode = ldiskfs_iget(osd_sb(osd),
+ le32_to_cpu(de->inode));
+ if (IS_ERR(inode)) {
+ CDEBUG(D_INODE, "%s: "DFID"get inode"
+ "error.\n", osd_name(osd),
+ PFID(fid));
+ rc = PTR_ERR(inode);
+ } else {
+ if (likely(inode->i_nlink != 0)) {
+ id = &osd_oti_get(env)->oti_id;
+ rc = osd_ea_fid_get(env, obj,
+ le32_to_cpu(de->inode),
+ fid, id);
+ } else {
+ CDEBUG(D_INFO, "%s: %u "DFID
+ "deleted.\n",
+ osd_name(osd),
+ le32_to_cpu(de->inode),
+ PFID(fid));
+ rc = -ESTALE;
+ }
+ iput(inode);
+ }
+ }
+ if (rc == 0 &&
+ unlikely(osd_remote_fid(env, osd, fid)))
+ /* Need to delete agent inode */
+ ino = le32_to_cpu(de->inode);
+ }
+ rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);