Whamcloud - gitweb
LU-3467 mdt: call MDT handlers via unified request handler
[fs/lustre-release.git] / lustre / mgs / mgs_handler.c
index 045e94c..1b5f2e0 100644 (file)
@@ -132,14 +132,20 @@ out_cfg:
        return rc;
 }
 
-static int mgs_completion_ast_config(struct ldlm_lock *lock, __u64 flags,
-                                    void *cbdata)
+enum ast_type {
+               AST_CONFIG = 1,
+               AST_PARAMS = 2,
+               AST_IR = 3
+};
+
+static int mgs_completion_ast_generic(struct ldlm_lock *lock, __u64 flags,
+                                    void *cbdata, enum ast_type type)
 {
        ENTRY;
 
        if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
                       LDLM_FL_BLOCK_CONV))) {
-                struct fs_db *fsdb;
+               struct fs_db *fsdb;
 
                /* l_ast_data is used as a marker to avoid cancel ldlm lock
                 * twice. See LU-2317. */
@@ -151,8 +157,22 @@ static int mgs_completion_ast_config(struct ldlm_lock *lock, __u64 flags,
                if (fsdb != NULL) {
                        struct lustre_handle lockh;
 
-                       /* clear the bit before lock put */
-                       clear_bit(FSDB_REVOKING_LOCK, &fsdb->fsdb_flags);
+                       switch(type) {
+                               case AST_CONFIG:
+                                       /* clear the bit before lock put */
+                                       clear_bit(FSDB_REVOKING_LOCK,
+                                                 &fsdb->fsdb_flags);
+                                       break;
+                               case AST_PARAMS:
+                                       clear_bit(FSDB_REVOKING_PARAMS,
+                                                 &fsdb->fsdb_flags);
+                                       break;
+                               case AST_IR:
+                                       mgs_ir_notify_complete(fsdb);
+                                       break;
+                               default:
+                                       LBUG();
+                       }
 
                        ldlm_lock2handle(lock, &lockh);
                        ldlm_lock_decref_and_cancel(&lockh, LCK_EX);
@@ -162,80 +182,77 @@ static int mgs_completion_ast_config(struct ldlm_lock *lock, __u64 flags,
        RETURN(ldlm_completion_ast(lock, flags, cbdata));
 }
 
-static int mgs_completion_ast_ir(struct ldlm_lock *lock, __u64 flags,
-                                 void *cbdata)
+static int mgs_completion_ast_config(struct ldlm_lock *lock, __u64 flags,
+                                    void *cbdata)
 {
-        ENTRY;
-
-        if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
-                       LDLM_FL_BLOCK_CONV))) {
-                struct fs_db *fsdb;
-
-                /* l_ast_data is used as a marker to avoid cancel ldlm lock
-                 * twice. See LU-1259. */
-                lock_res_and_lock(lock);
-                fsdb = (struct fs_db *)lock->l_ast_data;
-                lock->l_ast_data = NULL;
-                unlock_res_and_lock(lock);
-
-                if (fsdb != NULL) {
-                        struct lustre_handle lockh;
-
-                        mgs_ir_notify_complete(fsdb);
+       return mgs_completion_ast_generic(lock, flags, cbdata, AST_CONFIG);
+}
 
-                        ldlm_lock2handle(lock, &lockh);
-                        ldlm_lock_decref_and_cancel(&lockh, LCK_EX);
-                }
-        }
+static int mgs_completion_ast_params(struct ldlm_lock *lock, __u64 flags,
+                                    void *cbdata)
+{
+       return mgs_completion_ast_generic(lock, flags, cbdata, AST_PARAMS);
+}
 
