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) 2011, 2012 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 #ifdef HAVE_QUOTA_SUPPORT
55 # include <lustre_quota.h>
57 #include <lustre_acl.h>
58 #include <lustre_param.h>
59 #include <lustre_fsfilt.h>
63 struct md_device mds_md_dev;
64 struct ptlrpc_service *mds_regular_service;
65 struct ptlrpc_service *mds_readpage_service;
66 struct ptlrpc_service *mds_setattr_service;
67 struct ptlrpc_service *mds_mdsc_service;
68 struct ptlrpc_service *mds_mdss_service;
69 struct ptlrpc_service *mds_fld_service;
73 * * Initialized in mdt_mod_init().
75 static unsigned long mdt_num_threads;
76 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
77 "number of MDS service threads to start "
78 "(deprecated in favor of mds_num_threads)");
80 static unsigned long mds_num_threads;
81 CFS_MODULE_PARM(mds_num_threads, "ul", ulong, 0444,
82 "number of MDS service threads to start");
84 static char *mds_num_cpts;
85 CFS_MODULE_PARM(mds_num_cpts, "c", charp, 0444,
86 "CPU partitions MDS threads should run on");
88 static unsigned long mds_rdpg_num_threads;
89 CFS_MODULE_PARM(mds_rdpg_num_threads, "ul", ulong, 0444,
90 "number of MDS readpage service threads to start");
92 static char *mds_rdpg_num_cpts;
93 CFS_MODULE_PARM(mds_rdpg_num_cpts, "c", charp, 0444,
94 "CPU partitions MDS readpage threads should run on");
96 /* NB: these two should be removed along with setattr service in the future */
97 static unsigned long mds_attr_num_threads;
98 CFS_MODULE_PARM(mds_attr_num_threads, "ul", ulong, 0444,
99 "number of MDS setattr service threads to start");
101 static char *mds_attr_num_cpts;
102 CFS_MODULE_PARM(mds_attr_num_cpts, "c", charp, 0444,
103 "CPU partitions MDS setattr threads should run on");
105 #define DEFINE_RPC_HANDLER(base, flags, opc, fn, fmt) \
108 .mh_fail_id = OBD_FAIL_ ## opc ## _NET, \
115 /* Request with a format known in advance */
116 #define DEF_MDT_HDL(flags, name, fn) \
117 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, &RQF_ ## name)
119 /* Request with a format we do not yet know */
120 #define DEF_MDT_HDL_VAR(flags, name, fn) \
121 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, NULL)
123 /* Map one non-standard request format handler. This should probably get
124 * a common OBD_SET_INFO RPC opcode instead of this mismatch. */
125 #define RQF_MDS_SET_INFO RQF_OBD_SET_INFO
127 static struct mdt_handler mdt_mds_ops[] = {
128 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
129 DEF_MDT_HDL(0, MDS_DISCONNECT, mdt_disconnect),
130 DEF_MDT_HDL(0, MDS_SET_INFO, mdt_set_info),
131 DEF_MDT_HDL(0, MDS_GET_INFO, mdt_get_info),
132 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus),
133 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
134 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME, mdt_getattr_name),
135 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_getxattr),
136 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs),
137 DEF_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
138 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
139 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
140 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_PIN, mdt_pin),
141 DEF_MDT_HDL_VAR(0, MDS_SYNC, mdt_sync),
142 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir),
143 DEF_MDT_HDL(0, MDS_QUOTACHECK, mdt_quotacheck),
144 DEF_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl)
147 #define DEF_OBD_HDL(flags, name, fn) \
148 DEFINE_RPC_HANDLER(OBD_PING, flags, name, fn, NULL)
150 static struct mdt_handler mdt_obd_ops[] = {
151 DEF_OBD_HDL(0, OBD_PING, mdt_obd_ping),
152 DEF_OBD_HDL(0, OBD_LOG_CANCEL, mdt_obd_log_cancel),
153 DEF_OBD_HDL(0, OBD_QC_CALLBACK, mdt_obd_qc_callback),
154 DEF_OBD_HDL(0, OBD_IDX_READ, mdt_obd_idx_read)
157 #define DEF_DLM_HDL_VAR(flags, name, fn) \
158 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, NULL)
159 #define DEF_DLM_HDL(flags, name, fn) \
160 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, &RQF_ ## name)
162 static struct mdt_handler mdt_dlm_ops[] = {
163 DEF_DLM_HDL (HABEO_CLAVIS, LDLM_ENQUEUE, mdt_enqueue),
164 DEF_DLM_HDL_VAR(HABEO_CLAVIS, LDLM_CONVERT, mdt_convert),
165 DEF_DLM_HDL_VAR(0, LDLM_BL_CALLBACK, mdt_bl_callback),
166 DEF_DLM_HDL_VAR(0, LDLM_CP_CALLBACK, mdt_cp_callback)
169 #define DEF_LLOG_HDL(flags, name, fn) \
170 DEFINE_RPC_HANDLER(LLOG_ORIGIN_HANDLE_CREATE, flags, name, fn, NULL)
172 static struct mdt_handler mdt_llog_ops[] = {
173 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CREATE, mdt_llog_create),
174 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
175 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
176 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_WRITE_REC, NULL),
177 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CLOSE, NULL),
178 DEF_LLOG_HDL(0, LLOG_ORIGIN_CONNECT, NULL),
179 DEF_LLOG_HDL(0, LLOG_CATINFO, NULL),
180 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
181 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
184 #define DEF_SEC_HDL(flags, name, fn) \
185 DEFINE_RPC_HANDLER(SEC_CTX_INIT, flags, name, fn, NULL)
187 static struct mdt_handler mdt_sec_ctx_ops[] = {
188 DEF_SEC_HDL(0, SEC_CTX_INIT, mdt_sec_ctx_handle),
189 DEF_SEC_HDL(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle),
190 DEF_SEC_HDL(0, SEC_CTX_FINI, mdt_sec_ctx_handle)
193 #define DEF_QUOTA_HDL(flags, name, fn) \
194 DEFINE_RPC_HANDLER(QUOTA_DQACQ, flags, name, fn, &RQF_ ## name)
196 static struct mdt_handler mdt_quota_ops[] = {
197 DEF_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq),
200 struct mdt_opc_slice mdt_regular_handlers[] = {
202 .mos_opc_start = MDS_GETATTR,
203 .mos_opc_end = MDS_LAST_OPC,
204 .mos_hs = mdt_mds_ops
207 .mos_opc_start = OBD_PING,
208 .mos_opc_end = OBD_LAST_OPC,
209 .mos_hs = mdt_obd_ops
212 .mos_opc_start = LDLM_ENQUEUE,
213 .mos_opc_end = LDLM_LAST_OPC,
214 .mos_hs = mdt_dlm_ops
217 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
218 .mos_opc_end = LLOG_LAST_OPC,
219 .mos_hs = mdt_llog_ops
222 .mos_opc_start = SEC_CTX_INIT,
223 .mos_opc_end = SEC_LAST_OPC,
224 .mos_hs = mdt_sec_ctx_ops
227 .mos_opc_start = QUOTA_DQACQ,
228 .mos_opc_end = QUOTA_LAST_OPC,
229 .mos_hs = mdt_quota_ops
236 /* Readpage/readdir handlers */
237 static struct mdt_handler mdt_readpage_ops[] = {
238 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
239 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_READPAGE, mdt_readpage),
240 /* XXX: this is ugly and should be fixed one day, see mdc_close() for
241 * detailed comments. --umka */
242 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
243 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
246 static struct mdt_opc_slice mdt_readpage_handlers[] = {
248 .mos_opc_start = MDS_GETATTR,
249 .mos_opc_end = MDS_LAST_OPC,
250 .mos_hs = mdt_readpage_ops
253 .mos_opc_start = OBD_FIRST_OPC,
254 .mos_opc_end = OBD_LAST_OPC,
255 .mos_hs = mdt_obd_ops
262 /* Sequence service handlers */
263 #define DEF_SEQ_HDL(flags, name, fn) \
264 DEFINE_RPC_HANDLER(SEQ_QUERY, flags, name, fn, &RQF_ ## name)
266 static struct mdt_handler mdt_seq_ops[] = {
267 DEF_SEQ_HDL(0, SEQ_QUERY, (void *)seq_query),
270 struct mdt_opc_slice mdt_seq_handlers[] = {
272 .mos_opc_start = SEQ_QUERY,
273 .mos_opc_end = SEQ_LAST_OPC,
274 .mos_hs = mdt_seq_ops
281 /* FID Location Database handlers */
282 #define DEF_FLD_HDL(flags, name, fn) \
283 DEFINE_RPC_HANDLER(FLD_QUERY, flags, name, fn, &RQF_ ## name)
285 static struct mdt_handler mdt_fld_ops[] = {
286 DEF_FLD_HDL(0, FLD_QUERY, (void *)fld_query),
289 struct mdt_opc_slice mdt_fld_handlers[] = {
291 .mos_opc_start = FLD_QUERY,
292 .mos_opc_end = FLD_LAST_OPC,
293 .mos_hs = mdt_fld_ops
300 static int mds_regular_handle(struct ptlrpc_request *req)
302 return mdt_handle_common(req, mdt_regular_handlers);
305 static int mds_readpage_handle(struct ptlrpc_request *req)
307 return mdt_handle_common(req, mdt_readpage_handlers);
310 static int mds_mdsc_handle(struct ptlrpc_request *req)
312 return mdt_handle_common(req, mdt_seq_handlers);
315 static int mds_mdss_handle(struct ptlrpc_request *req)
317 return mdt_handle_common(req, mdt_seq_handlers);
320 static int mds_fld_handle(struct ptlrpc_request *req)
322 return mdt_handle_common(req, mdt_fld_handlers);
325 /* device init/fini methods */
326 static void mds_stop_ptlrpc_service(struct mds_device *m)
329 if (m->mds_regular_service != NULL) {
330 ptlrpc_unregister_service(m->mds_regular_service);
331 m->mds_regular_service = NULL;
333 if (m->mds_readpage_service != NULL) {
334 ptlrpc_unregister_service(m->mds_readpage_service);
335 m->mds_readpage_service = NULL;
337 if (m->mds_setattr_service != NULL) {
338 ptlrpc_unregister_service(m->mds_setattr_service);
339 m->mds_setattr_service = NULL;
341 if (m->mds_mdsc_service != NULL) {
342 ptlrpc_unregister_service(m->mds_mdsc_service);
343 m->mds_mdsc_service = NULL;
345 if (m->mds_mdss_service != NULL) {
346 ptlrpc_unregister_service(m->mds_mdss_service);
347 m->mds_mdss_service = NULL;
349 if (m->mds_fld_service != NULL) {
350 ptlrpc_unregister_service(m->mds_fld_service);
351 m->mds_fld_service = NULL;
356 static int mds_start_ptlrpc_service(struct mds_device *m)
358 static struct ptlrpc_service_conf conf;
359 struct obd_device *obd = m->mds_md_dev.md_lu_dev.ld_obd;
360 cfs_proc_dir_entry_t *procfs_entry;
364 procfs_entry = obd->obd_proc_entry;
365 LASSERT(procfs_entry != NULL);
367 conf = (typeof(conf)) {
368 .psc_name = LUSTRE_MDT_NAME,
369 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
371 .bc_nbufs = MDS_NBUFS,
372 .bc_buf_size = MDS_BUFSIZE,
373 .bc_req_max_size = MDS_MAXREQSIZE,
374 .bc_rep_max_size = MDS_MAXREPSIZE,
375 .bc_req_portal = MDS_REQUEST_PORTAL,
376 .bc_rep_portal = MDC_REPLY_PORTAL,
379 * We'd like to have a mechanism to set this on a per-device
383 .tc_thr_name = LUSTRE_MDT_NAME,
384 .tc_thr_factor = MDS_THR_FACTOR,
385 .tc_nthrs_init = MDS_NTHRS_INIT,
386 .tc_nthrs_base = MDS_NTHRS_BASE,
387 .tc_nthrs_max = MDS_NTHRS_MAX,
388 .tc_nthrs_user = mds_num_threads,
389 .tc_cpu_affinity = 1,
390 .tc_ctx_tags = LCT_MD_THREAD,
393 .cc_pattern = mds_num_cpts,
396 .so_req_handler = mds_regular_handle,
397 .so_req_printer = target_print_req,
398 .so_hpreq_handler = ptlrpc_hpreq_handler,
401 m->mds_regular_service = ptlrpc_register_service(&conf, procfs_entry);
402 if (IS_ERR(m->mds_regular_service)) {
403 rc = PTR_ERR(m->mds_regular_service);
404 CERROR("failed to start regular mdt service: %d\n", rc);
405 m->mds_regular_service = NULL;
411 * readpage service configuration. Parameters have to be adjusted,
414 memset(&conf, 0, sizeof(conf));
415 conf = (typeof(conf)) {
416 .psc_name = LUSTRE_MDT_NAME "_readpage",
417 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
419 .bc_nbufs = MDS_NBUFS,
420 .bc_buf_size = MDS_BUFSIZE,
421 .bc_req_max_size = MDS_MAXREQSIZE,
422 .bc_rep_max_size = MDS_MAXREPSIZE,
423 .bc_req_portal = MDS_READPAGE_PORTAL,
424 .bc_rep_portal = MDC_REPLY_PORTAL,
427 .tc_thr_name = LUSTRE_MDT_NAME "_rdpg",
428 .tc_thr_factor = MDS_RDPG_THR_FACTOR,
429 .tc_nthrs_init = MDS_RDPG_NTHRS_INIT,
430 .tc_nthrs_base = MDS_RDPG_NTHRS_BASE,
431 .tc_nthrs_max = MDS_RDPG_NTHRS_MAX,
432 .tc_nthrs_user = mds_rdpg_num_threads,
433 .tc_cpu_affinity = 1,
434 .tc_ctx_tags = LCT_MD_THREAD,
437 .cc_pattern = mds_rdpg_num_cpts,
440 .so_req_handler = mds_readpage_handle,
441 .so_req_printer = target_print_req,
444 m->mds_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
445 if (IS_ERR(m->mds_readpage_service)) {
446 rc = PTR_ERR(m->mds_readpage_service);
447 CERROR("failed to start readpage service: %d\n", rc);
448 m->mds_readpage_service = NULL;
450 GOTO(err_mds_svc, rc);
454 * setattr service configuration.
456 * XXX To keep the compatibility with old client(< 2.2), we need to
457 * preserve this portal for a certain time, it should be removed
458 * eventually. LU-617.
460 memset(&conf, 0, sizeof(conf));
461 conf = (typeof(conf)) {
462 .psc_name = LUSTRE_MDT_NAME "_setattr",
463 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
465 .bc_nbufs = MDS_NBUFS,
466 .bc_buf_size = MDS_BUFSIZE,
467 .bc_req_max_size = MDS_MAXREQSIZE,
468 .bc_rep_max_size = MDS_MAXREPSIZE,
469 .bc_req_portal = MDS_SETATTR_PORTAL,
470 .bc_rep_portal = MDC_REPLY_PORTAL,
473 .tc_thr_name = LUSTRE_MDT_NAME "_attr",
474 .tc_thr_factor = MDS_SETA_THR_FACTOR,
475 .tc_nthrs_init = MDS_SETA_NTHRS_INIT,
476 .tc_nthrs_base = MDS_SETA_NTHRS_BASE,
477 .tc_nthrs_max = MDS_SETA_NTHRS_MAX,
478 .tc_nthrs_user = mds_attr_num_threads,
479 .tc_cpu_affinity = 1,
480 .tc_ctx_tags = LCT_MD_THREAD,
483 .cc_pattern = mds_attr_num_cpts,
486 .so_req_handler = mds_regular_handle,
487 .so_req_printer = target_print_req,
488 .so_hpreq_handler = NULL,
491 m->mds_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
492 if (IS_ERR(m->mds_setattr_service)) {
493 rc = PTR_ERR(m->mds_setattr_service);
494 CERROR("failed to start setattr service: %d\n", rc);
495 m->mds_setattr_service = NULL;
497 GOTO(err_mds_svc, rc);
501 * sequence controller service configuration
503 memset(&conf, 0, sizeof(conf));
504 conf = (typeof(conf)) {
505 .psc_name = LUSTRE_MDT_NAME "_seqs",
506 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
508 .bc_nbufs = MDS_NBUFS,
509 .bc_buf_size = MDS_BUFSIZE,
510 .bc_req_max_size = SEQ_MAXREQSIZE,
511 .bc_rep_max_size = SEQ_MAXREPSIZE,
512 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
513 .bc_rep_portal = MDC_REPLY_PORTAL,
516 .tc_thr_name = LUSTRE_MDT_NAME "_seqs",
517 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
518 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
519 .tc_ctx_tags = LCT_MD_THREAD,
522 .so_req_handler = mds_mdsc_handle,
523 .so_req_printer = target_print_req,
524 .so_hpreq_handler = NULL,
527 m->mds_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
528 if (IS_ERR(m->mds_mdsc_service)) {
529 rc = PTR_ERR(m->mds_mdsc_service);
530 CERROR("failed to start seq controller service: %d\n", rc);
531 m->mds_mdsc_service = NULL;
533 GOTO(err_mds_svc, rc);
537 * metadata sequence server service configuration
539 memset(&conf, 0, sizeof(conf));
540 conf = (typeof(conf)) {
541 .psc_name = LUSTRE_MDT_NAME "_seqm",
542 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
544 .bc_nbufs = MDS_NBUFS,
545 .bc_buf_size = MDS_BUFSIZE,
546 .bc_req_max_size = SEQ_MAXREQSIZE,
547 .bc_rep_max_size = SEQ_MAXREPSIZE,
548 .bc_req_portal = SEQ_METADATA_PORTAL,
549 .bc_rep_portal = MDC_REPLY_PORTAL,
552 .tc_thr_name = LUSTRE_MDT_NAME "_seqm",
553 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
554 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
555 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
558 .so_req_handler = mds_mdss_handle,
559 .so_req_printer = target_print_req,
560 .so_hpreq_handler = NULL,
563 m->mds_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
564 if (IS_ERR(m->mds_mdss_service)) {
565 rc = PTR_ERR(m->mds_mdss_service);
566 CERROR("failed to start metadata seq server service: %d\n", rc);
567 m->mds_mdss_service = NULL;
569 GOTO(err_mds_svc, rc);
572 /* FLD service start */
573 memset(&conf, 0, sizeof(conf));
574 conf = (typeof(conf)) {
575 .psc_name = LUSTRE_MDT_NAME "_fld",
576 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
578 .bc_nbufs = MDS_NBUFS,
579 .bc_buf_size = MDS_BUFSIZE,
580 .bc_req_max_size = FLD_MAXREQSIZE,
581 .bc_rep_max_size = FLD_MAXREPSIZE,
582 .bc_req_portal = FLD_REQUEST_PORTAL,
583 .bc_rep_portal = MDC_REPLY_PORTAL,
586 .tc_thr_name = LUSTRE_MDT_NAME "_fld",
587 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
588 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
589 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
592 .so_req_handler = mds_fld_handle,
593 .so_req_printer = target_print_req,
594 .so_hpreq_handler = NULL,
597 m->mds_fld_service = ptlrpc_register_service(&conf, procfs_entry);
598 if (IS_ERR(m->mds_fld_service)) {
599 rc = PTR_ERR(m->mds_fld_service);
600 CERROR("failed to start fld service: %d\n", rc);
601 m->mds_fld_service = NULL;
603 GOTO(err_mds_svc, rc);
609 mds_stop_ptlrpc_service(m);
614 static inline struct mds_device *mds_dev(struct lu_device *d)
616 return container_of0(d, struct mds_device, mds_md_dev.md_lu_dev);
619 static struct lu_device *mds_device_fini(const struct lu_env *env,
622 struct mds_device *m = mds_dev(d);
623 struct obd_device *obd = d->ld_obd;
626 mds_stop_ptlrpc_service(m);
627 lprocfs_obd_cleanup(obd);
631 static struct lu_device *mds_device_free(const struct lu_env *env,
634 struct mds_device *m = mds_dev(d);
637 md_device_fini(&m->mds_md_dev);
642 static struct lu_device *mds_device_alloc(const struct lu_env *env,
643 struct lu_device_type *t,
644 struct lustre_cfg *cfg)
646 struct mds_device *m;
647 struct obd_device *obd;
653 return ERR_PTR(-ENOMEM);
655 md_device_init(&m->mds_md_dev, t);
656 l = &m->mds_md_dev.md_lu_dev;
658 obd = class_name2obd(lustre_cfg_string(cfg, 0));
659 LASSERT(obd != NULL);
662 /* set this lu_device to obd, because error handling need it */
665 rc = lprocfs_obd_setup(obd, lprocfs_mds_obd_vars);
667 mds_device_free(env, l);
672 rc = mds_start_ptlrpc_service(m);
675 mds_device_free(env, l);
683 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
684 LU_TYPE_INIT_FINI(mds, &mdt_thread_key);
686 static struct lu_device_type_operations mds_device_type_ops = {
687 .ldto_init = mds_type_init,
688 .ldto_fini = mds_type_fini,
690 .ldto_start = mds_type_start,
691 .ldto_stop = mds_type_stop,
693 .ldto_device_alloc = mds_device_alloc,
694 .ldto_device_free = mds_device_free,
695 .ldto_device_fini = mds_device_fini
698 static struct lu_device_type mds_device_type = {
699 .ldt_tags = LU_DEVICE_MD,
700 .ldt_name = LUSTRE_MDS_NAME,
701 .ldt_ops = &mds_device_type_ops,
702 .ldt_ctx_tags = LCT_MD_THREAD
705 static struct obd_ops mds_obd_device_ops = {
706 .o_owner = THIS_MODULE,
709 int mds_mod_init(void)
713 if (mdt_num_threads != 0 && mds_num_threads == 0) {
714 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated, "
715 "use mds_num_threads instead or unset both for "
716 "dynamic thread startup\n");
717 mds_num_threads = mdt_num_threads;
720 rc = class_register_type(&mds_obd_device_ops, NULL,
721 lprocfs_mds_module_vars, LUSTRE_MDS_NAME,
726 void mds_mod_exit(void)
728 class_unregister_type(LUSTRE_MDS_NAME);