+int ll_get_fid_by_name(struct inode *parent, const char *name,
+ int namelen, struct lu_fid *fid)
+{
+ struct md_op_data *op_data = NULL;
+ struct mdt_body *body;
+ struct ptlrpc_request *req;
+ int rc;
+ ENTRY;
+
+ op_data = ll_prep_md_op_data(NULL, parent, NULL, name, namelen, 0,
+ LUSTRE_OPC_ANY, NULL);
+ if (IS_ERR(op_data))
+ RETURN(PTR_ERR(op_data));
+
+ op_data->op_valid = OBD_MD_FLID;
+ rc = md_getattr_name(ll_i2sbi(parent)->ll_md_exp, op_data, &req);
+ ll_finish_md_op_data(op_data);
+ if (rc < 0)
+ RETURN(rc);
+
+ body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
+ if (body == NULL)
+ GOTO(out_req, rc = -EFAULT);
+ if (fid != NULL)
+ *fid = body->fid1;
+out_req:
+ ptlrpc_req_finished(req);
+ RETURN(rc);
+}
+
+int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
+ const char *name, int namelen)
+{
+ struct dentry *dchild = NULL;
+ struct inode *child_inode = NULL;
+ struct md_op_data *op_data;
+ struct ptlrpc_request *request = NULL;
+ struct qstr qstr;
+ int rc;
+ ENTRY;
+
+ CDEBUG(D_VFSTRACE, "migrate %s under "DFID" to MDT%04x\n",
+ name, PFID(ll_inode2fid(parent)), mdtidx);
+
+ op_data = ll_prep_md_op_data(NULL, parent, NULL, name, namelen,
+ 0, LUSTRE_OPC_ANY, NULL);
+ if (IS_ERR(op_data))
+ RETURN(PTR_ERR(op_data));
+
+ /* Get child FID first */
+ qstr.hash = full_name_hash(name, namelen);
+ qstr.name = name;
+ qstr.len = namelen;
+ dchild = d_lookup(file->f_dentry, &qstr);
+ if (dchild != NULL && dchild->d_inode != NULL) {
+ op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
+ if (dchild->d_inode != NULL) {
+ child_inode = igrab(dchild->d_inode);
+ ll_invalidate_aliases(child_inode);
+ }
+ dput(dchild);
+ } else {
+ rc = ll_get_fid_by_name(parent, name, namelen,
+ &op_data->op_fid3);
+ if (rc != 0)
+ GOTO(out_free, rc);
+ }
+
+ if (!fid_is_sane(&op_data->op_fid3)) {
+ CERROR("%s: migrate %s , but fid "DFID" is insane\n",
+ ll_get_fsname(parent->i_sb, NULL, 0), name,
+ PFID(&op_data->op_fid3));
+ GOTO(out_free, rc = -EINVAL);
+ }
+
+ rc = ll_get_mdt_idx_by_fid(ll_i2sbi(parent), &op_data->op_fid3);
+ if (rc < 0)
+ GOTO(out_free, rc);
+
+ if (rc == mdtidx) {
+ CDEBUG(D_INFO, "%s:"DFID" is already on MDT%d.\n", name,
+ PFID(&op_data->op_fid3), mdtidx);
+ GOTO(out_free, rc = 0);
+ }
+
+ op_data->op_mds = mdtidx;
+ op_data->op_cli_flags = CLI_MIGRATE;
+ rc = md_rename(ll_i2sbi(parent)->ll_md_exp, op_data, name,
+ namelen, name, namelen, &request);
+ if (rc == 0)
+ ll_update_times(request, parent);
+
+ ptlrpc_req_finished(request);
+ if (rc != 0)
+ GOTO(out_free, rc);
+
+out_free:
+ if (child_inode != NULL) {
+ clear_nlink(child_inode);
+ iput(child_inode);
+ }
+
+ ll_finish_md_op_data(op_data);
+ RETURN(rc);
+}
+
+static int
+ll_file_noflock(struct file *file, int cmd, struct file_lock *file_lock)