Whamcloud - gitweb
LU-6586 mgs: deactive MDT permanently
[fs/lustre-release.git] / lustre / lmv / lmv_obd.c
index 300710d..792cfd5 100644 (file)
@@ -71,6 +71,8 @@ static void lmv_activate_target(struct lmv_obd *lmv,
 
         tgt->ltd_active = activate;
         lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
+
+       tgt->ltd_exp->exp_obd->obd_inactive = !activate;
 }
 
 /**
@@ -422,6 +424,7 @@ static void lmv_del_target(struct lmv_obd *lmv, int index)
 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
                           __u32 index, int gen)
 {
+       struct obd_device *mdc_obd;
         struct lmv_obd      *lmv = &obd->u.lmv;
         struct lmv_tgt_desc *tgt;
        int                  orig_tgt_count = 0;
@@ -429,22 +432,15 @@ static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
         ENTRY;
 
        CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
-
-       mutex_lock(&lmv->lmv_init_mutex);
-
-       if (lmv->desc.ld_tgt_count == 0) {
-               struct obd_device *mdc_obd;
-
-               mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
-                                               &obd->obd_uuid);
-               if (!mdc_obd) {
-                       mutex_unlock(&lmv->lmv_init_mutex);
-                       CERROR("%s: Target %s not attached: rc = %d\n",
-                              obd->obd_name, uuidp->uuid, -EINVAL);
-                       RETURN(-EINVAL);
-               }
+       mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
+                                       &obd->obd_uuid);
+       if (!mdc_obd) {
+               CERROR("%s: Target %s not attached: rc = %d\n",
+                      obd->obd_name, uuidp->uuid, -EINVAL);
+               RETURN(-EINVAL);
        }
 
+       mutex_lock(&lmv->lmv_init_mutex);
        if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
                tgt = lmv->tgts[index];
                CERROR("%s: UUID %s already assigned at LOV target index %d:"
@@ -501,22 +497,27 @@ static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
                lmv->desc.ld_tgt_count = index + 1;
        }
 
-       if (lmv->connected) {
-               rc = lmv_connect_mdc(obd, tgt);
-               if (rc != 0) {
-                       spin_lock(&lmv->lmv_lock);
-                       if (lmv->desc.ld_tgt_count == index + 1)
-                               lmv->desc.ld_tgt_count = orig_tgt_count;
-                       memset(tgt, 0, sizeof(*tgt));
-                       spin_unlock(&lmv->lmv_lock);
-               } else {
-                       int easize = sizeof(struct lmv_stripe_md) +
-                               lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
-                       lmv_init_ea_size(obd->obd_self_export, easize, 0);
-               }
+       if (lmv->connected == 0) {
+               /* lmv_check_connect() will connect this target. */
+               mutex_unlock(&lmv->lmv_init_mutex);
+               RETURN(0);
        }
 
+       /* Otherwise let's connect it ourselves */
        mutex_unlock(&lmv->lmv_init_mutex);
+       rc = lmv_connect_mdc(obd, tgt);
+       if (rc != 0) {
+               spin_lock(&lmv->lmv_lock);
+               if (lmv->desc.ld_tgt_count == index + 1)
+                       lmv->desc.ld_tgt_count = orig_tgt_count;
+               memset(tgt, 0, sizeof(*tgt));
+               spin_unlock(&lmv->lmv_lock);
+       } else {
+               int easize = sizeof(struct lmv_stripe_md) +
+                       lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
+               lmv_init_ea_size(obd->obd_self_export, easize, 0);
+       }
+
        RETURN(rc);
 }
 
@@ -1499,9 +1500,7 @@ out_free_temp:
         return rc;
 }
 
-static int lmv_getstatus(struct obd_export *exp,
-                         struct lu_fid *fid,
-                         struct obd_capa **pc)
+static int lmv_getstatus(struct obd_export *exp, struct lu_fid *fid)
 {
         struct obd_device    *obd = exp->exp_obd;
         struct lmv_obd       *lmv = &obd->u.lmv;
@@ -1512,12 +1511,12 @@ static int lmv_getstatus(struct obd_export *exp,
         if (rc)
                 RETURN(rc);
 
-       rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
+       rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid);
        RETURN(rc);
 }
 
 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
-                       struct obd_capa *oc, u64 valid, const char *name,
+                       u64 valid, const char *name,
                        const char *input, int input_size, int output_size,
                        int flags, struct ptlrpc_request **request)
 {
@@ -1535,14 +1534,14 @@ static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
 
-        rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
-                         input_size, output_size, flags, request);
+       rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
+                        input_size, output_size, flags, request);
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
-                       struct obd_capa *oc, u64 valid, const char *name,
+                       u64 valid, const char *name,
                        const char *input, int input_size, int output_size,
                        int flags, __u32 suppgid,
                        struct ptlrpc_request **request)
@@ -1561,11 +1560,11 @@ static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
 
