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, 2015, 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 <uapi/linux/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;
67 struct mutex mds_health_mutex;
71 * * Initialized in mds_mod_init().
73 static unsigned long mds_num_threads;
74 module_param(mds_num_threads, ulong, 0444);
75 MODULE_PARM_DESC(mds_num_threads, "number of MDS service threads to start");
77 static char *mds_num_cpts;
78 module_param(mds_num_cpts, charp, 0444);
79 MODULE_PARM_DESC(mds_num_cpts, "CPU partitions MDS threads should run on");
81 static unsigned long mds_rdpg_num_threads;
82 module_param(mds_rdpg_num_threads, ulong, 0444);
83 MODULE_PARM_DESC(mds_rdpg_num_threads,
84 "number of MDS readpage service threads to start");
86 static char *mds_rdpg_num_cpts;
87 module_param(mds_rdpg_num_cpts, charp, 0444);
88 MODULE_PARM_DESC(mds_rdpg_num_cpts,
89 "CPU partitions MDS readpage threads should run on");
91 /* NB: these two should be removed along with setattr service in the future */
92 static unsigned long mds_attr_num_threads;
93 module_param(mds_attr_num_threads, ulong, 0444);
94 MODULE_PARM_DESC(mds_attr_num_threads,
95 "number of MDS setattr service threads to start");
97 static char *mds_attr_num_cpts;
98 module_param(mds_attr_num_cpts, charp, 0444);
99 MODULE_PARM_DESC(mds_attr_num_cpts,
100 "CPU partitions MDS setattr threads should run on");
102 /* device init/fini methods */
103 static void mds_stop_ptlrpc_service(struct mds_device *m)
107 mutex_lock(&m->mds_health_mutex);
108 if (m->mds_regular_service != NULL) {
109 ptlrpc_unregister_service(m->mds_regular_service);
110 m->mds_regular_service = NULL;
112 if (m->mds_readpage_service != NULL) {
113 ptlrpc_unregister_service(m->mds_readpage_service);
114 m->mds_readpage_service = NULL;
116 if (m->mds_out_service != NULL) {
117 ptlrpc_unregister_service(m->mds_out_service);
118 m->mds_out_service = NULL;
120 if (m->mds_setattr_service != NULL) {
121 ptlrpc_unregister_service(m->mds_setattr_service);
122 m->mds_setattr_service = NULL;
124 if (m->mds_mdsc_service != NULL) {
125 ptlrpc_unregister_service(m->mds_mdsc_service);
126 m->mds_mdsc_service = NULL;
128 if (m->mds_mdss_service != NULL) {
129 ptlrpc_unregister_service(m->mds_mdss_service);
130 m->mds_mdss_service = NULL;
132 if (m->mds_fld_service != NULL) {
133 ptlrpc_unregister_service(m->mds_fld_service);
134 m->mds_fld_service = NULL;
136 mutex_unlock(&m->mds_health_mutex);
141 static int mds_start_ptlrpc_service(struct mds_device *m)
143 static struct ptlrpc_service_conf conf;
144 struct obd_device *obd = m->mds_md_dev.md_lu_dev.ld_obd;
145 struct proc_dir_entry *procfs_entry;
149 procfs_entry = obd->obd_proc_entry;
150 LASSERT(procfs_entry != NULL);
152 conf = (typeof(conf)) {
153 .psc_name = LUSTRE_MDT_NAME,
154 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
156 .bc_nbufs = MDS_NBUFS,
157 .bc_buf_size = MDS_REG_BUFSIZE,
158 .bc_req_max_size = MDS_REG_MAXREQSIZE,
159 .bc_rep_max_size = MDS_REG_MAXREPSIZE,
160 .bc_req_portal = MDS_REQUEST_PORTAL,
161 .bc_rep_portal = MDC_REPLY_PORTAL,
164 * We'd like to have a mechanism to set this on a per-device
168 .tc_thr_name = LUSTRE_MDT_NAME,
169 .tc_thr_factor = MDS_THR_FACTOR,
170 .tc_nthrs_init = MDS_NTHRS_INIT,
171 .tc_nthrs_base = MDS_NTHRS_BASE,
172 .tc_nthrs_max = MDS_NTHRS_MAX,
173 .tc_nthrs_user = mds_num_threads,
174 .tc_cpu_affinity = 1,
175 .tc_ctx_tags = LCT_MD_THREAD,
178 .cc_pattern = mds_num_cpts,
181 .so_req_handler = tgt_request_handle,
182 .so_req_printer = target_print_req,
183 .so_hpreq_handler = ptlrpc_hpreq_handler,
186 m->mds_regular_service = ptlrpc_register_service(&conf, procfs_entry);
187 if (IS_ERR(m->mds_regular_service)) {
188 rc = PTR_ERR(m->mds_regular_service);
189 CERROR("failed to start regular mdt service: %d\n", rc);
190 m->mds_regular_service = NULL;
196 * readpage service configuration. Parameters have to be adjusted,
199 memset(&conf, 0, sizeof(conf));
200 conf = (typeof(conf)) {
201 .psc_name = LUSTRE_MDT_NAME "_readpage",
202 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
204 .bc_nbufs = MDS_NBUFS,
205 .bc_buf_size = MDS_BUFSIZE,
206 .bc_req_max_size = MDS_MAXREQSIZE,
207 .bc_rep_max_size = MDS_MAXREPSIZE,
208 .bc_req_portal = MDS_READPAGE_PORTAL,
209 .bc_rep_portal = MDC_REPLY_PORTAL,
212 .tc_thr_name = LUSTRE_MDT_NAME "_rdpg",
213 .tc_thr_factor = MDS_RDPG_THR_FACTOR,
214 .tc_nthrs_init = MDS_RDPG_NTHRS_INIT,
215 .tc_nthrs_base = MDS_RDPG_NTHRS_BASE,
216 .tc_nthrs_max = MDS_RDPG_NTHRS_MAX,
217 .tc_nthrs_user = mds_rdpg_num_threads,
218 .tc_cpu_affinity = 1,
219 .tc_ctx_tags = LCT_MD_THREAD,
222 .cc_pattern = mds_rdpg_num_cpts,
225 .so_req_handler = tgt_request_handle,
226 .so_req_printer = target_print_req,
229 m->mds_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
230 if (IS_ERR(m->mds_readpage_service)) {
231 rc = PTR_ERR(m->mds_readpage_service);
232 CERROR("failed to start readpage service: %d\n", rc);
233 m->mds_readpage_service = NULL;
235 GOTO(err_mds_svc, rc);
239 * setattr service configuration.
241 * XXX To keep the compatibility with old client(< 2.2), we need to
242 * preserve this portal for a certain time, it should be removed
243 * eventually. LU-617.
245 memset(&conf, 0, sizeof(conf));
246 conf = (typeof(conf)) {
247 .psc_name = LUSTRE_MDT_NAME "_setattr",
248 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
250 .bc_nbufs = MDS_NBUFS,
251 .bc_buf_size = MDS_BUFSIZE,
252 .bc_req_max_size = MDS_MAXREQSIZE,
253 .bc_rep_max_size = MDS_LOV_MAXREPSIZE,
254 .bc_req_portal = MDS_SETATTR_PORTAL,
255 .bc_rep_portal = MDC_REPLY_PORTAL,
258 .tc_thr_name = LUSTRE_MDT_NAME "_attr",
259 .tc_thr_factor = MDS_SETA_THR_FACTOR,
260 .tc_nthrs_init = MDS_SETA_NTHRS_INIT,
261 .tc_nthrs_base = MDS_SETA_NTHRS_BASE,
262 .tc_nthrs_max = MDS_SETA_NTHRS_MAX,
263 .tc_nthrs_user = mds_attr_num_threads,
264 .tc_cpu_affinity = 1,
265 .tc_ctx_tags = LCT_MD_THREAD,
268 .cc_pattern = mds_attr_num_cpts,
271 .so_req_handler = tgt_request_handle,
272 .so_req_printer = target_print_req,
273 .so_hpreq_handler = NULL,
276 m->mds_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
277 if (IS_ERR(m->mds_setattr_service)) {
278 rc = PTR_ERR(m->mds_setattr_service);
279 CERROR("failed to start setattr service: %d\n", rc);
280 m->mds_setattr_service = NULL;
282 GOTO(err_mds_svc, rc);
285 /* Object update service */
286 conf = (typeof(conf)) {
287 .psc_name = LUSTRE_MDT_NAME "_out",
288 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
290 .bc_nbufs = MDS_NBUFS,
291 .bc_buf_size = OUT_BUFSIZE,
292 .bc_req_max_size = OUT_MAXREQSIZE,
293 .bc_rep_max_size = OUT_MAXREPSIZE,
294 .bc_req_portal = OUT_PORTAL,
295 .bc_rep_portal = OSC_REPLY_PORTAL,
298 * We'd like to have a mechanism to set this on a per-device
302 .tc_thr_name = LUSTRE_MDT_NAME "_out",
303 .tc_thr_factor = MDS_THR_FACTOR,
304 .tc_nthrs_init = MDS_NTHRS_INIT,
305 .tc_nthrs_base = MDS_NTHRS_BASE,
306 .tc_nthrs_max = MDS_NTHRS_MAX,
307 .tc_nthrs_user = mds_num_threads,
308 .tc_cpu_affinity = 1,
309 .tc_ctx_tags = LCT_MD_THREAD |
313 .cc_pattern = mds_num_cpts,
316 .so_req_handler = tgt_request_handle,
317 .so_req_printer = target_print_req,
318 .so_hpreq_handler = NULL,
321 m->mds_out_service = ptlrpc_register_service(&conf, procfs_entry);
322 if (IS_ERR(m->mds_out_service)) {
323 rc = PTR_ERR(m->mds_out_service);
324 CERROR("failed to start out service: %d\n", rc);
325 m->mds_out_service = NULL;
326 GOTO(err_mds_svc, rc);
330 * sequence controller service configuration
332 memset(&conf, 0, sizeof(conf));
333 conf = (typeof(conf)) {
334 .psc_name = LUSTRE_MDT_NAME "_seqs",
335 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
337 .bc_nbufs = MDS_NBUFS,
338 .bc_buf_size = SEQ_BUFSIZE,
339 .bc_req_max_size = SEQ_MAXREQSIZE,
340 .bc_rep_max_size = SEQ_MAXREPSIZE,
341 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
342 .bc_rep_portal = MDC_REPLY_PORTAL,
345 .tc_thr_name = LUSTRE_MDT_NAME "_seqs",
346 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
347 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
348 .tc_ctx_tags = LCT_MD_THREAD,
351 .so_req_handler = tgt_request_handle,
352 .so_req_printer = target_print_req,
353 .so_hpreq_handler = NULL,
356 m->mds_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
357 if (IS_ERR(m->mds_mdsc_service)) {
358 rc = PTR_ERR(m->mds_mdsc_service);
359 CERROR("failed to start seq controller service: %d\n", rc);
360 m->mds_mdsc_service = NULL;
362 GOTO(err_mds_svc, rc);
366 * metadata sequence server service configuration
368 memset(&conf, 0, sizeof(conf));
369 conf = (typeof(conf)) {
370 .psc_name = LUSTRE_MDT_NAME "_seqm",
371 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
373 .bc_nbufs = MDS_NBUFS,
374 .bc_buf_size = SEQ_BUFSIZE,
375 .bc_req_max_size = SEQ_MAXREQSIZE,
376 .bc_rep_max_size = SEQ_MAXREPSIZE,
377 .bc_req_portal = SEQ_METADATA_PORTAL,
378 .bc_rep_portal = MDC_REPLY_PORTAL,
381 .tc_thr_name = LUSTRE_MDT_NAME "_seqm",
382 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
383 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
384 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
387 .so_req_handler = tgt_request_handle,
388 .so_req_printer = target_print_req,
389 .so_hpreq_handler = NULL,
392 m->mds_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
393 if (IS_ERR(m->mds_mdss_service)) {
394 rc = PTR_ERR(m->mds_mdss_service);
395 CERROR("failed to start metadata seq server service: %d\n", rc);
396 m->mds_mdss_service = NULL;
398 GOTO(err_mds_svc, rc);
401 /* FLD service start */
402 memset(&conf, 0, sizeof(conf));
403 conf = (typeof(conf)) {
404 .psc_name = LUSTRE_MDT_NAME "_fld",
405 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
407 .bc_nbufs = MDS_NBUFS,
408 .bc_buf_size = FLD_BUFSIZE,
409 .bc_req_max_size = FLD_MAXREQSIZE,
410 .bc_rep_max_size = FLD_MAXREPSIZE,
411 .bc_req_portal = FLD_REQUEST_PORTAL,
412 .bc_rep_portal = MDC_REPLY_PORTAL,
415 .tc_thr_name = LUSTRE_MDT_NAME "_fld",
416 .tc_nthrs_init = MDS_OTHR_NTHRS_INIT,
417 .tc_nthrs_max = MDS_OTHR_NTHRS_MAX,
418 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD,
421 .so_req_handler = tgt_request_handle,
422 .so_req_printer = target_print_req,
423 .so_hpreq_handler = NULL,
426 m->mds_fld_service = ptlrpc_register_service(&conf, procfs_entry);
427 if (IS_ERR(m->mds_fld_service)) {
428 rc = PTR_ERR(m->mds_fld_service);
429 CERROR("failed to start fld service: %d\n", rc);
430 m->mds_fld_service = NULL;
432 GOTO(err_mds_svc, rc);
438 mds_stop_ptlrpc_service(m);
443 static inline struct mds_device *mds_dev(struct lu_device *d)
445 return container_of0(d, struct mds_device, mds_md_dev.md_lu_dev);
448 static struct lu_device *mds_device_fini(const struct lu_env *env,
451 struct mds_device *m = mds_dev(d);
452 struct obd_device *obd = d->ld_obd;
455 mds_stop_ptlrpc_service(m);
456 lprocfs_obd_cleanup(obd);
460 static struct lu_device *mds_device_free(const struct lu_env *env,
463 struct mds_device *m = mds_dev(d);
466 md_device_fini(&m->mds_md_dev);
471 static struct lu_device *mds_device_alloc(const struct lu_env *env,
472 struct lu_device_type *t,
473 struct lustre_cfg *cfg)
475 struct mds_device *m;
476 struct obd_device *obd;
482 return ERR_PTR(-ENOMEM);
484 md_device_init(&m->mds_md_dev, t);
485 l = &m->mds_md_dev.md_lu_dev;
487 obd = class_name2obd(lustre_cfg_string(cfg, 0));
488 LASSERT(obd != NULL);
491 /* set this lu_device to obd, because error handling need it */
494 rc = lprocfs_obd_setup(obd, true);
496 mds_device_free(env, l);
501 mutex_init(&m->mds_health_mutex);
503 rc = mds_start_ptlrpc_service(m);
506 mds_device_free(env, l);
513 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
514 LU_TYPE_INIT_FINI(mds, &mdt_thread_key);
516 static struct lu_device_type_operations mds_device_type_ops = {
517 .ldto_init = mds_type_init,
518 .ldto_fini = mds_type_fini,
520 .ldto_start = mds_type_start,
521 .ldto_stop = mds_type_stop,
523 .ldto_device_alloc = mds_device_alloc,
524 .ldto_device_free = mds_device_free,
525 .ldto_device_fini = mds_device_fini
528 static struct lu_device_type mds_device_type = {
529 .ldt_tags = LU_DEVICE_MD,
530 .ldt_name = LUSTRE_MDS_NAME,
531 .ldt_ops = &mds_device_type_ops,
532 .ldt_ctx_tags = LCT_MD_THREAD
535 static int mds_health_check(const struct lu_env *env, struct obd_device *obd)
537 struct mds_device *mds = mds_dev(obd->obd_lu_dev);
541 mutex_lock(&mds->mds_health_mutex);
542 rc |= ptlrpc_service_health_check(mds->mds_regular_service);
543 rc |= ptlrpc_service_health_check(mds->mds_readpage_service);
544 rc |= ptlrpc_service_health_check(mds->mds_out_service);
545 rc |= ptlrpc_service_health_check(mds->mds_setattr_service);
546 rc |= ptlrpc_service_health_check(mds->mds_mdsc_service);
547 rc |= ptlrpc_service_health_check(mds->mds_mdss_service);
548 rc |= ptlrpc_service_health_check(mds->mds_fld_service);
549 mutex_unlock(&mds->mds_health_mutex);
551 return rc != 0 ? 1 : 0;
554 static struct obd_ops mds_obd_device_ops = {
555 .o_owner = THIS_MODULE,
556 .o_health_check = mds_health_check,
559 int mds_mod_init(void)
561 return class_register_type(&mds_obd_device_ops, NULL, true, NULL,
562 LUSTRE_MDS_NAME, &mds_device_type);
565 void mds_mod_exit(void)
567 class_unregister_type(LUSTRE_MDS_NAME);