Whamcloud - gitweb
LU-6034 lnet: add default case for check summing
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_LNET
38
39 #include "selftest.h"
40 #include "console.h"
41
42 enum {
43         LST_INIT_NONE           = 0,
44         LST_INIT_WI_SERIAL,
45         LST_INIT_WI_TEST,
46         LST_INIT_RPC,
47         LST_INIT_FW,
48         LST_INIT_CONSOLE
49 };
50
51 static int lst_init_step = LST_INIT_NONE;
52
53 struct cfs_wi_sched *lst_sched_serial;
54 struct cfs_wi_sched **lst_sched_test;
55
56 static void
57 lnet_selftest_fini(void)
58 {
59         int     i;
60
61         switch (lst_init_step) {
62 #ifdef __KERNEL__
63                 case LST_INIT_CONSOLE:
64                         lstcon_console_fini();
65 #endif
66                 case LST_INIT_FW:
67                         sfw_shutdown();
68                 case LST_INIT_RPC:
69                         srpc_shutdown();
70                 case LST_INIT_WI_TEST:
71                         for (i = 0;
72                              i < cfs_cpt_number(lnet_cpt_table()); i++) {
73                                 if (lst_sched_test[i] == NULL)
74                                         continue;
75                                 cfs_wi_sched_destroy(lst_sched_test[i]);
76                         }
77                         LIBCFS_FREE(lst_sched_test,
78                                     sizeof(lst_sched_test[0]) *
79                                     cfs_cpt_number(lnet_cpt_table()));
80                         lst_sched_test = NULL;
81
82                 case LST_INIT_WI_SERIAL:
83                         cfs_wi_sched_destroy(lst_sched_serial);
84                         lst_sched_serial = NULL;
85                 case LST_INIT_NONE:
86                         break;
87                 default:
88                         LBUG();
89         }
90         return;
91 }
92
93 void
94 lnet_selftest_structure_assertion(void)
95 {
96         CLASSERT(sizeof(srpc_msg_t) == 160);
97         CLASSERT(sizeof(srpc_test_reqst_t) == 70);
98         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_concur) == 72);
99         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_ndest) == 78);
100         CLASSERT(sizeof(srpc_stat_reply_t) == 136);
101         CLASSERT(sizeof(srpc_stat_reqst_t) == 28);
102 }
103
104 static int
105 lnet_selftest_init(void)
106 {
107         int     nscheds;
108         int     rc;
109         int     i;
110
111         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
112                                  1, &lst_sched_serial);
113         if (rc != 0) {
114                 CERROR("Failed to create serial WI scheduler for LST\n");
115                 return rc;
116         }
117         lst_init_step = LST_INIT_WI_SERIAL;
118
119         nscheds = cfs_cpt_number(lnet_cpt_table());
120         LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds);
121         if (lst_sched_test == NULL)
122                 goto error;
123
124         lst_init_step = LST_INIT_WI_TEST;
125         for (i = 0; i < nscheds; i++) {
126                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
127
128                 /* reserve at least one CPU for LND */
129                 nthrs = max(nthrs - 1, 1);
130                 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
131                                          nthrs, &lst_sched_test[i]);
132                 if (rc != 0) {
133                         CERROR("Failed to create CPT affinity WI scheduler "
134                                "%d for LST\n", i);
135                         goto error;
136                 }
137         }
138
139         rc = srpc_startup();
140         if (rc != 0) {
141                 CERROR("LST can't startup rpc\n");
142                 goto error;
143         }
144         lst_init_step = LST_INIT_RPC;
145
146         rc = sfw_startup();
147         if (rc != 0) {
148                 CERROR("LST can't startup framework\n");
149                 goto error;
150         }
151         lst_init_step = LST_INIT_FW;
152
153 #ifdef __KERNEL__
154         rc = lstcon_console_init();
155         if (rc != 0) {
156                 CERROR("LST can't startup console\n");
157                 goto error;
158         }
159         lst_init_step = LST_INIT_CONSOLE;
160 #endif
161         return 0;
162 error:
163         lnet_selftest_fini();
164         return rc;
165 }
166
167 #ifdef __KERNEL__
168
169 MODULE_DESCRIPTION("LNet Selftest");
170 MODULE_LICENSE("GPL");
171
172 cfs_module(lnet, "0.9.0", lnet_selftest_init, lnet_selftest_fini);
173
174 #else
175
176 int
177 selftest_wait_events (void)
178 {
179         int evts = 0;
180
181         for (;;) {
182                 /* Consume all pending events */
183                 while (srpc_check_event(0))
184                         evts++;
185                 evts += stt_check_events();
186                 evts += swi_check_events();
187                 if (evts != 0) break;
188
189                 /* Nothing happened, block for events */
190                 evts += srpc_check_event(stt_poll_interval());
191                 /* We may have blocked, check for expired timers */
192                 evts += stt_check_events();
193                 if (evts == 0) /* timed out and still no event */
194                         break;
195         }
196
197         return evts;
198 }
199
200 #endif