-        rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
-                         input_size, output_size, flags, suppgid,
-                         request);
+       rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
+                        input_size, output_size, flags, suppgid,
+                        request);
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
@@ -2040,6 +2039,9 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
        struct obd_device       *obd = exp->exp_obd;
        struct lmv_obd          *lmv = &obd->u.lmv;
        struct lmv_tgt_desc     *src_tgt;
+       struct lmv_tgt_desc     *tgt_tgt;
+       struct obd_export       *target_exp;
+       struct mdt_body         *body;
        int                     rc;
        ENTRY;
 
@@ -2080,6 +2082,10 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
                        RETURN(rc);
 
                src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
+               if (IS_ERR(src_tgt))
+                       RETURN(PTR_ERR(src_tgt));
+
+               target_exp = src_tgt->ltd_exp;
        } else {
                if (op_data->op_mea1 != NULL) {
                        struct lmv_stripe_md    *lsm = op_data->op_mea1;
@@ -2088,29 +2094,29 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
                                                             oldlen,
                                                             &op_data->op_fid1,
                                                             &op_data->op_mds);
-                       if (IS_ERR(src_tgt))
-                               RETURN(PTR_ERR(src_tgt));
                } else {
                        src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
-                       if (IS_ERR(src_tgt))
-                               RETURN(PTR_ERR(src_tgt));
-
-                       op_data->op_mds = src_tgt->ltd_idx;
                }
+               if (IS_ERR(src_tgt))
+                       RETURN(PTR_ERR(src_tgt));
+
 
-               if (op_data->op_mea2) {
+               if (op_data->op_mea2 != NULL) {
                        struct lmv_stripe_md    *lsm = op_data->op_mea2;
-                       const struct lmv_oinfo  *oinfo;
 
-                       oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
-                       if (IS_ERR(oinfo))
-                               RETURN(PTR_ERR(oinfo));
+                       tgt_tgt = lmv_locate_target_for_name(lmv, lsm, new,
+                                                            newlen,
+                                                            &op_data->op_fid2,
+                                                            &op_data->op_mds);
+               } else {
+                       tgt_tgt = lmv_find_target(lmv, &op_data->op_fid2);
 
-                       op_data->op_fid2 = oinfo->lmo_fid;
                }
+               if (IS_ERR(tgt_tgt))
+                       RETURN(PTR_ERR(tgt_tgt));
+
+               target_exp = tgt_tgt->ltd_exp;
        }
-       if (IS_ERR(src_tgt))
-               RETURN(PTR_ERR(src_tgt));
 
        /*
         * LOOKUP lock on src child (fid3) should also be cancelled for
@@ -2152,21 +2158,52 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
                        RETURN(rc);
        }
 
+retry_rename:
        /*
         * Cancel all the locks on tgt child (fid4).
         */
-       if (fid_is_sane(&op_data->op_fid4))
+       if (fid_is_sane(&op_data->op_fid4)) {
+               struct lmv_tgt_desc *tgt;
+
                rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
                                      LCK_EX, MDS_INODELOCK_FULL,
                                      MF_MDC_CANCEL_FID4);
+               if (rc != 0)
+                       RETURN(rc);
 
-       CDEBUG(D_INODE, DFID":m%d to "DFID"\n", PFID(&op_data->op_fid1),
-              op_data->op_mds, PFID(&op_data->op_fid2));
+               tgt = lmv_find_target(lmv, &op_data->op_fid4);
+               if (IS_ERR(tgt))
+                       RETURN(PTR_ERR(tgt));
 
-       rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen, new, newlen,
+               /* Since the target child might be destroyed, and it might
+                * become orphan, and we can only check orphan on the local
+                * MDT right now, so we send rename request to the MDT where
+                * target child is located. If target child does not exist,
+                * then it will send the request to the target parent */
+               target_exp = tgt->ltd_exp;
+       }
+
+       rc = md_rename(target_exp, op_data, old, oldlen, new, newlen,
                       request);
 
-       RETURN(rc);
+       if (rc != 0 && rc != -EXDEV)
+               RETURN(rc);
+
+       body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
+       if (body == NULL)
+               RETURN(-EPROTO);
+
+       /* Not cross-ref case, just get out of here. */
+       if (likely(!(body->mbo_valid & OBD_MD_MDS)))
+               RETURN(rc);
+
+       CDEBUG(D_INODE, "%s: try rename to another MDT for "DFID"\n",
+              exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
+
+       op_data->op_fid4 = body->mbo_fid1;
+       ptlrpc_req_finished(*request);
+       *request = NULL;
+       goto retry_rename;
 }
 
 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
@@ -2196,7 +2233,7 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
 }
 
 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
-                    struct obd_capa *oc, struct ptlrpc_request **request)
+                    struct ptlrpc_request **request)
 {
        struct obd_device       *obd = exp->exp_obd;
        struct lmv_obd          *lmv = &obd->u.lmv;
@@ -2212,7 +2249,7 @@ static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
        if (IS_ERR(tgt))
                RETURN(PTR_ERR(tgt));
 
-       rc = md_fsync(tgt->ltd_exp, fid, oc, request);
+       rc = md_fsync(tgt->ltd_exp, fid, request);
        RETURN(rc);
 }
 
