Whamcloud - gitweb
LU-14930 mdt: abort_recov_mdt shouldn't abort client recovery
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index aae5616..47b97cf 100644 (file)
@@ -270,6 +270,41 @@ static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o
         EXIT;
 }
 
+/**
+ * Check whether \a o is directory stripe object.
+ *
+ * \param[in]  info    thread environment
+ * \param[in]  o       MDT object
+ *
+ * \retval 1   is directory stripe.
+ * \retval 0   isn't directory stripe.
+ * \retval < 1  error code
+ */
+static int mdt_is_dir_stripe(struct mdt_thread_info *info,
+                               struct mdt_object *o)
+{
+       struct md_attr *ma = &info->mti_attr;
+       struct lmv_mds_md_v1 *lmv;
+       int rc;
+
+       rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LMV);
+       if (rc < 0)
+               return rc;
+
+       if (!(ma->ma_valid & MA_LMV))
+               return 0;
+
+       lmv = &ma->ma_lmv->lmv_md_v1;
+
+       if (!lmv_is_sane2(lmv))
+               return -EBADF;
+
+       if (le32_to_cpu(lmv->lmv_magic) == LMV_MAGIC_STRIPE)
+               return 1;
+
+       return 0;
+}
+
 static int mdt_lookup_fileset(struct mdt_thread_info *info, const char *fileset,
                              struct lu_fid *fid)
 {
@@ -1419,6 +1454,7 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
 
        if (mdt_body_has_lov(la, reqbody)) {
                u32 stripe_count = 1;
+               bool fixed_layout = false;
 
                if (ma->ma_valid & MA_LOV) {
                        LASSERT(ma->ma_lmm_size);
@@ -1443,6 +1479,7 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                        repbody->mbo_valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
 
                        stripe_count = le32_to_cpu(lmv->lmv_stripe_count);
+                       fixed_layout = lmv_is_fixed(lmv);
                        if (magic == LMV_MAGIC_STRIPE && lmv_is_restriping(lmv))
                                mdt_restripe_migrate_add(info, o);
                        else if (magic == LMV_MAGIC_V1 &&
@@ -1474,7 +1511,8 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                    !fid_is_root(mdt_object_fid(o)) &&
                    mdt->mdt_enable_dir_auto_split &&
                    !o->mot_restriping &&
-                   stripe_count < atomic_read(&mdt->mdt_mds_mds_conns) + 1)
+                   stripe_count < atomic_read(&mdt->mdt_mds_mds_conns) + 1 &&
+                   !fixed_layout)
                        mdt_auto_split_add(info, o);
        } else if (S_ISLNK(la->la_mode) &&
                   reqbody->mbo_valid & OBD_MD_LINKNAME) {
@@ -1805,30 +1843,62 @@ out:
 
 static int mdt_raw_lookup(struct mdt_thread_info *info,
                          struct mdt_object *parent,
-                         const struct lu_name *lname,
-                         struct ldlm_reply *ldlm_rep)
+                         const struct lu_name *lname)
 {
-       struct lu_fid   *child_fid = &info->mti_tmp_fid1;
-       int              rc;
+       struct lu_fid *fid = &info->mti_tmp_fid1;
+       struct mdt_body *repbody;
+       bool is_dotdot = false;
+       bool is_old_parent_stripe = false;
+       bool is_new_parent_checked = false;
+       int rc;
+
        ENTRY;
 
        LASSERT(!info->mti_cross_ref);
+       /* Always allow to lookup ".." */
+       if (lname->ln_namelen == 2 &&
+           lname->ln_name[0] == '.' && lname->ln_name[1] == '.') {
+               info->mti_spec.sp_permitted = 1;
+               is_dotdot = true;
+               if (mdt_is_dir_stripe(info, parent) == 1)
+                       is_old_parent_stripe = true;
+       }
 
+       mdt_object_get(info->mti_env, parent);
+lookup:
        /* Only got the fid of this obj by name */
-       fid_zero(child_fid);
-       rc = mdo_lookup(info->mti_env, mdt_object_child(info->mti_object),
-                       lname, child_fid, &info->mti_spec);
-       if (rc == 0) {
-               struct mdt_body *repbody;
+       fid_zero(fid);
+       rc = mdo_lookup(info->mti_env, mdt_object_child(parent), lname, fid,
+                       &info->mti_spec);
+       mdt_object_put(info->mti_env, parent);
+       if (rc)
+               RETURN(rc);
+
+       /* getattr_name("..") should return master object FID for striped dir */
+       if (is_dotdot && (is_old_parent_stripe || !is_new_parent_checked)) {
+               parent = mdt_object_find(info->mti_env, info->mti_mdt, fid);
+               if (IS_ERR(parent))
+                       RETURN(PTR_ERR(parent));
+
+               /* old client getattr_name("..") with stripe FID */
+               if (unlikely(is_old_parent_stripe)) {
+                       is_old_parent_stripe = false;
+                       goto lookup;
+               }
 
-               repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
-               repbody->mbo_fid1 = *child_fid;
-               repbody->mbo_valid = OBD_MD_FLID;
-               mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
-       } else if (rc == -ENOENT) {
-               mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
+               /* ".." may be a stripe */
+               if (unlikely(mdt_is_dir_stripe(info, parent) == 1)) {
+                       is_new_parent_checked = true;
+                       goto lookup;
+               }
+
+               mdt_object_put(info->mti_env, parent);
        }
 
+       repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
+       repbody->mbo_fid1 = *fid;
+       repbody->mbo_valid = OBD_MD_FLID;
+
        RETURN(rc);
 }
 
@@ -1988,14 +2058,8 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
        }
 
        if (lu_name_is_valid(lname)) {
-               /* Always allow to lookup ".." */
-               if (unlikely(lname->ln_namelen == 2 &&
-                            lname->ln_name[0] == '.' &&
-                            lname->ln_name[1] == '.'))
-                       info->mti_spec.sp_permitted = 1;
-
                if (info->mti_body->mbo_valid == OBD_MD_FLID) {
-                       rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
+                       rc = mdt_raw_lookup(info, parent, lname);
 
                        RETURN(rc);
                }
@@ -2130,6 +2194,16 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                         PLDLMRES(lock->l_resource),
                         PFID(mdt_object_fid(child)));
 
+               if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_PTLRPC_ENQ_RESEND))) {
+                       if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
+                               OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_ENQ_RESEND,
+                                                req->rq_deadline -
+                                                req->rq_arrival_time.tv_sec +
+                                                cfs_fail_val ?: 3);
+                       /* Put the lock to the waiting list and force the cancel */
+                       ldlm_set_ast_sent(lock);
+               }
+
                if (S_ISREG(lu_object_attr(&child->mot_obj)) &&
                    !mdt_object_remote(child) && child != parent) {
                        mdt_object_put(info->mti_env, child);
@@ -2289,7 +2363,7 @@ static int mdt_rmfid_check_permission(struct mdt_thread_info *info,
        if (la->la_flags & LUSTRE_IMMUTABLE_FL)
                        rc = -EACCES;
 
-       if (md_capable(uc, CAP_DAC_OVERRIDE))
+       if (cap_raised(uc->uc_cap, CAP_DAC_OVERRIDE))
                RETURN(0);
        if (uc->uc_fsuid == la->la_uid) {
                if ((la->la_mode & S_IWUSR) == 0)
@@ -2460,7 +2534,7 @@ static int mdt_set_info(struct tgt_session_info *tsi)
                               tgt_name(tsi->tsi_tgt), vallen);
                        RETURN(-EINVAL);
                }
-               if (ptlrpc_req_need_swab(req)) {
+               if (req_capsule_req_need_swab(&req->rq_pill)) {
                        __swab64s(&cs->cs_recno);
                        __swab32s(&cs->cs_id);
                }
@@ -5451,6 +5525,8 @@ TGT_OST_HDL_HP(HAS_BODY | HAS_REPLY | IS_MUTABLE,
                                         OST_PUNCH,     mdt_punch_hdl,
                                                        mdt_hp_punch),
 TGT_OST_HDL(HAS_BODY | HAS_REPLY, OST_SYNC,    mdt_data_sync),
+TGT_OST_HDL(HAS_BODY | HAS_REPLY | IS_MUTABLE, OST_FALLOCATE,
+                                                       mdt_fallocate_hdl),
 TGT_OST_HDL(HAS_BODY | HAS_REPLY, OST_SEEK, tgt_lseek),
 };
 
@@ -6442,7 +6518,8 @@ static int mdt_export_cleanup(struct obd_export *exp)
                                rc = mdt_ctxt_add_dirty_flag(&env, info, mfd);
 
                        /* Don't unlink orphan on failover umount, LU-184 */
-                       if (exp->exp_flags & OBD_OPT_FAILOVER) {
+                       if (exp->exp_flags & OBD_OPT_FAILOVER ||
+                           exp->exp_obd->obd_stopping) {
                                ma->ma_valid = MA_FLAGS;
                                ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
                        }
@@ -6730,7 +6807,6 @@ static int mdt_path_current(struct mdt_thread_info *info,
        struct lu_name *tmpname = &info->mti_name;
        struct lu_fid *tmpfid = &info->mti_tmp_fid1;
        struct lu_buf *buf = &info->mti_big_buf;
-       struct md_attr *ma = &info->mti_attr;
        struct linkea_data ldata = { NULL };
        bool first = true;
        struct mdt_object *mdt_obj;
@@ -6803,22 +6879,13 @@ static int mdt_path_current(struct mdt_thread_info *info,
                }
 
                /* Check if it is slave stripes */
-               rc = mdt_stripe_get(info, mdt_obj, ma, XATTR_NAME_LMV);
+               rc = mdt_is_dir_stripe(info, mdt_obj);
                mdt_object_put(info->mti_env, mdt_obj);
                if (rc < 0)
                        GOTO(out, rc);
-
-               if (ma->ma_valid & MA_LMV) {
-                       struct lmv_mds_md_v1 *lmv = &ma->ma_lmv->lmv_md_v1;
-
-                       if (!lmv_is_sane2(lmv))
-                               GOTO(out, rc = -EBADF);
-
-                       /* For slave stripes, get its master */
-                       if (le32_to_cpu(lmv->lmv_magic) == LMV_MAGIC_STRIPE) {
-                               fp->gf_fid = *tmpfid;
-                               continue;
-                       }
+               if (rc == 1) {
+                       fp->gf_fid = *tmpfid;
+                       continue;
                }
 
                /* Pack the name in the end of the buffer */
@@ -6970,7 +7037,7 @@ static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key, int keylen,
        fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
        fpout = val;
 
-       if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
+       if (req_capsule_req_need_swab(info->mti_pill))
                lustre_swab_fid2path(fpin);
 
        memcpy(fpout, fpin, sizeof(*fpin));
@@ -6981,7 +7048,7 @@ static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key, int keylen,
                      sizeof(struct lu_fid)) {
                /* client sent its root FID, which is normally fileset FID */
                root_fid = fpin->gf_u.gf_root_fid;
-               if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
+               if (req_capsule_req_need_swab(info->mti_pill))
                        lustre_swab_lu_fid(root_fid);
 
                if (root_fid != NULL && !fid_is_sane(root_fid))
@@ -7117,13 +7184,14 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                struct obd_ioctl_data *data = karg;
 
                CERROR("%s: Aborting recovery for device\n", mdt_obd_name(mdt));
-               if (data->ioc_type & OBD_FLG_ABORT_RECOV_MDT)
+               if (data->ioc_type & OBD_FLG_ABORT_RECOV_MDT) {
                        obd->obd_abort_recov_mdt = 1;
-               else /* if (data->ioc_type & OBD_FLG_ABORT_RECOV_OST) */
+                       wake_up(&obd->obd_next_transno_waitq);
+               } else { /* if (data->ioc_type & OBD_FLG_ABORT_RECOV_OST) */
                        /* lctl didn't set OBD_FLG_ABORT_RECOV_OST < 2.13.57 */
                        obd->obd_abort_recovery = 1;
-
-               target_stop_recovery_thread(obd);
+                       target_stop_recovery_thread(obd);
+               }
                rc = 0;
                break;
        }