4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/ost/ost_handler.c
33 * Author: Peter J. Braam <braam@clusterfs.com>
34 * Author: Phil Schwan <phil@clusterfs.com>
37 #define DEBUG_SUBSYSTEM S_OST
39 #include <linux/module.h>
40 #include <lustre_dlm.h>
41 #include <lprocfs_status.h>
42 #include <obd_class.h>
43 #include "ost_internal.h"
45 int oss_max_threads = 512;
46 module_param(oss_max_threads, int, 0444);
47 MODULE_PARM_DESC(oss_max_threads, "maximum number of OSS service threads");
49 static int oss_num_threads;
50 module_param(oss_num_threads, int, 0444);
51 MODULE_PARM_DESC(oss_num_threads, "number of OSS service threads to start");
53 static unsigned int oss_cpu_bind = 1;
54 module_param(oss_cpu_bind, uint, 0444);
55 MODULE_PARM_DESC(oss_cpu_bind,
56 "bind OSS service threads to particular CPU partitions");
58 static int oss_num_create_threads;
59 module_param(oss_num_create_threads, int, 0444);
60 MODULE_PARM_DESC(oss_num_create_threads,
61 "number of OSS create threads to start");
63 static unsigned int oss_create_cpu_bind = 1;
64 module_param(oss_create_cpu_bind, uint, 0444);
65 MODULE_PARM_DESC(oss_create_cpu_bind,
66 "bind OSS create threads to particular CPU partitions");
68 static char *oss_cpts;
69 module_param(oss_cpts, charp, 0444);
70 MODULE_PARM_DESC(oss_cpts, "CPU partitions OSS threads should run on");
72 static char *oss_io_cpts;
73 module_param(oss_io_cpts, charp, 0444);
74 MODULE_PARM_DESC(oss_io_cpts, "CPU partitions OSS IO threads should run on");
76 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
78 static struct cfs_cpt_table *ost_io_cptable;
80 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
81 static int ost_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
83 static struct ptlrpc_service_conf svc_conf;
84 struct ost_obd *ost = obd2ost(obd);
90 rc = lprocfs_obd_setup(obd, true);
94 mutex_init(&ost->ost_health_mutex);
96 svc_conf = (typeof(svc_conf)) {
97 .psc_name = LUSTRE_OSS_NAME,
98 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
100 .bc_nbufs = OST_NBUFS,
101 .bc_buf_size = OST_BUFSIZE,
102 .bc_req_max_size = OST_MAXREQSIZE,
103 .bc_rep_max_size = OST_MAXREPSIZE,
104 .bc_req_portal = OST_REQUEST_PORTAL,
105 .bc_rep_portal = OSC_REPLY_PORTAL,
108 .tc_thr_name = "ll_ost",
109 .tc_thr_factor = OSS_THR_FACTOR,
110 .tc_nthrs_init = OSS_NTHRS_INIT,
111 .tc_nthrs_base = OSS_NTHRS_BASE,
112 .tc_nthrs_max = oss_max_threads,
113 .tc_nthrs_user = oss_num_threads,
114 .tc_cpu_bind = oss_cpu_bind,
115 .tc_ctx_tags = LCT_DT_THREAD,
118 .cc_pattern = oss_cpts,
122 .so_req_handler = tgt_request_handle,
123 .so_req_printer = target_print_req,
124 .so_hpreq_handler = ptlrpc_hpreq_handler,
127 ost->ost_service = ptlrpc_register_service(&svc_conf,
129 obd->obd_debugfs_entry);
130 if (IS_ERR(ost->ost_service)) {
131 rc = PTR_ERR(ost->ost_service);
132 CERROR("failed to start service: %d\n", rc);
133 GOTO(out_lprocfs, rc);
136 memset(&svc_conf, 0, sizeof(svc_conf));
137 svc_conf = (typeof(svc_conf)) {
138 .psc_name = "ost_create",
139 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
141 .bc_nbufs = OST_NBUFS,
142 .bc_buf_size = OST_BUFSIZE,
143 .bc_req_max_size = OST_MAXREQSIZE,
144 .bc_rep_max_size = OST_MAXREPSIZE,
145 .bc_req_portal = OST_CREATE_PORTAL,
146 .bc_rep_portal = OSC_REPLY_PORTAL,
149 .tc_thr_name = "ll_ost_create",
150 .tc_thr_factor = OSS_CR_THR_FACTOR,
151 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
152 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
153 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
154 .tc_nthrs_user = oss_num_create_threads,
155 .tc_cpu_bind = oss_create_cpu_bind,
156 .tc_ctx_tags = LCT_DT_THREAD,
159 .cc_pattern = oss_cpts,
163 .so_req_handler = tgt_request_handle,
164 .so_req_printer = target_print_req,
167 ost->ost_create_service = ptlrpc_register_service(&svc_conf,
169 obd->obd_debugfs_entry
171 if (IS_ERR(ost->ost_create_service)) {
172 rc = PTR_ERR(ost->ost_create_service);
173 CERROR("failed to start OST create service: %d\n", rc);
174 GOTO(out_service, rc);
177 mask = cfs_cpt_nodemask(cfs_cpt_tab, CFS_CPT_ANY);
178 /* event CPT feature is disabled in libcfs level by set partition
179 * number to 1, we still want to set node affinity for io service
181 if (cfs_cpt_number(cfs_cpt_tab) == 1 && nodes_weight(*mask) > 1) {
185 ost_io_cptable = cfs_cpt_table_alloc(nodes_weight(*mask));
186 for_each_node_mask(i, *mask) {
187 if (!ost_io_cptable) {
188 CWARN("OSS failed to create CPT table\n");
192 rc = cfs_cpt_set_node(ost_io_cptable, cpt++, i);
194 CWARN("OSS Failed to set node %d for IO CPT table\n",
196 cfs_cpt_table_free(ost_io_cptable);
197 ost_io_cptable = NULL;
203 memset(&svc_conf, 0, sizeof(svc_conf));
204 svc_conf = (typeof(svc_conf)) {
205 .psc_name = "ost_io",
206 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
208 .bc_nbufs = OST_NBUFS,
209 .bc_buf_size = OST_IO_BUFSIZE,
210 .bc_req_max_size = OST_IO_MAXREQSIZE,
211 .bc_rep_max_size = OST_IO_MAXREPSIZE,
212 .bc_req_portal = OST_IO_PORTAL,
213 .bc_rep_portal = OSC_REPLY_PORTAL,
216 .tc_thr_name = "ll_ost_io",
217 .tc_thr_factor = OSS_THR_FACTOR,
218 .tc_nthrs_init = OSS_NTHRS_INIT,
219 .tc_nthrs_base = OSS_NTHRS_BASE,
220 .tc_nthrs_max = oss_max_threads,
221 .tc_nthrs_user = oss_num_threads,
222 .tc_cpu_bind = oss_cpu_bind,
223 .tc_ctx_tags = LCT_DT_THREAD,
226 .cc_cptable = ost_io_cptable,
227 .cc_pattern = ost_io_cptable == NULL ?
232 .so_thr_init = tgt_io_thread_init,
233 .so_thr_done = tgt_io_thread_done,
234 .so_req_handler = tgt_request_handle,
235 .so_hpreq_handler = tgt_hpreq_handler,
236 .so_req_printer = target_print_req,
239 ost->ost_io_service = ptlrpc_register_service(&svc_conf,
241 obd->obd_debugfs_entry);
242 if (IS_ERR(ost->ost_io_service)) {
243 rc = PTR_ERR(ost->ost_io_service);
244 CERROR("failed to start OST I/O service: %d\n", rc);
245 ost->ost_io_service = NULL;
246 GOTO(out_create, rc);
249 memset(&svc_conf, 0, sizeof(svc_conf));
250 svc_conf = (typeof(svc_conf)) {
251 .psc_name = "ost_seq",
252 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
254 .bc_nbufs = OST_NBUFS,
255 .bc_buf_size = OST_BUFSIZE,
256 .bc_req_max_size = OST_MAXREQSIZE,
257 .bc_rep_max_size = OST_MAXREPSIZE,
258 .bc_req_portal = SEQ_DATA_PORTAL,
259 .bc_rep_portal = OSC_REPLY_PORTAL,
262 .tc_thr_name = "ll_ost_seq",
263 .tc_thr_factor = OSS_CR_THR_FACTOR,
264 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
265 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
266 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
267 .tc_nthrs_user = oss_num_create_threads,
268 .tc_cpu_bind = oss_create_cpu_bind,
269 .tc_ctx_tags = LCT_DT_THREAD,
273 .cc_pattern = oss_cpts,
277 .so_req_handler = tgt_request_handle,
278 .so_req_printer = target_print_req,
279 .so_hpreq_handler = NULL,
282 ost->ost_seq_service = ptlrpc_register_service(&svc_conf,
284 obd->obd_debugfs_entry);
285 if (IS_ERR(ost->ost_seq_service)) {
286 rc = PTR_ERR(ost->ost_seq_service);
287 CERROR("failed to start OST seq service: %d\n", rc);
288 ost->ost_seq_service = NULL;
292 /* Object update service */
293 memset(&svc_conf, 0, sizeof(svc_conf));
294 svc_conf = (typeof(svc_conf)) {
295 .psc_name = "ost_out",
296 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
298 .bc_nbufs = OST_NBUFS,
299 .bc_buf_size = OUT_BUFSIZE,
300 .bc_req_max_size = OUT_MAXREQSIZE,
301 .bc_rep_max_size = OUT_MAXREPSIZE,
302 .bc_req_portal = OUT_PORTAL,
303 .bc_rep_portal = OSC_REPLY_PORTAL,
306 * We'd like to have a mechanism to set this on a per-device
310 .tc_thr_name = "ll_ost_out",
311 .tc_thr_factor = OSS_CR_THR_FACTOR,
312 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
313 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
314 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
315 .tc_nthrs_user = oss_num_create_threads,
316 .tc_cpu_bind = oss_create_cpu_bind,
317 .tc_ctx_tags = LCT_MD_THREAD |
321 .cc_pattern = oss_cpts,
325 .so_req_handler = tgt_request_handle,
326 .so_req_printer = target_print_req,
327 .so_hpreq_handler = NULL,
330 ost->ost_out_service = ptlrpc_register_service(&svc_conf,
332 obd->obd_debugfs_entry);
333 if (IS_ERR(ost->ost_out_service)) {
334 rc = PTR_ERR(ost->ost_out_service);
335 CERROR("failed to start out service: %d\n", rc);
336 ost->ost_out_service = NULL;
340 ping_evictor_start();
345 ptlrpc_unregister_service(ost->ost_seq_service);
346 ost->ost_seq_service = NULL;
348 ptlrpc_unregister_service(ost->ost_io_service);
349 ost->ost_io_service = NULL;
351 ptlrpc_unregister_service(ost->ost_create_service);
352 ost->ost_create_service = NULL;
354 ptlrpc_unregister_service(ost->ost_service);
355 ost->ost_service = NULL;
357 lprocfs_obd_cleanup(obd);
361 static int ost_cleanup(struct obd_device *obd)
363 struct ost_obd *ost = obd2ost(obd);
370 /* there is no recovery for OST OBD, all recovery is controlled by
373 LASSERT(obd->obd_recovering == 0);
374 mutex_lock(&ost->ost_health_mutex);
375 ptlrpc_unregister_service(ost->ost_service);
376 ptlrpc_unregister_service(ost->ost_create_service);
377 ptlrpc_unregister_service(ost->ost_io_service);
378 ptlrpc_unregister_service(ost->ost_seq_service);
379 ptlrpc_unregister_service(ost->ost_out_service);
381 ost->ost_service = NULL;
382 ost->ost_create_service = NULL;
383 ost->ost_io_service = NULL;
384 ost->ost_seq_service = NULL;
385 ost->ost_out_service = NULL;
387 mutex_unlock(&ost->ost_health_mutex);
389 lprocfs_obd_cleanup(obd);
391 if (ost_io_cptable) {
392 cfs_cpt_table_free(ost_io_cptable);
393 ost_io_cptable = NULL;
399 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
401 struct ost_obd *ost = obd2ost(obd);
404 mutex_lock(&ost->ost_health_mutex);
405 rc |= ptlrpc_service_health_check(ost->ost_service);
406 rc |= ptlrpc_service_health_check(ost->ost_create_service);
407 rc |= ptlrpc_service_health_check(ost->ost_io_service);
408 rc |= ptlrpc_service_health_check(ost->ost_seq_service);
409 mutex_unlock(&ost->ost_health_mutex);
411 return rc != 0 ? 1 : 0;
414 /* use obd ops to offer management infrastructure */
415 static const struct obd_ops ost_obd_ops = {
416 .o_owner = THIS_MODULE,
417 .o_setup = ost_setup,
418 .o_cleanup = ost_cleanup,
419 .o_health_check = ost_health_check,
422 static int __init ost_init(void)
428 rc = class_register_type(&ost_obd_ops, NULL, false,
429 LUSTRE_OSS_NAME, NULL);
434 static void __exit ost_exit(void)
436 class_unregister_type(LUSTRE_OSS_NAME);
439 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
440 MODULE_DESCRIPTION("Lustre Object Storage Target (OST)");
441 MODULE_VERSION(LUSTRE_VERSION_STRING);
442 MODULE_LICENSE("GPL");
444 module_init(ost_init);
445 module_exit(ost_exit);