]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/lustre/lnet/selftest/module.c
staging: lustre: make some lnet functions static
[karo-tx-linux.git] / drivers / staging / lustre / 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         case LST_INIT_CONSOLE:
63                 lstcon_console_fini();
64         case LST_INIT_FW:
65                 sfw_shutdown();
66         case LST_INIT_RPC:
67                 srpc_shutdown();
68         case LST_INIT_WI_TEST:
69                 for (i = 0;
70                      i < cfs_cpt_number(lnet_cpt_table()); i++) {
71                         if (!lst_sched_test[i])
72                                 continue;
73                         cfs_wi_sched_destroy(lst_sched_test[i]);
74                 }
75                 LIBCFS_FREE(lst_sched_test,
76                             sizeof(lst_sched_test[0]) *
77                             cfs_cpt_number(lnet_cpt_table()));
78                 lst_sched_test = NULL;
79
80         case LST_INIT_WI_SERIAL:
81                 cfs_wi_sched_destroy(lst_sched_serial);
82                 lst_sched_serial = NULL;
83         case LST_INIT_NONE:
84                 break;
85         default:
86                 LBUG();
87         }
88 }
89
90 static int
91 lnet_selftest_init(void)
92 {
93         int nscheds;
94         int rc;
95         int i;
96
97         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
98                                  1, &lst_sched_serial);
99         if (rc) {
100                 CERROR("Failed to create serial WI scheduler for LST\n");
101                 return rc;
102         }
103         lst_init_step = LST_INIT_WI_SERIAL;
104
105         nscheds = cfs_cpt_number(lnet_cpt_table());
106         LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds);
107         if (!lst_sched_test)
108                 goto error;
109
110         lst_init_step = LST_INIT_WI_TEST;
111         for (i = 0; i < nscheds; i++) {
112                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
113
114                 /* reserve at least one CPU for LND */
115                 nthrs = max(nthrs - 1, 1);
116                 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
117                                          nthrs, &lst_sched_test[i]);
118                 if (rc) {
119                         CERROR("Failed to create CPT affinity WI scheduler %d for LST\n",
120                                i);
121                         goto error;
122                 }
123         }
124
125         rc = srpc_startup();
126         if (rc) {
127                 CERROR("LST can't startup rpc\n");
128                 goto error;
129         }
130         lst_init_step = LST_INIT_RPC;
131
132         rc = sfw_startup();
133         if (rc) {
134                 CERROR("LST can't startup framework\n");
135                 goto error;
136         }
137         lst_init_step = LST_INIT_FW;
138
139         rc = lstcon_console_init();
140         if (rc) {
141                 CERROR("LST can't startup console\n");
142                 goto error;
143         }
144         lst_init_step = LST_INIT_CONSOLE;
145         return 0;
146 error:
147         lnet_selftest_fini();
148         return rc;
149 }
150
151 MODULE_DESCRIPTION("LNet Selftest");
152 MODULE_LICENSE("GPL");
153 MODULE_VERSION("0.9.0");
154
155 module_init(lnet_selftest_init);
156 module_exit(lnet_selftest_fini);