staging: lustre: lmv: honor MDT index when creating volatile file
authorwang di <di.wang@intel.com>
Sun, 18 Sep 2016 20:37:03 +0000 (16:37 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Sep 2016 07:24:10 +0000 (09:24 +0200)
LMV should honor MDT index embedded in the name of volatile
file, then during hsm restore, the file under striped dir can
be restored to the right MDT.

Signed-off-by: wang di <di.wang@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-4691
Reviewed-on: http://review.whamcloud.com/10866
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Henri Doreau <henri.doreau@cea.fr>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/include/lustre/lustre_user.h
drivers/staging/lustre/lustre/llite/dir.c
drivers/staging/lustre/lustre/llite/llite_lib.c
drivers/staging/lustre/lustre/lmv/lmv_fld.c
drivers/staging/lustre/lustre/lmv/lmv_internal.h
drivers/staging/lustre/lustre/lmv/lmv_obd.c

index 351fb4c..c69918b 100644 (file)
@@ -244,6 +244,7 @@ struct ost_id {
 #define LL_IOC_HSM_IMPORT              _IOWR('f', 245, struct hsm_user_import)
 #define LL_IOC_LMV_SET_DEFAULT_STRIPE  _IOWR('f', 246, struct lmv_user_md)
 #define LL_IOC_MIGRATE                 _IOR('f', 247, int)
+#define LL_IOC_FID2MDTIDX              _IOWR('f', 248, struct lu_fid)
 
 #define LL_STATFS_LMV     1
 #define LL_STATFS_LOV     2
index 532047b..c97a4a0 100644 (file)
@@ -1568,6 +1568,23 @@ out_quotactl:
                return rc;
        case OBD_IOC_FID2PATH:
                return ll_fid2path(inode, (void __user *)arg);
+       case LL_IOC_FID2MDTIDX: {
+               struct obd_export *exp = ll_i2mdexp(inode);
+               struct lu_fid fid;
+               __u32 index;
+
+               if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
+                                  sizeof(fid)))
+                       return -EFAULT;
+
+               /* Call mdc_iocontrol */
+               rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
+                                  &index);
+               if (rc)
+                       return rc;
+
+               return index;
+       }
        case LL_IOC_HSM_REQUEST: {
                struct hsm_user_request *hur;
                ssize_t                  totalsize;
index 1ff788e..99aba6b 100644 (file)
@@ -2373,9 +2373,10 @@ struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
        op_data->op_bias = 0;
        op_data->op_cli_flags = 0;
        if ((opc == LUSTRE_OPC_CREATE) && name &&
-           filename_is_volatile(name, namelen, NULL))
+           filename_is_volatile(name, namelen, &op_data->op_mds))
                op_data->op_bias |= MDS_CREATE_VOLATILE;
-       op_data->op_mds = 0;
+       else
+               op_data->op_mds = 0;
        op_data->op_data = data;
 
        /* When called by ll_setattr_raw, file is i1. */
index a3d170a..a5265f9 100644 (file)
 #include "../include/lprocfs_status.h"
 #include "lmv_internal.h"
 
-int lmv_fld_lookup(struct lmv_obd *lmv,
-                  const struct lu_fid *fid,
-                  u32 *mds)
+int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid, u32 *mds)
 {
+       struct obd_device *obd = lmv2obd_dev(lmv);
        int rc;
 
-       /* FIXME: Currently ZFS still use local seq for ROOT unfortunately, and
+       /*
+        * FIXME: Currently ZFS still use local seq for ROOT unfortunately, and
         * this fid_is_local check should be removed once LU-2240 is fixed
         */
-       LASSERTF((fid_seq_in_fldb(fid_seq(fid)) ||
-                 fid_seq_is_local_file(fid_seq(fid))) &&
-                fid_is_sane(fid), DFID" is insane!\n", PFID(fid));
+       if (!fid_is_sane(fid) || !(fid_seq_in_fldb(fid_seq(fid)) ||
+                                  fid_seq_is_local_file(fid_seq(fid)))) {
+               CERROR("%s: invalid FID " DFID "\n", obd->obd_name, PFID(fid));
+               return -EINVAL;
+       }
 
        rc = fld_client_lookup(&lmv->lmv_fld, fid_seq(fid), mds,
                               LU_SEQ_RANGE_MDT, NULL);
index c4961d9..4a5e385 100644 (file)
@@ -62,6 +62,11 @@ int lmv_revalidate_slaves(struct obd_export *exp, struct mdt_body *mbody,
                          ldlm_blocking_callback cb_blocking,
                          int extra_lock_flags);
 
+static inline struct obd_device *lmv2obd_dev(struct lmv_obd *lmv)
+{
+       return container_of0(lmv, struct obd_device, u.lmv);
+}
+
 static inline struct lmv_tgt_desc *
 lmv_get_target(struct lmv_obd *lmv, u32 mdt_idx, int *index)
 {
index 0713e55..1d53c76 100644 (file)
@@ -1073,6 +1073,21 @@ 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)
+                       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;
@@ -1671,13 +1686,44 @@ 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) {
+               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 || !op_data->op_namelen) {
                tgt = lmv_find_target(lmv, fid);
                if (IS_ERR(tgt))