Whamcloud - gitweb
LU-6142 selftest: SPDX for lnet/selftest/
[fs/lustre-release.git] / lnet / selftest / module.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2012, 2015, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  */
13
14 #define DEBUG_SUBSYSTEM S_LNET
15
16 #include "selftest.h"
17 #include "console.h"
18
19 enum {
20         LST_INIT_NONE           = 0,
21         LST_INIT_WI_SERIAL,
22         LST_INIT_WI_TEST,
23         LST_INIT_RPC,
24         LST_INIT_FW,
25         LST_INIT_CONSOLE
26 };
27
28 static int lst_init_step = LST_INIT_NONE;
29
30 struct workqueue_struct *lst_serial_wq;
31 struct workqueue_struct **lst_test_wq;
32
33 static void
34 lnet_selftest_exit(void)
35 {
36         int i;
37
38         switch (lst_init_step) {
39         case LST_INIT_CONSOLE:
40                 lstcon_console_fini();
41                 fallthrough;
42         case LST_INIT_FW:
43                 sfw_shutdown();
44                 fallthrough;
45         case LST_INIT_RPC:
46                 srpc_shutdown();
47                 fallthrough;
48         case LST_INIT_WI_TEST:
49                 for (i = 0;
50                      i < cfs_cpt_number(lnet_cpt_table()); i++) {
51                         if (!lst_test_wq[i])
52                                 continue;
53                         destroy_workqueue(lst_test_wq[i]);
54                 }
55                 CFS_FREE_PTR_ARRAY(lst_test_wq,
56                                    cfs_cpt_number(lnet_cpt_table()));
57                 lst_test_wq = NULL;
58                 fallthrough;
59         case LST_INIT_WI_SERIAL:
60                 destroy_workqueue(lst_serial_wq);
61                 lst_serial_wq = NULL;
62                 fallthrough;
63         case LST_INIT_NONE:
64                 break;
65         default:
66                 LBUG();
67         }
68 }
69
70 static int __init
71 lnet_selftest_init(void)
72 {
73         int nscheds;
74         int rc = -ENOMEM;
75         int i;
76
77         rc = libcfs_setup();
78         if (rc)
79                 return rc;
80
81         lst_serial_wq = alloc_ordered_workqueue("lst_s", 0);
82         if (!lst_serial_wq) {
83                 CERROR("Failed to create serial WI scheduler for LST\n");
84                 return rc;
85         }
86         lst_init_step = LST_INIT_WI_SERIAL;
87
88         nscheds = cfs_cpt_number(lnet_cpt_table());
89         CFS_ALLOC_PTR_ARRAY(lst_test_wq, nscheds);
90         if (!lst_test_wq) {
91                 rc = -ENOMEM;
92                 goto error;
93         }
94
95         lst_init_step = LST_INIT_WI_TEST;
96         for (i = 0; i < nscheds; i++) {
97                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
98
99                 /* reserve at least one CPU for LND */
100                 nthrs = max(nthrs - 1, 1);
101                 lst_test_wq[i] = cfs_cpt_bind_workqueue("lst_t",
102                                                         lnet_cpt_table(), 0,
103                                                         i, nthrs);
104                 if (IS_ERR(lst_test_wq[i])) {
105                         rc = PTR_ERR(lst_test_wq[i]);
106                         CERROR("Failed to create CPU partition affinity WI scheduler %d for LST: rc = %d\n",
107                                i, rc);
108                         lst_test_wq[i] = NULL;
109                         goto error;
110                 }
111         }
112
113         rc = srpc_startup();
114         if (rc != 0) {
115                 CERROR("LST can't startup rpc\n");
116                 goto error;
117         }
118         lst_init_step = LST_INIT_RPC;
119
120         rc = sfw_startup();
121         if (rc != 0) {
122                 CERROR("LST can't startup framework\n");
123                 goto error;
124         }
125         lst_init_step = LST_INIT_FW;
126
127         rc = lstcon_console_init();
128         if (rc != 0) {
129                 CERROR("LST can't startup console\n");
130                 goto error;
131         }
132         lst_init_step = LST_INIT_CONSOLE;
133         return 0;
134 error:
135         lnet_selftest_exit();
136         return rc;
137 }
138
139 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
140 MODULE_DESCRIPTION("LNet Selftest");
141 MODULE_VERSION("2.8.0");
142 MODULE_LICENSE("GPL");
143
144 module_init(lnet_selftest_init);
145 module_exit(lnet_selftest_exit);