Whamcloud - gitweb
LU-15938 lod: prevent endless retry in recovery thread
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 50abf84..e939c6e 100644 (file)
@@ -801,8 +801,9 @@ static inline bool mdt_hsm_is_released(struct lov_mds_md *lmm)
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid)
 {
-       struct md_attr *ma = &info->mti_attr;
+       struct mdt_device *mdt = info->mti_mdt;
        struct obd_export *exp = info->mti_exp;
+       struct md_attr *ma = &info->mti_attr;
        struct lu_nodemap *nodemap = NULL;
 
        LASSERT(ma->ma_valid & MA_INODE);
@@ -897,7 +898,9 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                        else
                                b->mbo_blocks = 1;
                        b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
-               } else if (info->mti_som_valid) { /* som is valid */
+               } else if (info->mti_som_strict &&
+                          mdt->mdt_opts.mo_enable_strict_som) {
+                       /* use SOM for size*/
                        b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
                } else if (ma->ma_valid & MA_SOM) { /* lsom is valid */
                        b->mbo_valid |= OBD_MD_FLLAZYSIZE | OBD_MD_FLLAZYBLOCKS;
@@ -1321,6 +1324,20 @@ out:
        RETURN(rc);
 }
 
+static void mdt_preset_encctx_size(struct mdt_thread_info *info)
+{
+       struct req_capsule *pill = info->mti_pill;
+
+       ENTRY;
+       if (req_capsule_has_field(pill, &RMF_FILE_ENCCTX,
+                                 RCL_SERVER))
+               /* pre-set size in server part with max size */
+               req_capsule_set_size(pill, &RMF_FILE_ENCCTX,
+                                    RCL_SERVER,
+                                    info->mti_mdt->mdt_max_mdsize);
+       EXIT;
+}
+
 static int mdt_getattr_internal(struct mdt_thread_info *info,
                                struct mdt_object *o, int ma_need)
 {
@@ -1641,6 +1658,7 @@ static int mdt_getattr(struct tgt_session_info *tsi)
         * enlarge the buffer when necessary. */
        req_capsule_set_size(pill, &RMF_ACL, RCL_SERVER,
                             LUSTRE_POSIX_ACL_MAX_SIZE_OLD);
+       mdt_preset_encctx_size(info);
 
        rc = req_capsule_server_pack(pill);
        if (unlikely(rc != 0))
@@ -1658,6 +1676,10 @@ static int mdt_getattr(struct tgt_session_info *tsi)
        info->mti_cross_ref = !!(reqbody->mbo_valid & OBD_MD_FLCROSSREF);
 
        rc = mdt_getattr_internal(info, obj, 0);
+       if (unlikely(rc))
+               GOTO(out_shrink, rc);
+
+       rc = mdt_pack_encctx_in_reply(info, obj);
        EXIT;
 out_shrink:
        mdt_client_compatibility(info);
@@ -1938,8 +1960,7 @@ int find_name_matching_hash(struct mdt_thread_info *info, struct lu_name *lname,
        int reclen, count, rc;
 
        ENTRY;
-
-       if (lname->ln_namelen < LLCRYPT_FNAME_DIGEST_SIZE)
+       if (lname->ln_namelen < LL_CRYPTO_BLOCK_SIZE)
                RETURN(-EINVAL);
 
        buf = lu_buf_check_and_alloc(buf, PATH_MAX);
@@ -1967,8 +1988,8 @@ int find_name_matching_hash(struct mdt_thread_info *info, struct lu_name *lname,
                        rc = critical_decode(name.ln_name, name.ln_namelen,
                                             link.lb_buf);
 
-                       if (memcmp(LLCRYPT_FNAME_DIGEST(link.lb_buf, rc),
-                                  hash, LLCRYPT_FNAME_DIGEST_SIZE) == 0) {
+                       if (memcmp(LLCRYPT_EXTRACT_DIGEST(link.lb_buf, rc),
+                                  hash, LL_CRYPTO_BLOCK_SIZE) == 0) {
                                *lname = name;
                                break;
                        }
@@ -2375,6 +2396,15 @@ out_child:
 unlock_parent:
        if (lhp)
                mdt_object_unlock(info, parent, lhp, 1);
+       if (rc == -ENOENT) {
+               /* return -ENOKEY instead of -ENOENT to encryption-unaware
+                * client if trying to access an encrypted file
+                */
+               int rc2 = mdt_check_enc(info, parent);
+
+               if (rc2)
+                       rc = rc2;
+       }
        return rc;
 }
 
@@ -2868,18 +2898,6 @@ static void mdt_preset_secctx_size(struct mdt_thread_info *info)
        }
 }
 
-static void mdt_preset_encctx_size(struct mdt_thread_info *info)
-{
-       struct req_capsule *pill = info->mti_pill;
-
-       if (req_capsule_has_field(pill, &RMF_FILE_ENCCTX,
-                                 RCL_SERVER))
-               /* pre-set size in server part with max size */
-               req_capsule_set_size(pill, &RMF_FILE_ENCCTX,
-                                    RCL_SERVER,
-                                    info->mti_mdt->mdt_max_mdsize);
-}
-
 static int mdt_reint_internal(struct mdt_thread_info *info,
                               struct mdt_lock_handle *lhc,
                               __u32 op)
@@ -3212,10 +3230,11 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
        case LUSTRE_Q_SETQUOTAPOOL:
        case LUSTRE_Q_SETINFOPOOL:
        case LUSTRE_Q_SETDEFAULT_POOL:
+       case LUSTRE_Q_DELETEQID:
                if (!nodemap_can_setquota(nodemap, oqctl->qc_type,
                                          oqctl->qc_id))
                        GOTO(out_nodemap, rc = -EPERM);
-               /* fallthrough */
+               fallthrough;
        case Q_GETINFO:
        case Q_GETQUOTA:
        case LUSTRE_Q_GETDEFAULT:
@@ -3225,7 +3244,7 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
                if (qmt == NULL)
                        GOTO(out_nodemap, rc = -EOPNOTSUPP);
                /* slave quotactl */
-               /* fallthrough */
+               fallthrough;
        case Q_GETOINFO:
        case Q_GETOQUOTA:
                break;
@@ -3282,6 +3301,7 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
        case LUSTRE_Q_GETINFOPOOL:
        case LUSTRE_Q_SETDEFAULT_POOL:
        case LUSTRE_Q_GETDEFAULT_POOL:
+       case LUSTRE_Q_DELETEQID:
                /* forward quotactl request to QMT */
                rc = qmt_hdls.qmth_quotactl(tsi->tsi_env, qmt, oqctl);
                break;
@@ -4240,7 +4260,7 @@ void mdt_thread_info_init(struct ptlrpc_request *req,
         info->mti_opdata = 0;
        info->mti_big_lmm_used = 0;
        info->mti_big_acl_used = 0;
-       info->mti_som_valid = 0;
+       info->mti_som_strict = 0;
 
         info->mti_spec.no_create = 0;
        info->mti_spec.sp_rm_entry = 0;
@@ -4559,13 +4579,14 @@ static int mdt_intent_getattr(enum ldlm_intent_flags it_opc,
        rc = mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
        ldlm_rep->lock_policy_res2 = clear_serious(rc);
 
-        if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
-                ldlm_rep->lock_policy_res2 = 0;
-        if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
-            ldlm_rep->lock_policy_res2) {
-                lhc->mlh_reg_lh.cookie = 0ull;
-                GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
-        }
+       if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG) &&
+           ldlm_rep->lock_policy_res2 != -ENOKEY)
+               ldlm_rep->lock_policy_res2 = 0;
+       if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
+           ldlm_rep->lock_policy_res2) {
+               lhc->mlh_reg_lh.cookie = 0ull;
+               GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
+       }
 
        rc = mdt_intent_lock_replace(info, lockp, lhc, flags, rc);
         EXIT;
