OSDN Git Service

92520c2e08fd8492dcdf1a043a0168487b7c1aab
[android-x86/kernel.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
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 static void
59 lnet_selftest_fini(void)
60 {
61         int     i;
62
63         switch (lst_init_step) {
64                 case LST_INIT_CONSOLE:
65                         lstcon_console_fini();
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 static int
94 lnet_selftest_init(void)
95 {
96         int     nscheds;
97         int     rc;
98         int     i;
99
100         rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
101                                  1, &lst_sched_serial);
102         if (rc != 0) {
103                 CERROR("Failed to create serial WI scheduler for LST\n");
104                 return rc;
105         }
106         lst_init_step = LST_INIT_WI_SERIAL;
107
108         nscheds = cfs_cpt_number(lnet_cpt_table());
109         LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds);
110         if (lst_sched_test == NULL)
111                 goto error;
112
113         lst_init_step = LST_INIT_WI_TEST;
114         for (i = 0; i < nscheds; i++) {
115                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
116
117                 /* reserve at least one CPU for LND */
118                 nthrs = max(nthrs - 1, 1);
119                 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
120                                          nthrs, &lst_sched_test[i]);
121                 if (rc != 0) {
122                         CERROR("Failed to create CPT affinity WI scheduler "
123                                "%d for LST\n", i);
124                         goto error;
125                 }
126         }
127
128         rc = srpc_startup();
129         if (rc != 0) {
130                 CERROR("LST can't startup rpc\n");
131                 goto error;
132         }
133         lst_init_step = LST_INIT_RPC;
134
135         rc = sfw_startup();
136         if (rc != 0) {
137                 CERROR("LST can't startup framework\n");
138                 goto error;
139         }
140         lst_init_step = LST_INIT_FW;
141
142         rc = lstcon_console_init();
143         if (rc != 0) {
144                 CERROR("LST can't startup console\n");
145                 goto error;
146         }
147         lst_init_step = LST_INIT_CONSOLE;
148         return 0;
149 error:
150         lnet_selftest_fini();
151         return rc;
152 }
153
154
155 MODULE_DESCRIPTION("LNet Selftest");
156 MODULE_LICENSE("GPL");
157 MODULE_VERSION("0.9.0");
158
159 module_init(lnet_selftest_init);
160 module_exit(lnet_selftest_fini);