Whamcloud - gitweb
a34aae865384b7fe1cdad19822956405d66c1a07
[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, 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                 case LST_INIT_FW:
61                         sfw_shutdown();
62                 case LST_INIT_RPC:
63                         srpc_shutdown();
64                 case LST_INIT_WI_TEST:
65                         for (i = 0;
66                              i < cfs_cpt_number(lnet_cpt_table()); i++) {
67                                 if (lst_sched_test[i] == NULL)
68                                         continue;
69                                 cfs_wi_sched_destroy(lst_sched_test[i]);
70                         }
71                         LIBCFS_FREE(lst_sched_test,
72                                     sizeof(lst_sched_test[0]) *
73                                     cfs_cpt_number(lnet_cpt_table()));
74                         lst_sched_test = NULL;
75
76                 case LST_INIT_WI_SERIAL:
77                         cfs_wi_sched_destroy(lst_sched_serial);
78                         lst_sched_serial = NULL;
79                 case LST_INIT_NONE:
80                         break;
81                 default:
82                         LBUG();
83         }
84         return;
85 }
86
87 void
88 lnet_selftest_structure_assertion(void)
89 {
90         CLASSERT(sizeof(srpc_msg_t) == 160);
91         CLASSERT(sizeof(srpc_test_reqst_t) == 70);
92         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_concur) == 72);
93         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_ndest) == 78);
94         CLASSERT(sizeof(srpc_stat_reply_t) == 136);
95         CLASSERT(sizeof(srpc_stat_reqst_t) == 28);
96 }
97
98 static int __init
99 lnet_selftest_init(void)
100 {
101         int     nscheds;
102         int     rc;
103         int     i;
104
105         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
106                                  1, &lst_sched_serial);
107         if (rc != 0) {
108                 CERROR("Failed to create serial WI scheduler for LST\n");
109                 return rc;
110         }
111         lst_init_step = LST_INIT_WI_SERIAL;
112
113         nscheds = cfs_cpt_number(lnet_cpt_table());
114         LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds);
115         if (lst_sched_test == NULL)
116                 goto error;
117
118         lst_init_step = LST_INIT_WI_TEST;
119         for (i = 0; i < nscheds; i++) {
120                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
121
122                 /* reserve at least one CPU for LND */
123                 nthrs = max(nthrs - 1, 1);
124                 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
125                                          nthrs, &lst_sched_test[i]);
126                 if (rc != 0) {
127                         CERROR("Failed to create CPU partition affinity WI "
128                                "scheduler %d for LST\n", i);
129                         goto error;
130                 }
131         }
132
133         rc = srpc_startup();
134         if (rc != 0) {
135                 CERROR("LST can't startup rpc\n");
136                 goto error;
137         }
138         lst_init_step = LST_INIT_RPC;
139
140         rc = sfw_startup();
141         if (rc != 0) {
142                 CERROR("LST can't startup framework\n");
143                 goto error;
144         }
145         lst_init_step = LST_INIT_FW;
146
147         rc = lstcon_console_init();
148         if (rc != 0) {
149                 CERROR("LST can't startup console\n");
150                 goto error;
151         }
152         lst_init_step = LST_INIT_CONSOLE;
153         return 0;
154 error:
155         lnet_selftest_exit();
156         return rc;
157 }
158
159 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
160 MODULE_DESCRIPTION("LNet Selftest");
161 MODULE_VERSION("2.8.0");
162 MODULE_LICENSE("GPL");
163
164 module_init(lnet_selftest_init);
165 module_exit(lnet_selftest_exit);