Whamcloud - gitweb
LU-11814 obdcalss: ensure LCT_QUIESCENT take sync
[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  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #define DEBUG_SUBSYSTEM S_LNET
34
35 #include "selftest.h"
36 #include "console.h"
37
38 enum {
39         LST_INIT_NONE           = 0,
40         LST_INIT_WI_SERIAL,
41         LST_INIT_WI_TEST,
42         LST_INIT_RPC,
43         LST_INIT_FW,
44         LST_INIT_CONSOLE
45 };
46
47 static int lst_init_step = LST_INIT_NONE;
48
49 struct cfs_wi_sched *lst_sched_serial;
50 struct cfs_wi_sched **lst_sched_test;
51
52 static void
53 lnet_selftest_exit(void)
54 {
55         int i;
56
57         switch (lst_init_step) {
58         case LST_INIT_CONSOLE:
59                 lstcon_console_fini();
60                 /* fallthrough */
61         case LST_INIT_FW:
62                 sfw_shutdown();
63                 /* fallthrough */
64         case LST_INIT_RPC:
65                 srpc_shutdown();
66                 /* fallthrough */
67         case LST_INIT_WI_TEST:
68                 for (i = 0;
69                      i < cfs_cpt_number(lnet_cpt_table()); i++) {
70                         if (lst_sched_test[i] == NULL)
71                                 continue;
72                         cfs_wi_sched_destroy(lst_sched_test[i]);
73                 }
74                 CFS_FREE_PTR_ARRAY(lst_sched_test,
75                                    cfs_cpt_number(lnet_cpt_table()));
76                 lst_sched_test = NULL;
77                 /* fallthrough */
78         case LST_INIT_WI_SERIAL:
79                 cfs_wi_sched_destroy(lst_sched_serial);
80                 lst_sched_serial = NULL;
81                 /* fallthrough */
82         case LST_INIT_NONE:
83                 break;
84         default:
85                 LBUG();
86         }
87 }
88
89 void
90 lnet_selftest_structure_assertion(void)
91 {
92         BUILD_BUG_ON(sizeof(struct srpc_msg) != 160);
93         BUILD_BUG_ON(sizeof(struct srpc_test_reqst) != 70);
94         BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_concur) !=
95                      72);
96         BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_ndest) !=
97                               78);
98         BUILD_BUG_ON(sizeof(struct srpc_stat_reply) != 136);
99         BUILD_BUG_ON(sizeof(struct srpc_stat_reqst) != 28);
100 }
101
102 static int __init
103 lnet_selftest_init(void)
104 {
105         int nscheds;
106         int rc;
107         int i;
108
109         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
110                                  1, &lst_sched_serial);
111         if (rc != 0) {
112                 CERROR("Failed to create serial WI scheduler for LST\n");
113                 return rc;
114         }
115         lst_init_step = LST_INIT_WI_SERIAL;
116
117         nscheds = cfs_cpt_number(lnet_cpt_table());
118         CFS_ALLOC_PTR_ARRAY(lst_sched_test, nscheds);
119         if (lst_sched_test == NULL)
120                 goto error;
121
122         lst_init_step = LST_INIT_WI_TEST;
123         for (i = 0; i < nscheds; i++) {
124                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
125
126                 /* reserve at least one CPU for LND */
127                 nthrs = max(nthrs - 1, 1);
128                 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
129                                          nthrs, &lst_sched_test[i]);
130                 if (rc != 0) {
131                         CERROR("Failed to create CPU partition affinity WI scheduler %d for LST\n",
132                                i);
133                         goto error;
134                 }
135         }
136
137         rc = srpc_startup();
138         if (rc != 0) {
139                 CERROR("LST can't startup rpc\n");
140                 goto error;
141         }
142         lst_init_step = LST_INIT_RPC;
143
144         rc = sfw_startup();
145         if (rc != 0) {
146                 CERROR("LST can't startup framework\n");
147                 goto error;
148         }
149         lst_init_step = LST_INIT_FW;
150
151         rc = lstcon_console_init();
152         if (rc != 0) {
153                 CERROR("LST can't startup console\n");
154                 goto error;
155         }
156         lst_init_step = LST_INIT_CONSOLE;
157         return 0;
158 error:
159         lnet_selftest_exit();
160         return rc;
161 }
162
163 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
164 MODULE_DESCRIPTION("LNet Selftest");
165 MODULE_VERSION("2.8.0");
166 MODULE_LICENSE("GPL");
167
168 module_init(lnet_selftest_init);
169 module_exit(lnet_selftest_exit);