Whamcloud - gitweb
56df17976f40413dc2c847c023d7a066d82a05dd
[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 void
71 lnet_selftest_structure_assertion(void)
72 {
73         BUILD_BUG_ON(sizeof(struct srpc_msg) != 160);
74         BUILD_BUG_ON(sizeof(struct srpc_test_reqst) != 70);
75         BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_concur) !=
76                      72);
77         BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_ndest) !=
78                               78);
79         BUILD_BUG_ON(sizeof(struct srpc_stat_reply) != 136);
80         BUILD_BUG_ON(sizeof(struct srpc_stat_reqst) != 28);
81 }
82
83 static int __init
84 lnet_selftest_init(void)
85 {
86         int nscheds;
87         int rc = -ENOMEM;
88         int i;
89
90         /* This assertion checks that struct sizes do not drift
91          * inadvertently and induce crashes when different nodes
92          * running LNet Selftest have mismatched structures.
93          */
94         lnet_selftest_structure_assertion();
95
96         rc = libcfs_setup();
97         if (rc)
98                 return rc;
99
100         lst_serial_wq = alloc_ordered_workqueue("lst_s", 0);
101         if (!lst_serial_wq) {
102                 CERROR("Failed to create serial WI scheduler for LST\n");
103                 return rc;
104         }
105         lst_init_step = LST_INIT_WI_SERIAL;
106
107         nscheds = cfs_cpt_number(lnet_cpt_table());
108         CFS_ALLOC_PTR_ARRAY(lst_test_wq, nscheds);
109         if (!lst_test_wq) {
110                 rc = -ENOMEM;
111                 goto error;
112         }
113
114         lst_init_step = LST_INIT_WI_TEST;
115         for (i = 0; i < nscheds; i++) {
116                 int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
117
118                 /* reserve at least one CPU for LND */
119                 nthrs = max(nthrs - 1, 1);
120                 lst_test_wq[i] = cfs_cpt_bind_workqueue("lst_t",
121                                                         lnet_cpt_table(), 0,
122                                                         i, nthrs);
123                 if (IS_ERR(lst_test_wq[i])) {
124                         rc = PTR_ERR(lst_test_wq[i]);
125                         CERROR("Failed to create CPU partition affinity WI scheduler %d for LST: rc = %d\n",
126                                i, rc);
127                         lst_test_wq[i] = NULL;
128                         goto error;
129                 }
130         }
131
132         rc = srpc_startup();
133         if (rc != 0) {
134                 CERROR("LST can't startup rpc\n");
135                 goto error;
136         }
137         lst_init_step = LST_INIT_RPC;
138
139         rc = sfw_startup();
140         if (rc != 0) {
141                 CERROR("LST can't startup framework\n");
142                 goto error;
143         }
144         lst_init_step = LST_INIT_FW;
145
146         rc = lstcon_console_init();
147         if (rc != 0) {
148                 CERROR("LST can't startup console\n");
149                 goto error;
150         }
151         lst_init_step = LST_INIT_CONSOLE;
152         return 0;
153 error:
154         lnet_selftest_exit();
155         return rc;
156 }
157
158 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
159 MODULE_DESCRIPTION("LNet Selftest");
160 MODULE_VERSION("2.8.0");
161 MODULE_LICENSE("GPL");
162
163 module_init(lnet_selftest_init);
164 module_exit(lnet_selftest_exit);