- lu_buf_free(&info->mti_big_buf);
-}
-
-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;
-
- rc = tgt_connect(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);
- if (rc != 0)
- GOTO(err, rc);
- RETURN(0);
-err:
- obd_disconnect(class_export_get(req->rq_export));
- 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);