From: Mikhail Pershin Date: Fri, 12 Jul 2013 04:53:07 +0000 (+0400) Subject: LU-3467 mdt: call MDT handlers via unified request handler X-Git-Tag: 2.5.51~76 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=f0c1b06f2418d2016e23eb6e8277be85ca13fc53 LU-3467 mdt: call MDT handlers via unified request handler Move MDT to the unified request handler. All MDT-specific handlers are swtched to use tgt_session_info instead of mdt_thread_info. To minimize amount of changes the mdt_thread_info is initialized just from tgt_session_info in most cases for now. Signed-off-by: Mikhail Pershin Change-Id: I72e342cc900dc3dd34ca709542ad67de5015dd1f Reviewed-on: http://review.whamcloud.com/6973 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Andreas Dilger --- diff --git a/lustre/include/lu_target.h b/lustre/include/lu_target.h index f87f8ce..aa2c142 100644 --- a/lustre/include/lu_target.h +++ b/lustre/include/lu_target.h @@ -94,6 +94,10 @@ struct tgt_session_info { struct obd_export *tsi_exp; const struct lu_env *tsi_env; struct lu_target *tsi_tgt; + + const struct mdt_body *tsi_mdt_body; + struct lu_object *tsi_corpus; + /* * Additional fail id that can be set by handler. */ @@ -208,6 +212,7 @@ int tgt_llog_prev_block(struct tgt_session_info *tsi); int tgt_sec_ctx_init(struct tgt_session_info *tsi); int tgt_sec_ctx_init_cont(struct tgt_session_info *tsi); int tgt_sec_ctx_fini(struct tgt_session_info *tsi); +int tgt_sendpage(struct tgt_session_info *tsi, struct lu_rdpg *rdpg, int nob); extern struct tgt_handler tgt_sec_ctx_handlers[]; extern struct tgt_handler tgt_obd_handlers[]; diff --git a/lustre/include/lustre_export.h b/lustre/include/lustre_export.h index 0b1f80e..649aa23 100644 --- a/lustre/include/lustre_export.h +++ b/lustre/include/lustre_export.h @@ -77,8 +77,6 @@ struct mdt_export_data { /** List of all files opened by client on this MDT */ cfs_list_t med_open_head; spinlock_t med_open_lock; /* med_open_head, mfd_list */ - /** Bitmask of all ibit locks this MDT understands */ - __u64 med_ibits_known; struct mutex med_idmap_mutex; struct lustre_idmap_table *med_idmap; }; diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 2ed976d..12a8166 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -102,6 +102,7 @@ struct mdd_thread_info *mdd_env_info(const struct lu_env *env) { struct mdd_thread_info *info; + lu_env_refill((struct lu_env *)env); info = lu_context_key_get(&env->le_ctx, &mdd_thread_key); LASSERT(info != NULL); return info; diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 757bae3..23a2136 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -258,32 +258,34 @@ static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o EXIT; } -int mdt_getstatus(struct mdt_thread_info *info) +int mdt_getstatus(struct tgt_session_info *tsi) { - struct mdt_device *mdt = info->mti_mdt; + struct mdt_thread_info *info = tsi2mdt_info(tsi); + struct mdt_device *mdt = info->mti_mdt; struct mdt_body *repbody; - int rc; + int rc; + ENTRY; - rc = mdt_check_ucred(info); - if (rc) - RETURN(err_serious(rc)); + rc = mdt_check_ucred(info); + if (rc) + GOTO(out, rc = err_serious(rc)); - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) - RETURN(err_serious(-ENOMEM)); + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) + GOTO(out, rc = err_serious(-ENOMEM)); repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); repbody->fid1 = mdt->mdt_md_root_fid; - repbody->valid |= OBD_MD_FLID; + repbody->valid |= OBD_MD_FLID; - if (mdt->mdt_opts.mo_mds_capa && + if (tsi->tsi_tgt->lut_mds_capa && exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) { - struct mdt_object *root; - struct lustre_capa *capa; + struct mdt_object *root; + struct lustre_capa *capa; - root = mdt_object_find(info->mti_env, mdt, &repbody->fid1); - if (IS_ERR(root)) - RETURN(PTR_ERR(root)); + root = mdt_object_find(info->mti_env, mdt, &repbody->fid1); + if (IS_ERR(root)) + GOTO(out, rc = PTR_ERR(root)); capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1); LASSERT(capa); @@ -294,13 +296,16 @@ int mdt_getstatus(struct mdt_thread_info *info) if (rc == 0) repbody->valid |= OBD_MD_FLMDSCAPA; } - - RETURN(rc); + EXIT; +out: + mdt_thread_info_fini(info); + return rc; } -int mdt_statfs(struct mdt_thread_info *info) +int mdt_statfs(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); + struct ptlrpc_request *req = tgt_ses_req(tsi); + struct mdt_thread_info *info = tsi2mdt_info(tsi); struct md_device *next = info->mti_mdt->mdt_child; struct ptlrpc_service_part *svcpt; struct obd_statfs *osfs; @@ -308,23 +313,23 @@ int mdt_statfs(struct mdt_thread_info *info) ENTRY; - svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt; + svcpt = req->rq_rqbd->rqbd_svcpt; /* This will trigger a watchdog timeout */ OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP, (MDT_SERVICE_WATCHDOG_FACTOR * at_get(&svcpt->scp_at_estimate)) + 1); - rc = mdt_check_ucred(info); - if (rc) - RETURN(err_serious(rc)); + rc = mdt_check_ucred(info); + if (rc) + GOTO(out, rc = err_serious(rc)); if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) - RETURN(err_serious(-ENOMEM)); + GOTO(out, rc = err_serious(-ENOMEM)); osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS); if (!osfs) - RETURN(-EPROTO); + GOTO(out, rc = -EPROTO); /** statfs information are cached in the mdt_device */ if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age, @@ -332,7 +337,7 @@ int mdt_statfs(struct mdt_thread_info *info) /** statfs data is too old, get up-to-date one */ rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs); if (rc) - RETURN(rc); + GOTO(out, rc); spin_lock(&info->mti_mdt->mdt_osfs_lock); info->mti_mdt->mdt_osfs = *osfs; info->mti_mdt->mdt_osfs_age = cfs_time_current_64(); @@ -346,7 +351,8 @@ int mdt_statfs(struct mdt_thread_info *info) if (rc == 0) mdt_counter_incr(req, LPROC_MDT_STATFS); - +out: + mdt_thread_info_fini(info); RETURN(rc); } @@ -909,7 +915,7 @@ static int mdt_getattr_internal(struct mdt_thread_info *info, #endif if (reqbody->valid & OBD_MD_FLMDSCAPA && - info->mti_mdt->mdt_opts.mo_mds_capa && + info->mti_mdt->mdt_lut.lut_mds_capa && exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) { struct lustre_capa *capa; @@ -941,7 +947,7 @@ static int mdt_renew_capa(struct mdt_thread_info *info) * return directly, client will find body->valid OBD_MD_FLOSSCAPA * flag not set. */ - if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa || + if (!obj || !info->mti_mdt->mdt_lut.lut_oss_capa || !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA)) RETURN(0); @@ -961,8 +967,9 @@ static int mdt_renew_capa(struct mdt_thread_info *info) RETURN(rc); } -int mdt_getattr(struct mdt_thread_info *info) +int mdt_getattr(struct tgt_session_info *tsi) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_object *obj = info->mti_object; struct req_capsule *pill = info->mti_pill; struct mdt_body *reqbody; @@ -987,15 +994,15 @@ int mdt_getattr(struct mdt_thread_info *info) mode = lu_object_attr(&obj->mot_obj); - /* old clients may not report needed easize, use max value then */ - req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, - reqbody->eadatasize == 0 ? - info->mti_mdt->mdt_max_mdsize : - reqbody->eadatasize); + /* old clients may not report needed easize, use max value then */ + req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, + reqbody->eadatasize == 0 ? + info->mti_mdt->mdt_max_mdsize : + reqbody->eadatasize); - rc = req_capsule_server_pack(pill); - if (unlikely(rc != 0)) - RETURN(err_serious(rc)); + rc = req_capsule_server_pack(pill); + if (unlikely(rc != 0)) + GOTO(out, rc = err_serious(rc)); repbody = req_capsule_server_get(pill, &RMF_MDT_BODY); LASSERT(repbody != NULL); @@ -1025,11 +1032,14 @@ out_shrink: rc2 = mdt_fix_reply(info); if (rc == 0) rc = rc2; - return rc; +out: + mdt_thread_info_fini(info); + return rc; } -int mdt_is_subdir(struct mdt_thread_info *info) +int mdt_is_subdir(struct tgt_session_info *tsi) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_object *o = info->mti_object; struct req_capsule *pill = info->mti_pill; const struct mdt_body *body = info->mti_body; @@ -1052,12 +1062,14 @@ int mdt_is_subdir(struct mdt_thread_info *info) if (rc == 0 || rc == -EREMOTE) repbody->valid |= OBD_MD_FLID; + mdt_thread_info_fini(info); RETURN(rc); } -int mdt_swap_layouts(struct mdt_thread_info *info) +int mdt_swap_layouts(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); + struct mdt_thread_info *info; + struct ptlrpc_request *req = tgt_ses_req(tsi); struct obd_export *exp = req->rq_export; struct mdt_object *o1, *o2, *o; struct mdt_lock_handle *lh1, *lh2; @@ -1075,6 +1087,7 @@ int mdt_swap_layouts(struct mdt_thread_info *info) if (!exp_connect_layout(exp)) RETURN(-EOPNOTSUPP); + info = tsi2mdt_info(tsi); if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, &info->mti_body->fid1, req_capsule_client_get(info->mti_pill, @@ -1142,6 +1155,7 @@ unlock1: put: mdt_object_put(info->mti_env, o); out: + mdt_thread_info_fini(info); RETURN(rc); } @@ -1483,8 +1497,9 @@ out_parent: } /* normal handler: should release the child lock */ -int mdt_getattr_name(struct mdt_thread_info *info) +int mdt_getattr_name(struct tgt_session_info *tsi) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD]; struct mdt_body *reqbody; struct mdt_body *repbody; @@ -1516,47 +1531,42 @@ out_shrink: rc2 = mdt_fix_reply(info); if (rc == 0) rc = rc2; - return rc; + mdt_thread_info_fini(info); + return rc; } static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg); -int mdt_set_info(struct mdt_thread_info *info) +int mdt_set_info(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); - char *key; - void *val; - int keylen, vallen, rc = 0; - ENTRY; - - rc = req_capsule_server_pack(info->mti_pill); - if (rc) - RETURN(rc); + struct ptlrpc_request *req = tgt_ses_req(tsi); + char *key; + void *val; + int keylen, vallen, rc = 0; - key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY); - if (key == NULL) { - DEBUG_REQ(D_HA, req, "no set_info key"); - RETURN(-EFAULT); - } + ENTRY; - keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY, - RCL_CLIENT); + key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY); + if (key == NULL) { + DEBUG_REQ(D_HA, req, "no set_info key"); + RETURN(err_serious(-EFAULT)); + } - val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL); - if (val == NULL) { - DEBUG_REQ(D_HA, req, "no set_info val"); - RETURN(-EFAULT); - } + keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY, + RCL_CLIENT); - vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL, - RCL_CLIENT); + val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL); + if (val == NULL) { + DEBUG_REQ(D_HA, req, "no set_info val"); + RETURN(err_serious(-EFAULT)); + } - /* Swab any part of val you need to here */ - if (KEY_IS(KEY_READ_ONLY)) { - req->rq_status = 0; - lustre_msg_set_status(req->rq_repmsg, 0); + vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL, + RCL_CLIENT); + /* Swab any part of val you need to here */ + if (KEY_IS(KEY_READ_ONLY)) { spin_lock(&req->rq_export->exp_lock); if (*(__u32 *)val) *exp_connect_flags_ptr(req->rq_export) |= @@ -1565,142 +1575,44 @@ int mdt_set_info(struct mdt_thread_info *info) *exp_connect_flags_ptr(req->rq_export) &= ~OBD_CONNECT_RDONLY; spin_unlock(&req->rq_export->exp_lock); + } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) { + struct changelog_setinfo *cs = val; - } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) { - struct changelog_setinfo *cs = - (struct changelog_setinfo *)val; - if (vallen != sizeof(*cs)) { - CERROR("Bad changelog_clear setinfo size %d\n", vallen); - RETURN(-EINVAL); - } - if (ptlrpc_req_need_swab(req)) { - __swab64s(&cs->cs_recno); - __swab32s(&cs->cs_id); - } - - rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp, - vallen, val, NULL); - lustre_msg_set_status(req->rq_repmsg, rc); + if (vallen != sizeof(*cs)) { + CERROR("%s: bad changelog_clear setinfo size %d\n", + tgt_name(tsi->tsi_tgt), vallen); + RETURN(-EINVAL); + } + if (ptlrpc_req_need_swab(req)) { + __swab64s(&cs->cs_recno); + __swab32s(&cs->cs_id); + } - } else { - RETURN(-EINVAL); - } - RETURN(0); + rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, req->rq_export, + vallen, val, NULL); + } else { + RETURN(-EINVAL); + } + RETURN(rc); } -int mdt_connect_check_sptlrpc(struct mdt_device *mdt, struct obd_export *exp, - struct ptlrpc_request *req); - -/** - * Top-level handler for MDT connection requests. - */ -int mdt_connect(struct mdt_thread_info *info) +int mdt_readpage(struct tgt_session_info *tsi) { - int rc; - struct obd_connect_data *reply; - struct obd_export *exp; - struct ptlrpc_request *req = mdt_info_req(info); + struct mdt_thread_info *info = mdt_th_info(tsi->tsi_env); + struct mdt_object *object = mdt_obj(tsi->tsi_corpus); + struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg; + const struct mdt_body *reqbody = tsi->tsi_mdt_body; + struct mdt_body *repbody; + int rc; + int i; ENTRY; - rc = target_handle_connect(req); - if (rc != 0) - RETURN(err_serious(rc)); - - LASSERT(req->rq_export != NULL); - exp = req->rq_export; - info->mti_exp = exp; - info->mti_mdt = mdt_dev(exp->exp_obd->obd_lu_dev); - rc = mdt_init_sec_level(info); - if (rc != 0) - GOTO(err, rc); - - rc = mdt_connect_check_sptlrpc(info->mti_mdt, exp, req); - if (rc) - GOTO(err, rc); - - /* To avoid exposing partially initialized connection flags, changes up - * to this point have been staged in reply->ocd_connect_flags. Now that - * connection handling has completed successfully, atomically update - * the connect flags in the shared export data structure. LU-1623 */ - reply = req_capsule_server_get(info->mti_pill, &RMF_CONNECT_DATA); - spin_lock(&exp->exp_lock); - *exp_connect_flags_ptr(exp) = reply->ocd_connect_flags; - exp->exp_mdt_data.med_ibits_known = reply->ocd_ibits_known; - exp->exp_connect_data.ocd_brw_size = reply->ocd_brw_size; - spin_unlock(&exp->exp_lock); - - rc = mdt_init_idmap(info); - if (rc != 0) - GOTO(err, rc); - RETURN(0); -err: - obd_disconnect(class_export_get(req->rq_export)); - return rc; -} - -int mdt_disconnect(struct mdt_thread_info *info) -{ - int rc; - ENTRY; - - rc = target_handle_disconnect(mdt_info_req(info)); - if (rc) - rc = err_serious(rc); - RETURN(rc); -} - -static int mdt_sendpage(struct mdt_thread_info *info, - struct lu_rdpg *rdpg, int nob) -{ - struct ptlrpc_request *req = mdt_info_req(info); - struct obd_export *exp = req->rq_export; - struct ptlrpc_bulk_desc *desc; - struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info; - int tmpcount; - int tmpsize; - int i; - int rc; - ENTRY; - - desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, 1, BULK_PUT_SOURCE, - MDS_BULK_PORTAL); - if (desc == NULL) - RETURN(-ENOMEM); - - if (!(exp_connect_flags(exp) & OBD_CONNECT_BRW_SIZE)) - /* old client requires reply size in it's PAGE_SIZE, - * which is rdpg->rp_count */ - nob = rdpg->rp_count; - - for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0; - i++, tmpcount -= tmpsize) { - tmpsize = min_t(int, tmpcount, PAGE_CACHE_SIZE); - ptlrpc_prep_bulk_page_pin(desc, rdpg->rp_pages[i], 0, tmpsize); - } - - LASSERT(desc->bd_nob == nob); - rc = target_bulk_io(exp, desc, lwi); - ptlrpc_free_bulk_pin(desc); - RETURN(rc); -} - -int mdt_readpage(struct mdt_thread_info *info) -{ - struct mdt_object *object = info->mti_object; - struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg; - struct mdt_body *reqbody; - struct mdt_body *repbody; - int rc; - int i; - ENTRY; - - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) - RETURN(err_serious(-ENOMEM)); + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) + RETURN(err_serious(-ENOMEM)); - reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY); - repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); - if (reqbody == NULL || repbody == NULL) + repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_MDT_BODY); + if (repbody == NULL || reqbody == NULL) RETURN(err_serious(-EFAULT)); /* @@ -1716,10 +1628,10 @@ int mdt_readpage(struct mdt_thread_info *info) } rdpg->rp_attrs = reqbody->mode; - if (exp_connect_flags(info->mti_exp) & OBD_CONNECT_64BITHASH) + if (exp_connect_flags(tsi->tsi_exp) & OBD_CONNECT_64BITHASH) rdpg->rp_attrs |= LUDA_64BITHASH; rdpg->rp_count = min_t(unsigned int, reqbody->nlink, - exp_max_brw_size(info->mti_exp)); + exp_max_brw_size(tsi->tsi_exp)); rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]); @@ -1733,36 +1645,36 @@ int mdt_readpage(struct mdt_thread_info *info) } /* call lower layers to fill allocated pages with directory data */ - rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg); - if (rc < 0) - GOTO(free_rdpg, rc); + rc = mo_readpage(tsi->tsi_env, mdt_object_child(object), rdpg); + if (rc < 0) + GOTO(free_rdpg, rc); - /* send pages to client */ - rc = mdt_sendpage(info, rdpg, rc); + /* send pages to client */ + rc = tgt_sendpage(tsi, rdpg, rc); - EXIT; + EXIT; free_rdpg: - for (i = 0; i < rdpg->rp_npages; i++) - if (rdpg->rp_pages[i] != NULL) + for (i = 0; i < rdpg->rp_npages; i++) + if (rdpg->rp_pages[i] != NULL) __free_page(rdpg->rp_pages[i]); - OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]); + OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]); - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) - RETURN(0); + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) + RETURN(0); - return rc; + return rc; } static int mdt_reint_internal(struct mdt_thread_info *info, struct mdt_lock_handle *lhc, __u32 op) { - struct req_capsule *pill = info->mti_pill; - struct mdt_body *repbody; - int rc = 0, rc2; - ENTRY; + struct req_capsule *pill = info->mti_pill; + struct mdt_body *repbody; + int rc = 0, rc2; + ENTRY; rc = mdt_reint_unpack(info, op); if (rc != 0) { @@ -1823,23 +1735,24 @@ out_shrink: return rc; } -static long mdt_reint_opcode(struct mdt_thread_info *info, +static long mdt_reint_opcode(struct ptlrpc_request *req, const struct req_format **fmt) { - struct mdt_rec_reint *rec; - long opc; + struct mdt_device *mdt; + struct mdt_rec_reint *rec; + long opc; - rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT); + rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); if (rec != NULL) { opc = rec->rr_opcode; - DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc); + DEBUG_REQ(D_INODE, req, "reint opt = %ld", opc); if (opc < REINT_MAX && fmt[opc] != NULL) - req_capsule_extend(info->mti_pill, fmt[opc]); + req_capsule_extend(&req->rq_pill, fmt[opc]); else { - CERROR("%s: Unsupported opcode '%ld' from client '%s': " - "rc = %d\n", mdt_obd_name(info->mti_mdt), opc, - info->mti_mdt->mdt_ldlm_client->cli_name, - -EFAULT); + mdt = mdt_exp2dev(req->rq_export); + CERROR("%s: Unsupported opcode '%ld' from client '%s':" + " rc = %d\n", req->rq_export->exp_obd->obd_name, + opc, mdt->mdt_ldlm_client->cli_name, -EFAULT); opc = err_serious(-EFAULT); } } else { @@ -1848,11 +1761,10 @@ static long mdt_reint_opcode(struct mdt_thread_info *info, return opc; } -int mdt_reint(struct mdt_thread_info *info) +int mdt_reint(struct tgt_session_info *tsi) { long opc; int rc; - static const struct req_format *reint_fmts[REINT_MAX] = { [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR, [REINT_CREATE] = &RQF_MDS_REINT_CREATE, @@ -1861,24 +1773,26 @@ int mdt_reint(struct mdt_thread_info *info) [REINT_RENAME] = &RQF_MDS_REINT_RENAME, [REINT_OPEN] = &RQF_MDS_REINT_OPEN, [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR, - [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK + [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK }; - ENTRY; + ENTRY; - opc = mdt_reint_opcode(info, reint_fmts); - if (opc >= 0) { - /* - * No lock possible here from client to pass it to reint code - * path. - */ - rc = mdt_reint_internal(info, NULL, opc); - } else { - rc = opc; - } + opc = mdt_reint_opcode(tgt_ses_req(tsi), reint_fmts); + if (opc >= 0) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); + /* + * No lock possible here from client to pass it to reint code + * path. + */ + rc = mdt_reint_internal(info, NULL, opc); + mdt_thread_info_fini(info); + } else { + rc = opc; + } - info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP; - RETURN(rc); + tsi->tsi_reply_fail_id = OBD_FAIL_MDS_REINT_NET_REP; + RETURN(rc); } /* this should sync the whole device */ @@ -1910,93 +1824,60 @@ static int mdt_object_sync(struct mdt_thread_info *info) RETURN(rc); } -int mdt_sync(struct mdt_thread_info *info) +int mdt_sync(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); - struct req_capsule *pill = info->mti_pill; - struct mdt_body *body; - int rc; - ENTRY; - - /* The fid may be zero, so we req_capsule_set manually */ - req_capsule_set(pill, &RQF_MDS_SYNC); - - body = req_capsule_client_get(pill, &RMF_MDT_BODY); - if (body == NULL) - RETURN(err_serious(-EINVAL)); - - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) - RETURN(err_serious(-ENOMEM)); - - if (fid_seq(&body->fid1) == 0) { - /* sync the whole device */ - rc = req_capsule_server_pack(pill); - if (rc == 0) - rc = mdt_device_sync(info->mti_env, info->mti_mdt); - else - rc = err_serious(rc); - } else { - /* sync an object */ - rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO); - if (rc == 0) { - rc = mdt_object_sync(info); - if (rc == 0) { - const struct lu_fid *fid; - struct lu_attr *la = &info->mti_attr.ma_attr; - - info->mti_attr.ma_need = MA_INODE; - info->mti_attr.ma_valid = 0; - rc = mdt_attr_get_complex(info, info->mti_object, - &info->mti_attr); - if (rc == 0) { - body = req_capsule_server_get(pill, - &RMF_MDT_BODY); - fid = mdt_object_fid(info->mti_object); - mdt_pack_attr2body(info, body, la, fid); - } - } - } else - rc = err_serious(rc); - } - if (rc == 0) - mdt_counter_incr(req, LPROC_MDT_SYNC); - - RETURN(rc); -} - -/* - * Quotacheck handler. - * in-kernel quotacheck isn't supported any more. - */ -int mdt_quotacheck(struct mdt_thread_info *info) -{ - struct obd_quotactl *oqctl; + struct ptlrpc_request *req = tgt_ses_req(tsi); + struct req_capsule *pill = tsi->tsi_pill; + struct mdt_body *body; int rc; + ENTRY; - oqctl = req_capsule_client_get(info->mti_pill, &RMF_OBD_QUOTACTL); - if (oqctl == NULL) - RETURN(err_serious(-EPROTO)); + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) + RETURN(err_serious(-ENOMEM)); - rc = req_capsule_server_pack(info->mti_pill); - if (rc) - RETURN(err_serious(rc)); + if (fid_seq(&tsi->tsi_mdt_body->fid1) == 0) { + rc = mdt_device_sync(tsi->tsi_env, mdt_exp2dev(tsi->tsi_exp)); + } else { + struct mdt_thread_info *info = tsi2mdt_info(tsi); + + /* sync an object */ + rc = mdt_object_sync(info); + if (rc == 0) { + const struct lu_fid *fid; + struct lu_attr *la = &info->mti_attr.ma_attr; + + info->mti_attr.ma_need = MA_INODE; + info->mti_attr.ma_valid = 0; + rc = mdt_attr_get_complex(info, info->mti_object, + &info->mti_attr); + if (rc == 0) { + body = req_capsule_server_get(pill, + &RMF_MDT_BODY); + fid = mdt_object_fid(info->mti_object); + mdt_pack_attr2body(info, body, la, fid); + } + } + mdt_thread_info_fini(info); + } + if (rc == 0) + mdt_counter_incr(req, LPROC_MDT_SYNC); - /* deprecated, not used any more */ - RETURN(-EOPNOTSUPP); + RETURN(rc); } /* * Handle quota control requests to consult current usage/limit, but also * to configure quota enforcement */ -int mdt_quotactl(struct mdt_thread_info *info) +int mdt_quotactl(struct tgt_session_info *tsi) { - struct obd_export *exp = info->mti_exp; - struct req_capsule *pill = info->mti_pill; + struct obd_export *exp = tsi->tsi_exp; + struct req_capsule *pill = tsi->tsi_pill; struct obd_quotactl *oqctl, *repoqc; int id, rc; - struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev; + struct mdt_device *mdt = mdt_exp2dev(exp); + struct lu_device *qmt = mdt->mdt_qmt_dev; ENTRY; oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL); @@ -2037,7 +1918,7 @@ int mdt_quotactl(struct mdt_thread_info *info) if (exp_connect_rmtclient(exp)) { struct lustre_idmap_table *idmap; - idmap = mdt_req2med(mdt_info_req(info))->med_idmap; + idmap = exp->exp_mdt_data.med_idmap; if (unlikely(oqctl->qc_cmd != Q_GETQUOTA && oqctl->qc_cmd != Q_GETINFO)) @@ -2072,13 +1953,13 @@ int mdt_quotactl(struct mdt_thread_info *info) case Q_SETQUOTA: case Q_GETQUOTA: /* forward quotactl request to QMT */ - rc = qmt_hdls.qmth_quotactl(info->mti_env, qmt, oqctl); + rc = qmt_hdls.qmth_quotactl(tsi->tsi_env, qmt, oqctl); break; case Q_GETOINFO: case Q_GETOQUOTA: /* slave quotactl */ - rc = lquotactl_slv(info->mti_env, info->mti_mdt->mdt_bottom, + rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom, oqctl); break; @@ -2094,120 +1975,6 @@ int mdt_quotactl(struct mdt_thread_info *info) RETURN(rc); } -/* - * OBD PING and other handlers. - */ -int mdt_obd_ping(struct mdt_thread_info *info) -{ - int rc; - ENTRY; - - req_capsule_set(info->mti_pill, &RQF_OBD_PING); - - rc = target_handle_ping(mdt_info_req(info)); - if (rc < 0) - rc = err_serious(rc); - RETURN(rc); -} - -/* - * OBD_IDX_READ handler - */ -int mdt_obd_idx_read(struct mdt_thread_info *info) -{ - struct mdt_device *mdt = info->mti_mdt; - struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg; - struct idx_info *req_ii, *rep_ii; - int rc, i; - ENTRY; - - memset(rdpg, 0, sizeof(*rdpg)); - req_capsule_set(info->mti_pill, &RQF_OBD_IDX_READ); - - /* extract idx_info buffer from request & reply */ - req_ii = req_capsule_client_get(info->mti_pill, &RMF_IDX_INFO); - if (req_ii == NULL || req_ii->ii_magic != IDX_INFO_MAGIC) - RETURN(err_serious(-EPROTO)); - - rc = req_capsule_server_pack(info->mti_pill); - if (rc) - RETURN(err_serious(rc)); - - rep_ii = req_capsule_server_get(info->mti_pill, &RMF_IDX_INFO); - if (rep_ii == NULL) - RETURN(err_serious(-EFAULT)); - rep_ii->ii_magic = IDX_INFO_MAGIC; - - /* extract hash to start with */ - rdpg->rp_hash = req_ii->ii_hash_start; - - /* extract requested attributes */ - rdpg->rp_attrs = req_ii->ii_attrs; - - /* check that fid packed in request is valid and supported */ - if (!fid_is_sane(&req_ii->ii_fid)) - RETURN(-EINVAL); - rep_ii->ii_fid = req_ii->ii_fid; - - /* copy flags */ - rep_ii->ii_flags = req_ii->ii_flags; - - /* compute number of pages to allocate, ii_count is the number of 4KB - * containers */ - if (req_ii->ii_count <= 0) - GOTO(out, rc = -EFAULT); - rdpg->rp_count = min_t(unsigned int, req_ii->ii_count << LU_PAGE_SHIFT, - exp_max_brw_size(info->mti_exp)); - rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >> - PAGE_CACHE_SHIFT; - - /* allocate pages to store the containers */ - OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof(rdpg->rp_pages[0])); - if (rdpg->rp_pages == NULL) - GOTO(out, rc = -ENOMEM); - for (i = 0; i < rdpg->rp_npages; i++) { - rdpg->rp_pages[i] = alloc_page(GFP_IOFS); - if (rdpg->rp_pages[i] == NULL) - GOTO(out, rc = -ENOMEM); - } - - /* populate pages with key/record pairs */ - rc = dt_index_read(info->mti_env, mdt->mdt_bottom, rep_ii, rdpg); - if (rc < 0) - GOTO(out, rc); - - LASSERTF(rc <= rdpg->rp_count, "dt_index_read() returned more than " - "asked %d > %d\n", rc, rdpg->rp_count); - - /* send pages to client */ - rc = mdt_sendpage(info, rdpg, rc); - - GOTO(out, rc); -out: - if (rdpg->rp_pages) { - for (i = 0; i < rdpg->rp_npages; i++) - if (rdpg->rp_pages[i]) - __free_page(rdpg->rp_pages[i]); - OBD_FREE(rdpg->rp_pages, - rdpg->rp_npages * sizeof(rdpg->rp_pages[0])); - } - return rc; -} - -int mdt_obd_log_cancel(struct mdt_thread_info *info) -{ - return err_serious(-EOPNOTSUPP); -} - -int mdt_obd_qc_callback(struct mdt_thread_info *info) -{ - return err_serious(-EOPNOTSUPP); -} - -/* - * LLOG handlers. - */ - /** clone llog ctxt from child (mdd) * This allows remote llog (replicator) access. * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the @@ -2252,150 +2019,45 @@ static int mdt_llog_ctxt_unclone(const struct lu_env *env, return 0; } -int mdt_llog_create(struct mdt_thread_info *info) -{ - int rc; - - req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE); - rc = llog_origin_handle_open(mdt_info_req(info)); - return (rc < 0 ? err_serious(rc) : rc); -} - -int mdt_llog_destroy(struct mdt_thread_info *info) -{ - int rc; - - req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY); - rc = llog_origin_handle_destroy(mdt_info_req(info)); - return (rc < 0 ? err_serious(rc) : rc); -} - -int mdt_llog_read_header(struct mdt_thread_info *info) -{ - int rc; - - req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER); - rc = llog_origin_handle_read_header(mdt_info_req(info)); - return (rc < 0 ? err_serious(rc) : rc); -} - -int mdt_llog_next_block(struct mdt_thread_info *info) -{ - int rc; - - req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK); - rc = llog_origin_handle_next_block(mdt_info_req(info)); - return (rc < 0 ? err_serious(rc) : rc); -} - -int mdt_llog_prev_block(struct mdt_thread_info *info) -{ - int rc; - - req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK); - rc = llog_origin_handle_prev_block(mdt_info_req(info)); - return (rc < 0 ? err_serious(rc) : rc); -} - - -/* - * DLM handlers. - */ - -static struct ldlm_callback_suite cbs = { - .lcs_completion = ldlm_server_completion_ast, - .lcs_blocking = ldlm_server_blocking_ast, - .lcs_glimpse = ldlm_server_glimpse_ast -}; - -int mdt_enqueue(struct mdt_thread_info *info) -{ - struct ptlrpc_request *req; - int rc; - - /* - * info->mti_dlm_req already contains swapped and (if necessary) - * converted dlm request. - */ - LASSERT(info->mti_dlm_req != NULL); - - req = mdt_info_req(info); - rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace, - req, info->mti_dlm_req, &cbs); - info->mti_fail_id = OBD_FAIL_LDLM_REPLY; - return rc ? err_serious(rc) : req->rq_status; -} - -int mdt_convert(struct mdt_thread_info *info) -{ - int rc; - struct ptlrpc_request *req; - - LASSERT(info->mti_dlm_req); - req = mdt_info_req(info); - rc = ldlm_handle_convert0(req, info->mti_dlm_req); - return rc ? err_serious(rc) : req->rq_status; -} - -int mdt_bl_callback(struct mdt_thread_info *info) -{ - CERROR("bl callbacks should not happen on MDS\n"); - LBUG(); - return err_serious(-EOPNOTSUPP); -} - -int mdt_cp_callback(struct mdt_thread_info *info) -{ - CERROR("cp callbacks should not happen on MDS\n"); - LBUG(); - return err_serious(-EOPNOTSUPP); -} - /* * sec context handlers */ -int mdt_sec_ctx_handle(struct mdt_thread_info *info) -{ - int rc; - - rc = mdt_handle_idmap(info); +int mdt_sec_ctx_handle(struct tgt_session_info *tsi) +{ + int rc; - if (unlikely(rc)) { - struct ptlrpc_request *req = mdt_info_req(info); - __u32 opc; + rc = mdt_handle_idmap(tsi); + if (unlikely(rc)) { + struct ptlrpc_request *req = tgt_ses_req(tsi); + __u32 opc; - opc = lustre_msg_get_opc(req->rq_reqmsg); - if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT) - sptlrpc_svc_ctx_invalidate(req); - } + opc = lustre_msg_get_opc(req->rq_reqmsg); + if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT) + sptlrpc_svc_ctx_invalidate(req); + } - CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val); + CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val); - return rc; + return rc; } /* * quota request handlers */ -int mdt_quota_dqacq(struct mdt_thread_info *info) +int mdt_quota_dqacq(struct tgt_session_info *tsi) { - struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev; + struct mdt_device *mdt = mdt_exp2dev(tsi->tsi_exp); + struct lu_device *qmt = mdt->mdt_qmt_dev; int rc; ENTRY; if (qmt == NULL) RETURN(err_serious(-EOPNOTSUPP)); - rc = qmt_hdls.qmth_dqacq(info->mti_env, qmt, mdt_info_req(info)); + rc = qmt_hdls.qmth_dqacq(tsi->tsi_env, qmt, tgt_ses_req(tsi)); RETURN(rc); } -static struct mdt_object *mdt_obj(struct lu_object *o) -{ - LASSERT(lu_device_is_mdt(o->lo_dev)); - return container_of0(o, struct mdt_object, mot_obj); -} - struct mdt_object *mdt_object_new(const struct lu_env *env, struct mdt_device *d, const struct lu_fid *f) @@ -2814,40 +2476,6 @@ void mdt_object_unlock_put(struct mdt_thread_info * info, mdt_object_put(info->mti_env, o); } -struct mdt_handler *mdt_handler_find(__u32 opc, struct mdt_opc_slice *supported) -{ - struct mdt_opc_slice *s; - struct mdt_handler *h; - - h = NULL; - for (s = supported; s->mos_hs != NULL; s++) { - if (s->mos_opc_start <= opc && opc < s->mos_opc_end) { - h = s->mos_hs + (opc - s->mos_opc_start); - if (likely(h->mh_opc != 0)) - LASSERTF(h->mh_opc == opc, - "opcode mismatch %d != %d\n", - h->mh_opc, opc); - else - h = NULL; /* unsupported opc */ - break; - } - } - return h; -} - -static int mdt_lock_resname_compat(struct mdt_device *m, - struct ldlm_request *req) -{ - /* XXX something... later. */ - return 0; -} - -static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep) -{ - /* XXX something... later. */ - return 0; -} - /* * Generic code handling requests that have struct mdt_body passed in: * @@ -2942,151 +2570,13 @@ static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags) static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m) { - struct md_device *next = m->mdt_child; - - return next->md_ops->mdo_init_capa_ctxt(env, next, - m->mdt_opts.mo_mds_capa, - m->mdt_capa_timeout, - m->mdt_capa_alg, - m->mdt_capa_keys); -} - -/* - * Invoke handler for this request opc. Also do necessary preprocessing - * (according to handler ->mh_flags), and post-processing (setting of - * ->last_{xid,committed}). - */ -static int mdt_req_handle(struct mdt_thread_info *info, - struct mdt_handler *h, struct ptlrpc_request *req) -{ - int rc, serious = 0; - __u32 flags; - - ENTRY; - - LASSERT(h->mh_act != NULL); - LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg)); - LASSERT(current->journal_info == NULL); - - /* - * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try - * to put same checks into handlers like mdt_close(), mdt_reint(), - * etc., without talking to mdt authors first. Checking same thing - * there again is useless and returning 0 error without packing reply - * is buggy! Handlers either pack reply or return error. - * - * We return 0 here and do not send any reply in order to emulate - * network failure. Do not send any reply in case any of NET related - * fail_id has occured. - */ - if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE)) - RETURN(0); - - rc = 0; - flags = h->mh_flags; - LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL)); - - if (h->mh_fmt != NULL) { - req_capsule_set(info->mti_pill, h->mh_fmt); - rc = mdt_unpack_req_pack_rep(info, flags); - } - - if (rc == 0 && flags & MUTABOR && - exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY) - /* should it be rq_status? */ - rc = -EROFS; - - if (rc == 0 && flags & HABEO_CLAVIS) { - struct ldlm_request *dlm_req; - - LASSERT(h->mh_fmt != NULL); - - dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ); - if (dlm_req != NULL) { - if (unlikely(dlm_req->lock_desc.l_resource.lr_type == - LDLM_IBITS && - dlm_req->lock_desc.l_policy_data.\ - l_inodebits.bits == 0)) { - /* - * Lock without inodebits makes no sense and - * will oops later in ldlm. If client miss to - * set such bits, do not trigger ASSERTION. - * - * For liblustre flock case, it maybe zero. - */ - rc = -EPROTO; - } else { - if (info->mti_mdt && - info->mti_mdt->mdt_opts.mo_compat_resname) - rc = mdt_lock_resname_compat( - info->mti_mdt, - dlm_req); - info->mti_dlm_req = dlm_req; - } - } else { - rc = -EFAULT; - } - } - - /* capability setting changed via /proc, needs reinitialize ctxt */ - if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) { - mdt_init_capa_ctxt(info->mti_env, info->mti_mdt); - info->mti_mdt->mdt_capa_conf = 0; - } - - if (likely(rc == 0)) { - /* - * Process request, there can be two types of rc: - * 1) errors with msg unpack/pack, other failures outside the - * operation itself. This is counted as serious errors; - * 2) errors during fs operation, should be placed in rq_status - * only - */ - rc = h->mh_act(info); - if (rc == 0 && - !req->rq_no_reply && req->rq_reply_state == NULL) { - DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not " - "pack reply and returned 0 error\n", - h->mh_name); - LBUG(); - } - serious = is_serious(rc); - rc = clear_serious(rc); - } else - serious = 1; - - req->rq_status = rc; - - /* - * ELDLM_* codes which > 0 should be in rq_status only as well as - * all non-serious errors. - */ - if (rc > 0 || !serious) - rc = 0; - - LASSERT(current->journal_info == NULL); - - if (rc == 0 && (flags & HABEO_CLAVIS) && info->mti_mdt && - info->mti_mdt->mdt_opts.mo_compat_resname) { - struct ldlm_reply *dlmrep; + struct md_device *next = m->mdt_child; - dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP); - if (dlmrep != NULL) - rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep); - } - - /* If we're DISCONNECTing, the mdt_export_data is already freed */ - if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT)) - target_committed_to_req(req); - - if (unlikely(req_is_replay(req) && - lustre_msg_get_transno(req->rq_reqmsg) == 0)) { - DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY"); - LBUG(); - } - - target_send_reply(req, rc, info->mti_fail_id); - RETURN(0); + return next->md_ops->mdo_init_capa_ctxt(env, next, + m->mdt_lut.lut_mds_capa, + m->mdt_capa_timeout, + m->mdt_capa_alg, + m->mdt_capa_keys); } void mdt_lock_handle_init(struct mdt_lock_handle *lh) @@ -3128,10 +2618,9 @@ void mdt_thread_info_init(struct ptlrpc_request *req, info->mti_exp = req->rq_export; } else info->mti_mdt = NULL; - info->mti_env = req->rq_svc_thread->t_env; - info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET; - info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg); - info->mti_mos = NULL; + info->mti_env = req->rq_svc_thread->t_env; + info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg); + info->mti_mos = NULL; memset(&info->mti_attr, 0, sizeof(info->mti_attr)); info->mti_big_buf = LU_BUF_NULL; @@ -3167,10 +2656,40 @@ void mdt_thread_info_fini(struct mdt_thread_info *info) lu_buf_free(&info->mti_big_buf); } +struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi) +{ + struct mdt_thread_info *mti; + struct lustre_capa *lc; + + mti = mdt_th_info(tsi->tsi_env); + LASSERT(mti != NULL); + + mdt_thread_info_init(tgt_ses_req(tsi), mti); + if (tsi->tsi_corpus != NULL) { + struct req_capsule *pill = tsi->tsi_pill; + + mti->mti_object = mdt_obj(tsi->tsi_corpus); + lu_object_get(tsi->tsi_corpus); + + /* + * XXX: must be part of tgt_mdt_body_unpack but moved here + * due to mdt_set_capainfo(). + */ + if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) && + req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT) > 0) { + lc = req_capsule_client_get(pill, &RMF_CAPA1); + mdt_set_capainfo(mti, 0, &tsi->tsi_mdt_body->fid1, lc); + } + } + mti->mti_body = tsi->tsi_mdt_body; + mti->mti_dlm_req = tsi->tsi_dlm_req; + + return mti; +} + int mdt_tgt_connect(struct tgt_session_info *tsi) { struct ptlrpc_request *req = tgt_ses_req(tsi); - struct mdt_thread_info *mti; int rc; ENTRY; @@ -3179,14 +2698,7 @@ int mdt_tgt_connect(struct tgt_session_info *tsi) if (rc != 0) RETURN(rc); - /* XXX: switch mdt_init_idmap() to use tgt_session_info */ - lu_env_refill((void *)tsi->tsi_env); - mti = lu_context_key_get(&tsi->tsi_env->le_ctx, &mdt_thread_key); - LASSERT(mti != NULL); - - mdt_thread_info_init(req, mti); - rc = mdt_init_idmap(mti); - mdt_thread_info_fini(mti); + rc = mdt_init_idmap(tsi); if (rc != 0) GOTO(err, rc); RETURN(0); @@ -3195,305 +2707,6 @@ err: return rc; } -static int mdt_filter_recovery_request(struct ptlrpc_request *req, - struct obd_device *obd, int *process) -{ - switch (lustre_msg_get_opc(req->rq_reqmsg)) { - case MDS_CONNECT: /* This will never get here, but for completeness. */ - case OST_CONNECT: /* This will never get here, but for completeness. */ - case MDS_DISCONNECT: - case OST_DISCONNECT: - case OBD_IDX_READ: - *process = 1; - RETURN(0); - - case MDS_CLOSE: - case MDS_DONE_WRITING: - case MDS_SYNC: /* used in unmounting */ - case OBD_PING: - case MDS_REINT: - case UPDATE_OBJ: - case SEQ_QUERY: - case FLD_QUERY: - case LDLM_ENQUEUE: - *process = target_queue_recovery_request(req, obd); - RETURN(0); - - default: - DEBUG_REQ(D_ERROR, req, "not permitted during recovery"); - *process = -EAGAIN; - RETURN(0); - } -} - -/* - * Handle recovery. Return: - * +1: continue request processing; - * -ve: abort immediately with the given error code; - * 0: send reply with error code in req->rq_status; - */ -static int mdt_recovery(struct mdt_thread_info *info) -{ - struct ptlrpc_request *req = mdt_info_req(info); - struct obd_device *obd; - - ENTRY; - - switch (lustre_msg_get_opc(req->rq_reqmsg)) { - case MDS_CONNECT: - case SEC_CTX_INIT: - case SEC_CTX_INIT_CONT: - case SEC_CTX_FINI: - { -#if 0 - int rc; - - rc = mdt_handle_idmap(info); - if (rc) - RETURN(rc); - else -#endif - RETURN(+1); - } - } - - if (unlikely(!class_connected_export(req->rq_export))) { - CDEBUG(D_HA, "operation %d on unconnected MDS from %s\n", - lustre_msg_get_opc(req->rq_reqmsg), - libcfs_id2str(req->rq_peer)); - /* FIXME: For CMD cleanup, when mds_B stop, the req from - * mds_A will get -ENOTCONN(especially for ping req), - * which will cause that mds_A deactive timeout, then when - * mds_A cleanup, the cleanup process will be suspended since - * deactive timeout is not zero. - */ - req->rq_status = -ENOTCONN; - target_send_reply(req, -ENOTCONN, info->mti_fail_id); - RETURN(0); - } - - /* sanity check: if the xid matches, the request must be marked as a - * resent or replayed */ - if (req_xid_is_last(req)) { - if (!(lustre_msg_get_flags(req->rq_reqmsg) & - (MSG_RESENT | MSG_REPLAY))) { - DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, " - "expected REPLAY or RESENT flag (%x)", req->rq_xid, - lustre_msg_get_flags(req->rq_reqmsg)); - LBUG(); - req->rq_status = -ENOTCONN; - RETURN(-ENOTCONN); - } - } - - /* else: note the opposite is not always true; a RESENT req after a - * failover will usually not match the last_xid, since it was likely - * never committed. A REPLAYed request will almost never match the - * last xid, however it could for a committed, but still retained, - * open. */ - - obd = req->rq_export->exp_obd; - - /* Check for aborted recovery... */ - if (unlikely(obd->obd_recovering)) { - int rc; - int should_process; - DEBUG_REQ(D_INFO, req, "Got new replay"); - rc = mdt_filter_recovery_request(req, obd, &should_process); - if (rc != 0 || !should_process) - RETURN(rc); - else if (should_process < 0) { - req->rq_status = should_process; - rc = ptlrpc_error(req); - RETURN(rc); - } - } - RETURN(+1); -} - -static int mdt_msg_check_version(struct lustre_msg *msg) -{ - int rc; - - switch (lustre_msg_get_opc(msg)) { - case MDS_CONNECT: - case MDS_DISCONNECT: - case OBD_PING: - case SEC_CTX_INIT: - case SEC_CTX_INIT_CONT: - case SEC_CTX_FINI: - case OBD_IDX_READ: - rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION); - if (rc) - CERROR("bad opc %u version %08x, expecting %08x\n", - lustre_msg_get_opc(msg), - lustre_msg_get_version(msg), - LUSTRE_OBD_VERSION); - break; - case MDS_GETSTATUS: - case MDS_GETATTR: - case MDS_GETATTR_NAME: - case MDS_STATFS: - case MDS_READPAGE: - case MDS_WRITEPAGE: - case MDS_IS_SUBDIR: - case MDS_REINT: - case MDS_CLOSE: - case MDS_DONE_WRITING: - case MDS_PIN: - case MDS_SYNC: - case MDS_GETXATTR: - case MDS_SETXATTR: - case MDS_SET_INFO: - case MDS_GET_INFO: - case MDS_HSM_PROGRESS: - case MDS_HSM_REQUEST: - case MDS_HSM_CT_REGISTER: - case MDS_HSM_CT_UNREGISTER: - case MDS_HSM_STATE_GET: - case MDS_HSM_STATE_SET: - case MDS_HSM_ACTION: - case MDS_QUOTACHECK: - case MDS_QUOTACTL: - case UPDATE_OBJ: - case MDS_SWAP_LAYOUTS: - case QUOTA_DQACQ: - case QUOTA_DQREL: - case SEQ_QUERY: - case FLD_QUERY: - rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION); - if (rc) - CERROR("bad opc %u version %08x, expecting %08x\n", - lustre_msg_get_opc(msg), - lustre_msg_get_version(msg), - LUSTRE_MDS_VERSION); - break; - case LDLM_ENQUEUE: - case LDLM_CONVERT: - case LDLM_BL_CALLBACK: - case LDLM_CP_CALLBACK: - rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION); - if (rc) - CERROR("bad opc %u version %08x, expecting %08x\n", - lustre_msg_get_opc(msg), - lustre_msg_get_version(msg), - LUSTRE_DLM_VERSION); - break; - case OBD_LOG_CANCEL: - case LLOG_ORIGIN_HANDLE_CREATE: - case LLOG_ORIGIN_HANDLE_NEXT_BLOCK: - case LLOG_ORIGIN_HANDLE_READ_HEADER: - case LLOG_ORIGIN_HANDLE_CLOSE: - case LLOG_ORIGIN_HANDLE_DESTROY: - case LLOG_ORIGIN_HANDLE_PREV_BLOCK: - case LLOG_CATINFO: - rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION); - if (rc) - CERROR("bad opc %u version %08x, expecting %08x\n", - lustre_msg_get_opc(msg), - lustre_msg_get_version(msg), - LUSTRE_LOG_VERSION); - break; - default: - CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg)); - rc = -ENOTSUPP; - } - return rc; -} - -static int mdt_handle0(struct ptlrpc_request *req, - struct mdt_thread_info *info, - struct mdt_opc_slice *supported) -{ - struct mdt_handler *h; - struct lustre_msg *msg; - int rc; - - ENTRY; - - if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE)) - RETURN(0); - - LASSERT(current->journal_info == NULL); - - msg = req->rq_reqmsg; - rc = mdt_msg_check_version(msg); - if (likely(rc == 0)) { - rc = mdt_recovery(info); - if (likely(rc == +1)) { - h = mdt_handler_find(lustre_msg_get_opc(msg), - supported); - if (likely(h != NULL)) { - rc = mdt_req_handle(info, h, req); - } else { - CERROR("%s: opc unsupported: 0x%x\n", - mdt_obd_name(info->mti_mdt), - lustre_msg_get_opc(msg)); - req->rq_status = -ENOTSUPP; - rc = ptlrpc_error(req); - RETURN(rc); - } - } - } else { - CDEBUG(D_INFO, "%s: drops mal-formed request: rc = %d\n", - mdt_obd_name(info->mti_mdt), rc); - req->rq_status = rc; - rc = ptlrpc_error(req); - } - RETURN(rc); -} - -/* - * MDT handler function called by ptlrpc service thread when request comes. - * - * XXX common "target" functionality should be factored into separate module - * shared by mdt, ost and stand-alone services like fld. - */ -int mdt_handle_common(struct ptlrpc_request *req, - struct mdt_opc_slice *supported) -{ - struct lu_env *env; - struct mdt_thread_info *info; - int rc; - ENTRY; - - env = req->rq_svc_thread->t_env; - LASSERT(env != NULL); - /* Refill(initilize) the context(mdt_thread_info), in case it is - * not initialized yet. Usually it happens during start up, after - * MDS(ptlrpc threads) is start up, it gets the first CONNECT request, - * before MDT_thread_info is initialized */ - lu_env_refill(env); - LASSERT(env->le_ses != NULL); - LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread); - info = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - LASSERT(info != NULL); - - req_capsule_init(&req->rq_pill, req, RCL_SERVER); - mdt_thread_info_init(req, info); - - rc = mdt_handle0(req, info, supported); - - mdt_thread_info_fini(info); - req_capsule_fini(&req->rq_pill); - RETURN(rc); -} - -/* - * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ - * as well. - */ -int mdt_recovery_handle(struct ptlrpc_request *req) -{ - int rc; - - ENTRY; - - rc = mdt_handle_common(req, mdt_regular_handlers); - - RETURN(rc); -} - enum mdt_it_code { MDT_IT_OPEN, MDT_IT_OCREAT, @@ -3926,7 +3139,7 @@ static int mdt_intent_reint(enum mdt_it_code opcode, ENTRY; - opc = mdt_reint_opcode(info, intent_fmts); + opc = mdt_reint_opcode(mdt_info_req(info), intent_fmts); if (opc < 0) RETURN(opc); @@ -4108,18 +3321,20 @@ static int mdt_intent_policy(struct ldlm_namespace *ns, struct ldlm_lock **lockp, void *req_cookie, ldlm_mode_t mode, __u64 flags, void *data) { - struct mdt_thread_info *info; - struct ptlrpc_request *req = req_cookie; - struct ldlm_intent *it; - struct req_capsule *pill; - int rc; + struct tgt_session_info *tsi; + struct mdt_thread_info *info; + struct ptlrpc_request *req = req_cookie; + struct ldlm_intent *it; + struct req_capsule *pill; + int rc; - ENTRY; + ENTRY; + + LASSERT(req != NULL); - LASSERT(req != NULL); + tsi = tgt_ses_info(req->rq_svc_thread->t_env); - info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx, - &mdt_thread_key); + info = tsi2mdt_info(tsi); LASSERT(info != NULL); pill = info->mti_pill; LASSERT(pill->rc_req == req); @@ -4151,7 +3366,8 @@ static int mdt_intent_policy(struct ldlm_namespace *ns, if (rc) rc = err_serious(rc); } - RETURN(rc); + mdt_thread_info_fini(info); + RETURN(rc); } static int mdt_seq_fini(const struct lu_env *env, @@ -4702,6 +3918,20 @@ static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt) EXIT; } +/* mdt_getxattr() is used from mdt_intent_getxattr(), use this wrapper + * for now. This will be removed along with converting rest of MDT code + * to use tgt_session_info */ +int mdt_tgt_getxattr(struct tgt_session_info *tsi) +{ + struct mdt_thread_info *info = tsi2mdt_info(tsi); + int rc; + + rc = mdt_getxattr(info); + + mdt_thread_info_fini(info); + return rc; +} + static struct tgt_handler mdt_tgt_handlers[] = { TGT_RPC_HANDLER(MDS_FIRST_OPC, 0, MDS_CONNECT, mdt_tgt_connect, @@ -4709,6 +3939,49 @@ TGT_RPC_HANDLER(MDS_FIRST_OPC, TGT_RPC_HANDLER(MDS_FIRST_OPC, 0, MDS_DISCONNECT, tgt_disconnect, &RQF_MDS_DISCONNECT, LUSTRE_OBD_VERSION), +TGT_RPC_HANDLER(MDS_FIRST_OPC, + HABEO_REFERO, MDS_SET_INFO, mdt_set_info, + &RQF_OBD_SET_INFO, LUSTRE_MDS_VERSION), +TGT_MDT_HDL(0, MDS_GET_INFO, mdt_get_info), +TGT_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus), +TGT_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME, + mdt_getattr_name), +TGT_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_tgt_getxattr), +TGT_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs), +TGT_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint), +TGT_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close), +TGT_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, + mdt_done_writing), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_READPAGE, mdt_readpage), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_SYNC, mdt_sync), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir), +TGT_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_PROGRESS, + mdt_hsm_progress), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_REGISTER, + mdt_hsm_ct_register), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_UNREGISTER, + mdt_hsm_ct_unregister), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_GET, + mdt_hsm_state_get), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_STATE_SET, + mdt_hsm_state_set), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_ACTION, mdt_hsm_action), +TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_REQUEST, + mdt_hsm_request), +TGT_MDT_HDL(HABEO_CORPUS|HABEO_REFERO | MUTABOR, MDS_SWAP_LAYOUTS, + mdt_swap_layouts) +}; + +static struct tgt_handler mdt_sec_ctx_ops[] = { +TGT_SEC_HDL_VAR(0, SEC_CTX_INIT, mdt_sec_ctx_handle), +TGT_SEC_HDL_VAR(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle), +TGT_SEC_HDL_VAR(0, SEC_CTX_FINI, mdt_sec_ctx_handle) +}; + +static struct tgt_handler mdt_quota_ops[] = { +TGT_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq), }; static struct tgt_opc_slice mdt_common_slice[] = { @@ -4730,7 +4003,7 @@ static struct tgt_opc_slice mdt_common_slice[] = { { .tos_opc_start = SEC_FIRST_OPC, .tos_opc_end = SEC_LAST_OPC, - .tos_hs = tgt_sec_ctx_handlers + .tos_hs = mdt_sec_ctx_ops }, { .tos_opc_start = UPDATE_OBJ, @@ -4748,6 +4021,17 @@ static struct tgt_opc_slice mdt_common_slice[] = { .tos_hs = seq_handlers }, { + .tos_opc_start = QUOTA_DQACQ, + .tos_opc_end = QUOTA_LAST_OPC, + .tos_hs = mdt_quota_ops + }, + { + .tos_opc_start = LLOG_FIRST_OPC, + .tos_opc_end = LLOG_LAST_OPC, + .tos_hs = tgt_llog_handlers + }, + + { .tos_hs = NULL } }; @@ -4801,7 +4085,6 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) mdt_seq_fini(env, m); mdt_fld_fini(env, m); - sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset); next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL); cfs_timer_disarm(&m->mdt_ck_timer); @@ -4835,10 +4118,10 @@ static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial) sptlrpc_target_update_exp_flavor(obd, &tmp_rset); - write_lock(&m->mdt_sptlrpc_lock); - sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset); - m->mdt_sptlrpc_rset = tmp_rset; - write_unlock(&m->mdt_sptlrpc_lock); + write_lock(&m->mdt_lut.lut_sptlrpc_lock); + sptlrpc_rule_set_free(&m->mdt_lut.lut_sptlrpc_rset); + m->mdt_lut.lut_sptlrpc_rset = tmp_rset; + write_unlock(&m->mdt_lut.lut_sptlrpc_lock); return 0; } @@ -4902,15 +4185,9 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, LASSERT(num); node_id = simple_strtol(num, NULL, 10); obd->u.obt.obt_magic = OBT_MAGIC; - } - - rwlock_init(&m->mdt_sptlrpc_lock); - sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset); + } spin_lock_init(&m->mdt_ioepoch_lock); - m->mdt_opts.mo_compat_resname = 0; - m->mdt_opts.mo_mds_capa = 1; - m->mdt_opts.mo_oss_capa = 1; m->mdt_capa_timeout = CAPA_TIMEOUT; m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1; m->mdt_ck_timeout = CAPA_KEY_TIMEOUT; @@ -5314,7 +4591,7 @@ static int mdt_prepare(const struct lu_env *env, } LASSERT(!test_bit(MDT_FL_CFGLOG, &mdt->mdt_state)); - target_recovery_init(&mdt->mdt_lut, mdt_recovery_handle); + target_recovery_init(&mdt->mdt_lut, tgt_request_handle); set_bit(MDT_FL_CFGLOG, &mdt->mdt_state); LASSERT(obd->obd_no_conn); spin_lock(&obd->obd_dev_lock); @@ -5466,49 +4743,6 @@ static int mdt_connect_internal(struct obd_export *exp, return 0; } -int mdt_connect_check_sptlrpc(struct mdt_device *mdt, struct obd_export *exp, - struct ptlrpc_request *req) -{ - struct sptlrpc_flavor flvr; - int rc = 0; - - if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) { - read_lock(&mdt->mdt_sptlrpc_lock); - sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset, - req->rq_sp_from, - req->rq_peer.nid, - &flvr); - read_unlock(&mdt->mdt_sptlrpc_lock); - - spin_lock(&exp->exp_lock); - - exp->exp_sp_peer = req->rq_sp_from; - exp->exp_flvr = flvr; - - if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY && - exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) { - CERROR("unauthorized rpc flavor %x from %s, " - "expect %x\n", req->rq_flvr.sf_rpc, - libcfs_nid2str(req->rq_peer.nid), - exp->exp_flvr.sf_rpc); - rc = -EACCES; - } - - spin_unlock(&exp->exp_lock); - } else { - if (exp->exp_sp_peer != req->rq_sp_from) { - CERROR("RPC source %s doesn't match %s\n", - sptlrpc_part2name(req->rq_sp_from), - sptlrpc_part2name(exp->exp_sp_peer)); - rc = -EACCES; - } else { - rc = sptlrpc_target_export_check(exp, req); - } - } - - return rc; -} - /* mds_connect copy */ static int mdt_obd_connect(const struct lu_env *env, struct obd_export **exp, struct obd_device *obd, @@ -6032,47 +5266,51 @@ static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key, RETURN(rc); } -int mdt_get_info(struct mdt_thread_info *info) +int mdt_get_info(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); - char *key; - int keylen; - __u32 *vallen; - void *valout; - int rc; - ENTRY; + char *key; + int keylen; + __u32 *vallen; + void *valout; + int rc; - key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY); - if (key == NULL) { - CDEBUG(D_IOCTL, "No GETINFO key"); - RETURN(-EFAULT); - } - keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY, - RCL_CLIENT); + ENTRY; - vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN); - if (vallen == NULL) { - CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer"); - RETURN(-EFAULT); - } + key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY); + if (key == NULL) { + CDEBUG(D_IOCTL, "No GETINFO key"); + RETURN(err_serious(-EFAULT)); + } + keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY, + RCL_CLIENT); - req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER, - *vallen); - rc = req_capsule_server_pack(info->mti_pill); - valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL); - if (valout == NULL) { - CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer"); - RETURN(-EFAULT); - } + vallen = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_VALLEN); + if (vallen == NULL) { + CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer"); + RETURN(err_serious(-EFAULT)); + } - if (KEY_IS(KEY_FID2PATH)) - rc = mdt_rpc_fid2path(info, key, valout, *vallen); - else - rc = -EINVAL; + req_capsule_set_size(tsi->tsi_pill, &RMF_GETINFO_VAL, RCL_SERVER, + *vallen); + rc = req_capsule_server_pack(tsi->tsi_pill); + if (rc) + RETURN(err_serious(rc)); - lustre_msg_set_status(req->rq_repmsg, rc); + valout = req_capsule_server_get(tsi->tsi_pill, &RMF_GETINFO_VAL); + if (valout == NULL) { + CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer"); + RETURN(err_serious(-EFAULT)); + } - RETURN(rc); + if (KEY_IS(KEY_FID2PATH)) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); + + rc = mdt_rpc_fid2path(info, key, valout, *vallen); + mdt_thread_info_fini(info); + } else { + rc = -EINVAL; + } + RETURN(rc); } /* Pass the ioc down */ diff --git a/lustre/mdt/mdt_hsm.c b/lustre/mdt/mdt_hsm.c index 58a91ee..75c2024 100644 --- a/lustre/mdt/mdt_hsm.c +++ b/lustre/mdt/mdt_hsm.c @@ -104,19 +104,19 @@ static inline bool mdt_hsm_is_admin(struct mdt_thread_info *info) * * This is HSM_PROGRESS RPC handler. */ -int mdt_hsm_progress(struct mdt_thread_info *info) +int mdt_hsm_progress(struct tgt_session_info *tsi) { + struct mdt_thread_info *info; struct hsm_progress_kernel *hpk; int rc; ENTRY; - hpk = req_capsule_client_get(info->mti_pill, &RMF_MDS_HSM_PROGRESS); - - if (info->mti_body == NULL || hpk == NULL) + if (tsi->tsi_mdt_body == NULL) RETURN(-EPROTO); - if (!mdt_hsm_is_admin(info)) - RETURN(-EPERM); + hpk = req_capsule_client_get(tsi->tsi_pill, &RMF_MDS_HSM_PROGRESS); + if (hpk == NULL) + RETURN(err_serious(-EPROTO)); hpk->hpk_errval = lustre_errno_ntoh(hpk->hpk_errval); @@ -132,47 +132,56 @@ int mdt_hsm_progress(struct mdt_thread_info *info) CDEBUG(D_HSM, "Finished "DFID" (%d) cancel cookie="LPX64"\n", PFID(&hpk->hpk_fid), hpk->hpk_errval, hpk->hpk_cookie); - rc = mdt_hsm_coordinator_update(info, hpk); + info = tsi2mdt_info(tsi); + if (!mdt_hsm_is_admin(info)) + GOTO(out, rc = -EPERM); + rc = mdt_hsm_coordinator_update(info, hpk); +out: + mdt_thread_info_fini(info); RETURN(rc); } -int mdt_hsm_ct_register(struct mdt_thread_info *info) +int mdt_hsm_ct_register(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); + struct mdt_thread_info *info; __u32 *archives; int rc; ENTRY; - if (!mdt_hsm_is_admin(info)) - RETURN(-EPERM); - - archives = req_capsule_client_get(info->mti_pill, &RMF_MDS_HSM_ARCHIVE); + archives = req_capsule_client_get(tsi->tsi_pill, &RMF_MDS_HSM_ARCHIVE); if (archives == NULL) - RETURN(-EPROTO); + RETURN(err_serious(-EPROTO)); + + info = tsi2mdt_info(tsi); + if (!mdt_hsm_is_admin(info)) + GOTO(out, rc = -EPERM); /* XXX: directly include this function here? */ - rc = mdt_hsm_agent_register_mask(info, &req->rq_export->exp_client_uuid, + rc = mdt_hsm_agent_register_mask(info, &tsi->tsi_exp->exp_client_uuid, *archives); - +out: + mdt_thread_info_fini(info); RETURN(rc); } -int mdt_hsm_ct_unregister(struct mdt_thread_info *info) +int mdt_hsm_ct_unregister(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); + struct mdt_thread_info *info; int rc; ENTRY; - if (info->mti_body == NULL) + if (tsi->tsi_mdt_body == NULL) RETURN(-EPROTO); + info = tsi2mdt_info(tsi); if (!mdt_hsm_is_admin(info)) - RETURN(-EPERM); + GOTO(out, rc = -EPERM); /* XXX: directly include this function here? */ - rc = mdt_hsm_agent_unregister(info, &req->rq_export->exp_client_uuid); - + rc = mdt_hsm_agent_unregister(info, &tsi->tsi_exp->exp_client_uuid); +out: + mdt_thread_info_fini(info); RETURN(rc); } @@ -184,8 +193,9 @@ int mdt_hsm_ct_unregister(struct mdt_thread_info *info) * * This is MDS_HSM_STATE_GET RPC handler. */ -int mdt_hsm_state_get(struct mdt_thread_info *info) +int mdt_hsm_state_get(struct tgt_session_info *tsi) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_object *obj = info->mti_object; struct md_attr *ma = &info->mti_attr; struct hsm_user_state *hus; @@ -194,12 +204,12 @@ int mdt_hsm_state_get(struct mdt_thread_info *info) ENTRY; if (info->mti_body == NULL || obj == NULL) - RETURN(-EPROTO); + GOTO(out, rc = -EPROTO); /* Only valid if client is remote */ rc = mdt_init_ucred(info, (struct mdt_body *)info->mti_body); if (rc < 0) - RETURN(err_serious(rc)); + GOTO(out, rc = err_serious(rc)); lh = &info->mti_lh[MDT_LH_CHILD]; mdt_lock_reg_init(lh, LCK_PR); @@ -216,9 +226,10 @@ int mdt_hsm_state_get(struct mdt_thread_info *info) if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, &info->mti_body->fid1, - req_capsule_client_get(info->mti_pill, &RMF_CAPA1)); + req_capsule_client_get(info->mti_pill, + &RMF_CAPA1)); - hus = req_capsule_server_get(info->mti_pill, &RMF_HSM_USER_STATE); + hus = req_capsule_server_get(tsi->tsi_pill, &RMF_HSM_USER_STATE); if (hus == NULL) GOTO(out_unlock, rc = -EPROTO); @@ -231,7 +242,8 @@ out_unlock: mdt_object_unlock(info, obj, lh, 1); out_ucred: mdt_exit_ucred(info); - +out: + mdt_thread_info_fini(info); return rc; } @@ -244,8 +256,9 @@ out_ucred: * * This is MDS_HSM_STATE_SET RPC handler. */ -int mdt_hsm_state_set(struct mdt_thread_info *info) +int mdt_hsm_state_set(struct tgt_session_info *tsi) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_object *obj = info->mti_object; struct md_attr *ma = &info->mti_attr; struct hsm_state_set *hss; @@ -257,12 +270,12 @@ int mdt_hsm_state_set(struct mdt_thread_info *info) hss = req_capsule_client_get(info->mti_pill, &RMF_HSM_STATE_SET); if (info->mti_body == NULL || obj == NULL || hss == NULL) - RETURN(-EPROTO); + GOTO(out, rc = -EPROTO); /* Only valid if client is remote */ rc = mdt_init_ucred(info, (struct mdt_body *)info->mti_body); if (rc < 0) - RETURN(err_serious(rc)); + GOTO(out, rc = err_serious(rc)); lh = &info->mti_lh[MDT_LH_CHILD]; mdt_lock_reg_init(lh, LCK_PW); @@ -333,7 +346,8 @@ out_unlock: mdt_object_unlock(info, obj, lh, 1); out_ucred: mdt_exit_ucred(info); - +out: + mdt_thread_info_fini(info); return rc; } @@ -343,8 +357,9 @@ out_ucred: * * This is MDS_HSM_ACTION RPC handler. */ -int mdt_hsm_action(struct mdt_thread_info *info) +int mdt_hsm_action(struct tgt_session_info *tsi) { + struct mdt_thread_info *info; struct hsm_current_action *hca; struct hsm_action_list *hal = NULL; struct hsm_action_item *hai; @@ -352,18 +367,21 @@ int mdt_hsm_action(struct mdt_thread_info *info) int rc; ENTRY; - hca = req_capsule_server_get(info->mti_pill, + hca = req_capsule_server_get(tsi->tsi_pill, &RMF_MDS_HSM_CURRENT_ACTION); + if (hca == NULL) + RETURN(err_serious(-EPROTO)); - if (info->mti_body == NULL || hca == NULL) + if (tsi->tsi_mdt_body == NULL) RETURN(-EPROTO); + info = tsi2mdt_info(tsi); /* Only valid if client is remote */ rc = mdt_init_ucred(info, (struct mdt_body *)info->mti_body); if (rc) - RETURN(rc = err_serious(rc)); + GOTO(out, rc = err_serious(rc)); - if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT)) + if (req_capsule_get_size(tsi->tsi_pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, &info->mti_body->fid1, req_capsule_client_get(info->mti_pill, &RMF_CAPA1)); @@ -431,6 +449,8 @@ out_free: MDT_HSM_FREE(hal, hal_size); out_ucred: mdt_exit_ucred(info); +out: + mdt_thread_info_fini(info); return rc; } @@ -442,9 +462,10 @@ out_ucred: * * This is MDS_HSM_REQUEST RPC handler. */ -int mdt_hsm_request(struct mdt_thread_info *info) +int mdt_hsm_request(struct tgt_session_info *tsi) { - struct req_capsule *pill = info->mti_pill; + struct mdt_thread_info *info; + struct req_capsule *pill = tsi->tsi_pill; struct hsm_request *hr; struct hsm_user_item *hui; struct hsm_action_list *hal; @@ -461,7 +482,7 @@ int mdt_hsm_request(struct mdt_thread_info *info) hui = req_capsule_client_get(pill, &RMF_MDS_HSM_USER_ITEM); data = req_capsule_client_get(pill, &RMF_GENERIC_DATA); - if (info->mti_body == NULL || hr == NULL || hui == NULL || data == NULL) + if (tsi->tsi_mdt_body == NULL || hr == NULL || hui == NULL || data == NULL) RETURN(-EPROTO); /* Sanity check. Nothing to do with an empty list */ @@ -477,10 +498,11 @@ int mdt_hsm_request(struct mdt_thread_info *info) if (data_size != hr->hr_data_len) RETURN(-EPROTO); + info = tsi2mdt_info(tsi); /* Only valid if client is remote */ rc = mdt_init_ucred(info, (struct mdt_body *)info->mti_body); if (rc) - RETURN(err_serious(rc)); + GOTO(out, rc); switch (hr->hr_action) { /* code to be removed in hsm1_merge and final patch */ @@ -540,5 +562,7 @@ int mdt_hsm_request(struct mdt_thread_info *info) out_ucred: mdt_exit_ucred(info); +out: + mdt_thread_info_fini(info); return rc; } diff --git a/lustre/mdt/mdt_idmap.c b/lustre/mdt/mdt_idmap.c index bc3e85f..e6b8c46 100644 --- a/lustre/mdt/mdt_idmap.c +++ b/lustre/mdt/mdt_idmap.c @@ -69,135 +69,9 @@ #include "mdt_internal.h" -#define mdt_init_sec_none(reply, exp) \ -do { \ - reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \ - OBD_CONNECT_RMT_CLIENT_FORCE | \ - OBD_CONNECT_MDS_CAPA | \ - OBD_CONNECT_OSS_CAPA); \ -} while (0) - -int mdt_init_sec_level(struct mdt_thread_info *info) +int mdt_init_idmap(struct tgt_session_info *tsi) { - struct mdt_device *mdt = info->mti_mdt; - struct ptlrpc_request *req = mdt_info_req(info); - char *client = libcfs_nid2str(req->rq_peer.nid); - struct obd_connect_data *data, *reply; - int rc = 0, remote; - ENTRY; - - data = req_capsule_client_get(info->mti_pill, &RMF_CONNECT_DATA); - reply = req_capsule_server_get(info->mti_pill, &RMF_CONNECT_DATA); - if (data == NULL || reply == NULL) - RETURN(-EFAULT); - - /* connection from MDT is always trusted */ - if (req->rq_auth_usr_mdt) { - mdt_init_sec_none(reply, exp); - RETURN(0); - } - - /* no GSS support case */ - if (!req->rq_auth_gss) { - if (mdt->mdt_sec_level > LUSTRE_SEC_NONE) { - CWARN("%s: client %s -> target %s does not user GSS, " - "can not run under security level %d.\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt), - mdt->mdt_sec_level); - RETURN(-EACCES); - } else { - mdt_init_sec_none(reply, exp); - RETURN(0); - } - } - - /* old version case */ - if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) || - !(data->ocd_connect_flags & OBD_CONNECT_MDS_CAPA) || - !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) { - if (mdt->mdt_sec_level > LUSTRE_SEC_NONE) { - CWARN("%s: client %s -> target %s uses old version, " - "can not run under security level %d.\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt), - mdt->mdt_sec_level); - RETURN(-EACCES); - } else { - CWARN("%s: client %s -> target %s uses old version, " - "run under security level %d.\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt), - mdt->mdt_sec_level); - mdt_init_sec_none(reply, exp); - RETURN(0); - } - } - - remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE; - if (remote) { - if (!req->rq_auth_remote) - CDEBUG(D_SEC, "%s: client (local realm) %s -> " - "target %s asked to be remote.\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt)); - } else if (req->rq_auth_remote) { - remote = 1; - CDEBUG(D_SEC, "%s: client (remote realm) %s -> " - "target %s is set as remote by default.\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt)); - } - - if (remote) { - if (!mdt->mdt_opts.mo_oss_capa) { - CDEBUG(D_SEC, "%s: client %s -> target %s is set as " - "remote,but OSS capabilities are not enabled: " - "%d.\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt), - mdt->mdt_opts.mo_oss_capa); - RETURN(-EACCES); - } - } else { - if (req->rq_auth_uid == INVALID_UID) { - CDEBUG(D_SEC, "%s: client %s -> target %s: user is not " - "authenticated!\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt)); - RETURN(-EACCES); - } - } - - switch (mdt->mdt_sec_level) { - case LUSTRE_SEC_NONE: - if (!remote) { - mdt_init_sec_none(reply, exp); - break; - } else { - CDEBUG(D_SEC, "%s: client %s -> target %s is set as " - "remote, can not run under security level %d.\n", - mdt_obd_name(mdt), client, mdt_obd_name(mdt), - mdt->mdt_sec_level); - RETURN(-EACCES); - } - case LUSTRE_SEC_REMOTE: - if (!remote) - mdt_init_sec_none(reply, exp); - break; - case LUSTRE_SEC_ALL: - if (!remote) { - reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | - OBD_CONNECT_RMT_CLIENT_FORCE); - if (!mdt->mdt_opts.mo_mds_capa) - reply->ocd_connect_flags &= ~OBD_CONNECT_MDS_CAPA; - if (!mdt->mdt_opts.mo_oss_capa) - reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA; - } - break; - default: - RETURN(-EINVAL); - } - - RETURN(rc); -} - -int mdt_init_idmap(struct mdt_thread_info *info) -{ - struct ptlrpc_request *req = mdt_info_req(info); + struct ptlrpc_request *req = tgt_ses_req(tsi); struct mdt_export_data *med = mdt_req2med(req); struct obd_export *exp = req->rq_export; char *client = libcfs_nid2str(req->rq_peer.nid); @@ -216,22 +90,22 @@ int mdt_init_idmap(struct mdt_thread_info *info) med->med_idmap = NULL; CERROR("%s: client %s -> target %s " "failed to init idmap [%ld]!\n", - mdt_obd_name(info->mti_mdt), client, - mdt_obd_name(info->mti_mdt), err); + tgt_name(tsi->tsi_tgt), client, + tgt_name(tsi->tsi_tgt), err); RETURN(err); } else if (!med->med_idmap) { CERROR("%s: client %s -> target %s " "failed to init(2) idmap!\n", - mdt_obd_name(info->mti_mdt), client, - mdt_obd_name(info->mti_mdt)); + tgt_name(tsi->tsi_tgt), client, + tgt_name(tsi->tsi_tgt)); RETURN(-ENOMEM); } CDEBUG(D_SEC, "%s: client %s -> target %s is remote.\n", - mdt_obd_name(info->mti_mdt), client, - mdt_obd_name(info->mti_mdt)); + tgt_name(tsi->tsi_tgt), client, + tgt_name(tsi->tsi_tgt)); /* NB, MDS_CONNECT establish root idmap too! */ - rc = mdt_handle_idmap(info); + rc = mdt_handle_idmap(tsi); } RETURN(rc); } @@ -255,10 +129,10 @@ static inline void mdt_revoke_export_locks(struct obd_export *exp) ldlm_revoke_export_locks(exp); } -int mdt_handle_idmap(struct mdt_thread_info *info) +int mdt_handle_idmap(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); - struct mdt_device *mdt = info->mti_mdt; + struct ptlrpc_request *req = tgt_ses_req(tsi); + struct mdt_device *mdt = mdt_exp2dev(req->rq_export); struct mdt_export_data *med; struct ptlrpc_user_desc *pud = req->rq_user_desc; struct md_identity *identity; @@ -270,7 +144,7 @@ int mdt_handle_idmap(struct mdt_thread_info *info) RETURN(0); med = mdt_req2med(req); - if (!exp_connect_rmtclient(info->mti_exp)) + if (!exp_connect_rmtclient(req->rq_export)) RETURN(0); opc = lustre_msg_get_opc(req->rq_reqmsg); diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 8cb416e..dc26857 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -176,9 +176,6 @@ struct mdt_device { struct { unsigned int mo_user_xattr:1, mo_acl:1, - mo_compat_resname:1, - mo_mds_capa:1, - mo_oss_capa:1, mo_cos:1, mo_coordinator:1; } mdt_opts; @@ -200,10 +197,6 @@ struct mdt_device { struct upcall_cache *mdt_identity_cache; - /* sptlrpc rules */ - rwlock_t mdt_sptlrpc_lock; - struct sptlrpc_rule_set mdt_sptlrpc_rset; - /* capability keys */ unsigned long mdt_capa_timeout; __u32 mdt_capa_alg; @@ -232,7 +225,6 @@ struct mdt_device { int mdt_nosquash_strlen; struct rw_semaphore mdt_squash_sem; - int mdt_sec_level; struct rename_stats mdt_rename_stats; struct lu_fid mdt_md_root_fid; @@ -426,12 +418,6 @@ struct mdt_thread_info { * to be removed upon moving MDT to the unified target code */ bool mti_txn_compat; - /* - * Additional fail id that can be set by handler. Passed to - * target_send_reply(). - */ - int mti_fail_id; - /* transaction number of current request */ __u64 mti_transno; @@ -551,6 +537,18 @@ struct mdt_thread_info { struct ldlm_enqueue_info mti_einfo; }; +extern struct lu_context_key mdt_thread_key; + +static inline struct mdt_thread_info *mdt_th_info(const struct lu_env *env) +{ + struct mdt_thread_info *mti; + + lu_env_refill((void *)env); + mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); + LASSERT(mti); + return mti; +} + /* ptlrpc request handler for MDT. All handlers are * grouped into several slices - struct mdt_opc_slice, * and stored in an array - mdt_handlers[]. @@ -781,8 +779,6 @@ int mdt_export_stats_init(struct obd_device *obd, struct obd_export *exp, void *client_nid); -int mdt_pin(struct mdt_thread_info* info); - int mdt_lock_new_child(struct mdt_thread_info *info, struct mdt_object *o, struct mdt_lock_handle *child_lockh); @@ -808,6 +804,7 @@ enum { MDT_SOM_ENABLE = 1, }; +int mdt_get_info(struct tgt_session_info *tsi); int mdt_attr_get_complex(struct mdt_thread_info *info, struct mdt_object *o, struct md_attr *ma); int mdt_ioepoch_open(struct mdt_thread_info *info, struct mdt_object *o, @@ -819,12 +816,12 @@ int mdt_write_read(struct mdt_object *o); struct mdt_file_data *mdt_mfd_new(const struct mdt_export_data *med); int mdt_mfd_close(struct mdt_thread_info *info, struct mdt_file_data *mfd); void mdt_mfd_free(struct mdt_file_data *mfd); -int mdt_close(struct mdt_thread_info *info); +int mdt_close(struct tgt_session_info *tsi); int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo, struct md_attr *ma, int flags); int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo, struct md_attr *ma); -int mdt_done_writing(struct mdt_thread_info *info); +int mdt_done_writing(struct tgt_session_info *tsi); int mdt_fix_reply(struct mdt_thread_info *info); int mdt_handle_last_unlink(struct mdt_thread_info *, struct mdt_object *, const struct md_attr *); @@ -844,47 +841,10 @@ int mdt_version_get_check(struct mdt_thread_info *, struct mdt_object *, int); void mdt_version_get_save(struct mdt_thread_info *, struct mdt_object *, int); int mdt_version_get_check_save(struct mdt_thread_info *, struct mdt_object *, int); -int mdt_handle_common(struct ptlrpc_request *req, - struct mdt_opc_slice *supported); -int mdt_connect(struct mdt_thread_info *info); -int mdt_disconnect(struct mdt_thread_info *info); -int mdt_set_info(struct mdt_thread_info *info); -int mdt_get_info(struct mdt_thread_info *info); -int mdt_getstatus(struct mdt_thread_info *info); -int mdt_getattr(struct mdt_thread_info *info); -int mdt_getattr_name(struct mdt_thread_info *info); -int mdt_statfs(struct mdt_thread_info *info); -int mdt_reint(struct mdt_thread_info *info); -int mdt_sync(struct mdt_thread_info *info); -int mdt_is_subdir(struct mdt_thread_info *info); -int mdt_obd_ping(struct mdt_thread_info *info); -int mdt_obd_log_cancel(struct mdt_thread_info *info); -int mdt_obd_qc_callback(struct mdt_thread_info *info); -int mdt_enqueue(struct mdt_thread_info *info); -int mdt_convert(struct mdt_thread_info *info); -int mdt_bl_callback(struct mdt_thread_info *info); -int mdt_cp_callback(struct mdt_thread_info *info); -int mdt_llog_create(struct mdt_thread_info *info); -int mdt_llog_destroy(struct mdt_thread_info *info); -int mdt_llog_read_header(struct mdt_thread_info *info); -int mdt_llog_next_block(struct mdt_thread_info *info); -int mdt_llog_prev_block(struct mdt_thread_info *info); -int mdt_sec_ctx_handle(struct mdt_thread_info *info); -int mdt_readpage(struct mdt_thread_info *info); -int mdt_obd_idx_read(struct mdt_thread_info *info); -int mdt_tgt_connect(struct tgt_session_info *tsi); void mdt_thread_info_init(struct ptlrpc_request *req, struct mdt_thread_info *mti); void mdt_thread_info_fini(struct mdt_thread_info *mti); - -extern struct mdt_opc_slice mdt_regular_handlers[]; -extern struct mdt_opc_slice mdt_seq_handlers[]; -extern struct mdt_opc_slice mdt_fld_handlers[]; - -int mdt_quotacheck(struct mdt_thread_info *info); -int mdt_quotactl(struct mdt_thread_info *info); -int mdt_quota_dqacq(struct mdt_thread_info *info); -int mdt_swap_layouts(struct mdt_thread_info *info); +struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi); extern struct lprocfs_vars lprocfs_mds_module_vars[]; extern struct lprocfs_vars lprocfs_mds_obd_vars[]; @@ -892,13 +852,10 @@ extern struct lprocfs_vars lprocfs_mds_obd_vars[]; int mdt_hsm_attr_set(struct mdt_thread_info *info, struct mdt_object *obj, const struct md_hsm *mh); -struct mdt_handler *mdt_handler_find(__u32 opc, - struct mdt_opc_slice *supported); /* mdt_idmap.c */ -int mdt_init_sec_level(struct mdt_thread_info *); -int mdt_init_idmap(struct mdt_thread_info *); +int mdt_init_idmap(struct tgt_session_info *tsi); void mdt_cleanup_idmap(struct mdt_export_data *); -int mdt_handle_idmap(struct mdt_thread_info *); +int mdt_handle_idmap(struct tgt_session_info *tsi); int ptlrpc_user_desc_do_idmap(struct ptlrpc_request *, struct ptlrpc_user_desc *); void mdt_body_reverse_idmap(struct mdt_thread_info *, @@ -912,6 +869,11 @@ static inline struct mdt_device *mdt_dev(struct lu_device *d) return container_of0(d, struct mdt_device, mdt_lu_dev); } +static inline struct mdt_object *mdt_obj(struct lu_object *o) +{ + return container_of0(o, struct mdt_object, mot_obj); +} + static inline struct dt_object *mdt_obj2dt(struct mdt_object *mo) { struct lu_object *lo; @@ -939,13 +901,14 @@ __u32 mdt_identity_get_perm(struct md_identity *, __u32, lnet_nid_t); int mdt_pack_remote_perm(struct mdt_thread_info *, struct mdt_object *, void *); /* mdt/mdt_hsm.c */ -int mdt_hsm_state_get(struct mdt_thread_info *info); -int mdt_hsm_state_set(struct mdt_thread_info *info); -int mdt_hsm_action(struct mdt_thread_info *info); -int mdt_hsm_progress(struct mdt_thread_info *info); -int mdt_hsm_ct_register(struct mdt_thread_info *info); -int mdt_hsm_ct_unregister(struct mdt_thread_info *info); -int mdt_hsm_request(struct mdt_thread_info *info); +int mdt_hsm_state_get(struct tgt_session_info *tsi); +int mdt_hsm_state_set(struct tgt_session_info *tsi); +int mdt_hsm_action(struct tgt_session_info *tsi); +int mdt_hsm_progress(struct tgt_session_info *tsi); +int mdt_hsm_ct_register(struct tgt_session_info *tsi); +int mdt_hsm_ct_unregister(struct tgt_session_info *tsi); +int mdt_hsm_request(struct tgt_session_info *tsi); + /* mdt/mdt_hsm_cdt_actions.c */ extern const struct file_operations mdt_hsm_actions_fops; void dump_llog_agent_req_rec(const char *prefix, @@ -1040,6 +1003,7 @@ int mdt_hsm_update_request_state(struct mdt_thread_info *mti, const int update_record); extern struct lu_context_key mdt_thread_key; + /* debug issues helper starts here*/ static inline int mdt_fail_write(const struct lu_env *env, struct dt_device *dd, int id) @@ -1056,7 +1020,12 @@ static inline int mdt_fail_write(const struct lu_env *env, static inline struct mdt_export_data *mdt_req2med(struct ptlrpc_request *req) { - return &req->rq_export->exp_mdt_data; + return &req->rq_export->exp_mdt_data; +} + +static inline struct mdt_device *mdt_exp2dev(struct obd_export *exp) +{ + return mdt_dev(exp->exp_obd->obd_lu_dev); } typedef void (*mdt_reconstruct_t)(struct mdt_thread_info *mti, @@ -1211,18 +1180,6 @@ static inline struct obd_device *mdt2obd_dev(const struct mdt_device *mdt) extern const struct lu_device_operations mdt_lu_ops; -static inline int lu_device_is_mdt(struct lu_device *d) -{ - return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops); -} - -static inline struct mdt_device *lu2mdt_dev(struct lu_device *d) -{ - LASSERTF(lu_device_is_mdt(d), "It is %s instead of MDT %p %p\n", - d->ld_type->ldt_name, d->ld_ops, &mdt_lu_ops); - return container_of0(d, struct mdt_device, mdt_lu_dev); -} - static inline char *mdt_obd_name(struct mdt_device *mdt) { return mdt->mdt_lu_dev.ld_obd->obd_name; diff --git a/lustre/mdt/mdt_lib.c b/lustre/mdt/mdt_lib.c index a92089a..c611462 100644 --- a/lustre/mdt/mdt_lib.c +++ b/lustre/mdt/mdt_lib.c @@ -693,7 +693,7 @@ int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo, repbody->valid |= OBD_MD_FLCOOKIE; } - if (info->mti_mdt->mdt_opts.mo_oss_capa && + if (info->mti_mdt->mdt_lut.lut_oss_capa && exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA && repbody->valid & OBD_MD_FLEASIZE) { struct lustre_capa *capa; @@ -764,7 +764,7 @@ void mdt_set_capainfo(struct mdt_thread_info *info, int offset, struct lu_capainfo *lci; LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX); - if (!info->mti_mdt->mdt_opts.mo_mds_capa || + if (!info->mti_mdt->mdt_lut.lut_mds_capa || !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA)) return; diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index 4bdf984..010caf4 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -473,12 +473,12 @@ out: static int lprocfs_rd_capa(char *page, char **start, off_t off, int count, int *eof, void *data) { - struct obd_device *obd = data; - struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); + struct obd_device *obd = data; + struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); - return snprintf(page, count, "capability on: %s %s\n", - mdt->mdt_opts.mo_oss_capa ? "oss" : "", - mdt->mdt_opts.mo_mds_capa ? "mds" : ""); + return snprintf(page, count, "capability on: %s %s\n", + mdt->mdt_lut.lut_oss_capa ? "oss" : "", + mdt->mdt_lut.lut_mds_capa ? "mds" : ""); } static int lprocfs_wr_capa(struct file *file, const char *buffer, @@ -508,15 +508,15 @@ static int lprocfs_wr_capa(struct file *file, const char *buffer, return -EINVAL; } - mdt->mdt_opts.mo_oss_capa = (val & 0x1); - mdt->mdt_opts.mo_mds_capa = !!(val & 0x2); + mdt->mdt_lut.lut_oss_capa = !!(val & 0x1); + mdt->mdt_lut.lut_mds_capa = !!(val & 0x2); mdt->mdt_capa_conf = 1; LCONSOLE_INFO("MDS %s %s MDS fid capability.\n", mdt_obd_name(mdt), - mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled"); + mdt->mdt_lut.lut_mds_capa ? "enabled" : "disabled"); LCONSOLE_INFO("MDS %s %s OSS fid capability.\n", mdt_obd_name(mdt), - mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled"); + mdt->mdt_lut.lut_oss_capa ? "enabled" : "disabled"); return count; } @@ -631,7 +631,7 @@ static int lprocfs_rd_sec_level(char *page, char **start, off_t off, struct obd_device *obd = data; struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); - return snprintf(page, count, "%d\n", mdt->mdt_sec_level); + return snprintf(page, count, "%d\n", mdt->mdt_lut.lut_sec_level); } static int lprocfs_wr_sec_level(struct file *file, const char *buffer, @@ -654,8 +654,8 @@ static int lprocfs_wr_sec_level(struct file *file, const char *buffer, return -EINVAL; } - mdt->mdt_sec_level = val; - return count; + mdt->mdt_lut.lut_sec_level = val; + return count; } static int lprocfs_rd_cos(char *page, char **start, off_t off, diff --git a/lustre/mdt/mdt_mds.c b/lustre/mdt/mdt_mds.c index 8084dab..d91d1d4 100644 --- a/lustre/mdt/mdt_mds.c +++ b/lustre/mdt/mdt_mds.c @@ -99,186 +99,6 @@ static char *mds_attr_num_cpts; CFS_MODULE_PARM(mds_attr_num_cpts, "c", charp, 0444, "CPU partitions MDS setattr threads should run on"); -#define DEFINE_RPC_HANDLER(base, flags, opc, fn, fmt) \ -[opc - base] = { \ - .mh_name = #opc, \ - .mh_fail_id = OBD_FAIL_ ## opc ## _NET, \ - .mh_opc = opc, \ - .mh_flags = flags, \ - .mh_act = fn, \ - .mh_fmt = fmt \ -} - -/* Request with a format known in advance */ -#define DEF_MDT_HDL(flags, name, fn) \ - DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, &RQF_ ## name) - -/* Request with a format we do not yet know */ -#define DEF_MDT_HDL_VAR(flags, name, fn) \ - DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, NULL) - -/* Map one non-standard request format handler. This should probably get - * a common OBD_SET_INFO RPC opcode instead of this mismatch. */ -#define RQF_MDS_SET_INFO RQF_OBD_SET_INFO - -static struct mdt_handler mdt_mds_ops[] = { -DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect), -DEF_MDT_HDL(0, MDS_DISCONNECT, mdt_disconnect), -DEF_MDT_HDL(0, MDS_SET_INFO, mdt_set_info), -DEF_MDT_HDL(0, MDS_GET_INFO, mdt_get_info), -DEF_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus), -DEF_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr), -DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME, mdt_getattr_name), -DEF_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_getxattr), -DEF_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs), -DEF_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint), -DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close), -DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing), -DEF_MDT_HDL(0 | HABEO_REFERO, MDS_PIN, mdt_pin), -DEF_MDT_HDL_VAR(0, MDS_SYNC, mdt_sync), -DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir), -DEF_MDT_HDL(0, MDS_QUOTACHECK, mdt_quotacheck), -DEF_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_PROGRESS, - mdt_hsm_progress), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_CT_REGISTER, - mdt_hsm_ct_register), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_CT_UNREGISTER, - mdt_hsm_ct_unregister), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_HSM_STATE_GET, mdt_hsm_state_get), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_STATE_SET, - mdt_hsm_state_set), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_HSM_ACTION, mdt_hsm_action), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_HSM_REQUEST, mdt_hsm_request), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_SWAP_LAYOUTS, - mdt_swap_layouts), -}; - -#define DEF_OBD_HDL(flags, name, fn) \ - DEFINE_RPC_HANDLER(OBD_PING, flags, name, fn, NULL) - -static struct mdt_handler mdt_obd_ops[] = { -DEF_OBD_HDL(0, OBD_PING, mdt_obd_ping), -DEF_OBD_HDL(0, OBD_LOG_CANCEL, mdt_obd_log_cancel), -DEF_OBD_HDL(0, OBD_QC_CALLBACK, mdt_obd_qc_callback), -DEF_OBD_HDL(0, OBD_IDX_READ, mdt_obd_idx_read) -}; - -#define DEF_DLM_HDL_VAR(flags, name, fn) \ - DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, NULL) -#define DEF_DLM_HDL(flags, name, fn) \ - DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, &RQF_ ## name) - -static struct mdt_handler mdt_dlm_ops[] = { -DEF_DLM_HDL (HABEO_CLAVIS, LDLM_ENQUEUE, mdt_enqueue), -DEF_DLM_HDL_VAR(HABEO_CLAVIS, LDLM_CONVERT, mdt_convert), -DEF_DLM_HDL_VAR(0, LDLM_BL_CALLBACK, mdt_bl_callback), -DEF_DLM_HDL_VAR(0, LDLM_CP_CALLBACK, mdt_cp_callback) -}; - -#define DEF_LLOG_HDL(flags, name, fn) \ - DEFINE_RPC_HANDLER(LLOG_ORIGIN_HANDLE_CREATE, flags, name, fn, NULL) - -static struct mdt_handler mdt_llog_ops[] = { -DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CREATE, mdt_llog_create), -DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block), -DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header), -DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_WRITE_REC, NULL), -DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CLOSE, NULL), -DEF_LLOG_HDL(0, LLOG_ORIGIN_CONNECT, NULL), -DEF_LLOG_HDL(0, LLOG_CATINFO, NULL), -DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block), -DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_DESTROY, mdt_llog_destroy), -}; - -#define DEF_SEC_HDL(flags, name, fn) \ - DEFINE_RPC_HANDLER(SEC_CTX_INIT, flags, name, fn, NULL) - -static struct mdt_handler mdt_sec_ctx_ops[] = { -DEF_SEC_HDL(0, SEC_CTX_INIT, mdt_sec_ctx_handle), -DEF_SEC_HDL(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle), -DEF_SEC_HDL(0, SEC_CTX_FINI, mdt_sec_ctx_handle) -}; - -#define DEF_QUOTA_HDL(flags, name, fn) \ - DEFINE_RPC_HANDLER(QUOTA_DQACQ, flags, name, fn, &RQF_ ## name) - -static struct mdt_handler mdt_quota_ops[] = { -DEF_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq), -}; - -struct mdt_opc_slice mdt_regular_handlers[] = { - { - .mos_opc_start = MDS_GETATTR, - .mos_opc_end = MDS_LAST_OPC, - .mos_hs = mdt_mds_ops - }, - { - .mos_opc_start = OBD_PING, - .mos_opc_end = OBD_LAST_OPC, - .mos_hs = mdt_obd_ops - }, - { - .mos_opc_start = LDLM_ENQUEUE, - .mos_opc_end = LDLM_LAST_OPC, - .mos_hs = mdt_dlm_ops - }, - { - .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE, - .mos_opc_end = LLOG_LAST_OPC, - .mos_hs = mdt_llog_ops - }, - { - .mos_opc_start = SEC_CTX_INIT, - .mos_opc_end = SEC_LAST_OPC, - .mos_hs = mdt_sec_ctx_ops - }, - { - .mos_opc_start = QUOTA_DQACQ, - .mos_opc_end = QUOTA_LAST_OPC, - .mos_hs = mdt_quota_ops - }, - { - .mos_hs = NULL - } -}; - -/* Readpage/readdir handlers */ -static struct mdt_handler mdt_readpage_ops[] = { -DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect), -DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_READPAGE, mdt_readpage), -/* XXX: this is ugly and should be fixed one day, see mdc_close() for - * detailed comments. --umka */ -DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close), -DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing), -}; - -static struct mdt_opc_slice mdt_readpage_handlers[] = { - { - .mos_opc_start = MDS_GETATTR, - .mos_opc_end = MDS_LAST_OPC, - .mos_hs = mdt_readpage_ops - }, - { - .mos_opc_start = OBD_FIRST_OPC, - .mos_opc_end = OBD_LAST_OPC, - .mos_hs = mdt_obd_ops - }, - { - .mos_hs = NULL - } -}; - -static int mds_regular_handle(struct ptlrpc_request *req) -{ - return mdt_handle_common(req, mdt_regular_handlers); -} - -static int mds_readpage_handle(struct ptlrpc_request *req) -{ - return mdt_handle_common(req, mdt_readpage_handlers); -} - /* device init/fini methods */ static void mds_stop_ptlrpc_service(struct mds_device *m) { @@ -354,7 +174,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m) .cc_pattern = mds_num_cpts, }, .psc_ops = { - .so_req_handler = mds_regular_handle, + .so_req_handler = tgt_request_handle, .so_req_printer = target_print_req, .so_hpreq_handler = ptlrpc_hpreq_handler, }, @@ -398,7 +218,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m) .cc_pattern = mds_rdpg_num_cpts, }, .psc_ops = { - .so_req_handler = mds_readpage_handle, + .so_req_handler = tgt_request_handle, .so_req_printer = target_print_req, }, }; @@ -444,7 +264,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m) .cc_pattern = mds_attr_num_cpts, }, .psc_ops = { - .so_req_handler = mds_regular_handle, + .so_req_handler = tgt_request_handle, .so_req_printer = target_print_req, .so_hpreq_handler = NULL, }, diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index 76ed060..dcd18c5 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -905,7 +905,7 @@ int mdt_finish_open(struct mdt_thread_info *info, } #endif - if (info->mti_mdt->mdt_opts.mo_mds_capa && + if (info->mti_mdt->mdt_lut.lut_mds_capa && exp_connect_flags(exp) & OBD_CONNECT_MDS_CAPA) { struct lustre_capa *capa; @@ -917,8 +917,7 @@ int mdt_finish_open(struct mdt_thread_info *info, RETURN(rc); repbody->valid |= OBD_MD_FLMDSCAPA; } - - if (info->mti_mdt->mdt_opts.mo_oss_capa && + if (info->mti_mdt->mdt_lut.lut_oss_capa && exp_connect_flags(exp) & OBD_CONNECT_OSS_CAPA && S_ISREG(lu_object_attr(&o->mot_obj))) { struct lustre_capa *capa; @@ -1492,12 +1491,6 @@ out: return rc; } -int mdt_pin(struct mdt_thread_info* info) -{ - ENTRY; - RETURN(err_serious(-EOPNOTSUPP)); -} - /* Cross-ref request. Currently it can only be a pure open (w/o create) */ static int mdt_cross_open(struct mdt_thread_info *info, const struct lu_fid *parent_fid, @@ -2243,22 +2236,23 @@ int mdt_mfd_close(struct mdt_thread_info *info, struct mdt_file_data *mfd) RETURN(rc ? rc : ret); } -int mdt_close(struct mdt_thread_info *info) +int mdt_close(struct tgt_session_info *tsi) { + struct mdt_thread_info *info = tsi2mdt_info(tsi); + struct ptlrpc_request *req = tgt_ses_req(tsi); struct mdt_export_data *med; struct mdt_file_data *mfd; struct mdt_object *o; struct md_attr *ma = &info->mti_attr; struct mdt_body *repbody = NULL; - struct ptlrpc_request *req = mdt_info_req(info); int rc, ret = 0; ENTRY; mdt_counter_incr(req, LPROC_MDT_CLOSE); - /* Close may come with the Size-on-MDS update. Unpack it. */ - rc = mdt_close_unpack(info); - if (rc) - RETURN(err_serious(rc)); + /* Close may come with the Size-on-MDS update. Unpack it. */ + rc = mdt_close_unpack(info); + if (rc) + GOTO(out, rc = err_serious(rc)); LASSERT(info->mti_ioepoch); @@ -2272,7 +2266,7 @@ int mdt_close(struct mdt_thread_info *info) if (rc == 0) mdt_fix_reply(info); mdt_exit_ucred(info); - RETURN(lustre_msg_get_status(req->rq_repmsg)); + GOTO(out, rc = lustre_msg_get_status(req->rq_repmsg)); } /* Continue to close handle even if we can not pack reply */ @@ -2327,13 +2321,15 @@ int mdt_close(struct mdt_thread_info *info) } mdt_exit_ucred(info); - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) - RETURN(err_serious(-ENOMEM)); + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) + GOTO(out, rc = err_serious(-ENOMEM)); - if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_CLOSE_NET_REP, - OBD_FAIL_MDS_CLOSE_NET_REP)) - info->mti_fail_id = OBD_FAIL_MDS_CLOSE_NET_REP; - RETURN(rc ? rc : ret); + if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_CLOSE_NET_REP, + OBD_FAIL_MDS_CLOSE_NET_REP)) + tsi->tsi_reply_fail_id = OBD_FAIL_MDS_CLOSE_NET_REP; +out: + mdt_thread_info_fini(info); + RETURN(rc ? rc : ret); } /** @@ -2344,35 +2340,35 @@ int mdt_close(struct mdt_thread_info *info) * and got a trasid. Waiting for such DONE_WRITING is not reliable, so just * skip attributes and reconstruct the reply here. */ -int mdt_done_writing(struct mdt_thread_info *info) +int mdt_done_writing(struct tgt_session_info *tsi) { - struct ptlrpc_request *req = mdt_info_req(info); + struct ptlrpc_request *req = tgt_ses_req(tsi); + struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_body *repbody = NULL; struct mdt_export_data *med; struct mdt_file_data *mfd; int rc; ENTRY; - rc = req_capsule_server_pack(info->mti_pill); - if (rc) - RETURN(err_serious(rc)); + rc = req_capsule_server_pack(tsi->tsi_pill); + if (rc) + GOTO(out, rc = err_serious(rc)); - repbody = req_capsule_server_get(info->mti_pill, - &RMF_MDT_BODY); - repbody->eadatasize = 0; - repbody->aclsize = 0; + repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_MDT_BODY); + repbody->eadatasize = 0; + repbody->aclsize = 0; - /* Done Writing may come with the Size-on-MDS update. Unpack it. */ - rc = mdt_close_unpack(info); - if (rc) - RETURN(err_serious(rc)); + /* Done Writing may come with the Size-on-MDS update. Unpack it. */ + rc = mdt_close_unpack(info); + if (rc) + GOTO(out, rc = err_serious(rc)); if (mdt_check_resent(info, mdt_reconstruct_generic, NULL)) { mdt_exit_ucred(info); - RETURN(lustre_msg_get_status(req->rq_repmsg)); + GOTO(out, rc = lustre_msg_get_status(req->rq_repmsg)); } - med = &info->mti_exp->exp_mdt_data; + med = &info->mti_exp->exp_mdt_data; spin_lock(&med->med_open_lock); mfd = mdt_handle2mfd(med, &info->mti_ioepoch->handle, req_is_replay(req)); @@ -2414,5 +2410,7 @@ int mdt_done_writing(struct mdt_thread_info *info) mdt_empty_transno(info, rc); error_ucred: mdt_exit_ucred(info); +out: + mdt_thread_info_fini(info); RETURN(rc); } diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index 80a7aa7..617ac43 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -66,7 +66,7 @@ static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc, if (repbody->valid & OBD_MD_FLMDSCAPA) RETURN(rc); - if (rc == 0 && info->mti_mdt->mdt_opts.mo_mds_capa && + if (rc == 0 && info->mti_mdt->mdt_lut.lut_mds_capa && exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) { struct lustre_capa *capa; @@ -598,12 +598,12 @@ static int mdt_reint_setattr(struct mdt_thread_info *info, ma->ma_need = MA_INODE; ma->ma_valid = 0; rc = mdt_attr_get_complex(info, mo, ma); - if (rc != 0) - GOTO(out_put, rc); + if (rc != 0) + GOTO(out_put, rc); - mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo)); + mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo)); - if (info->mti_mdt->mdt_opts.mo_oss_capa && + if (info->mti_mdt->mdt_lut.lut_oss_capa && exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA && S_ISREG(lu_object_attr(&mo->mot_obj)) && (ma->ma_attr.la_valid & LA_SIZE) && !som_au) { diff --git a/lustre/mdt/mdt_xattr.c b/lustre/mdt/mdt_xattr.c index f7c5f60..a89013d 100644 --- a/lustre/mdt/mdt_xattr.c +++ b/lustre/mdt/mdt_xattr.c @@ -220,9 +220,9 @@ out: int mdt_getxattr(struct mdt_thread_info *info) { - struct ptlrpc_request *req = mdt_info_req(info); - struct mdt_export_data *med = mdt_req2med(req); - struct lu_ucred *uc = mdt_ucred(info); + struct ptlrpc_request *req = mdt_info_req(info); + struct mdt_export_data *med = mdt_req2med(req); + struct lu_ucred *uc = lu_ucred(info->mti_env); struct mdt_body *reqbody; struct mdt_body *repbody = NULL; struct md_object *next; @@ -357,8 +357,8 @@ _out: int mdt_reint_setxattr(struct mdt_thread_info *info, struct mdt_lock_handle *unused) { - struct ptlrpc_request *req = mdt_info_req(info); - struct lu_ucred *uc = mdt_ucred(info); + struct ptlrpc_request *req = mdt_info_req(info); + struct lu_ucred *uc = lu_ucred(info->mti_env); struct mdt_lock_handle *lh; const struct lu_env *env = info->mti_env; struct lu_buf *buf = &info->mti_buf; diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 9c6af86..1b5f2e0 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -880,7 +880,20 @@ TGT_OBD_HDL(0, OBD_PING, tgt_obd_ping), }; static struct tgt_handler mgs_dlm_handlers[] = { -TGT_DLM_HDL(HABEO_CLAVIS, LDLM_ENQUEUE, tgt_enqueue), +[LDLM_ENQUEUE - LDLM_FIRST_OPC] = { + .th_name = "LDLM_ENQUEUE", + /* don't use th_fail_id for MGS to don't interfere with MDS tests. + * * There are no tests for MGS with OBD_FAIL_LDLM_ENQUEUE_NET so it + * * is safe. If such tests will be needed we have to distinguish + * * MDS and MGS fail ids, e.g use OBD_FAIL_MGS_ENQUEUE_NET for MGS + * * instead of common OBD_FAIL_LDLM_ENQUEUE_NET */ + .th_fail_id = 0, + .th_opc = LDLM_ENQUEUE, + .th_flags = HABEO_CLAVIS, + .th_act = tgt_enqueue, + .th_fmt = &RQF_LDLM_ENQUEUE, + .th_version = LUSTRE_DLM_VERSION, + }, }; static struct tgt_handler mgs_llog_handlers[] = { diff --git a/lustre/target/tgt_handler.c b/lustre/target/tgt_handler.c index c5a9fde..e3e63db 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -46,25 +46,87 @@ char *tgt_name(struct lu_target *tgt) } EXPORT_SYMBOL(tgt_name); +/* + * Generic code handling requests that have struct mdt_body passed in: + * + * - extract mdt_body from request and save it in @tsi, if present; + * + * - create lu_object, corresponding to the fid in mdt_body, and save it in + * @tsi; + * + * - if HABEO_CORPUS flag is set for this request type check whether object + * actually exists on storage (lu_object_exists()). + * + */ +static int tgt_mdt_body_unpack(struct tgt_session_info *tsi, __u32 flags) +{ + const struct mdt_body *body; + struct lu_object *obj; + struct req_capsule *pill = tsi->tsi_pill; + int rc; + + ENTRY; + + body = req_capsule_client_get(pill, &RMF_MDT_BODY); + if (body == NULL) + RETURN(-EFAULT); + + tsi->tsi_mdt_body = body; + + if (!(body->valid & OBD_MD_FLID)) + RETURN(0); + + /* mdc_pack_body() doesn't check if fid is zero and set OBD_ML_FID + * in any case in pre-2.5 clients. Fix that here if needed */ + if (unlikely(fid_is_zero(&body->fid1))) + RETURN(0); + + if (!fid_is_sane(&body->fid1)) { + CERROR("%s: invalid FID: "DFID"\n", tgt_name(tsi->tsi_tgt), + PFID(&body->fid1)); + RETURN(-EINVAL); + } + + obj = lu_object_find(tsi->tsi_env, + &tsi->tsi_tgt->lut_bottom->dd_lu_dev, + &body->fid1, NULL); + if (!IS_ERR(obj)) { + if ((flags & HABEO_CORPUS) && !lu_object_exists(obj)) { + lu_object_put(tsi->tsi_env, obj); + /* for capability renew ENOENT will be handled in + * mdt_renew_capa */ + if (body->valid & OBD_MD_FLOSSCAPA) + rc = 0; + else + rc = -ENOENT; + } else { + tsi->tsi_corpus = obj; + rc = 0; + } + } else { + rc = PTR_ERR(obj); + } + RETURN(rc); +} + static int tgt_unpack_req_pack_rep(struct tgt_session_info *tsi, __u32 flags) { struct req_capsule *pill = tsi->tsi_pill; - const struct mdt_body *body = NULL; - int rc = 0; + int rc; ENTRY; if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT)) { - body = req_capsule_client_get(pill, &RMF_MDT_BODY); - if (body == NULL) - RETURN(-EFAULT); + rc = tgt_mdt_body_unpack(tsi, flags); + } else { + rc = 0; } if (flags & HABEO_REFERO) { /* Pack reply */ if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, - body ? body->eadatasize : 0); + tsi->tsi_mdt_body->eadatasize); if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0); @@ -93,6 +155,20 @@ static int tgt_handle_request0(struct tgt_session_info *tsi, LASSERT(h->th_opc == lustre_msg_get_opc(req->rq_reqmsg)); LASSERT(current->journal_info == NULL); + /* + * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try + * to put same checks into handlers like mdt_close(), mdt_reint(), + * etc., without talking to mdt authors first. Checking same thing + * there again is useless and returning 0 error without packing reply + * is buggy! Handlers either pack reply or return error. + * + * We return 0 here and do not send any reply in order to emulate + * network failure. Do not send any reply in case any of NET related + * fail_id has occured. + */ + if (OBD_FAIL_CHECK_ORSET(h->th_fail_id, OBD_FAIL_ONCE)) + RETURN(0); + rc = 0; flags = h->th_flags; LASSERT(ergo(flags & (HABEO_CORPUS | HABEO_REFERO), @@ -281,14 +357,12 @@ int tgt_request_handle(struct ptlrpc_request *req) ENTRY; - /* Refill(initilize) the context, in case it is - * not initialized yet. */ + /* Refill the context, to make sure all thread keys are allocated */ lu_env_refill(req->rq_svc_thread->t_env); req_capsule_init(&req->rq_pill, req, RCL_SERVER); tsi->tsi_pill = &req->rq_pill; tsi->tsi_env = req->rq_svc_thread->t_env; - tsi->tsi_dlm_req = NULL; /* if request has export then get handlers slice from corresponding * target, otherwise that should be connect operation */ @@ -364,6 +438,13 @@ int tgt_request_handle(struct ptlrpc_request *req) out: req_capsule_fini(tsi->tsi_pill); tsi->tsi_pill = NULL; + if (tsi->tsi_corpus != NULL) { + lu_object_put(tsi->tsi_env, tsi->tsi_corpus); + tsi->tsi_corpus = NULL; + } + tsi->tsi_env = NULL; + tsi->tsi_mdt_body = NULL; + tsi->tsi_dlm_req = NULL; return rc; } EXPORT_SYMBOL(tgt_request_handle); @@ -583,6 +664,7 @@ int tgt_connect(struct tgt_session_info *tsi) reply = req_capsule_server_get(tsi->tsi_pill, &RMF_CONNECT_DATA); spin_lock(&tsi->tsi_exp->exp_lock); *exp_connect_flags_ptr(tsi->tsi_exp) = reply->ocd_connect_flags; + tsi->tsi_exp->exp_connect_data.ocd_brw_size = reply->ocd_brw_size; spin_unlock(&tsi->tsi_exp->exp_lock); RETURN(0); @@ -635,8 +717,7 @@ int tgt_obd_qc_callback(struct tgt_session_info *tsi) } EXPORT_SYMBOL(tgt_obd_qc_callback); -static int tgt_sendpage(struct tgt_session_info *tsi, struct lu_rdpg *rdpg, - int nob) +int tgt_sendpage(struct tgt_session_info *tsi, struct lu_rdpg *rdpg, int nob) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct ptlrpc_request *req = tgt_ses_req(tsi); @@ -787,7 +868,6 @@ int tgt_enqueue(struct tgt_session_info *tsi) * tsi->tsi_dlm_cbs was set by the *_req_handle() function. */ LASSERT(tsi->tsi_dlm_req != NULL); - rc = ldlm_handle_enqueue0(tsi->tsi_exp->exp_obd->obd_namespace, req, tsi->tsi_dlm_req, &tgt_dlm_cbs); if (rc)