Whamcloud - gitweb
LU-6356 tgt: add handlers for SEC_CTX_* requests
[fs/lustre-release.git] / lustre / target / tgt_handler.c
index 5be36e2..1110902 100644 (file)
@@ -389,6 +389,7 @@ static int tgt_handle_request0(struct tgt_session_info *tsi,
        case SEC_CTX_INIT:
        case SEC_CTX_INIT_CONT:
        case SEC_CTX_FINI:
+               CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
                GOTO(out, rc = 0);
        }
 
@@ -405,6 +406,9 @@ static int tgt_handle_request0(struct tgt_session_info *tsi,
         */
        if (OBD_FAIL_CHECK_ORSET(h->th_fail_id, OBD_FAIL_ONCE))
                RETURN(0);
+       if (unlikely(lustre_msg_get_opc(req->rq_reqmsg) == MDS_REINT &&
+                    OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_MULTI_NET)))
+               RETURN(0);
 
        rc = tgt_request_preprocess(tsi, h, req);
        /* pack reply if reply format is fixed */
@@ -526,11 +530,11 @@ static int tgt_handle_recovery(struct ptlrpc_request *req, int reply_fail_id)
 
        /* sanity check: if the xid matches, the request must be marked as a
         * resent or replayed */
-       if (req_xid_is_last(req)) {
+       if (req_can_reconstruct(req, NULL)) {
                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 "
+                                 "saved xid, expected REPLAY or RESENT flag "
                                  "(%x)", req->rq_xid,
                                  lustre_msg_get_flags(req->rq_reqmsg));
                        req->rq_status = -ENOTCONN;
@@ -667,9 +671,38 @@ int tgt_request_handle(struct ptlrpc_request *req)
                GOTO(out, rc);
        }
 
+       /* check request's xid is consistent with export's last_xid */
+       if (req->rq_export != NULL) {
+               __u64 last_xid = lustre_msg_get_last_xid(req->rq_reqmsg);
+               if (last_xid != 0)
+                       req->rq_export->exp_last_xid = last_xid;
+               if (req->rq_xid == 0 ||
+                   req->rq_xid <= req->rq_export->exp_last_xid) {
+                       DEBUG_REQ(D_ERROR, req,
+                                 "Unexpected xid %llx vs. last_xid %llx\n",
+                                 req->rq_xid, req->rq_export->exp_last_xid);
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 93, 0)
+                       LBUG();
+#endif
+                       req->rq_status = -EPROTO;
+                       rc = ptlrpc_error(req);
+                       GOTO(out, rc);
+               }
+       }
+
        request_fail_id = tgt->lut_request_fail_id;
        tsi->tsi_reply_fail_id = tgt->lut_reply_fail_id;
 
