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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2013, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/mdt/mdt_mds.c
33 * Lustre Metadata Service Layer
35 * Author: Di Wang <di.wang@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <linux/module.h>
42 #include <obd_support.h>
43 /* struct ptlrpc_request */
44 #include <lustre_net.h>
45 /* struct obd_export */
46 #include <lustre_export.h>
47 /* struct obd_device */
50 #include <dt_object.h>
51 #include <lustre_mds.h>
52 #include <lustre_mdt.h>
53 #include "mdt_internal.h"
54 #include <lustre_quota.h>
55 #include <lustre_acl.h>
56 #include <lustre_param.h>
60 struct md_device mds_md_dev;
61 struct ptlrpc_service *mds_regular_service;
62 struct ptlrpc_service *mds_readpage_service;
63 struct ptlrpc_service *mds_out_service;
64 struct ptlrpc_service *mds_setattr_service;
65 struct ptlrpc_service *mds_mdsc_service;
66 struct ptlrpc_service *mds_mdss_service;
67 struct ptlrpc_service *mds_fld_service;
71 * * Initialized in mdt_mod_init().
73 static unsigned long mdt_num_threads;
74 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
75 "number of MDS service threads to start "
76 "(deprecated in favor of mds_num_threads)");
78 static unsigned long mds_num_threads;
79 CFS_MODULE_PARM(mds_num_threads, "ul", ulong, 0444,
80 "number of MDS service threads to start");
82 static char *mds_num_cpts;
83 CFS_MODULE_PARM(mds_num_cpts, "c", charp, 0444,
84 "CPU partitions MDS threads should run on");
86 static unsigned long mds_rdpg_num_threads;
87 CFS_MODULE_PARM(mds_rdpg_num_threads, "ul", ulong, 0444,
88 "number of MDS readpage service threads to start");
90 static char *mds_rdpg_num_cpts;
91 CFS_MODULE_PARM(mds_rdpg_num_cpts, "c", charp, 0444,
92 "CPU partitions MDS readpage threads should run on");
94 /* NB: these two should be removed along with setattr service in the future */
95 static unsigned long mds_attr_num_threads;
96 CFS_MODULE_PARM(mds_attr_num_threads, "ul", ulong, 0444,
97 "number of MDS setattr service threads to start");
99 static char *mds_attr_num_cpts;
100 CFS_MODULE_PARM(mds_attr_num_cpts, "c", charp, 0444,
101 "CPU partitions MDS setattr threads should run on");
103 #define DEFINE_RPC_HANDLER(base, flags, opc, fn, fmt) \
106 .mh_fail_id = OBD_FAIL_ ## opc ## _NET, \
113 /* Request with a format known in advance */
114 #define DEF_MDT_HDL(flags, name, fn) \
115 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, &RQF_ ## name)
117 /* Request with a format we do not yet know */
118 #define DEF_MDT_HDL_VAR(flags, name, fn) \
119 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, NULL)
121 /* Map one non-standard request format handler. This should probably get
122 * a common OBD_SET_INFO RPC opcode instead of this mismatch. */
123 #define RQF_MDS_SET_INFO RQF_OBD_SET_INFO
125 static struct mdt_handler mdt_mds_ops[] = {
126 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
127 DEF_MDT_HDL(0, MDS_DISCONNECT, mdt_disconnect),
128 DEF_MDT_HDL(0, MDS_SET_INFO, mdt_set_info),
129 DEF_MDT_HDL(0, MDS_GET_INFO, mdt_get_info),
130 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus),
131 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
132 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME, mdt_getattr_name),
133 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_getxattr),
134 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs),
135 DEF_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
136 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
137 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
138 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_PIN, mdt_pin),
139 DEF_MDT_HDL_VAR(0, MDS_SYNC, mdt_sync),
140 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir),
141 DEF_MDT_HDL(0, MDS_QUOTACHECK, mdt_quotacheck),
142 DEF_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl),
143 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_PROGRESS, mdt_hsm_progress),
144 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_CT_REGISTER,
145 mdt_hsm_ct_register),
146 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_CT_UNREGISTER,
147 mdt_hsm_ct_unregister),
148 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_GET,
150 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_SET,
152 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_ACTION, mdt_hsm_action),
153 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_REQUEST, mdt_hsm_request),
154 DEF_MDT_HDL(HABEO_CORPUS|HABEO_REFERO, MDS_SWAP_LAYOUTS, mdt_swap_layouts)
157 #define DEF_OBD_HDL(flags, name, fn) \
158 DEFINE_RPC_HANDLER(OBD_PING, flags, name, fn, NULL)
160 static struct mdt_handler mdt_obd_ops[] = {
161 DEF_OBD_HDL(0, OBD_PING, mdt_obd_ping),
162 DEF_OBD_HDL(0, OBD_LOG_CANCEL, mdt_obd_log_cancel),
163 DEF_OBD_HDL(0, OBD_QC_CALLBACK, mdt_obd_qc_callback),
164 DEF_OBD_HDL(0, OBD_IDX_READ, mdt_obd_idx_read)
167 #define DEF_DLM_HDL_VAR(flags, name, fn) \
168 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, NULL)
169 #define DEF_DLM_HDL(flags, name, fn) \
170 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, &RQF_ ## name)
172 static struct mdt_handler mdt_dlm_ops[] = {
173 DEF_DLM_HDL (HABEO_CLAVIS, LDLM_ENQUEUE, mdt_enqueue),
174 DEF_DLM_HDL_VAR(HABEO_CLAVIS, LDLM_CONVERT, mdt_convert),
175 DEF_DLM_HDL_VAR(0, LDLM_BL_CALLBACK, mdt_bl_callback),
176 DEF_DLM_HDL_VAR(0, LDLM_CP_CALLBACK, mdt_cp_callback)
179 #define DEF_LLOG_HDL(flags, name, fn) \
180 DEFINE_RPC_HANDLER(LLOG_ORIGIN_HANDLE_CREATE, flags, name, fn, NULL)
182 static struct mdt_handler mdt_llog_ops[] = {
183 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CREATE, mdt_llog_create),
184 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
185 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
186 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_WRITE_REC, NULL),
187 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CLOSE, NULL),
188 DEF_LLOG_HDL(0, LLOG_ORIGIN_CONNECT, NULL),
189 DEF_LLOG_HDL(0, LLOG_CATINFO, NULL),
190 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
191 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
194 #define DEF_SEC_HDL(flags, name, fn) \
195 DEFINE_RPC_HANDLER(SEC_CTX_INIT, flags, name, fn, NULL)
197 static struct mdt_handler mdt_sec_ctx_ops[] = {
198 DEF_SEC_HDL(0, SEC_CTX_INIT, mdt_sec_ctx_handle),
199 DEF_SEC_HDL(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle),
200 DEF_SEC_HDL(0, SEC_CTX_FINI, mdt_sec_ctx_handle)
203 #define DEF_QUOTA_HDL(flags, name, fn) \
204 DEFINE_RPC_HANDLER(QUOTA_DQACQ, flags, name, fn, &RQF_ ## name)
206 static struct mdt_handler mdt_quota_ops[] = {
207 DEF_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq),
210 struct mdt_opc_slice mdt_regular_handlers[] = {
212 .mos_opc_start = MDS_GETATTR,
213 .mos_opc_end = MDS_LAST_OPC,
214 .mos_hs = mdt_mds_ops
217 .mos_opc_start = OBD_PING,
218 .mos_opc_end = OBD_LAST_OPC,
219 .mos_hs = mdt_obd_ops
222 .mos_opc_start = LDLM_ENQUEUE,
223 .mos_opc_end = LDLM_LAST_OPC,
224 .mos_hs = mdt_dlm_ops
227 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
228 .mos_opc_end = LLOG_LAST_OPC,
229 .mos_hs = mdt_llog_ops
232 .mos_opc_start = SEC_CTX_INIT,
233 .mos_opc_end = SEC_LAST_OPC,
234 .mos_hs = mdt_sec_ctx_ops
237 .mos_opc_start = QUOTA_DQACQ,
238 .mos_opc_end = QUOTA_LAST_OPC,
239 .mos_hs = mdt_quota_ops
246 /* Readpage/readdir handlers */
247 static struct mdt_handler mdt_readpage_ops[] = {
248 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
249 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_READPAGE, mdt_readpage),
250 /* XXX: this is ugly and should be fixed one day, see mdc_close() for
251 * detailed comments. --umka */
252 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
253 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
256 static struct mdt_opc_slice mdt_readpage_handlers[] = {
258 .mos_opc_start = MDS_GETATTR,
259 .mos_opc_end = MDS_LAST_OPC,
260 .mos_hs = mdt_readpage_ops
263 .mos_opc_start = OBD_FIRST_OPC,
264 .mos_opc_end = OBD_LAST_OPC,
265 .mos_hs = mdt_obd_ops
272 /* Sequence service handlers */
273 #define DEF_SEQ_HDL(flags, name, fn) \
274 DEFINE_RPC_HANDLER(SEQ_QUERY, flags, name, fn, &RQF_ ## name)
276 static struct mdt_handler mdt_seq_ops[] = {
277 DEF_SEQ_HDL(0, SEQ_QUERY, (void *)seq_query),
280 struct mdt_opc_slice mdt_seq_handlers[] = {
282 .mos_opc_start = SEQ_QUERY,
283 .mos_opc_end = SEQ_LAST_OPC,
284 .mos_hs = mdt_seq_ops
291 /* FID Location Database handlers */
292 #define DEF_FLD_HDL(flags, name, fn) \
293 DEFINE_RPC_HANDLER(FLD_QUERY, flags, name, fn, &RQF_ ## name)
295 static struct mdt_handler mdt_fld_ops[] = {
296 DEF_FLD_HDL(0, FLD_QUERY, (void *)fld_query),
299 struct mdt_opc_slice mdt_fld_handlers[] = {
301 .mos_opc_start = FLD_QUERY,
302 .mos_opc_end = FLD_LAST_OPC,
303 .mos_hs = mdt_fld_ops
310 /* Request with a format known in advance */
311 #define DEF_UPDATE_HDL(flags, name, fn) \
312 DEFINE_RPC_HANDLER(UPDATE_OBJ, flags, name, fn, &RQF_ ## name)
314 #define target_handler mdt_handler
315 static struct target_handler out_ops[] = {
316 DEF_UPDATE_HDL(MUTABOR, UPDATE_OBJ, out_handle),
319 static struct mdt_opc_slice update_handlers[] = {
321 .mos_opc_start = MDS_GETATTR,
322 .mos_opc_end = MDS_LAST_OPC,
323 .mos_hs = mdt_mds_ops
326 .mos_opc_start = OBD_PING,
327 .mos_opc_end = OBD_LAST_OPC,
328 .mos_hs = mdt_obd_ops
331 .mos_opc_start = LDLM_ENQUEUE,
332 .mos_opc_end = LDLM_LAST_OPC,
333 .mos_hs = mdt_dlm_ops
336 .mos_opc_start = SEC_CTX_INIT,
337 .mos_opc_end = SEC_LAST_OPC,
338 .mos_hs = mdt_sec_ctx_ops
341 .mos_opc_start = UPDATE_OBJ,
342 .mos_opc_end = UPDATE_LAST_OPC,
350 static int mds_regular_handle(struct ptlrpc_request *req)
352 return mdt_handle_common(req, mdt_regular_handlers);
355 static int mds_readpage_handle(struct ptlrpc_request *req)
357 return mdt_handle_common(req, mdt_readpage_handlers);
360 static int mds_mdsc_handle(struct ptlrpc_request *req)
362 return mdt_handle_common(req, mdt_seq_handlers);
365 static int mdt_out_handle(struct ptlrpc_request *req)
367 return mdt_handle_common(req, update_handlers);
370 static int mds_mdss_handle(struct ptlrpc_request *req)
372 return mdt_handle_common(req, mdt_seq_handlers);
375 static int mds_fld_handle(struct ptlrpc_request *req)
377 return mdt_handle_common(req, mdt_fld_handlers);
380 /* device init/fini methods */
381 static void mds_stop_ptlrpc_service(struct mds_device *m)
384 if (m->mds_regular_service != NULL) {
385 ptlrpc_unregister_service(m->mds_regular_service);
386 m->mds_regular_service = NULL;
388 if (m->mds_readpage_service != NULL) {
389 ptlrpc_unregister_service(m->mds_readpage_service);
390 m->mds_readpage_service = NULL;
392 if (m->mds_out_service != NULL) {
393 ptlrpc_unregister_service(m->mds_out_service);
394 m->mds_out_service = NULL;
396 if (m->mds_setattr_service != NULL) {
397 ptlrpc_unregister_service(m->mds_setattr_service);
398 m->mds_setattr_service = NULL;
400 if (m->mds_mdsc_service != NULL) {
401 ptlrpc_unregister_service(m->mds_mdsc_service);
402 m->mds_mdsc_service = NULL;
404 if (m->mds_mdss_service != NULL) {
405 ptlrpc_unregister_service(m->mds_mdss_service);
406 m->mds_mdss_service = NULL;
408 if (m->mds_fld_service != NULL) {
409 ptlrpc_unregister_service(m->mds_fld_service);
410 m->mds_fld_service = NULL;
415 static int mds_start_ptlrpc_service(struct mds_device *m)
417 static struct ptlrpc_service_conf conf;
418 struct obd_device *obd = m->mds_md_dev.md_lu_dev.ld_obd;
419 cfs_proc_dir_entry_t *procfs_entry;
423 procfs_entry = obd->obd_proc_entry;
424 LASSERT(procfs_entry != NULL);
426 conf = (typeof(conf)) {
427 .psc_name = LUSTRE_MDT_NAME,
428 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
430 .bc_nbufs = MDS_NBUFS,
431 .bc_buf_size = MDS_REG_BUFSIZE,
432 .bc_req_max_size = MDS_REG_MAXREQSIZE,
433 .bc_rep_max_size = MDS_REG_MAXREPSIZE,
434 .bc_req_portal = MDS_REQUEST_PORTAL,
435 .bc_rep_portal = MDC_REPLY_PORTAL,
438 * We'd like to have a mechanism to set this on a per-device
442 .tc_thr_name = LUSTRE_MDT_NAME,
443 .tc_thr_factor = MDS_THR_FACTOR,
444 .tc_nthrs_init = MDS_NTHRS_INIT,
445 .tc_nthrs_base = MDS_NTHRS_BASE,
446 .tc_nthrs_max = MDS_NTHRS_MAX,
447 .tc_nthrs_user = mds_num_threads,
448 .tc_cpu_affinity = 1,
449 .tc_ctx_tags = LCT_MD_THREAD,
452 .cc_pattern = mds_num_cpts,
455 .so_req_handler = mds_regular_handle,
456 .so_req_printer = target_print_req,
457 .so_hpreq_handler = ptlrpc_hpreq_handler,
460 m->mds_regular_service = ptlrpc_register_service(&conf, procfs_entry);
461 if (IS_ERR(m->mds_regular_service)) {
462 rc = PTR_ERR(m->mds_regular_service);
463 CERROR("failed to start regular mdt service: %d\n", rc);
464 m->mds_regular_service = NULL;
470 * readpage service configuration. Parameters have to be adjusted,
473 memset(&conf, 0, sizeof(conf));
474 conf = (typeof(conf)) {
475 .psc_name = LUSTRE_MDT_NAME "_readpage",
476 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
478 .bc_nbufs = MDS_NBUFS,
479 .bc_buf_size = MDS_BUFSIZE,
480 .bc_req_max_size = MDS_MAXREQSIZE,
481 .bc_rep_max_size = MDS_MAXREPSIZE,
482 .bc_req_portal = MDS_READPAGE_PORTAL,
483 .bc_rep_portal = MDC_REPLY_PORTAL,
486 .tc_thr_name = LUSTRE_MDT_NAME "_rdpg",
487 .tc_thr_factor = MDS_RDPG_THR_FACTOR,
488 .tc_nthrs_init = MDS_RDPG_NTHRS_INIT,
489 .tc_nthrs_base = MDS_RDPG_NTHRS_BASE,
490 .tc_nthrs_max = MDS_RDPG_NTHRS_MAX,
491 .tc_nthrs_user = mds_rdpg_num_threads,
492 .tc_cpu_affinity = 1,
493 .tc_ctx_tags = LCT_MD_THREAD,
496 .cc_pattern = mds_rdpg_num_cpts,
499 .so_req_handler = mds_readpage_handle,
500 .so_req_printer = target_print_req,
503 m->mds_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
504 if (IS_ERR(m->mds_readpage_service)) {
505 rc = PTR_ERR(m->mds_readpage_service);
506 CERROR("failed to start readpage service: %d\n", rc);
507 m->mds_readpage_service = NULL;
509 GOTO(err_mds_svc, rc);
513 * setattr service configuration.
515 * XXX To keep the compatibility with old client(< 2.2), we need to
516 * preserve this portal for a certain time, it should be removed
517 * eventually. LU-617.
519 memset(&conf, 0, sizeof(conf));
520 conf = (typeof(conf)) {
521 .psc_name = LUSTRE_MDT_NAME "_setattr",
522 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
524 .bc_nbufs = MDS_NBUFS,
525 .bc_buf_size = MDS_BUFSIZE,
526 .bc_req_max_size = MDS_MAXREQSIZE,
527 .bc_rep_max_size = MDS_LOV_MAXREPSIZE,
528 .bc_req_portal = MDS_SETATTR_PORTAL,
529 .bc_rep_portal = MDC_REPLY_PORTAL,
532 .tc_thr_name = LUSTRE_MDT_NAME "_attr",
533 .tc_thr_factor = MDS_SETA_THR_FACTOR,
534 .tc_nthrs_init = MDS_SETA_NTHRS_INIT,
535 .tc_nthrs_base = MDS_SETA_NTHRS_BASE,
536 .tc_nthrs_max = MDS_SETA_NTHRS_MAX,
537 .tc_nthrs_user = mds_attr_num_threads,
538 .tc_cpu_affinity = 1,
539 .tc_ctx_tags = LCT_MD_THREAD,
542 .cc_pattern = mds_attr_num_cpts,
545 .so_req_handler = mds_regular_handle,
546 .so_req_printer = target_print_req,
547 .so_hpreq_handler = NULL,
550 m->mds_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
551 if (IS_ERR(m->mds_setattr_service)) {
552 rc = PTR_ERR(m->mds_setattr_service);
553 CERROR("failed to start setattr service: %d\n", rc);
554 m->mds_setattr_service = NULL;
556 GOTO(err_mds_svc, rc);
559 /* Object update service */
560 conf = (typeof(conf)) {
561 .psc_name = LUSTRE_MDT_NAME "_out",
562 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
564 .bc_nbufs = MDS_NBUFS,
565 .bc_buf_size = MDS_OUT_BUFSIZE,
566 .bc_req_max_size = MDS_OUT_MAXREQSIZE,
567 .bc_rep_max_size = MDS_OUT_MAXREPSIZE,
568 .bc_req_portal = MDS_MDS_PORTAL,
569 .bc_rep_portal = MDC_REPLY_PORTAL,
572 * We'd like to have a mechanism to set this on a per-device
576 .tc_thr_name = LUSTRE_MDT_NAME "_out",
577 .tc_thr_factor = MDS_THR_FACTOR,
578 .tc_nthrs_init = MDS_NTHRS_INIT,
579 .tc_nthrs_base = MDS_NTHRS_BASE,
580 .tc_nthrs_max = MDS_NTHRS_MAX,
581 .tc_nthrs_user = mds_num_threads,
582 .tc_cpu_affinity = 1,
583 .tc_ctx_tags = LCT_MD_THREAD,
586 .cc_pattern = mds_num_cpts,
589 .so_req_handler = mdt_out_handle,
590 .so_req_printer = target_print_req,
591 .so_hpreq_handler = NULL,
594 m->mds_out_service = ptlrpc_register_service(&conf, procfs_entry);
595 if (IS_ERR(m->mds_out_service)) {
596 rc = PTR_ERR(m->mds_out_service);
597 CERROR("failed to start out service: %d\n", rc);
598 m->mds_out_service = NULL;
599 GOTO(err_mds_svc, rc);
603 * sequence controller service configuration
605 memset(&conf, 0, sizeof(conf));
606 conf = (typeof(conf)) {
607 .psc_name = LUSTRE_MDT_NAME "_seqs",
608 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
610 .bc_nbufs = MDS_NBUFS,
611 .bc_buf_size = SEQ_BUFSIZE,
612 .bc_req_max_size = SEQ_MAXREQSIZE,
613 .bc_rep_max_size = SEQ_MAXREPSIZE,
614 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
615 .bc_rep_portal = MDC_REPLY_PORTAL,
618 .tc_thr_name = LUSTRE_MDT_NAME "_seqs",
619 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
620 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
621 .tc_ctx_tags = LCT_MD_THREAD,
624 .so_req_handler = mds_mdsc_handle,
625 .so_req_printer = target_print_req,
626 .so_hpreq_handler = NULL,
629 m->mds_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
630 if (IS_ERR(m->mds_mdsc_service)) {
631 rc = PTR_ERR(m->mds_mdsc_service);
632 CERROR("failed to start seq controller service: %d\n", rc);
633 m->mds_mdsc_service = NULL;
635 GOTO(err_mds_svc, rc);
639 * metadata sequence server service configuration
641 memset(&conf, 0, sizeof(conf));
642 conf = (typeof(conf)) {
643 .psc_name = LUSTRE_MDT_NAME "_seqm",
644 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
646 .bc_nbufs = MDS_NBUFS,
647 .bc_buf_size = SEQ_BUFSIZE,
648 .bc_req_max_size = SEQ_MAXREQSIZE,
649 .bc_rep_max_size = SEQ_MAXREPSIZE,
650 .bc_req_portal = SEQ_METADATA_PORTAL,
651 .bc_rep_portal = MDC_REPLY_PORTAL,
654 .tc_thr_name = LUSTRE_MDT_NAME "_seqm",
655 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
656 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
657 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
660 .so_req_handler = mds_mdss_handle,
661 .so_req_printer = target_print_req,
662 .so_hpreq_handler = NULL,
665 m->mds_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
666 if (IS_ERR(m->mds_mdss_service)) {
667 rc = PTR_ERR(m->mds_mdss_service);
668 CERROR("failed to start metadata seq server service: %d\n", rc);
669 m->mds_mdss_service = NULL;
671 GOTO(err_mds_svc, rc);
674 /* FLD service start */
675 memset(&conf, 0, sizeof(conf));
676 conf = (typeof(conf)) {
677 .psc_name = LUSTRE_MDT_NAME "_fld",
678 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
680 .bc_nbufs = MDS_NBUFS,
681 .bc_buf_size = FLD_BUFSIZE,
682 .bc_req_max_size = FLD_MAXREQSIZE,
683 .bc_rep_max_size = FLD_MAXREPSIZE,
684 .bc_req_portal = FLD_REQUEST_PORTAL,
685 .bc_rep_portal = MDC_REPLY_PORTAL,
688 .tc_thr_name = LUSTRE_MDT_NAME "_fld",
689 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
690 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
691 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
694 .so_req_handler = mds_fld_handle,
695 .so_req_printer = target_print_req,
696 .so_hpreq_handler = NULL,
699 m->mds_fld_service = ptlrpc_register_service(&conf, procfs_entry);
700 if (IS_ERR(m->mds_fld_service)) {
701 rc = PTR_ERR(m->mds_fld_service);
702 CERROR("failed to start fld service: %d\n", rc);
703 m->mds_fld_service = NULL;
705 GOTO(err_mds_svc, rc);
711 mds_stop_ptlrpc_service(m);
716 static inline struct mds_device *mds_dev(struct lu_device *d)
718 return container_of0(d, struct mds_device, mds_md_dev.md_lu_dev);
721 static struct lu_device *mds_device_fini(const struct lu_env *env,
724 struct mds_device *m = mds_dev(d);
725 struct obd_device *obd = d->ld_obd;
728 mds_stop_ptlrpc_service(m);
729 lprocfs_obd_cleanup(obd);
733 static struct lu_device *mds_device_free(const struct lu_env *env,
736 struct mds_device *m = mds_dev(d);
739 md_device_fini(&m->mds_md_dev);
744 static struct lu_device *mds_device_alloc(const struct lu_env *env,
745 struct lu_device_type *t,
746 struct lustre_cfg *cfg)
748 struct mds_device *m;
749 struct obd_device *obd;
755 return ERR_PTR(-ENOMEM);
757 md_device_init(&m->mds_md_dev, t);
758 l = &m->mds_md_dev.md_lu_dev;
760 obd = class_name2obd(lustre_cfg_string(cfg, 0));
761 LASSERT(obd != NULL);
764 /* set this lu_device to obd, because error handling need it */
767 rc = lprocfs_obd_setup(obd, lprocfs_mds_obd_vars);
769 mds_device_free(env, l);
774 rc = mds_start_ptlrpc_service(m);
777 mds_device_free(env, l);
785 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
786 LU_TYPE_INIT_FINI(mds, &mdt_thread_key);
788 static struct lu_device_type_operations mds_device_type_ops = {
789 .ldto_init = mds_type_init,
790 .ldto_fini = mds_type_fini,
792 .ldto_start = mds_type_start,
793 .ldto_stop = mds_type_stop,
795 .ldto_device_alloc = mds_device_alloc,
796 .ldto_device_free = mds_device_free,
797 .ldto_device_fini = mds_device_fini
800 static struct lu_device_type mds_device_type = {
801 .ldt_tags = LU_DEVICE_MD,
802 .ldt_name = LUSTRE_MDS_NAME,
803 .ldt_ops = &mds_device_type_ops,
804 .ldt_ctx_tags = LCT_MD_THREAD
807 static struct obd_ops mds_obd_device_ops = {
808 .o_owner = THIS_MODULE,
811 int mds_mod_init(void)
815 if (mdt_num_threads != 0 && mds_num_threads == 0) {
816 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated, "
817 "use mds_num_threads instead or unset both for "
818 "dynamic thread startup\n");
819 mds_num_threads = mdt_num_threads;
822 rc = class_register_type(&mds_obd_device_ops, NULL,
823 lprocfs_mds_module_vars, LUSTRE_MDS_NAME,
828 void mds_mod_exit(void)
830 class_unregister_type(LUSTRE_MDS_NAME);