- struct ptlrpc_request *req = mdt_info_req(info);
- struct mdt_export_data *med = mdt_req2med(req);
- struct md_ucred *uc = mdt_ucred(info);
- struct lu_buf *buf = &info->mti_buf;
- int rc;
- ENTRY;
-
- rc = lustre_ext_acl_xattr_id2server(uc, med->med_idmap, header);
- if (rc)
- RETURN(rc);
-
- rc = mo_xattr_get(info->mti_env, next, &LU_BUF_NULL, xattr_name);
- if (rc == -ENODATA)
- rc = 0;
- else if (rc < 0)
- RETURN(rc);
-
- buf->lb_len = rc;
- if (buf->lb_len > 0) {
- OBD_ALLOC_LARGE(buf->lb_buf, buf->lb_len);
- if (unlikely(buf->lb_buf == NULL))
- RETURN(-ENOMEM);
-
- rc = mo_xattr_get(info->mti_env, next, buf, xattr_name);
- if (rc < 0) {
- CERROR("getxattr failed: %d\n", rc);
- GOTO(_out, rc);
- }
- } else
- buf->lb_buf = NULL;
-
- rc = lustre_acl_xattr_merge2posix((posix_acl_xattr_header *)(buf->lb_buf),
- buf->lb_len, header, out);
- EXIT;
-
-_out:
- if (rc <= 0 && buf->lb_buf != NULL)
- OBD_FREE_LARGE(buf->lb_buf, buf->lb_len);
- return rc;
+ const struct lu_env *env = info->mti_env;
+ struct mdt_device *mdt = info->mti_mdt;
+ struct lu_ucred *uc = mdt_ucred(info);
+ struct mdt_reint_record *rr = &info->mti_rr;
+ struct lmv_user_md *lmu = rr->rr_eadata;
+ __u32 lum_stripe_count = lmu->lum_stripe_count;
+ struct lu_buf *buf = &info->mti_buf;
+ struct lmv_mds_md_v1 *lmv;
+ struct md_attr *ma = &info->mti_attr;
+ struct ldlm_enqueue_info *einfo = &info->mti_einfo[0];
+ struct mdt_object *pobj = NULL;
+ struct mdt_object *obj;
+ struct mdt_lock_handle *lhp = NULL;
+ struct mdt_lock_handle *lhc;
+ int rc;
+
+ ENTRY;
+
+ if (!mdt->mdt_enable_dir_migration)
+ RETURN(-EPERM);
+
+ if (!md_capable(uc, CFS_CAP_SYS_ADMIN) &&
+ uc->uc_gid != mdt->mdt_enable_remote_dir_gid &&
+ mdt->mdt_enable_remote_dir_gid != -1)
+ RETURN(-EPERM);
+
+ /* mti_big_lmm is used to save LMV, but it may be uninitialized. */
+ if (unlikely(!info->mti_big_lmm)) {
+ info->mti_big_lmmsize = lmv_mds_md_size(64, LMV_MAGIC);
+ OBD_ALLOC(info->mti_big_lmm, info->mti_big_lmmsize);
+ if (!info->mti_big_lmm)
+ RETURN(-ENOMEM);
+ }
+
+ obj = mdt_object_find(env, mdt, rr->rr_fid1);
+ if (IS_ERR(obj))
+ RETURN(PTR_ERR(obj));
+
+ /* get parent from PFID */
+ rc = mdt_attr_get_pfid(info, obj, &ma->ma_pfid);
+ if (rc)
+ GOTO(put_obj, rc);
+
+ pobj = mdt_object_find(env, mdt, &ma->ma_pfid);
+ if (IS_ERR(pobj))
+ GOTO(put_obj, rc = PTR_ERR(pobj));
+
+ /* revoke object remote LOOKUP lock */
+ if (mdt_object_remote(pobj)) {
+ rc = mdt_revoke_remote_lookup_lock(info, pobj, obj);
+ if (rc)
+ GOTO(put_pobj, rc);
+ }
+
+ /*
+ * lock parent if dir will be shrunk to 1 stripe, because dir will be
+ * converted to normal directory, as will change dir fid and update
+ * namespace of parent.
+ */
+ lhp = &info->mti_lh[MDT_LH_PARENT];
+ mdt_lock_reg_init(lhp, LCK_PW);
+
+ if (le32_to_cpu(lmu->lum_stripe_count) < 2) {
+ rc = mdt_reint_object_lock(info, pobj, lhp,
+ MDS_INODELOCK_UPDATE, true);
+ if (rc)
+ GOTO(put_pobj, rc);
+ }
+
+ /* lock object */
+ lhc = &info->mti_lh[MDT_LH_CHILD];
+ mdt_lock_reg_init(lhc, LCK_EX);
+ rc = mdt_reint_striped_lock(info, obj, lhc, MDS_INODELOCK_FULL, einfo,
+ true);
+ if (rc)
+ GOTO(unlock_pobj, rc);
+
+ ma->ma_lmv = info->mti_big_lmm;
+ ma->ma_lmv_size = info->mti_big_lmmsize;
+ ma->ma_valid = 0;
+ rc = mdt_stripe_get(info, obj, ma, XATTR_NAME_LMV);
+ if (rc)
+ GOTO(unlock_obj, rc);
+
+ /* user may run 'lfs migrate' multiple times, so it's shrunk already */
+ if (!(ma->ma_valid & MA_LMV))
+ GOTO(unlock_obj, rc = -EALREADY);
+
+ lmv = &ma->ma_lmv->lmv_md_v1;
+
+ /* ditto */
+ if (!(le32_to_cpu(lmv->lmv_hash_type) & LMV_HASH_FLAG_MIGRATION))
+ GOTO(unlock_obj, rc = -EALREADY);
+
+ lum_stripe_count = lmu->lum_stripe_count;
+ if (!lum_stripe_count)
+ lum_stripe_count = cpu_to_le32(1);
+
+ if (lmv->lmv_migrate_offset != lum_stripe_count) {
+ CERROR("%s: "DFID" migrate mdt count mismatch %u != %u\n",
+ mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
+ lmv->lmv_migrate_offset, lmu->lum_stripe_count);
+ GOTO(unlock_obj, rc = -EINVAL);
+ }
+
+ if (lmv->lmv_master_mdt_index != lmu->lum_stripe_offset) {
+ CERROR("%s: "DFID" migrate mdt index mismatch %u != %u\n",
+ mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
+ lmv->lmv_master_mdt_index, lmu->lum_stripe_offset);
+ GOTO(unlock_obj, rc = -EINVAL);
+ }
+
+ if (lum_stripe_count > 1 &&
+ (lmv->lmv_hash_type & cpu_to_le32(LMV_HASH_TYPE_MASK)) !=
+ lmu->lum_hash_type) {
+ CERROR("%s: "DFID" migrate mdt hash mismatch %u != %u\n",
+ mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
+ lmv->lmv_hash_type, lmu->lum_hash_type);
+ GOTO(unlock_obj, rc = -EINVAL);
+ }
+
+ buf->lb_buf = rr->rr_eadata;
+ buf->lb_len = rr->rr_eadatalen;
+ rc = mo_xattr_set(env, mdt_object_child(obj), buf, XATTR_NAME_LMV, 0);
+ GOTO(unlock_obj, rc);
+
+unlock_obj:
+ mdt_reint_striped_unlock(info, obj, lhc, einfo, rc);
+unlock_pobj:
+ mdt_object_unlock(info, pobj, lhp, rc);
+put_pobj:
+ mdt_object_put(env, pobj);
+put_obj:
+ mdt_object_put(env, obj);
+
+ return rc;