+       /* try to release in-memory reply data */
+       if (tgt_is_multimodrpcs_client(req->rq_export)) {
+               tgt_handle_received_xid(req->rq_export,
+                               lustre_msg_get_last_xid(req->rq_reqmsg));
+               if (!(lustre_msg_get_flags(req->rq_reqmsg) &
+                     (MSG_RESENT | MSG_REPLAY)))
+                       tgt_handle_tag(req->rq_export,
+                                      lustre_msg_get_tag(req->rq_reqmsg));
+       }
+
        h = tgt_handler_find_check(req);
        if (IS_ERR(h)) {
                req->rq_status = PTR_ERR(h);
@@ -902,6 +935,16 @@ int tgt_connect_check_sptlrpc(struct ptlrpc_request *req, struct obd_export *exp
                spin_lock(&exp->exp_lock);
                exp->exp_sp_peer = req->rq_sp_from;
                exp->exp_flvr = flvr;
+
+               /* when on mgs, if no restriction is set, or if client
+                * is loopback, allow any flavor */
+               if ((strcmp(exp->exp_obd->obd_type->typ_name,
+                          LUSTRE_MGS_NAME) == 0) &&
+                    (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_NULL ||
+                     LNET_NETTYP(LNET_NIDNET(exp->exp_connection->c_peer.nid))
+                     == LOLND))
+                       exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
+
                if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
                    exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
                        CERROR("%s: unauthorized rpc flavor %x from %s, "
@@ -1408,6 +1451,22 @@ TGT_LLOG_HDL_VAR(0,      LLOG_ORIGIN_HANDLE_CLOSE,       tgt_llog_close),
 };
 EXPORT_SYMBOL(tgt_llog_handlers);
 
+/*
+ * sec context handlers
+ */
+/* XXX: Implement based on mdt_sec_ctx_handle()? */
+static int tgt_sec_ctx_handle(struct tgt_session_info *tsi)
+{
+       return 0;
+}
+
+struct tgt_handler tgt_sec_ctx_handlers[] = {
+TGT_SEC_HDL_VAR(0,     SEC_CTX_INIT,           tgt_sec_ctx_handle),
+TGT_SEC_HDL_VAR(0,     SEC_CTX_INIT_CONT,      tgt_sec_ctx_handle),
+TGT_SEC_HDL_VAR(0,     SEC_CTX_FINI,           tgt_sec_ctx_handle),
+};
+EXPORT_SYMBOL(tgt_sec_ctx_handlers);
+
 int (*tgt_lfsck_in_notify)(const struct lu_env *env,
                           struct dt_device *key,
                           struct lfsck_request *lr,
@@ -1530,8 +1589,8 @@ int tgt_extent_lock(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
                    __u64 start, __u64 end, struct lustre_handle *lh,
                    int mode, __u64 *flags)
 {
-       ldlm_policy_data_t       policy;
-       int                      rc;
+       union ldlm_policy_data policy;
+       int rc;
 
        ENTRY;
 
@@ -1559,7 +1618,7 @@ int tgt_extent_lock(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
 }
 EXPORT_SYMBOL(tgt_extent_lock);
 
-void tgt_extent_unlock(struct lustre_handle *lh, ldlm_mode_t mode)
+void tgt_extent_unlock(struct lustre_handle *lh, enum ldlm_mode mode)
 {
        LASSERT(lustre_handle_is_used(lh));
        ldlm_lock_decref(lh, mode);
@@ -1568,7 +1627,7 @@ EXPORT_SYMBOL(tgt_extent_unlock);
 
 int tgt_brw_lock(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
                 struct obd_ioobj *obj, struct niobuf_remote *nb,
-                struct lustre_handle *lh, int mode)
+                struct lustre_handle *lh, enum ldlm_mode mode)
 {
        __u64                    flags = 0;
        int                      nrbufs = obj->ioo_bufcnt;
@@ -1593,7 +1652,7 @@ int tgt_brw_lock(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
 }
 
 void tgt_brw_unlock(struct obd_ioobj *obj, struct niobuf_remote *niob,
-                   struct lustre_handle *lh, int mode)
+                   struct lustre_handle *lh, enum ldlm_mode mode)
 {
        ENTRY;
 
@@ -2153,3 +2212,44 @@ out:
        RETURN(rc);
 }
 EXPORT_SYMBOL(tgt_brw_write);
+
+/* Check if request can be reconstructed from saved reply data
+ * A copy of the reply data is returned in @trd if the pointer is not NULL
+ */
+bool req_can_reconstruct(struct ptlrpc_request *req,
+                        struct tg_reply_data *trd)
+{
+       struct tg_export_data *ted = &req->rq_export->exp_target_data;
+       struct lsd_client_data *lcd = ted->ted_lcd;
+       bool found;
+
+       if (tgt_is_multimodrpcs_client(req->rq_export))
+               return tgt_lookup_reply(req, trd);
+
+       mutex_lock(&ted->ted_lcd_lock);
+       found = req->rq_xid == lcd->lcd_last_xid ||
+               req->rq_xid == lcd->lcd_last_close_xid;
+
+       if (found && trd != NULL) {
+               if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE) {
+                       trd->trd_reply.lrd_xid = lcd->lcd_last_close_xid;
+                       trd->trd_reply.lrd_transno =
+                                               lcd->lcd_last_close_transno;
+                       trd->trd_reply.lrd_result = lcd->lcd_last_close_result;
+               } else {
+                       trd->trd_reply.lrd_xid = lcd->lcd_last_xid;
+                       trd->trd_reply.lrd_transno = lcd->lcd_last_transno;
+                       trd->trd_reply.lrd_result = lcd->lcd_last_result;
+                       trd->trd_reply.lrd_data = lcd->lcd_last_data;
+                       trd->trd_pre_versions[0] = lcd->lcd_pre_versions[0];
+                       trd->trd_pre_versions[1] = lcd->lcd_pre_versions[1];
+                       trd->trd_pre_versions[2] = lcd->lcd_pre_versions[2];
+                       trd->trd_pre_versions[3] = lcd->lcd_pre_versions[3];
+               }
+       }
+       mutex_unlock(&ted->ted_lcd_lock);
+
+       return found;
+}
+EXPORT_SYMBOL(req_can_reconstruct);
+