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),
145 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_HSM_PROGRESS, mdt_hsm_progress),
146 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_HSM_CT_REGISTER,
147 mdt_hsm_ct_register),
148 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_HSM_CT_UNREGISTER,
149 mdt_hsm_ct_unregister),
150 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_GET,
152 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_SET,
156 #define DEF_OBD_HDL(flags, name, fn) \
157 DEFINE_RPC_HANDLER(OBD_PING, flags, name, fn, NULL)
159 static struct mdt_handler mdt_obd_ops[] = {
160 DEF_OBD_HDL(0, OBD_PING, mdt_obd_ping),
161 DEF_OBD_HDL(0, OBD_LOG_CANCEL, mdt_obd_log_cancel),
162 DEF_OBD_HDL(0, OBD_QC_CALLBACK, mdt_obd_qc_callback),
163 DEF_OBD_HDL(0, OBD_IDX_READ, mdt_obd_idx_read)
166 #define DEF_DLM_HDL_VAR(flags, name, fn) \
167 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, NULL)
168 #define DEF_DLM_HDL(flags, name, fn) \
169 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, &RQF_ ## name)
171 static struct mdt_handler mdt_dlm_ops[] = {
172 DEF_DLM_HDL (HABEO_CLAVIS, LDLM_ENQUEUE, mdt_enqueue),
173 DEF_DLM_HDL_VAR(HABEO_CLAVIS, LDLM_CONVERT, mdt_convert),
174 DEF_DLM_HDL_VAR(0, LDLM_BL_CALLBACK, mdt_bl_callback),
175 DEF_DLM_HDL_VAR(0, LDLM_CP_CALLBACK, mdt_cp_callback)
178 #define DEF_LLOG_HDL(flags, name, fn) \
179 DEFINE_RPC_HANDLER(LLOG_ORIGIN_HANDLE_CREATE, flags, name, fn, NULL)
181 static struct mdt_handler mdt_llog_ops[] = {
182 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CREATE, mdt_llog_create),
183 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
184 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
185 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_WRITE_REC, NULL),
186 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CLOSE, NULL),
187 DEF_LLOG_HDL(0, LLOG_ORIGIN_CONNECT, NULL),
188 DEF_LLOG_HDL(0, LLOG_CATINFO, NULL),
189 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
190 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
193 #define DEF_SEC_HDL(flags, name, fn) \
194 DEFINE_RPC_HANDLER(SEC_CTX_INIT, flags, name, fn, NULL)
196 static struct mdt_handler mdt_sec_ctx_ops[] = {
197 DEF_SEC_HDL(0, SEC_CTX_INIT, mdt_sec_ctx_handle),
198 DEF_SEC_HDL(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle),
199 DEF_SEC_HDL(0, SEC_CTX_FINI, mdt_sec_ctx_handle)
202 #define DEF_QUOTA_HDL(flags, name, fn) \
203 DEFINE_RPC_HANDLER(QUOTA_DQACQ, flags, name, fn, &RQF_ ## name)
205 static struct mdt_handler mdt_quota_ops[] = {
206 DEF_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq),
209 struct mdt_opc_slice mdt_regular_handlers[] = {
211 .mos_opc_start = MDS_GETATTR,
212 .mos_opc_end = MDS_LAST_OPC,
213 .mos_hs = mdt_mds_ops
216 .mos_opc_start = OBD_PING,
217 .mos_opc_end = OBD_LAST_OPC,
218 .mos_hs = mdt_obd_ops
221 .mos_opc_start = LDLM_ENQUEUE,
222 .mos_opc_end = LDLM_LAST_OPC,
223 .mos_hs = mdt_dlm_ops
226 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
227 .mos_opc_end = LLOG_LAST_OPC,
228 .mos_hs = mdt_llog_ops
231 .mos_opc_start = SEC_CTX_INIT,
232 .mos_opc_end = SEC_LAST_OPC,
233 .mos_hs = mdt_sec_ctx_ops
236 .mos_opc_start = QUOTA_DQACQ,
237 .mos_opc_end = QUOTA_LAST_OPC,
238 .mos_hs = mdt_quota_ops
245 /* Readpage/readdir handlers */
246 static struct mdt_handler mdt_readpage_ops[] = {
247 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
248 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_READPAGE, mdt_readpage),
249 /* XXX: this is ugly and should be fixed one day, see mdc_close() for
250 * detailed comments. --umka */
251 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
252 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
255 static struct mdt_opc_slice mdt_readpage_handlers[] = {
257 .mos_opc_start = MDS_GETATTR,
258 .mos_opc_end = MDS_LAST_OPC,
259 .mos_hs = mdt_readpage_ops
262 .mos_opc_start = OBD_FIRST_OPC,
263 .mos_opc_end = OBD_LAST_OPC,
264 .mos_hs = mdt_obd_ops
271 /* Sequence service handlers */
272 #define DEF_SEQ_HDL(flags, name, fn) \
273 DEFINE_RPC_HANDLER(SEQ_QUERY, flags, name, fn, &RQF_ ## name)
275 static struct mdt_handler mdt_seq_ops[] = {
276 DEF_SEQ_HDL(0, SEQ_QUERY, (void *)seq_query),
279 struct mdt_opc_slice mdt_seq_handlers[] = {
281 .mos_opc_start = SEQ_QUERY,
282 .mos_opc_end = SEQ_LAST_OPC,
283 .mos_hs = mdt_seq_ops
290 /* FID Location Database handlers */
291 #define DEF_FLD_HDL(flags, name, fn) \
292 DEFINE_RPC_HANDLER(FLD_QUERY, flags, name, fn, &RQF_ ## name)
294 static struct mdt_handler mdt_fld_ops[] = {
295 DEF_FLD_HDL(0, FLD_QUERY, (void *)fld_query),
298 struct mdt_opc_slice mdt_fld_handlers[] = {
300 .mos_opc_start = FLD_QUERY,
301 .mos_opc_end = FLD_LAST_OPC,
302 .mos_hs = mdt_fld_ops
309 static int mds_regular_handle(struct ptlrpc_request *req)
311 return mdt_handle_common(req, mdt_regular_handlers);
314 static int mds_readpage_handle(struct ptlrpc_request *req)
316 return mdt_handle_common(req, mdt_readpage_handlers);
319 static int mds_mdsc_handle(struct ptlrpc_request *req)
321 return mdt_handle_common(req, mdt_seq_handlers);
324 static int mds_mdss_handle(struct ptlrpc_request *req)
326 return mdt_handle_common(req, mdt_seq_handlers);
329 static int mds_fld_handle(struct ptlrpc_request *req)
331 return mdt_handle_common(req, mdt_fld_handlers);
334 /* device init/fini methods */
335 static void mds_stop_ptlrpc_service(struct mds_device *m)
338 if (m->mds_regular_service != NULL) {
339 ptlrpc_unregister_service(m->mds_regular_service);
340 m->mds_regular_service = NULL;
342 if (m->mds_readpage_service != NULL) {
343 ptlrpc_unregister_service(m->mds_readpage_service);
344 m->mds_readpage_service = NULL;
346 if (m->mds_setattr_service != NULL) {
347 ptlrpc_unregister_service(m->mds_setattr_service);
348 m->mds_setattr_service = NULL;
350 if (m->mds_mdsc_service != NULL) {
351 ptlrpc_unregister_service(m->mds_mdsc_service);
352 m->mds_mdsc_service = NULL;
354 if (m->mds_mdss_service != NULL) {
355 ptlrpc_unregister_service(m->mds_mdss_service);
356 m->mds_mdss_service = NULL;
358 if (m->mds_fld_service != NULL) {
359 ptlrpc_unregister_service(m->mds_fld_service);
360 m->mds_fld_service = NULL;
365 static int mds_start_ptlrpc_service(struct mds_device *m)
367 static struct ptlrpc_service_conf conf;
368 struct obd_device *obd = m->mds_md_dev.md_lu_dev.ld_obd;
369 cfs_proc_dir_entry_t *procfs_entry;
373 procfs_entry = obd->obd_proc_entry;
374 LASSERT(procfs_entry != NULL);
376 conf = (typeof(conf)) {
377 .psc_name = LUSTRE_MDT_NAME,
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_REQUEST_PORTAL,
385 .bc_rep_portal = MDC_REPLY_PORTAL,
388 * We'd like to have a mechanism to set this on a per-device
392 .tc_thr_name = LUSTRE_MDT_NAME,
393 .tc_thr_factor = MDS_THR_FACTOR,
394 .tc_nthrs_init = MDS_NTHRS_INIT,
395 .tc_nthrs_base = MDS_NTHRS_BASE,
396 .tc_nthrs_max = MDS_NTHRS_MAX,
397 .tc_nthrs_user = mds_num_threads,
398 .tc_cpu_affinity = 1,
399 .tc_ctx_tags = LCT_MD_THREAD,
402 .cc_pattern = mds_num_cpts,
405 .so_req_handler = mds_regular_handle,
406 .so_req_printer = target_print_req,
407 .so_hpreq_handler = ptlrpc_hpreq_handler,
410 m->mds_regular_service = ptlrpc_register_service(&conf, procfs_entry);
411 if (IS_ERR(m->mds_regular_service)) {
412 rc = PTR_ERR(m->mds_regular_service);
413 CERROR("failed to start regular mdt service: %d\n", rc);
414 m->mds_regular_service = NULL;
420 * readpage service configuration. Parameters have to be adjusted,
423 memset(&conf, 0, sizeof(conf));
424 conf = (typeof(conf)) {
425 .psc_name = LUSTRE_MDT_NAME "_readpage",
426 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
428 .bc_nbufs = MDS_NBUFS,
429 .bc_buf_size = MDS_BUFSIZE,
430 .bc_req_max_size = MDS_MAXREQSIZE,
431 .bc_rep_max_size = MDS_MAXREPSIZE,
432 .bc_req_portal = MDS_READPAGE_PORTAL,
433 .bc_rep_portal = MDC_REPLY_PORTAL,
436 .tc_thr_name = LUSTRE_MDT_NAME "_rdpg",
437 .tc_thr_factor = MDS_RDPG_THR_FACTOR,
438 .tc_nthrs_init = MDS_RDPG_NTHRS_INIT,
439 .tc_nthrs_base = MDS_RDPG_NTHRS_BASE,
440 .tc_nthrs_max = MDS_RDPG_NTHRS_MAX,
441 .tc_nthrs_user = mds_rdpg_num_threads,
442 .tc_cpu_affinity = 1,
443 .tc_ctx_tags = LCT_MD_THREAD,
446 .cc_pattern = mds_rdpg_num_cpts,
449 .so_req_handler = mds_readpage_handle,
450 .so_req_printer = target_print_req,
453 m->mds_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
454 if (IS_ERR(m->mds_readpage_service)) {
455 rc = PTR_ERR(m->mds_readpage_service);
456 CERROR("failed to start readpage service: %d\n", rc);
457 m->mds_readpage_service = NULL;
459 GOTO(err_mds_svc, rc);
463 * setattr service configuration.
465 * XXX To keep the compatibility with old client(< 2.2), we need to
466 * preserve this portal for a certain time, it should be removed
467 * eventually. LU-617.
469 memset(&conf, 0, sizeof(conf));
470 conf = (typeof(conf)) {
471 .psc_name = LUSTRE_MDT_NAME "_setattr",
472 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
474 .bc_nbufs = MDS_NBUFS,
475 .bc_buf_size = MDS_BUFSIZE,
476 .bc_req_max_size = MDS_MAXREQSIZE,
477 .bc_rep_max_size = MDS_MAXREPSIZE,
478 .bc_req_portal = MDS_SETATTR_PORTAL,
479 .bc_rep_portal = MDC_REPLY_PORTAL,
482 .tc_thr_name = LUSTRE_MDT_NAME "_attr",
483 .tc_thr_factor = MDS_SETA_THR_FACTOR,
484 .tc_nthrs_init = MDS_SETA_NTHRS_INIT,
485 .tc_nthrs_base = MDS_SETA_NTHRS_BASE,
486 .tc_nthrs_max = MDS_SETA_NTHRS_MAX,
487 .tc_nthrs_user = mds_attr_num_threads,
488 .tc_cpu_affinity = 1,
489 .tc_ctx_tags = LCT_MD_THREAD,
492 .cc_pattern = mds_attr_num_cpts,
495 .so_req_handler = mds_regular_handle,
496 .so_req_printer = target_print_req,
497 .so_hpreq_handler = NULL,
500 m->mds_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
501 if (IS_ERR(m->mds_setattr_service)) {
502 rc = PTR_ERR(m->mds_setattr_service);
503 CERROR("failed to start setattr service: %d\n", rc);
504 m->mds_setattr_service = NULL;
506 GOTO(err_mds_svc, rc);
510 * sequence controller service configuration
512 memset(&conf, 0, sizeof(conf));
513 conf = (typeof(conf)) {
514 .psc_name = LUSTRE_MDT_NAME "_seqs",
515 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
517 .bc_nbufs = MDS_NBUFS,
518 .bc_buf_size = MDS_BUFSIZE,
519 .bc_req_max_size = SEQ_MAXREQSIZE,
520 .bc_rep_max_size = SEQ_MAXREPSIZE,
521 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
522 .bc_rep_portal = MDC_REPLY_PORTAL,
525 .tc_thr_name = LUSTRE_MDT_NAME "_seqs",
526 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
527 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
528 .tc_ctx_tags = LCT_MD_THREAD,
531 .so_req_handler = mds_mdsc_handle,
532 .so_req_printer = target_print_req,
533 .so_hpreq_handler = NULL,
536 m->mds_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
537 if (IS_ERR(m->mds_mdsc_service)) {
538 rc = PTR_ERR(m->mds_mdsc_service);
539 CERROR("failed to start seq controller service: %d\n", rc);
540 m->mds_mdsc_service = NULL;
542 GOTO(err_mds_svc, rc);
546 * metadata sequence server service configuration
548 memset(&conf, 0, sizeof(conf));
549 conf = (typeof(conf)) {
550 .psc_name = LUSTRE_MDT_NAME "_seqm",
551 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
553 .bc_nbufs = MDS_NBUFS,
554 .bc_buf_size = MDS_BUFSIZE,
555 .bc_req_max_size = SEQ_MAXREQSIZE,
556 .bc_rep_max_size = SEQ_MAXREPSIZE,
557 .bc_req_portal = SEQ_METADATA_PORTAL,
558 .bc_rep_portal = MDC_REPLY_PORTAL,
561 .tc_thr_name = LUSTRE_MDT_NAME "_seqm",
562 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
563 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
564 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
567 .so_req_handler = mds_mdss_handle,
568 .so_req_printer = target_print_req,
569 .so_hpreq_handler = NULL,
572 m->mds_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
573 if (IS_ERR(m->mds_mdss_service)) {
574 rc = PTR_ERR(m->mds_mdss_service);
575 CERROR("failed to start metadata seq server service: %d\n", rc);
576 m->mds_mdss_service = NULL;
578 GOTO(err_mds_svc, rc);
581 /* FLD service start */
582 memset(&conf, 0, sizeof(conf));
583 conf = (typeof(conf)) {
584 .psc_name = LUSTRE_MDT_NAME "_fld",
585 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
587 .bc_nbufs = MDS_NBUFS,
588 .bc_buf_size = MDS_BUFSIZE,
589 .bc_req_max_size = FLD_MAXREQSIZE,
590 .bc_rep_max_size = FLD_MAXREPSIZE,
591 .bc_req_portal = FLD_REQUEST_PORTAL,
592 .bc_rep_portal = MDC_REPLY_PORTAL,
595 .tc_thr_name = LUSTRE_MDT_NAME "_fld",
596 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
597 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
598 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
601 .so_req_handler = mds_fld_handle,
602 .so_req_printer = target_print_req,
603 .so_hpreq_handler = NULL,
606 m->mds_fld_service = ptlrpc_register_service(&conf, procfs_entry);
607 if (IS_ERR(m->mds_fld_service)) {
608 rc = PTR_ERR(m->mds_fld_service);
609 CERROR("failed to start fld service: %d\n", rc);
610 m->mds_fld_service = NULL;
612 GOTO(err_mds_svc, rc);
618 mds_stop_ptlrpc_service(m);
623 static inline struct mds_device *mds_dev(struct lu_device *d)
625 return container_of0(d, struct mds_device, mds_md_dev.md_lu_dev);
628 static struct lu_device *mds_device_fini(const struct lu_env *env,
631 struct mds_device *m = mds_dev(d);
632 struct obd_device *obd = d->ld_obd;
635 mds_stop_ptlrpc_service(m);
636 lprocfs_obd_cleanup(obd);
640 static struct lu_device *mds_device_free(const struct lu_env *env,
643 struct mds_device *m = mds_dev(d);
646 md_device_fini(&m->mds_md_dev);
651 static struct lu_device *mds_device_alloc(const struct lu_env *env,
652 struct lu_device_type *t,
653 struct lustre_cfg *cfg)
655 struct mds_device *m;
656 struct obd_device *obd;
662 return ERR_PTR(-ENOMEM);
664 md_device_init(&m->mds_md_dev, t);
665 l = &m->mds_md_dev.md_lu_dev;
667 obd = class_name2obd(lustre_cfg_string(cfg, 0));
668 LASSERT(obd != NULL);
671 /* set this lu_device to obd, because error handling need it */
674 rc = lprocfs_obd_setup(obd, lprocfs_mds_obd_vars);
676 mds_device_free(env, l);
681 rc = mds_start_ptlrpc_service(m);
684 mds_device_free(env, l);
692 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
693 LU_TYPE_INIT_FINI(mds, &mdt_thread_key);
695 static struct lu_device_type_operations mds_device_type_ops = {
696 .ldto_init = mds_type_init,
697 .ldto_fini = mds_type_fini,
699 .ldto_start = mds_type_start,
700 .ldto_stop = mds_type_stop,
702 .ldto_device_alloc = mds_device_alloc,
703 .ldto_device_free = mds_device_free,
704 .ldto_device_fini = mds_device_fini
707 static struct lu_device_type mds_device_type = {
708 .ldt_tags = LU_DEVICE_MD,
709 .ldt_name = LUSTRE_MDS_NAME,
710 .ldt_ops = &mds_device_type_ops,
711 .ldt_ctx_tags = LCT_MD_THREAD
714 static struct obd_ops mds_obd_device_ops = {
715 .o_owner = THIS_MODULE,
718 int mds_mod_init(void)
722 if (mdt_num_threads != 0 && mds_num_threads == 0) {
723 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated, "
724 "use mds_num_threads instead or unset both for "
725 "dynamic thread startup\n");
726 mds_num_threads = mdt_num_threads;
729 rc = class_register_type(&mds_obd_device_ops, NULL,
730 lprocfs_mds_module_vars, LUSTRE_MDS_NAME,
735 void mds_mod_exit(void)
737 class_unregister_type(LUSTRE_MDS_NAME);