@@ -4829,7 +4850,7 @@ static int mdt_intent_opc(enum ldlm_intent_flags it_opc,
                break;
        case IT_GETATTR:
                check_mdt_object = true;
-               /* fallthrough */
+               fallthrough;
        case IT_LOOKUP:
                it_format = &RQF_LDLM_INTENT_GETATTR;
                it_handler = &mdt_intent_getattr;
@@ -5974,16 +5995,19 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
        INIT_LIST_HEAD(&m->mdt_squash.rsi_nosquash_nids);
        spin_lock_init(&m->mdt_squash.rsi_lock);
        spin_lock_init(&m->mdt_lock);
-       m->mdt_enable_remote_dir = 1;
-       m->mdt_enable_striped_dir = 1;
+       m->mdt_enable_chprojid_gid = 0;
        m->mdt_enable_dir_migration = 1;
        m->mdt_enable_dir_restripe = 0;
        m->mdt_enable_dir_auto_split = 0;
+       m->mdt_enable_parallel_rename_dir = 1;
+       m->mdt_enable_parallel_rename_file = 1;
+       m->mdt_enable_remote_dir = 1;
        m->mdt_enable_remote_dir_gid = 0;
-       m->mdt_enable_chprojid_gid = 0;
        m->mdt_enable_remote_rename = 1;
-       m->mdt_dir_restripe_nsonly = 1;
        m->mdt_enable_remote_subdir_mount = 1;
+       m->mdt_enable_striped_dir = 1;
+       m->mdt_dir_restripe_nsonly = 1;
+       m->mdt_rename_stats.rs_init = ktime_get();
 
        atomic_set(&m->mdt_mds_mds_conns, 0);
        atomic_set(&m->mdt_async_commit_count, 0);
@@ -6106,6 +6130,8 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
        else
                m->mdt_opts.mo_acl = 0;
 
+       m->mdt_opts.mo_enable_strict_som = 1;
+
        /* XXX: to support suppgid for ACL, we enable identity_upcall
         * by default, otherwise, maybe got unexpected -EACCESS. */
        if (m->mdt_opts.mo_acl)
@@ -7407,12 +7433,15 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
        case OBD_IOC_ABORT_RECOVERY: {
                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) {
+                       CERROR("%s: Aborting MDT recovery\n",
+                              mdt_obd_name(mdt));
                        obd->obd_abort_recov_mdt = 1;
                        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 */
+                       CERROR("%s: Aborting client recovery\n",
+                              mdt_obd_name(mdt));
                        obd->obd_abort_recovery = 1;
                        target_stop_recovery_thread(obd);
                }