Whamcloud - gitweb
LU-14945 lnet: don't use hops to determine the route state
[fs/lustre-release.git] / lnet / selftest / module.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #define DEBUG_SUBSYSTEM S_LNET
33
34 #include "selftest.h"
35 #include "console.h"
36
37 enum {
38         LST_INIT_NONE           = 0,
39         LST_INIT_WI_SERIAL,
40         LST_INIT_WI_TEST,
41         LST_INIT_RPC,
42         LST_INIT_FW,
43         LST_INIT_CONSOLE
44 };
45
46 static int lst_init_step = LST_INIT_NONE;
47
48 struct cfs_wi_sched *lst_sched_serial;
49 struct cfs_wi_sched **lst_sched_test;
50
51 static void
52 lnet_selftest_exit(void)
53 {
54         int i;
55
56         switch (lst_init_step) {
57         case LST_INIT_CONSOLE:
58                 lstcon_console_fini();
59                 /* fallthrough */
60         case LST_INIT_FW:
61                 sfw_shutdown();
62                 /* fallthrough */
63         case LST_INIT_RPC:
64                 srpc_shutdown();
65                 /* fallthrough */
66         case LST_INIT_WI_TEST:
67                 for (i = 0;
68                      i < cfs_cpt_number(lnet_cpt_table()); i++) {
69                         if (lst_sched_test[i] == NULL)
70                                 continue;
71                         cfs_wi_sched_destroy(lst_sched_test[i]);
72                 }
73                 CFS_FREE_PTR_ARRAY(lst_sched_test,
74                                    cfs_cpt_number(lnet_cpt_table()));
75                 lst_sched_test = NULL;
76                 /* fallthrough */
77         case LST_INIT_WI_SERIAL:
78                 cfs_wi_sched_destroy(lst_sched_serial);
79                 lst_sched_serial = NULL;
80                 /* fallthrough */
81         case LST_INIT_NONE:
82                 break;
83         default:
84                 LBUG();
85         }
86 }
87
88 void
89 lnet_selftest_structure_assertion(void)
90 {
91         BUILD_BUG_ON(sizeof(struct srpc_msg) != 160);
92         BUILD_BUG_ON(sizeof(struct srpc_test_reqst) != 70);
93         BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_concur) !=
94                      72);
95         BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_ndest) !=
96                               78);
97         BUILD_BUG_ON(sizeof(struct srpc_stat_reply) != 136);
98         BUILD_BUG_ON(sizeof(struct srpc_stat_reqst) != 28);
99 }
100
101 static int __init
102 lnet_selftest_init(void)
103 {
104         int nscheds;
105         int rc;
106         int i;
107
108         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
109                                  1, &lst_sched_serial);
110         if (rc != 0) {
111                 CERROR("Failed to create serial WI scheduler for LST\n");
112                 return rc;
113         }
114         lst_init_step = LST_INIT_WI_SERIAL;
115
116         nscheds = cfs_cpt_number(lnet_cpt_table());
117         CFS_ALLOC_PTR_ARRAY(lst_sched_test, nscheds);
118         if (lst_sched_test == NULL)
119                 goto error;
120
121         lst_init_step = LST_INIT_WI_TEST;
122         for (i = 0; i < nscheds; i++) {
123                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
124
125                 /* reserve at least one CPU for LND */
126                 nthrs = max(nthrs - 1, 1);
127                 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
128                                          nthrs, &lst_sched_test[i]);
129                 if (rc != 0) {
130                         CERROR("Failed to create CPU partition affinity WI scheduler %d for LST\n",
131                                i);
132                         goto error;
133                 }
134         }
135
136         rc = srpc_startup();
137         if (rc != 0) {
138                 CERROR("LST can't startup rpc\n");
139                 goto error;
140         }
141         lst_init_step = LST_INIT_RPC;
142
143         rc = sfw_startup();
144         if (rc != 0) {
145                 CERROR("LST can't startup framework\n");
146                 goto error;
147         }
148         lst_init_step = LST_INIT_FW;
149
150         rc = lstcon_console_init();
151         if (rc != 0) {
152                 CERROR("LST can't startup console\n");
153                 goto error;
154         }
155         lst_init_step = LST_INIT_CONSOLE;
156         return 0;
157 error:
158         lnet_selftest_exit();
159         return rc;
160 }
161
162 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
163 MODULE_DESCRIPTION("LNet Selftest");
164 MODULE_VERSION("2.8.0");
165 MODULE_LICENSE("GPL");
166
167 module_init(lnet_selftest_init);
168 module_exit(lnet_selftest_exit);