-        RETURN(ldlm_completion_ast(lock, flags, cbdata));
+static int mgs_completion_ast_ir(struct ldlm_lock *lock, __u64 flags,
+                                void *cbdata)
+{
+       return mgs_completion_ast_generic(lock, flags, cbdata, AST_IR);
 }
 
 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type)
 {
-        ldlm_completion_callback cp = NULL;
-        struct lustre_handle     lockh = { 0 };
-        struct ldlm_res_id       res_id;
+       ldlm_completion_callback cp = NULL;
+       struct lustre_handle     lockh = { 0 };
+       struct ldlm_res_id       res_id;
        __u64 flags = LDLM_FL_ATOMIC_CB;
-        int rc;
-        ENTRY;
-
-        LASSERT(fsdb->fsdb_name[0] != '\0');
-        rc = mgc_fsname2resid(fsdb->fsdb_name, &res_id, type);
-        LASSERT(rc == 0);
+       int rc;
+       ENTRY;
 
-        switch (type) {
-        case CONFIG_T_CONFIG:
-                cp = mgs_completion_ast_config;
+       LASSERT(fsdb->fsdb_name[0] != '\0');
+       rc = mgc_fsname2resid(fsdb->fsdb_name, &res_id, type);
+       LASSERT(rc == 0);
+       switch (type) {
+       case CONFIG_T_CONFIG:
+               cp = mgs_completion_ast_config;
                if (test_and_set_bit(FSDB_REVOKING_LOCK, &fsdb->fsdb_flags))
-                        rc = -EALREADY;
-                break;
-        case CONFIG_T_RECOVER:
-                cp = mgs_completion_ast_ir;
-        default:
-                break;
-        }
+                       rc = -EALREADY;
+               break;
+       case CONFIG_T_PARAMS:
+               cp = mgs_completion_ast_params;
+               if (test_and_set_bit(FSDB_REVOKING_PARAMS, &fsdb->fsdb_flags))
+                       rc = -EALREADY;
+               break;
+       case CONFIG_T_RECOVER:
+               cp = mgs_completion_ast_ir;
+       default:
+               break;
+       }
 
-        if (!rc) {
-                LASSERT(cp != NULL);
+       if (!rc) {
+               LASSERT(cp != NULL);
                rc = ldlm_cli_enqueue_local(mgs->mgs_obd->obd_namespace,
                                            &res_id, LDLM_PLAIN, NULL, LCK_EX,
                                            &flags, ldlm_blocking_ast, cp,
                                            NULL, fsdb, 0, LVB_T_NONE, NULL,
                                            &lockh);
-                if (rc != ELDLM_OK) {
-                        CERROR("can't take cfg lock for "LPX64"/"LPX64"(%d)\n",
-                               le64_to_cpu(res_id.name[0]),
-                               le64_to_cpu(res_id.name[1]), rc);
+               if (rc != ELDLM_OK) {
+                       CERROR("can't take cfg lock for "LPX64"/"LPX64"(%d)\n",
+                              le64_to_cpu(res_id.name[0]),
+                              le64_to_cpu(res_id.name[1]), rc);
 
-                        if (type == CONFIG_T_CONFIG)
+                       if (type == CONFIG_T_CONFIG)
                                clear_bit(FSDB_REVOKING_LOCK,
-                                              &fsdb->fsdb_flags);
-                }
-                /* lock has been cancelled in completion_ast. */
-        }
+                                         &fsdb->fsdb_flags);
 
-        RETURN_EXIT;
+                       if (type == CONFIG_T_PARAMS)
+                               clear_bit(FSDB_REVOKING_PARAMS,
+                                         &fsdb->fsdb_flags);
+               }
+               /* lock has been cancelled in completion_ast. */
+       }
+
+       RETURN_EXIT;
 }
 
 /* rc=0 means ok
@@ -550,15 +567,6 @@ static int mgs_llog_open(struct tgt_session_info *tsi)
        RETURN(rc);
 }
 
-/*
- * sec context handlers
- */
-/* XXX: Implement based on mdt_sec_ctx_handle()? */
-static int mgs_sec_ctx_handle(struct tgt_session_info *tsi)
-{
-       return 0;
-}
-
 static inline int mgs_init_export(struct obd_export *exp)
 {
        struct mgs_export_data *data = &exp->u.eu_mgs_data;
@@ -872,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[] = {
@@ -883,12 +904,6 @@ TGT_LLOG_HDL_VAR(0,        LLOG_ORIGIN_HANDLE_CLOSE,       tgt_llog_close),
 TGT_LLOG_HDL    (0,    LLOG_ORIGIN_HANDLE_PREV_BLOCK,  tgt_llog_prev_block),
 };
 
-static struct tgt_handler mgs_sec_ctx_handlers[] = {
-TGT_SEC_HDL_VAR(0,     SEC_CTX_INIT,           mgs_sec_ctx_handle),
-TGT_SEC_HDL_VAR(0,     SEC_CTX_INIT_CONT,      mgs_sec_ctx_handle),
-TGT_SEC_HDL_VAR(0,     SEC_CTX_FINI,           mgs_sec_ctx_handle),
-};
-
 static struct tgt_opc_slice mgs_common_slice[] = {
        {
                .tos_opc_start = MGS_FIRST_OPC,
@@ -913,7 +928,7 @@ static struct tgt_opc_slice mgs_common_slice[] = {
        {
                .tos_opc_start = SEC_FIRST_OPC,
                .tos_opc_end   = SEC_LAST_OPC,
-               .tos_hs        = mgs_sec_ctx_handlers
+               .tos_hs        = tgt_sec_ctx_handlers
        },
        {
                .tos_hs        = NULL