Whamcloud - gitweb
LU-5342 lmv: fix some byte order issues
[fs/lustre-release.git] / lustre / lmv / lmv_obd.c
index 745c215..5c452db 100644 (file)
@@ -1120,6 +1120,19 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
                rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
                break;
        }
+       case LL_IOC_FID2MDTIDX: {
+               struct lu_fid *fid = karg;
+               int             mdt_index;
+
+               rc = lmv_fld_lookup(lmv, fid, &mdt_index);
+               if (rc != 0)
+                       RETURN(rc);
+
+               /* Note: this is from llite(see ll_dir_ioctl()), @uarg does not
+                * point to user space memory for FID2MDTIDX. */
+               *(__u32 *)uarg = mdt_index;
+               break;
+       }
        case OBD_IOC_FID2PATH: {
                rc = lmv_fid2path(exp, len, karg, uarg);
                break;
@@ -1807,13 +1820,41 @@ lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
  * retval              pointer to the lmv_tgt_desc if succeed.
  *                      ERR_PTR(errno) if failed.
  */
-struct lmv_tgt_desc
-*lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
-               struct lu_fid *fid)
+struct lmv_tgt_desc*
+lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
+              struct lu_fid *fid)
 {
        struct lmv_stripe_md    *lsm = op_data->op_mea1;
        struct lmv_tgt_desc     *tgt;
 
+       /* During creating VOLATILE file, it should honor the mdt
+        * index if the file under striped dir is being restored, see
+        * ct_restore(). */
+       if (op_data->op_bias & MDS_CREATE_VOLATILE &&
+           (int)op_data->op_mds != -1 && lsm != NULL) {
+               int i;
+               tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
+               if (IS_ERR(tgt))
+                       return tgt;
+
+               /* refill the right parent fid */
+               for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
+                       struct lmv_oinfo *oinfo;
+
+                       oinfo = &lsm->lsm_md_oinfo[i];
+                       if (oinfo->lmo_mds == op_data->op_mds) {
+                               *fid = oinfo->lmo_fid;
+                               break;
+                       }
+               }
+
+               /* Hmm, can not find the stripe by mdt_index(op_mds) */
+               if (i == lsm->lsm_md_stripe_count)
+                       tgt = ERR_PTR(-EINVAL);
+
+               return tgt;
+       }
+
        if (lsm == NULL || op_data->op_namelen == 0) {
                tgt = lmv_find_target(lmv, fid);
                if (IS_ERR(tgt))
@@ -2725,7 +2766,7 @@ try_next_stripe:
 
        /* Not cross-ref case, just get out of here. */
        if (likely(!(body->mbo_valid & OBD_MD_MDS)))
-               RETURN(0);
+               RETURN(rc);
 
        CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
               exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
@@ -2995,7 +3036,7 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
               lsm->lsm_md_layout_version);
 
        stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
-       for (i = 0; i < le32_to_cpu(stripe_count); i++) {
+       for (i = 0; i < stripe_count; i++) {
                fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
                              &lmm1->lmv_stripe_fids[i]);
                rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,