@@ -2911,8 +2948,8 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
        RETURN(rc);
 }
 
-int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
-                 const union lmv_mds_md *lmm, int stripe_count)
+static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
+                       const union lmv_mds_md *lmm, size_t lmm_size)
 {
        struct lmv_stripe_md     *lsm;
        int                      lsm_size;
@@ -2940,17 +2977,6 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
                RETURN(0);
        }
 
-       /* Alloc memmd */
-       if (lsm == NULL && lmm == NULL) {
-               lsm_size = lmv_stripe_md_size(stripe_count);
-               OBD_ALLOC(lsm, lsm_size);
-               if (lsm == NULL)
-                       RETURN(-ENOMEM);
-               lsm->lsm_md_stripe_count = stripe_count;
-               *lsmp = lsm;
-               RETURN(0);
-       }
-
        if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
                RETURN(-EPERM);
 
@@ -3000,24 +3026,12 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
        RETURN(lsm_size);
 }
 
-int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripes)
-{
-       return lmv_unpack_md(NULL, lsmp, NULL, stripes);
-}
-
 void lmv_free_memmd(struct lmv_stripe_md *lsm)
 {
-       lmv_unpack_md(NULL, &lsm, NULL, 0);
+       lmv_unpackmd(NULL, &lsm, NULL, 0);
 }
 EXPORT_SYMBOL(lmv_free_memmd);
 
-int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
-                 struct lov_mds_md *lmm, int disk_len)
-{
-       return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
-                            (union lmv_mds_md *)lmm, disk_len);
-}
-
 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
                              ldlm_policy_data_t *policy, ldlm_mode_t mode,
                              ldlm_cancel_flags_t flags, void *opaque)
@@ -3162,10 +3176,8 @@ int lmv_clear_open_replay_data(struct obd_export *exp,
         RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
 }
 
-static int lmv_get_remote_perm(struct obd_export *exp,
-                               const struct lu_fid *fid,
-                               struct obd_capa *oc, __u32 suppgid,
-                               struct ptlrpc_request **request)
+static int lmv_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
+                              u32 suppgid, struct ptlrpc_request **request)
 {
         struct obd_device       *obd = exp->exp_obd;
         struct lmv_obd          *lmv = &obd->u.lmv;
@@ -3181,40 +3193,8 @@ static int lmv_get_remote_perm(struct obd_export *exp,
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
 
-        rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
-        RETURN(rc);
-}
-
-static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
-                          renew_capa_cb_t cb)
-{
-        struct obd_device       *obd = exp->exp_obd;
-        struct lmv_obd          *lmv = &obd->u.lmv;
-        struct lmv_tgt_desc     *tgt;
-        int                      rc;
-        ENTRY;
-
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
-        tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
-        if (IS_ERR(tgt))
-                RETURN(PTR_ERR(tgt));
-
-        rc = md_renew_capa(tgt->ltd_exp, oc, cb);
-        RETURN(rc);
-}
-
-int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
-                   const struct req_msg_field *field, struct obd_capa **oc)
-{
-       struct lmv_obd          *lmv = &exp->exp_obd->u.lmv;
-       struct lmv_tgt_desc     *tgt = lmv->tgts[0];
-
-       if (tgt == NULL || tgt->ltd_exp == NULL)
-               RETURN(-EINVAL);
-       return md_unpack_capa(tgt->ltd_exp, req, field, oc);
+       rc = md_get_remote_perm(tgt->ltd_exp, fid, suppgid, request);
+       RETURN(rc);
 }
 
 int lmv_intent_getattr_async(struct obd_export *exp,
@@ -3384,7 +3364,6 @@ struct obd_ops lmv_obd_ops = {
         .o_statfs               = lmv_statfs,
         .o_get_info             = lmv_get_info,
         .o_set_info_async       = lmv_set_info_async,
-        .o_unpackmd             = lmv_unpackmd,
         .o_notify               = lmv_notify,
         .o_get_uuid             = lmv_get_uuid,
         .o_iocontrol            = lmv_iocontrol,
@@ -3418,12 +3397,11 @@ struct md_ops lmv_md_ops = {
        .m_merge_attr           = lmv_merge_attr,
         .m_set_open_replay_data = lmv_set_open_replay_data,
         .m_clear_open_replay_data = lmv_clear_open_replay_data,
-        .m_renew_capa           = lmv_renew_capa,
-        .m_unpack_capa          = lmv_unpack_capa,
         .m_get_remote_perm      = lmv_get_remote_perm,
         .m_intent_getattr_async = lmv_intent_getattr_async,
        .m_revalidate_lock      = lmv_revalidate_lock,
        .m_get_fid_from_lsm     = lmv_get_fid_from_lsm,
+       .m_unpackmd             = lmv_unpackmd,
 };
 
 int __init lmv_init(void)