+ struct lustre_nfs_fid *nfs_fid = (struct lustre_nfs_fid *)fid;
+
+ if (fh_type != FILEID_LUSTRE)
+ RETURN(ERR_PTR(-EPROTO));
+
+ RETURN(ll_iget_for_nfs(sb, &nfs_fid->lnf_child, &nfs_fid->lnf_parent));
+}
+
+static struct dentry *ll_fh_to_parent(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type)
+{
+ struct lustre_nfs_fid *nfs_fid = (struct lustre_nfs_fid *)fid;
+
+ if (fh_type != FILEID_LUSTRE)
+ RETURN(ERR_PTR(-EPROTO));
+
+ RETURN(ll_iget_for_nfs(sb, &nfs_fid->lnf_parent, NULL));
+}
+
+int ll_dir_get_parent_fid(struct inode *dir, struct lu_fid *parent_fid)
+{
+ struct ptlrpc_request *req = NULL;
+ struct ll_sb_info *sbi;
+ struct mdt_body *body;
+ static const char dotdot[] = "..";
+ struct md_op_data *op_data;
+ int rc;
+ int lmmsize;
+
+ ENTRY;
+
+ LASSERT(dir && S_ISDIR(dir->i_mode));
+
+ sbi = ll_s2sbi(dir->i_sb);
+
+ CDEBUG(D_INFO, "%s: getting parent for ("DFID")\n",
+ ll_get_fsname(dir->i_sb, NULL, 0),
+ PFID(ll_inode2fid(dir)));
+
+ rc = ll_get_default_mdsize(sbi, &lmmsize);
+ if (rc != 0)
+ RETURN(rc);
+
+ op_data = ll_prep_md_op_data(NULL, dir, NULL, dotdot,
+ strlen(dotdot), lmmsize,
+ LUSTRE_OPC_ANY, NULL);
+ if (IS_ERR(op_data))
+ RETURN(PTR_ERR(op_data));
+
+ rc = md_getattr_name(sbi->ll_md_exp, op_data, &req);
+ ll_finish_md_op_data(op_data);
+ if (rc != 0) {
+ CERROR("%s: failure inode "DFID" get parent: rc = %d\n",
+ ll_get_fsname(dir->i_sb, NULL, 0),
+ PFID(ll_inode2fid(dir)), rc);
+ RETURN(rc);
+ }
+ body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
+
+ /*
+ * LU-3952: MDT may lost the FID of its parent, we should not crash
+ * the NFS server, ll_iget_for_nfs() will handle the error.
+ */
+ if (body->mbo_valid & OBD_MD_FLID) {
+ CDEBUG(D_INFO, "parent for "DFID" is "DFID"\n",
+ PFID(ll_inode2fid(dir)), PFID(&body->mbo_fid1));
+ *parent_fid = body->mbo_fid1;
+ }
+
+ ptlrpc_req_finished(req);
+ RETURN(0);