Whamcloud - gitweb
LU-10308 misc: update Intel copyright messages for 2017
[fs/lustre-release.git] / lustre / mdt / mdt_mds.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9
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.
15
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2013, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/mdt/mdt_mds.c
32  *
33  * Lustre Metadata Service Layer
34  *
35  * Author: Di Wang <di.wang@whamcloud.com>
36  **/
37
38 #define DEBUG_SUBSYSTEM S_MDS
39
40 #include <linux/module.h>
41
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 */
48 #include <obd.h>
49 /* lu2dt_dev() */
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/lustre_param.h>
56
57 struct mds_device {
58         /* super-class */
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 ptlrpc_service   *mds_io_service;
68         struct mutex             mds_health_mutex;
69 };
70
71 /*
72  *  * Initialized in mds_mod_init().
73  *   */
74 static unsigned long mds_num_threads;
75 module_param(mds_num_threads, ulong, 0444);
76 MODULE_PARM_DESC(mds_num_threads, "number of MDS service threads to start");
77
78 int mds_max_io_threads = 512;
79 module_param(mds_max_io_threads, int, 0444);
80 MODULE_PARM_DESC(mds_max_io_threads, "maximum number of MDS IO service threads");
81
82 static char *mds_num_cpts;
83 module_param(mds_num_cpts, charp, 0444);
84 MODULE_PARM_DESC(mds_num_cpts, "CPU partitions MDS threads should run on");
85
86 static unsigned long mds_rdpg_num_threads;
87 module_param(mds_rdpg_num_threads, ulong, 0444);
88 MODULE_PARM_DESC(mds_rdpg_num_threads,
89                  "number of MDS readpage service threads to start");
90
91 static char *mds_rdpg_num_cpts;
92 module_param(mds_rdpg_num_cpts, charp, 0444);
93 MODULE_PARM_DESC(mds_rdpg_num_cpts,
94                  "CPU partitions MDS readpage threads should run on");
95
96 /* NB: these two should be removed along with setattr service in the future */
97 static unsigned long mds_attr_num_threads;
98 module_param(mds_attr_num_threads, ulong, 0444);
99 MODULE_PARM_DESC(mds_attr_num_threads,
100                  "number of MDS setattr service threads to start");
101
102 static char *mds_attr_num_cpts;
103 module_param(mds_attr_num_cpts, charp, 0444);
104 MODULE_PARM_DESC(mds_attr_num_cpts,
105                  "CPU partitions MDS setattr threads should run on");
106
107 /* device init/fini methods */
108 static void mds_stop_ptlrpc_service(struct mds_device *m)
109 {
110         ENTRY;
111
112         mutex_lock(&m->mds_health_mutex);
113         if (m->mds_regular_service != NULL) {
114                 ptlrpc_unregister_service(m->mds_regular_service);
115                 m->mds_regular_service = NULL;
116         }
117         if (m->mds_readpage_service != NULL) {
118                 ptlrpc_unregister_service(m->mds_readpage_service);
119                 m->mds_readpage_service = NULL;
120         }
121         if (m->mds_out_service != NULL) {
122                 ptlrpc_unregister_service(m->mds_out_service);
123                 m->mds_out_service = NULL;
124         }
125         if (m->mds_setattr_service != NULL) {
126                 ptlrpc_unregister_service(m->mds_setattr_service);
127                 m->mds_setattr_service = NULL;
128         }
129         if (m->mds_mdsc_service != NULL) {
130                 ptlrpc_unregister_service(m->mds_mdsc_service);
131                 m->mds_mdsc_service = NULL;
132         }
133         if (m->mds_mdss_service != NULL) {
134                 ptlrpc_unregister_service(m->mds_mdss_service);
135                 m->mds_mdss_service = NULL;
136         }
137         if (m->mds_fld_service != NULL) {
138                 ptlrpc_unregister_service(m->mds_fld_service);
139                 m->mds_fld_service = NULL;
140         }
141         if (m->mds_io_service != NULL) {
142                 ptlrpc_unregister_service(m->mds_io_service);
143                 m->mds_io_service = NULL;
144         }
145         mutex_unlock(&m->mds_health_mutex);
146
147         EXIT;
148 }
149
150 static int mds_start_ptlrpc_service(struct mds_device *m)
151 {
152         static struct ptlrpc_service_conf conf;
153         struct obd_device *obd = m->mds_md_dev.md_lu_dev.ld_obd;
154         struct proc_dir_entry *procfs_entry;
155         int rc = 0;
156         ENTRY;
157
158         procfs_entry = obd->obd_proc_entry;
159         LASSERT(procfs_entry != NULL);
160
161         conf = (typeof(conf)) {
162                 .psc_name               = LUSTRE_MDT_NAME,
163                 .psc_watchdog_factor    = MDT_SERVICE_WATCHDOG_FACTOR,
164                 .psc_buf                = {
165                         .bc_nbufs               = MDS_NBUFS,
166                         .bc_buf_size            = MDS_REG_BUFSIZE,
167                         .bc_req_max_size        = MDS_REG_MAXREQSIZE,
168                         .bc_rep_max_size        = MDS_REG_MAXREPSIZE,
169                         .bc_req_portal          = MDS_REQUEST_PORTAL,
170                         .bc_rep_portal          = MDC_REPLY_PORTAL,
171                 },
172                 /*
173                  * We'd like to have a mechanism to set this on a per-device
174                  * basis, but alas...
175                  */
176                 .psc_thr                = {
177                         .tc_thr_name            = LUSTRE_MDT_NAME,
178                         .tc_thr_factor          = MDS_THR_FACTOR,
179                         .tc_nthrs_init          = MDS_NTHRS_INIT,
180                         .tc_nthrs_base          = MDS_NTHRS_BASE,
181                         .tc_nthrs_max           = MDS_NTHRS_MAX,
182                         .tc_nthrs_user          = mds_num_threads,
183                         .tc_cpu_affinity        = 1,
184                         .tc_ctx_tags            = LCT_MD_THREAD,
185                 },
186                 .psc_cpt                = {
187                         .cc_pattern             = mds_num_cpts,
188                 },
189                 .psc_ops                = {
190                         .so_req_handler         = tgt_request_handle,
191                         .so_req_printer         = target_print_req,
192                         .so_hpreq_handler       = ptlrpc_hpreq_handler,
193                 },
194         };
195         m->mds_regular_service = ptlrpc_register_service(&conf, &obd->obd_kset,
196                                                          procfs_entry);
197         if (IS_ERR(m->mds_regular_service)) {
198                 rc = PTR_ERR(m->mds_regular_service);
199                 CERROR("failed to start regular mdt service: %d\n", rc);
200                 m->mds_regular_service = NULL;
201
202                 RETURN(rc);
203         }
204
205         /*
206          * readpage service configuration. Parameters have to be adjusted,
207          * ideally.
208          */
209         memset(&conf, 0, sizeof(conf));
210         conf = (typeof(conf)) {
211                 .psc_name               = LUSTRE_MDT_NAME "_readpage",
212                 .psc_watchdog_factor    = MDT_SERVICE_WATCHDOG_FACTOR,
213                 .psc_buf                = {
214                         .bc_nbufs               = MDS_NBUFS,
215                         .bc_buf_size            = MDS_BUFSIZE,
216                         .bc_req_max_size        = MDS_MAXREQSIZE,
217                         .bc_rep_max_size        = MDS_MAXREPSIZE,
218                         .bc_req_portal          = MDS_READPAGE_PORTAL,
219                         .bc_rep_portal          = MDC_REPLY_PORTAL,
220                 },
221                 .psc_thr                = {
222                         .tc_thr_name            = LUSTRE_MDT_NAME "_rdpg",
223                         .tc_thr_factor          = MDS_RDPG_THR_FACTOR,
224                         .tc_nthrs_init          = MDS_RDPG_NTHRS_INIT,
225                         .tc_nthrs_base          = MDS_RDPG_NTHRS_BASE,
226                         .tc_nthrs_max           = MDS_RDPG_NTHRS_MAX,
227                         .tc_nthrs_user          = mds_rdpg_num_threads,
228                         .tc_cpu_affinity        = 1,
229                         .tc_ctx_tags            = LCT_MD_THREAD,
230                 },
231                 .psc_cpt                = {
232                         .cc_pattern             = mds_rdpg_num_cpts,
233                 },
234                 .psc_ops                = {
235                         .so_req_handler         = tgt_request_handle,
236                         .so_req_printer         = target_print_req,
237                 },
238         };
239         m->mds_readpage_service = ptlrpc_register_service(&conf, &obd->obd_kset,
240                                                           procfs_entry);
241         if (IS_ERR(m->mds_readpage_service)) {
242                 rc = PTR_ERR(m->mds_readpage_service);
243                 CERROR("failed to start readpage service: %d\n", rc);
244                 m->mds_readpage_service = NULL;
245
246                 GOTO(err_mds_svc, rc);
247         }
248
249         /*
250          * setattr service configuration.
251          *
252          * XXX To keep the compatibility with old client(< 2.2), we need to
253          * preserve this portal for a certain time, it should be removed
254          * eventually. LU-617.
255          */
256         memset(&conf, 0, sizeof(conf));
257         conf = (typeof(conf)) {
258                 .psc_name               = LUSTRE_MDT_NAME "_setattr",
259                 .psc_watchdog_factor    = MDT_SERVICE_WATCHDOG_FACTOR,
260                 .psc_buf                = {
261                         .bc_nbufs               = MDS_NBUFS,
262                         .bc_buf_size            = MDS_BUFSIZE,
263                         .bc_req_max_size        = MDS_MAXREQSIZE,
264                         .bc_rep_max_size        = MDS_LOV_MAXREPSIZE,
265                         .bc_req_portal          = MDS_SETATTR_PORTAL,
266                         .bc_rep_portal          = MDC_REPLY_PORTAL,
267                 },
268                 .psc_thr                = {
269                         .tc_thr_name            = LUSTRE_MDT_NAME "_attr",
270                         .tc_thr_factor          = MDS_SETA_THR_FACTOR,
271                         .tc_nthrs_init          = MDS_SETA_NTHRS_INIT,
272                         .tc_nthrs_base          = MDS_SETA_NTHRS_BASE,
273                         .tc_nthrs_max           = MDS_SETA_NTHRS_MAX,
274                         .tc_nthrs_user          = mds_attr_num_threads,
275                         .tc_cpu_affinity        = 1,
276                         .tc_ctx_tags            = LCT_MD_THREAD,
277                 },
278                 .psc_cpt                = {
279                         .cc_pattern             = mds_attr_num_cpts,
280                 },
281                 .psc_ops                = {
282                         .so_req_handler         = tgt_request_handle,
283                         .so_req_printer         = target_print_req,
284                         .so_hpreq_handler       = NULL,
285                 },
286         };
287         m->mds_setattr_service = ptlrpc_register_service(&conf, &obd->obd_kset,
288                                                          procfs_entry);
289         if (IS_ERR(m->mds_setattr_service)) {
290                 rc = PTR_ERR(m->mds_setattr_service);
291                 CERROR("failed to start setattr service: %d\n", rc);
292                 m->mds_setattr_service = NULL;
293
294                 GOTO(err_mds_svc, rc);
295         }
296
297         /* Object update service */
298         conf = (typeof(conf)) {
299                 .psc_name               = LUSTRE_MDT_NAME "_out",
300                 .psc_watchdog_factor    = MDT_SERVICE_WATCHDOG_FACTOR,
301                 .psc_buf                = {
302                         .bc_nbufs               = MDS_NBUFS,
303                         .bc_buf_size            = OUT_BUFSIZE,
304                         .bc_req_max_size        = OUT_MAXREQSIZE,
305                         .bc_rep_max_size        = OUT_MAXREPSIZE,
306                         .bc_req_portal          = OUT_PORTAL,
307                         .bc_rep_portal          = OSC_REPLY_PORTAL,
308                 },
309                 /*
310                  * We'd like to have a mechanism to set this on a per-device
311                  * basis, but alas...
312                  */
313                 .psc_thr                = {
314                         .tc_thr_name            = LUSTRE_MDT_NAME "_out",
315                         .tc_thr_factor          = MDS_THR_FACTOR,
316                         .tc_nthrs_init          = MDS_NTHRS_INIT,
317                         .tc_nthrs_base          = MDS_NTHRS_BASE,
318                         .tc_nthrs_max           = MDS_NTHRS_MAX,
319                         .tc_nthrs_user          = mds_num_threads,
320                         .tc_cpu_affinity        = 1,
321                         .tc_ctx_tags            = LCT_MD_THREAD |
322                                                   LCT_DT_THREAD,
323                 },
324                 .psc_cpt                = {
325                         .cc_pattern             = mds_num_cpts,
326                 },
327                 .psc_ops                = {
328                         .so_req_handler         = tgt_request_handle,
329                         .so_req_printer         = target_print_req,
330                         .so_hpreq_handler       = NULL,
331                 },
332         };
333         m->mds_out_service = ptlrpc_register_service(&conf, &obd->obd_kset,
334                                                      procfs_entry);
335         if (IS_ERR(m->mds_out_service)) {
336                 rc = PTR_ERR(m->mds_out_service);
337                 CERROR("failed to start out service: %d\n", rc);
338                 m->mds_out_service = NULL;
339                 GOTO(err_mds_svc, rc);
340         }
341
342         /*
343          * sequence controller service configuration
344          */
345         memset(&conf, 0, sizeof(conf));
346         conf = (typeof(conf)) {
347                 .psc_name               = LUSTRE_MDT_NAME "_seqs",
348                 .psc_watchdog_factor    = MDT_SERVICE_WATCHDOG_FACTOR,
349                 .psc_buf                = {
350                         .bc_nbufs               = MDS_NBUFS,
351                         .bc_buf_size            = SEQ_BUFSIZE,
352                         .bc_req_max_size        = SEQ_MAXREQSIZE,
353                         .bc_rep_max_size        = SEQ_MAXREPSIZE,
354                         .bc_req_portal          = SEQ_CONTROLLER_PORTAL,
355                         .bc_rep_portal          = MDC_REPLY_PORTAL,
356                 },
357                 .psc_thr                = {
358                         .tc_thr_name            = LUSTRE_MDT_NAME "_seqs",
359                         .tc_nthrs_init          = MDS_OTHR_NTHRS_INIT,
360                         .tc_nthrs_max           = MDS_OTHR_NTHRS_MAX,
361                         .tc_ctx_tags            = LCT_MD_THREAD,
362                 },
363                 .psc_ops                = {
364                         .so_req_handler         = tgt_request_handle,
365                         .so_req_printer         = target_print_req,
366                         .so_hpreq_handler       = NULL,
367                 },
368         };
369         m->mds_mdsc_service = ptlrpc_register_service(&conf, &obd->obd_kset,
370                                                       procfs_entry);
371         if (IS_ERR(m->mds_mdsc_service)) {
372                 rc = PTR_ERR(m->mds_mdsc_service);
373                 CERROR("failed to start seq controller service: %d\n", rc);
374                 m->mds_mdsc_service = NULL;
375
376                 GOTO(err_mds_svc, rc);
377         }
378
379         /*
380          * metadata sequence server service configuration
381          */
382         memset(&conf, 0, sizeof(conf));
383         conf = (typeof(conf)) {
384                 .psc_name               = LUSTRE_MDT_NAME "_seqm",
385                 .psc_watchdog_factor    = MDT_SERVICE_WATCHDOG_FACTOR,
386                 .psc_buf                = {
387                         .bc_nbufs               = MDS_NBUFS,
388                         .bc_buf_size            = SEQ_BUFSIZE,
389                         .bc_req_max_size        = SEQ_MAXREQSIZE,
390                         .bc_rep_max_size        = SEQ_MAXREPSIZE,
391                         .bc_req_portal          = SEQ_METADATA_PORTAL,
392                         .bc_rep_portal          = MDC_REPLY_PORTAL,
393                 },
394                 .psc_thr                = {
395                         .tc_thr_name            = LUSTRE_MDT_NAME "_seqm",
396                         .tc_nthrs_init          = MDS_OTHR_NTHRS_INIT,
397                         .tc_nthrs_max           = MDS_OTHR_NTHRS_MAX,
398                         .tc_ctx_tags            = LCT_MD_THREAD | LCT_DT_THREAD
399                 },
400                 .psc_ops                = {
401                         .so_req_handler         = tgt_request_handle,
402                         .so_req_printer         = target_print_req,
403                         .so_hpreq_handler       = NULL,
404                 },
405         };
406         m->mds_mdss_service = ptlrpc_register_service(&conf, &obd->obd_kset,
407                                                       procfs_entry);
408         if (IS_ERR(m->mds_mdss_service)) {
409                 rc = PTR_ERR(m->mds_mdss_service);
410                 CERROR("failed to start metadata seq server service: %d\n", rc);
411                 m->mds_mdss_service = NULL;
412
413                 GOTO(err_mds_svc, rc);
414         }
415
416         /* FLD service start */
417         memset(&conf, 0, sizeof(conf));
418         conf = (typeof(conf)) {
419                 .psc_name            = LUSTRE_MDT_NAME "_fld",
420                 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
421                 .psc_buf                = {
422                         .bc_nbufs               = MDS_NBUFS,
423                         .bc_buf_size            = FLD_BUFSIZE,
424                         .bc_req_max_size        = FLD_MAXREQSIZE,
425                         .bc_rep_max_size        = FLD_MAXREPSIZE,
426                         .bc_req_portal          = FLD_REQUEST_PORTAL,
427                         .bc_rep_portal          = MDC_REPLY_PORTAL,
428                 },
429                 .psc_thr                = {
430                         .tc_thr_name            = LUSTRE_MDT_NAME "_fld",
431                         .tc_nthrs_init          = MDS_OTHR_NTHRS_INIT,
432                         .tc_nthrs_max           = MDS_OTHR_NTHRS_MAX,
433                         .tc_ctx_tags            = LCT_DT_THREAD | LCT_MD_THREAD,
434                 },
435                 .psc_ops                = {
436                         .so_req_handler         = tgt_request_handle,
437                         .so_req_printer         = target_print_req,
438                         .so_hpreq_handler       = NULL,
439                 },
440         };
441         m->mds_fld_service = ptlrpc_register_service(&conf, &obd->obd_kset,
442                                                      procfs_entry);
443         if (IS_ERR(m->mds_fld_service)) {
444                 rc = PTR_ERR(m->mds_fld_service);
445                 CERROR("failed to start fld service: %d\n", rc);
446                 m->mds_fld_service = NULL;
447
448                 GOTO(err_mds_svc, rc);
449         }
450
451         memset(&conf, 0, sizeof(conf));
452         conf = (typeof(conf)) {
453                 .psc_name               = LUSTRE_MDT_NAME "_io",
454                 .psc_watchdog_factor    = MDT_SERVICE_WATCHDOG_FACTOR,
455                 .psc_buf                = {
456                         .bc_nbufs               = OST_NBUFS,
457                         .bc_buf_size            = OST_IO_BUFSIZE,
458                         .bc_req_max_size        = OST_IO_MAXREQSIZE,
459                         .bc_rep_max_size        = OST_IO_MAXREPSIZE,
460                         .bc_req_portal          = MDS_IO_PORTAL,
461                         .bc_rep_portal          = MDC_REPLY_PORTAL,
462                 },
463                 .psc_thr                = {
464                         .tc_thr_name            = "ll_mdt_io",
465                         .tc_thr_factor          = OSS_THR_FACTOR,
466                         .tc_nthrs_init          = OSS_NTHRS_INIT,
467                         .tc_nthrs_base          = OSS_NTHRS_BASE,
468                         .tc_nthrs_max           = mds_max_io_threads,
469                         .tc_cpu_affinity        = 1,
470                         .tc_ctx_tags            = LCT_DT_THREAD | LCT_MD_THREAD,
471                 },
472                 .psc_ops                = {
473                         .so_thr_init            = tgt_io_thread_init,
474                         .so_thr_done            = tgt_io_thread_done,
475                         .so_req_handler         = tgt_request_handle,
476                         .so_req_printer         = target_print_req,
477                 },
478         };
479         m->mds_io_service = ptlrpc_register_service(&conf, &obd->obd_kset,
480                                                     procfs_entry);
481         if (IS_ERR(m->mds_io_service)) {
482                 rc = PTR_ERR(m->mds_io_service);
483                 CERROR("failed to start MDT I/O service: %d\n", rc);
484                 m->mds_io_service = NULL;
485                 GOTO(err_mds_svc, rc);
486         }
487
488         EXIT;
489 err_mds_svc:
490         if (rc)
491                 mds_stop_ptlrpc_service(m);
492
493         return rc;
494 }
495
496 static inline struct mds_device *mds_dev(struct lu_device *d)
497 {
498         return container_of0(d, struct mds_device, mds_md_dev.md_lu_dev);
499 }
500
501 static struct lu_device *mds_device_fini(const struct lu_env *env,
502                                          struct lu_device *d)
503 {
504         struct mds_device *m = mds_dev(d);
505         struct obd_device *obd = d->ld_obd;
506         ENTRY;
507
508         mds_stop_ptlrpc_service(m);
509         lprocfs_obd_cleanup(obd);
510         RETURN(NULL);
511 }
512
513 static struct lu_device *mds_device_free(const struct lu_env *env,
514                                          struct lu_device *d)
515 {
516         struct mds_device *m = mds_dev(d);
517         ENTRY;
518
519         md_device_fini(&m->mds_md_dev);
520         OBD_FREE_PTR(m);
521         RETURN(NULL);
522 }
523
524 static struct lu_device *mds_device_alloc(const struct lu_env *env,
525                                           struct lu_device_type *t,
526                                           struct lustre_cfg *cfg)
527 {
528         struct mds_device        *m;
529         struct obd_device        *obd;
530         struct lu_device          *l;
531         int rc;
532
533         OBD_ALLOC_PTR(m);
534         if (m == NULL)
535                 return ERR_PTR(-ENOMEM);
536
537         md_device_init(&m->mds_md_dev, t);
538         l = &m->mds_md_dev.md_lu_dev;
539
540         obd = class_name2obd(lustre_cfg_string(cfg, 0));
541         LASSERT(obd != NULL);
542
543         l->ld_obd = obd;
544         /* set this lu_device to obd, because error handling need it */
545         obd->obd_lu_dev = l;
546
547         rc = lprocfs_obd_setup(obd, true);
548         if (rc != 0) {
549                 mds_device_free(env, l);
550                 l = ERR_PTR(rc);
551                 return l;
552         }
553
554         mutex_init(&m->mds_health_mutex);
555
556         rc = mds_start_ptlrpc_service(m);
557         if (rc != 0) {
558                 lprocfs_obd_cleanup(obd);
559                 mds_device_free(env, l);
560                 l = ERR_PTR(rc);
561                 return l;
562         }
563         return l;
564 }
565
566 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
567 LU_TYPE_INIT_FINI(mds, &mdt_thread_key);
568
569 static struct lu_device_type_operations mds_device_type_ops = {
570         .ldto_init = mds_type_init,
571         .ldto_fini = mds_type_fini,
572
573         .ldto_start = mds_type_start,
574         .ldto_stop  = mds_type_stop,
575
576         .ldto_device_alloc = mds_device_alloc,
577         .ldto_device_free  = mds_device_free,
578         .ldto_device_fini  = mds_device_fini
579 };
580
581 static struct lu_device_type mds_device_type = {
582         .ldt_tags     = LU_DEVICE_MD,
583         .ldt_name     = LUSTRE_MDS_NAME,
584         .ldt_ops      = &mds_device_type_ops,
585         .ldt_ctx_tags = LCT_MD_THREAD
586 };
587
588 static int mds_health_check(const struct lu_env *env, struct obd_device *obd)
589 {
590         struct mds_device *mds = mds_dev(obd->obd_lu_dev);
591         int rc = 0;
592
593
594         mutex_lock(&mds->mds_health_mutex);
595         rc |= ptlrpc_service_health_check(mds->mds_regular_service);
596         rc |= ptlrpc_service_health_check(mds->mds_readpage_service);
597         rc |= ptlrpc_service_health_check(mds->mds_out_service);
598         rc |= ptlrpc_service_health_check(mds->mds_setattr_service);
599         rc |= ptlrpc_service_health_check(mds->mds_mdsc_service);
600         rc |= ptlrpc_service_health_check(mds->mds_mdss_service);
601         rc |= ptlrpc_service_health_check(mds->mds_fld_service);
602         rc |= ptlrpc_service_health_check(mds->mds_io_service);
603         mutex_unlock(&mds->mds_health_mutex);
604
605         return rc != 0 ? 1 : 0;
606 }
607
608 static struct obd_ops mds_obd_device_ops = {
609         .o_owner           = THIS_MODULE,
610         .o_health_check    = mds_health_check,
611 };
612
613 int mds_mod_init(void)
614 {
615         return class_register_type(&mds_obd_device_ops, NULL, true, NULL,
616                                    LUSTRE_MDS_NAME, &mds_device_type);
617 }
618
619 void mds_mod_exit(void)
620 {
621         class_unregister_type(LUSTRE_MDS_NAME);
622 }