+ * Get parent FID from the linkEA.
+ *
+ * For a directory which parent resides on remote MDT, to satisfy the
+ * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
+ * the other hand, to make the lookup(..) on the directory can return
+ * the real parent FID, we append the real parent FID after its ".."
+ * name entry in the /REMOTE_PARENT_DIR.
+ *
+ * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
+ * backup. So after the restore, we cannot get the right parent FID from
+ * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
+ * we have stored the real parent FID in the directory object's linkEA,
+ * we can parse the linkEA for the real parent FID.
+ *
+ * \param[in] env pointer to the thread context
+ * \param[in] obj pointer to the object to be handled
+ * \param[out]fid pointer to the buffer to hold the parent FID
+ *
+ * \retval 0 for getting the real parent FID successfully
+ * \retval negative error number on failure
+ */
+static int osd_get_pfid_from_linkea(const struct lu_env *env,
+ struct osd_object *obj,
+ struct lu_fid *fid)
+{
+ struct osd_thread_info *oti = osd_oti_get(env);
+ struct lu_buf *buf = &oti->oti_big_buf;
+ struct dentry *dentry = &oti->oti_obj_dentry;
+ struct inode *inode = obj->oo_inode;
+ struct linkea_data ldata = { 0 };
+ int rc;
+ ENTRY;
+
+ fid_zero(fid);
+ if (!S_ISDIR(inode->i_mode))
+ RETURN(-EIO);
+
+again:
+ rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
+ buf->lb_buf, buf->lb_len);
+ if (rc == -ERANGE) {
+ rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
+ NULL, 0);
+ if (rc > 0) {
+ lu_buf_realloc(buf, rc);
+ if (buf->lb_buf == NULL)
+ RETURN(-ENOMEM);
+
+ goto again;
+ }
+ }
+
+ if (unlikely(rc == 0))
+ RETURN(-ENODATA);
+
+ if (rc < 0)
+ RETURN(rc);
+
+ if (unlikely(buf->lb_buf == NULL)) {
+ lu_buf_realloc(buf, rc);
+ if (buf->lb_buf == NULL)
+ RETURN(-ENOMEM);
+
+ goto again;
+ }
+
+ ldata.ld_buf = buf;
+ rc = linkea_init(&ldata);
+ if (rc == 0) {
+ linkea_first_entry(&ldata);
+ linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
+ }
+
+ RETURN(rc);
+}
+
+/**