Whamcloud - gitweb
LU-4629 lov: fix sscanf format specification
[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
41 enum {
42         LST_INIT_NONE           = 0,
43         LST_INIT_WI_SERIAL,
44         LST_INIT_WI_TEST,
45         LST_INIT_RPC,
46         LST_INIT_FW,
47         LST_INIT_CONSOLE
48 };
49
50 extern int lstcon_console_init(void);
51 extern int lstcon_console_fini(void);
52
53 static int lst_init_step = LST_INIT_NONE;
54
55 struct cfs_wi_sched *lst_sched_serial;
56 struct cfs_wi_sched **lst_sched_test;
57
58 void
59 lnet_selftest_fini(void)
60 {
61         int     i;
62
63         switch (lst_init_step) {
64 #ifdef __KERNEL__
65                 case LST_INIT_CONSOLE:
66                         lstcon_console_fini();
67 #endif
68                 case LST_INIT_FW:
69                         sfw_shutdown();
70                 case LST_INIT_RPC:
71                         srpc_shutdown();
72                 case LST_INIT_WI_TEST:
73                         for (i = 0;
74                              i < cfs_cpt_number(lnet_cpt_table()); i++) {
75                                 if (lst_sched_test[i] == NULL)
76                                         continue;
77                                 cfs_wi_sched_destroy(lst_sched_test[i]);
78                         }
79                         LIBCFS_FREE(lst_sched_test,
80                                     sizeof(lst_sched_test[0]) *
81                                     cfs_cpt_number(lnet_cpt_table()));
82                         lst_sched_test = NULL;
83
84                 case LST_INIT_WI_SERIAL:
85                         cfs_wi_sched_destroy(lst_sched_serial);
86                         lst_sched_serial = NULL;
87                 case LST_INIT_NONE:
88                         break;
89                 default:
90                         LBUG();
91         }
92         return;
93 }
94
95 void
96 lnet_selftest_structure_assertion(void)
97 {
98         CLASSERT(sizeof(srpc_msg_t) == 160);
99         CLASSERT(sizeof(srpc_test_reqst_t) == 70);
100         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_concur) == 72);
101         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_ndest) == 78);
102         CLASSERT(sizeof(srpc_stat_reply_t) == 136);
103         CLASSERT(sizeof(srpc_stat_reqst_t) == 28);
104 }
105
106 int
107 lnet_selftest_init(void)
108 {
109         int     nscheds;
110         int     rc;
111         int     i;
112
113         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
114                                  1, &lst_sched_serial);
115         if (rc != 0) {
116                 CERROR("Failed to create serial WI scheduler for LST\n");
117                 return rc;
118         }
119         lst_init_step = LST_INIT_WI_SERIAL;
120
121         nscheds = cfs_cpt_number(lnet_cpt_table());
122         LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds);
123         if (lst_sched_test == NULL)
124                 goto error;
125
126         lst_init_step = LST_INIT_WI_TEST;
127         for (i = 0; i < nscheds; i++) {
128                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
129
130                 /* reserve at least one CPU for LND */
131                 nthrs = max(nthrs - 1, 1);
132                 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
133                                          nthrs, &lst_sched_test[i]);
134                 if (rc != 0) {
135                         CERROR("Failed to create CPT affinity WI scheduler "
136                                "%d for LST\n", i);
137                         goto error;
138                 }
139         }
140
141         rc = srpc_startup();
142         if (rc != 0) {
143                 CERROR("LST can't startup rpc\n");
144                 goto error;
145         }
146         lst_init_step = LST_INIT_RPC;
147
148         rc = sfw_startup();
149         if (rc != 0) {
150                 CERROR("LST can't startup framework\n");
151                 goto error;
152         }
153         lst_init_step = LST_INIT_FW;
154
155 #ifdef __KERNEL__
156         rc = lstcon_console_init();
157         if (rc != 0) {
158                 CERROR("LST can't startup console\n");
159                 goto error;
160         }
161         lst_init_step = LST_INIT_CONSOLE;
162 #endif
163         return 0;
164 error:
165         lnet_selftest_fini();
166         return rc;
167 }
168
169 #ifdef __KERNEL__
170
171 MODULE_DESCRIPTION("LNet Selftest");
172 MODULE_LICENSE("GPL");
173
174 cfs_module(lnet, "0.9.0", lnet_selftest_init, lnet_selftest_fini);
175
176 #else
177
178 int
179 selftest_wait_events (void)
180 {
181         int evts = 0;
182
183         for (;;) {
184                 /* Consume all pending events */
185                 while (srpc_check_event(0))
186                         evts++;
187                 evts += stt_check_events();
188                 evts += swi_check_events();
189                 if (evts != 0) break;
190
191                 /* Nothing happened, block for events */
192                 evts += srpc_check_event(stt_poll_interval());
193                 /* We may have blocked, check for expired timers */
194                 evts += stt_check_events();
195                 if (evts == 0) /* timed out and still no event */
196                         break;
197         }
198
199         return evts;
200 }
201
202 #endif