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 "mdt_internal.h"
53 #include <lustre_quota.h>
54 #include <lustre_acl.h>
55 #include <lustre_param.h>
59 struct md_device mds_md_dev;
60 struct ptlrpc_service *mds_regular_service;
61 struct ptlrpc_service *mds_readpage_service;
62 struct ptlrpc_service *mds_out_service;
63 struct ptlrpc_service *mds_setattr_service;
64 struct ptlrpc_service *mds_mdsc_service;
65 struct ptlrpc_service *mds_mdss_service;
66 struct ptlrpc_service *mds_fld_service;
70 * * Initialized in mdt_mod_init().
72 static unsigned long mdt_num_threads;
73 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
74 "number of MDS service threads to start "
75 "(deprecated in favor of mds_num_threads)");
77 static unsigned long mds_num_threads;
78 CFS_MODULE_PARM(mds_num_threads, "ul", ulong, 0444,
79 "number of MDS service threads to start");
81 static char *mds_num_cpts;
82 CFS_MODULE_PARM(mds_num_cpts, "c", charp, 0444,
83 "CPU partitions MDS threads should run on");
85 static unsigned long mds_rdpg_num_threads;
86 CFS_MODULE_PARM(mds_rdpg_num_threads, "ul", ulong, 0444,
87 "number of MDS readpage service threads to start");
89 static char *mds_rdpg_num_cpts;
90 CFS_MODULE_PARM(mds_rdpg_num_cpts, "c", charp, 0444,
91 "CPU partitions MDS readpage threads should run on");
93 /* NB: these two should be removed along with setattr service in the future */
94 static unsigned long mds_attr_num_threads;
95 CFS_MODULE_PARM(mds_attr_num_threads, "ul", ulong, 0444,
96 "number of MDS setattr service threads to start");
98 static char *mds_attr_num_cpts;
99 CFS_MODULE_PARM(mds_attr_num_cpts, "c", charp, 0444,
100 "CPU partitions MDS setattr threads should run on");
102 #define DEFINE_RPC_HANDLER(base, flags, opc, fn, fmt) \
105 .mh_fail_id = OBD_FAIL_ ## opc ## _NET, \
112 /* Request with a format known in advance */
113 #define DEF_MDT_HDL(flags, name, fn) \
114 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, &RQF_ ## name)
116 /* Request with a format we do not yet know */
117 #define DEF_MDT_HDL_VAR(flags, name, fn) \
118 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, NULL)
120 /* Map one non-standard request format handler. This should probably get
121 * a common OBD_SET_INFO RPC opcode instead of this mismatch. */
122 #define RQF_MDS_SET_INFO RQF_OBD_SET_INFO
124 static struct mdt_handler mdt_mds_ops[] = {
125 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
126 DEF_MDT_HDL(0, MDS_DISCONNECT, mdt_disconnect),
127 DEF_MDT_HDL(0, MDS_SET_INFO, mdt_set_info),
128 DEF_MDT_HDL(0, MDS_GET_INFO, mdt_get_info),
129 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus),
130 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
131 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME, mdt_getattr_name),
132 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_getxattr),
133 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs),
134 DEF_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
135 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
136 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
137 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_PIN, mdt_pin),
138 DEF_MDT_HDL_VAR(0, MDS_SYNC, mdt_sync),
139 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir),
140 DEF_MDT_HDL(0, MDS_QUOTACHECK, mdt_quotacheck),
141 DEF_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl),
142 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_PROGRESS,
144 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_CT_REGISTER,
145 mdt_hsm_ct_register),
146 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_CT_UNREGISTER,
147 mdt_hsm_ct_unregister),
148 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_HSM_STATE_GET, mdt_hsm_state_get),
149 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_HSM_STATE_SET,
151 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_HSM_ACTION, mdt_hsm_action),
152 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_HSM_REQUEST, mdt_hsm_request),
153 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, MDS_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 static int mds_regular_handle(struct ptlrpc_request *req)
274 return mdt_handle_common(req, mdt_regular_handlers);
277 static int mds_readpage_handle(struct ptlrpc_request *req)
279 return mdt_handle_common(req, mdt_readpage_handlers);
282 /* device init/fini methods */
283 static void mds_stop_ptlrpc_service(struct mds_device *m)
286 if (m->mds_regular_service != NULL) {
287 ptlrpc_unregister_service(m->mds_regular_service);
288 m->mds_regular_service = NULL;
290 if (m->mds_readpage_service != NULL) {
291 ptlrpc_unregister_service(m->mds_readpage_service);
292 m->mds_readpage_service = NULL;
294 if (m->mds_out_service != NULL) {
295 ptlrpc_unregister_service(m->mds_out_service);
296 m->mds_out_service = NULL;
298 if (m->mds_setattr_service != NULL) {
299 ptlrpc_unregister_service(m->mds_setattr_service);
300 m->mds_setattr_service = NULL;
302 if (m->mds_mdsc_service != NULL) {
303 ptlrpc_unregister_service(m->mds_mdsc_service);
304 m->mds_mdsc_service = NULL;
306 if (m->mds_mdss_service != NULL) {
307 ptlrpc_unregister_service(m->mds_mdss_service);
308 m->mds_mdss_service = NULL;
310 if (m->mds_fld_service != NULL) {
311 ptlrpc_unregister_service(m->mds_fld_service);
312 m->mds_fld_service = NULL;
317 static int mds_start_ptlrpc_service(struct mds_device *m)
319 static struct ptlrpc_service_conf conf;
320 struct obd_device *obd = m->mds_md_dev.md_lu_dev.ld_obd;
321 cfs_proc_dir_entry_t *procfs_entry;
325 procfs_entry = obd->obd_proc_entry;
326 LASSERT(procfs_entry != NULL);
328 conf = (typeof(conf)) {
329 .psc_name = LUSTRE_MDT_NAME,
330 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
332 .bc_nbufs = MDS_NBUFS,
333 .bc_buf_size = MDS_REG_BUFSIZE,
334 .bc_req_max_size = MDS_REG_MAXREQSIZE,
335 .bc_rep_max_size = MDS_REG_MAXREPSIZE,
336 .bc_req_portal = MDS_REQUEST_PORTAL,
337 .bc_rep_portal = MDC_REPLY_PORTAL,
340 * We'd like to have a mechanism to set this on a per-device
344 .tc_thr_name = LUSTRE_MDT_NAME,
345 .tc_thr_factor = MDS_THR_FACTOR,
346 .tc_nthrs_init = MDS_NTHRS_INIT,
347 .tc_nthrs_base = MDS_NTHRS_BASE,
348 .tc_nthrs_max = MDS_NTHRS_MAX,
349 .tc_nthrs_user = mds_num_threads,
350 .tc_cpu_affinity = 1,
351 .tc_ctx_tags = LCT_MD_THREAD,
354 .cc_pattern = mds_num_cpts,
357 .so_req_handler = mds_regular_handle,
358 .so_req_printer = target_print_req,
359 .so_hpreq_handler = ptlrpc_hpreq_handler,
362 m->mds_regular_service = ptlrpc_register_service(&conf, procfs_entry);
363 if (IS_ERR(m->mds_regular_service)) {
364 rc = PTR_ERR(m->mds_regular_service);
365 CERROR("failed to start regular mdt service: %d\n", rc);
366 m->mds_regular_service = NULL;
372 * readpage service configuration. Parameters have to be adjusted,
375 memset(&conf, 0, sizeof(conf));
376 conf = (typeof(conf)) {
377 .psc_name = LUSTRE_MDT_NAME "_readpage",
378 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
380 .bc_nbufs = MDS_NBUFS,
381 .bc_buf_size = MDS_BUFSIZE,
382 .bc_req_max_size = MDS_MAXREQSIZE,
383 .bc_rep_max_size = MDS_MAXREPSIZE,
384 .bc_req_portal = MDS_READPAGE_PORTAL,
385 .bc_rep_portal = MDC_REPLY_PORTAL,
388 .tc_thr_name = LUSTRE_MDT_NAME "_rdpg",
389 .tc_thr_factor = MDS_RDPG_THR_FACTOR,
390 .tc_nthrs_init = MDS_RDPG_NTHRS_INIT,
391 .tc_nthrs_base = MDS_RDPG_NTHRS_BASE,
392 .tc_nthrs_max = MDS_RDPG_NTHRS_MAX,
393 .tc_nthrs_user = mds_rdpg_num_threads,
394 .tc_cpu_affinity = 1,
395 .tc_ctx_tags = LCT_MD_THREAD,
398 .cc_pattern = mds_rdpg_num_cpts,
401 .so_req_handler = mds_readpage_handle,
402 .so_req_printer = target_print_req,
405 m->mds_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
406 if (IS_ERR(m->mds_readpage_service)) {
407 rc = PTR_ERR(m->mds_readpage_service);
408 CERROR("failed to start readpage service: %d\n", rc);
409 m->mds_readpage_service = NULL;
411 GOTO(err_mds_svc, rc);
415 * setattr service configuration.
417 * XXX To keep the compatibility with old client(< 2.2), we need to
418 * preserve this portal for a certain time, it should be removed
419 * eventually. LU-617.
421 memset(&conf, 0, sizeof(conf));
422 conf = (typeof(conf)) {
423 .psc_name = LUSTRE_MDT_NAME "_setattr",
424 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
426 .bc_nbufs = MDS_NBUFS,
427 .bc_buf_size = MDS_BUFSIZE,
428 .bc_req_max_size = MDS_MAXREQSIZE,
429 .bc_rep_max_size = MDS_LOV_MAXREPSIZE,
430 .bc_req_portal = MDS_SETATTR_PORTAL,
431 .bc_rep_portal = MDC_REPLY_PORTAL,
434 .tc_thr_name = LUSTRE_MDT_NAME "_attr",
435 .tc_thr_factor = MDS_SETA_THR_FACTOR,
436 .tc_nthrs_init = MDS_SETA_NTHRS_INIT,
437 .tc_nthrs_base = MDS_SETA_NTHRS_BASE,
438 .tc_nthrs_max = MDS_SETA_NTHRS_MAX,
439 .tc_nthrs_user = mds_attr_num_threads,
440 .tc_cpu_affinity = 1,
441 .tc_ctx_tags = LCT_MD_THREAD,
444 .cc_pattern = mds_attr_num_cpts,
447 .so_req_handler = mds_regular_handle,
448 .so_req_printer = target_print_req,
449 .so_hpreq_handler = NULL,
452 m->mds_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
453 if (IS_ERR(m->mds_setattr_service)) {
454 rc = PTR_ERR(m->mds_setattr_service);
455 CERROR("failed to start setattr service: %d\n", rc);
456 m->mds_setattr_service = NULL;
458 GOTO(err_mds_svc, rc);
461 /* Object update service */
462 conf = (typeof(conf)) {
463 .psc_name = LUSTRE_MDT_NAME "_out",
464 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
466 .bc_nbufs = MDS_NBUFS,
467 .bc_buf_size = OUT_BUFSIZE,
468 .bc_req_max_size = OUT_MAXREQSIZE,
469 .bc_rep_max_size = OUT_MAXREPSIZE,
470 .bc_req_portal = OUT_PORTAL,
471 .bc_rep_portal = MDC_REPLY_PORTAL,
474 * We'd like to have a mechanism to set this on a per-device
478 .tc_thr_name = LUSTRE_MDT_NAME "_out",
479 .tc_thr_factor = MDS_THR_FACTOR,
480 .tc_nthrs_init = MDS_NTHRS_INIT,
481 .tc_nthrs_base = MDS_NTHRS_BASE,
482 .tc_nthrs_max = MDS_NTHRS_MAX,
483 .tc_nthrs_user = mds_num_threads,
484 .tc_cpu_affinity = 1,
485 .tc_ctx_tags = LCT_MD_THREAD,
488 .cc_pattern = mds_num_cpts,
491 .so_req_handler = tgt_request_handle,
492 .so_req_printer = target_print_req,
493 .so_hpreq_handler = NULL,
496 m->mds_out_service = ptlrpc_register_service(&conf, procfs_entry);
497 if (IS_ERR(m->mds_out_service)) {
498 rc = PTR_ERR(m->mds_out_service);
499 CERROR("failed to start out service: %d\n", rc);
500 m->mds_out_service = NULL;
501 GOTO(err_mds_svc, rc);
505 * sequence controller service configuration
507 memset(&conf, 0, sizeof(conf));
508 conf = (typeof(conf)) {
509 .psc_name = LUSTRE_MDT_NAME "_seqs",
510 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
512 .bc_nbufs = MDS_NBUFS,
513 .bc_buf_size = SEQ_BUFSIZE,
514 .bc_req_max_size = SEQ_MAXREQSIZE,
515 .bc_rep_max_size = SEQ_MAXREPSIZE,
516 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
517 .bc_rep_portal = MDC_REPLY_PORTAL,
520 .tc_thr_name = LUSTRE_MDT_NAME "_seqs",
521 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
522 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
523 .tc_ctx_tags = LCT_MD_THREAD,
526 .so_req_handler = tgt_request_handle,
527 .so_req_printer = target_print_req,
528 .so_hpreq_handler = NULL,
531 m->mds_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
532 if (IS_ERR(m->mds_mdsc_service)) {
533 rc = PTR_ERR(m->mds_mdsc_service);
534 CERROR("failed to start seq controller service: %d\n", rc);
535 m->mds_mdsc_service = NULL;
537 GOTO(err_mds_svc, rc);
541 * metadata sequence server service configuration
543 memset(&conf, 0, sizeof(conf));
544 conf = (typeof(conf)) {
545 .psc_name = LUSTRE_MDT_NAME "_seqm",
546 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
548 .bc_nbufs = MDS_NBUFS,
549 .bc_buf_size = SEQ_BUFSIZE,
550 .bc_req_max_size = SEQ_MAXREQSIZE,
551 .bc_rep_max_size = SEQ_MAXREPSIZE,
552 .bc_req_portal = SEQ_METADATA_PORTAL,
553 .bc_rep_portal = MDC_REPLY_PORTAL,
556 .tc_thr_name = LUSTRE_MDT_NAME "_seqm",
557 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
558 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
559 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
562 .so_req_handler = tgt_request_handle,
563 .so_req_printer = target_print_req,
564 .so_hpreq_handler = NULL,
567 m->mds_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
568 if (IS_ERR(m->mds_mdss_service)) {
569 rc = PTR_ERR(m->mds_mdss_service);
570 CERROR("failed to start metadata seq server service: %d\n", rc);
571 m->mds_mdss_service = NULL;
573 GOTO(err_mds_svc, rc);
576 /* FLD service start */
577 memset(&conf, 0, sizeof(conf));
578 conf = (typeof(conf)) {
579 .psc_name = LUSTRE_MDT_NAME "_fld",
580 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
582 .bc_nbufs = MDS_NBUFS,
583 .bc_buf_size = FLD_BUFSIZE,
584 .bc_req_max_size = FLD_MAXREQSIZE,
585 .bc_rep_max_size = FLD_MAXREPSIZE,
586 .bc_req_portal = FLD_REQUEST_PORTAL,
587 .bc_rep_portal = MDC_REPLY_PORTAL,
590 .tc_thr_name = LUSTRE_MDT_NAME "_fld",
591 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
592 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
593 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD,
596 .so_req_handler = tgt_request_handle,
597 .so_req_printer = target_print_req,
598 .so_hpreq_handler = NULL,
601 m->mds_fld_service = ptlrpc_register_service(&conf, procfs_entry);
602 if (IS_ERR(m->mds_fld_service)) {
603 rc = PTR_ERR(m->mds_fld_service);
604 CERROR("failed to start fld service: %d\n", rc);
605 m->mds_fld_service = NULL;
607 GOTO(err_mds_svc, rc);
613 mds_stop_ptlrpc_service(m);
618 static inline struct mds_device *mds_dev(struct lu_device *d)
620 return container_of0(d, struct mds_device, mds_md_dev.md_lu_dev);
623 static struct lu_device *mds_device_fini(const struct lu_env *env,
626 struct mds_device *m = mds_dev(d);
627 struct obd_device *obd = d->ld_obd;
630 mds_stop_ptlrpc_service(m);
631 lprocfs_obd_cleanup(obd);
635 static struct lu_device *mds_device_free(const struct lu_env *env,
638 struct mds_device *m = mds_dev(d);
641 md_device_fini(&m->mds_md_dev);
646 static struct lu_device *mds_device_alloc(const struct lu_env *env,
647 struct lu_device_type *t,
648 struct lustre_cfg *cfg)
650 struct mds_device *m;
651 struct obd_device *obd;
657 return ERR_PTR(-ENOMEM);
659 md_device_init(&m->mds_md_dev, t);
660 l = &m->mds_md_dev.md_lu_dev;
662 obd = class_name2obd(lustre_cfg_string(cfg, 0));
663 LASSERT(obd != NULL);
666 /* set this lu_device to obd, because error handling need it */
669 rc = lprocfs_obd_setup(obd, lprocfs_mds_obd_vars);
671 mds_device_free(env, l);
676 rc = mds_start_ptlrpc_service(m);
679 mds_device_free(env, l);
686 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
687 LU_TYPE_INIT_FINI(mds, &mdt_thread_key);
689 static struct lu_device_type_operations mds_device_type_ops = {
690 .ldto_init = mds_type_init,
691 .ldto_fini = mds_type_fini,
693 .ldto_start = mds_type_start,
694 .ldto_stop = mds_type_stop,
696 .ldto_device_alloc = mds_device_alloc,
697 .ldto_device_free = mds_device_free,
698 .ldto_device_fini = mds_device_fini
701 static struct lu_device_type mds_device_type = {
702 .ldt_tags = LU_DEVICE_MD,
703 .ldt_name = LUSTRE_MDS_NAME,
704 .ldt_ops = &mds_device_type_ops,
705 .ldt_ctx_tags = LCT_MD_THREAD
708 static struct obd_ops mds_obd_device_ops = {
709 .o_owner = THIS_MODULE,
712 int mds_mod_init(void)
716 if (mdt_num_threads != 0 && mds_num_threads == 0) {
717 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated, "
718 "use mds_num_threads instead or unset both for "
719 "dynamic thread startup\n");
720 mds_num_threads = mdt_num_threads;
723 rc = class_register_type(&mds_obd_device_ops, NULL,
724 lprocfs_mds_module_vars, LUSTRE_MDS_NAME,
729 void mds_mod_exit(void)
731 class_unregister_type(LUSTRE_MDS_NAME);