Whamcloud - gitweb
LU-9680 lnet: Empty route/peer table is not an error
[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, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #define DEBUG_SUBSYSTEM S_LNET
33
34 #include "selftest.h"
35 #include "console.h"
36
37 enum {
38         LST_INIT_NONE           = 0,
39         LST_INIT_WI_SERIAL,
40         LST_INIT_WI_TEST,
41         LST_INIT_RPC,
42         LST_INIT_FW,
43         LST_INIT_CONSOLE
44 };
45
46 static int lst_init_step = LST_INIT_NONE;
47
48 struct workqueue_struct *lst_serial_wq;
49 struct workqueue_struct **lst_test_wq;
50
51 static void
52 lnet_selftest_exit(void)
53 {
54         int i;
55
56         switch (lst_init_step) {
57         case LST_INIT_CONSOLE:
58                 lstcon_console_fini();
59                 fallthrough;
60         case LST_INIT_FW:
61                 sfw_shutdown();
62                 fallthrough;
63         case LST_INIT_RPC:
64                 srpc_shutdown();
65                 fallthrough;
66         case LST_INIT_WI_TEST:
67                 for (i = 0;
68                      i < cfs_cpt_number(lnet_cpt_table()); i++) {
69                         if (!lst_test_wq[i])
70                                 continue;
71                         destroy_workqueue(lst_test_wq[i]);
72                 }
73                 CFS_FREE_PTR_ARRAY(lst_test_wq,
74                                    cfs_cpt_number(lnet_cpt_table()));
75                 lst_test_wq = NULL;
76                 fallthrough;
77         case LST_INIT_WI_SERIAL:
78                 destroy_workqueue(lst_serial_wq);
79                 lst_serial_wq = NULL;
80                 fallthrough;
81         case LST_INIT_NONE:
82                 break;
83         default:
84                 LBUG();
85         }
86 }
87
88 static int __init
89 lnet_selftest_init(void)
90 {
91         int nscheds;
92         int rc = -ENOMEM;
93         int i;
94
95         rc = libcfs_setup();
96         if (rc)
97                 return rc;
98
99         lst_serial_wq = alloc_ordered_workqueue("lst_s", 0);
100         if (!lst_serial_wq) {
101                 CERROR("Failed to create serial WI scheduler for LST\n");
102                 return rc;
103         }
104         lst_init_step = LST_INIT_WI_SERIAL;
105
106         nscheds = cfs_cpt_number(lnet_cpt_table());
107         CFS_ALLOC_PTR_ARRAY(lst_test_wq, nscheds);
108         if (!lst_test_wq) {
109                 rc = -ENOMEM;
110                 goto error;
111         }
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                 lst_test_wq[i] = cfs_cpt_bind_workqueue("lst_t",
120                                                         lnet_cpt_table(), 0,
121                                                         i, nthrs);
122                 if (IS_ERR(lst_test_wq[i])) {
123                         rc = PTR_ERR(lst_test_wq[i]);
124                         CERROR("Failed to create CPU partition affinity WI scheduler %d for LST: rc = %d\n",
125                                i, rc);
126                         lst_test_wq[i] = NULL;
127                         goto error;
128                 }
129         }
130
131         rc = srpc_startup();
132         if (rc != 0) {
133                 CERROR("LST can't startup rpc\n");
134                 goto error;
135         }
136         lst_init_step = LST_INIT_RPC;
137
138         rc = sfw_startup();
139         if (rc != 0) {
140                 CERROR("LST can't startup framework\n");
141                 goto error;
142         }
143         lst_init_step = LST_INIT_FW;
144
145         rc = lstcon_console_init();
146         if (rc != 0) {
147                 CERROR("LST can't startup console\n");
148                 goto error;
149         }
150         lst_init_step = LST_INIT_CONSOLE;
151         return 0;
152 error:
153         lnet_selftest_exit();
154         return rc;
155 }
156
157 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
158 MODULE_DESCRIPTION("LNet Selftest");
159 MODULE_VERSION("2.8.0");
160 MODULE_LICENSE("GPL");
161
162 module_init(lnet_selftest_init);
163 module_exit(lnet_selftest_exit);