Whamcloud - gitweb
c0e3f8f82c6d71788ef704104d085def5b5bbba5
[fs/lustre-release.git] / lustre / ofd / ofd_dev.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, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Whamcloud, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ofd/ofd.c
37  *
38  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39  * Author: Mike Pershin <tappro@whamcloud.com>
40  * Author: Johann Lombardi <johann@whamcloud.com>
41  */
42
43 #define DEBUG_SUBSYSTEM S_FILTER
44
45 #include <obd_class.h>
46 #include <lustre_param.h>
47
48 #include "ofd_internal.h"
49
50 /* Slab for OFD object allocation */
51 static cfs_mem_cache_t *ofd_object_kmem;
52
53 static struct lu_kmem_descr ofd_caches[] = {
54         {
55                 .ckd_cache = &ofd_object_kmem,
56                 .ckd_name  = "ofd_obj",
57                 .ckd_size  = sizeof(struct ofd_object)
58         },
59         {
60                 .ckd_cache = NULL
61         }
62 };
63
64 static int ofd_stack_init(const struct lu_env *env,
65                           struct ofd_device *m, struct lustre_cfg *cfg)
66 {
67         struct lu_device        *ofd_lu = &m->ofd_dt_dev.dd_lu_dev;
68         const char              *dev = lustre_cfg_string(cfg, 0);
69         struct obd_type         *type;
70         struct lu_device_type   *ldt;
71         struct lu_device        *d;
72         struct ofd_thread_info  *info = ofd_info(env);
73         int                      rc;
74
75         ENTRY;
76
77         /* XXX: we should be able to use different OSDs here */
78         type = class_get_type(LUSTRE_OSD_NAME);
79         if (!type) {
80                 CERROR("Unknown type: '%s'\n", LUSTRE_OSD_NAME);
81                 RETURN(-ENODEV);
82         }
83
84         rc = lu_env_refill((struct lu_env *)env);
85         if (rc != 0) {
86                 CERROR("Failure to refill session: '%d'\n", rc);
87                 GOTO(out_type, rc);
88         }
89
90         ldt = type->typ_lu;
91         if (ldt == NULL) {
92                 CERROR("type: '%s'\n", LUSTRE_OSD_NAME);
93                 GOTO(out_type, rc = -EINVAL);
94         }
95
96         ldt->ldt_obd_type = type;
97         d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
98         if (IS_ERR(d)) {
99                 CERROR("Cannot allocate device: '%s'\n", LUSTRE_OSD_NAME);
100                 GOTO(out_type, rc = -ENODEV);
101         }
102
103         LASSERT(ofd_lu->ld_site);
104         d->ld_site = ofd_lu->ld_site;
105
106         snprintf(info->fti_u.name, sizeof(info->fti_u.name),
107                  "%s-osd", lustre_cfg_string(cfg, 0));
108
109         type->typ_refcnt++;
110         rc = ldt->ldt_ops->ldto_device_init(env, d, dev, NULL);
111         if (rc) {
112                 CERROR("can't init device '%s', rc %d\n", LUSTRE_OSD_NAME, rc);
113                 GOTO(out_free, rc);
114         }
115         lu_device_get(d);
116         lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
117
118         m->ofd_osd = lu2dt_dev(d);
119
120         /* process setup config */
121         rc = d->ld_ops->ldo_process_config(env, d, cfg);
122         if (rc)
123                 GOTO(out_fini, rc);
124
125         RETURN(rc);
126
127 out_fini:
128         ldt->ldt_ops->ldto_device_fini(env, d);
129 out_free:
130         type->typ_refcnt--;
131         ldt->ldt_ops->ldto_device_free(env, d);
132 out_type:
133         class_put_type(type);
134         RETURN(rc);
135 }
136
137 static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m,
138                            struct lu_device *top)
139 {
140         struct obd_device       *obd = ofd_obd(m);
141         struct lustre_cfg_bufs   bufs;
142         struct lustre_cfg       *lcfg;
143         char                     flags[3] = "";
144
145         ENTRY;
146
147         lu_site_purge(env, top->ld_site, ~0);
148
149         /* process cleanup, pass mdt obd name to get obd umount flags */
150         lustre_cfg_bufs_reset(&bufs, obd->obd_name);
151         if (obd->obd_force)
152                 strcat(flags, "F");
153         if (obd->obd_fail)
154                 strcat(flags, "A");
155         lustre_cfg_bufs_set_string(&bufs, 1, flags);
156         lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
157         if (!lcfg) {
158                 CERROR("Cannot alloc lcfg!\n");
159                 RETURN_EXIT;
160         }
161
162         LASSERT(top);
163         top->ld_ops->ldo_process_config(env, top, lcfg);
164         lustre_cfg_free(lcfg);
165
166         lu_stack_fini(env, &m->ofd_osd->dd_lu_dev);
167         m->ofd_osd = NULL;
168
169         EXIT;
170 }
171
172 /* used by MGS to process specific configurations */
173 static int ofd_process_config(const struct lu_env *env, struct lu_device *d,
174                               struct lustre_cfg *cfg)
175 {
176         struct ofd_device       *m = ofd_dev(d);
177         struct dt_device        *dt_next = m->ofd_osd;
178         struct lu_device        *next = &dt_next->dd_lu_dev;
179         int                      rc;
180
181         ENTRY;
182
183         switch (cfg->lcfg_command) {
184         case LCFG_PARAM: {
185                 struct lprocfs_static_vars lvars;
186
187                 lprocfs_ofd_init_vars(&lvars);
188                 rc = class_process_proc_param(PARAM_OST, lvars.obd_vars, cfg,
189                                               d->ld_obd);
190                 if (rc > 0 || rc == -ENOSYS)
191                         /* we don't understand; pass it on */
192                         rc = next->ld_ops->ldo_process_config(env, next, cfg);
193                 break;
194         }
195         case LCFG_SPTLRPC_CONF: {
196                 rc = -ENOTSUPP;
197                 break;
198         }
199         default:
200                 /* others are passed further */
201                 rc = next->ld_ops->ldo_process_config(env, next, cfg);
202                 break;
203         }
204         RETURN(rc);
205 }
206
207 static int ofd_object_init(const struct lu_env *env, struct lu_object *o,
208                            const struct lu_object_conf *conf)
209 {
210         struct ofd_device       *d = ofd_dev(o->lo_dev);
211         struct lu_device        *under;
212         struct lu_object        *below;
213         int                      rc = 0;
214
215         ENTRY;
216
217         CDEBUG(D_INFO, "object init, fid = "DFID"\n",
218                PFID(lu_object_fid(o)));
219
220         under = &d->ofd_osd->dd_lu_dev;
221         below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
222         if (below != NULL)
223                 lu_object_add(o, below);
224         else
225                 rc = -ENOMEM;
226
227         RETURN(rc);
228 }
229
230 static void ofd_object_free(const struct lu_env *env, struct lu_object *o)
231 {
232         struct ofd_object       *of = ofd_obj(o);
233         struct lu_object_header *h;
234
235         ENTRY;
236
237         h = o->lo_header;
238         CDEBUG(D_INFO, "object free, fid = "DFID"\n",
239                PFID(lu_object_fid(o)));
240
241         lu_object_fini(o);
242         lu_object_header_fini(h);
243         OBD_SLAB_FREE_PTR(of, ofd_object_kmem);
244         EXIT;
245 }
246
247 static int ofd_object_print(const struct lu_env *env, void *cookie,
248                             lu_printer_t p, const struct lu_object *o)
249 {
250         return (*p)(env, cookie, LUSTRE_OST_NAME"-object@%p", o);
251 }
252
253 struct lu_object_operations ofd_obj_ops = {
254         .loo_object_init        = ofd_object_init,
255         .loo_object_free        = ofd_object_free,
256         .loo_object_print       = ofd_object_print
257 };
258
259 static struct lu_object *ofd_object_alloc(const struct lu_env *env,
260                                           const struct lu_object_header *hdr,
261                                           struct lu_device *d)
262 {
263         struct ofd_object *of;
264
265         ENTRY;
266
267         OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, CFS_ALLOC_IO);
268         if (of != NULL) {
269                 struct lu_object        *o;
270                 struct lu_object_header *h;
271
272                 o = &of->ofo_obj.do_lu;
273                 h = &of->ofo_header;
274                 lu_object_header_init(h);
275                 lu_object_init(o, h, d);
276                 lu_object_add_top(h, o);
277                 o->lo_ops = &ofd_obj_ops;
278                 RETURN(o);
279         } else {
280                 RETURN(NULL);
281         }
282 }
283
284 extern int ost_handle(struct ptlrpc_request *req);
285
286 static int ofd_start(const struct lu_env *env, struct lu_device *dev)
287 {
288         struct ofd_device       *ofd = ofd_dev(dev);
289         struct lu_device        *next = &ofd->ofd_osd->dd_lu_dev;
290         int                      rc;
291
292         ENTRY;
293
294         /* initialize lower device */
295         rc = next->ld_ops->ldo_prepare(env, dev, next);
296
297         RETURN(rc);
298 }
299
300 static int ofd_recovery_complete(const struct lu_env *env,
301                                  struct lu_device *dev)
302 {
303         struct ofd_device       *ofd = ofd_dev(dev);
304         struct lu_device        *next = &ofd->ofd_osd->dd_lu_dev;
305         int                      rc = 0;
306
307         ENTRY;
308
309         /* Grant space for object precreation on the self export.
310          * This initial reserved space (i.e. 20MB for zfs and 560KB for ldiskfs)
311          * is enough to create 20k objects. It is then adapted based on the
312          * precreate request size (see ofd_grant_create()
313          */
314         ofd_grant_connect(env, dev->ld_obd->obd_self_export,
315                           OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace);
316         rc = next->ld_ops->ldo_recovery_complete(env, next);
317         RETURN(rc);
318 }
319
320 static struct lu_device_operations ofd_lu_ops = {
321         .ldo_object_alloc       = ofd_object_alloc,
322         .ldo_process_config     = ofd_process_config,
323         .ldo_recovery_complete  = ofd_recovery_complete,
324 };
325
326 static int ofd_procfs_init(struct ofd_device *ofd)
327 {
328         struct lprocfs_static_vars       lvars;
329         struct obd_device               *obd = ofd_obd(ofd);
330         cfs_proc_dir_entry_t            *entry;
331         int                              rc = 0;
332
333         ENTRY;
334
335         /* lprocfs must be setup before the ofd so state can be safely added
336          * to /proc incrementally as the ofd is setup */
337         lprocfs_ofd_init_vars(&lvars);
338         rc = lprocfs_obd_setup(obd, lvars.obd_vars);
339         if (rc) {
340                 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
341                        obd->obd_name, rc);
342                 RETURN(rc);
343         }
344
345         rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_LAST);
346         if (rc) {
347                 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
348                        obd->obd_name, rc);
349                 GOTO(obd_cleanup, rc);
350         }
351
352         /* Init OFD private stats here */
353         lprocfs_counter_init(obd->obd_stats, LPROC_OFD_READ_BYTES,
354                              LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
355         lprocfs_counter_init(obd->obd_stats, LPROC_OFD_WRITE_BYTES,
356                              LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
357
358         rc = lproc_ofd_attach_seqstat(obd);
359         if (rc) {
360                 CERROR("%s: create seqstat failed: %d.\n", obd->obd_name, rc);
361                 GOTO(free_obd_stats, rc);
362         }
363
364         entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
365         if (IS_ERR(entry)) {
366                 rc = PTR_ERR(entry);
367                 CERROR("%s: error %d setting up lprocfs for %s\n",
368                        obd->obd_name, rc, "exports");
369                 GOTO(free_obd_stats, rc);
370         }
371         obd->obd_proc_exports_entry = entry;
372
373         entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
374                                    lprocfs_nid_stats_clear_read,
375                                    lprocfs_nid_stats_clear_write, obd, NULL);
376         if (IS_ERR(entry)) {
377                 rc = PTR_ERR(entry);
378                 CERROR("%s: add proc entry 'clear' failed: %d.\n",
379                        obd->obd_name, rc);
380                 GOTO(free_obd_stats, rc);
381         }
382         RETURN(0);
383
384 free_obd_stats:
385         lprocfs_free_obd_stats(obd);
386 obd_cleanup:
387         lprocfs_obd_cleanup(obd);
388         return rc;
389 }
390
391 static int ofd_procfs_fini(struct ofd_device *ofd)
392 {
393         struct obd_device *obd = ofd_obd(ofd);
394
395         lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
396         lprocfs_free_per_client_stats(obd);
397         lprocfs_free_obd_stats(obd);
398         lprocfs_obd_cleanup(obd);
399         return 0;
400 }
401
402 extern int ost_handle(struct ptlrpc_request *req);
403
404 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
405                      struct lu_device_type *ldt, struct lustre_cfg *cfg)
406 {
407         const char              *dev = lustre_cfg_string(cfg, 0);
408         struct ofd_thread_info  *info = NULL;
409         struct obd_device       *obd;
410         struct obd_statfs       *osfs;
411         int                      rc;
412
413         ENTRY;
414
415         obd = class_name2obd(dev);
416         if (obd == NULL) {
417                 CERROR("Cannot find obd with name %s\n", dev);
418                 RETURN(-ENODEV);
419         }
420
421         rc = lu_env_refill((struct lu_env *)env);
422         if (rc != 0)
423                 RETURN(rc);
424
425         obd->u.obt.obt_magic = OBT_MAGIC;
426
427         m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT;
428         m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT;
429
430         cfs_spin_lock_init(&m->ofd_flags_lock);
431         m->ofd_raid_degraded = 0;
432         m->ofd_syncjournal = 0;
433         ofd_slc_set(m);
434         m->ofd_grant_compat_disable = 0;
435
436         /* statfs data */
437         cfs_spin_lock_init(&m->ofd_osfs_lock);
438         m->ofd_osfs_age = cfs_time_shift_64(-1000);
439         m->ofd_osfs_unstable = 0;
440         m->ofd_statfs_inflight = 0;
441         m->ofd_osfs_inflight = 0;
442
443         /* grant data */
444         cfs_spin_lock_init(&m->ofd_grant_lock);
445         m->ofd_tot_dirty = 0;
446         m->ofd_tot_granted = 0;
447         m->ofd_tot_pending = 0;
448         m->ofd_max_group = 0;
449
450         cfs_rwlock_init(&obd->u.filter.fo_sptlrpc_lock);
451         sptlrpc_rule_set_init(&obd->u.filter.fo_sptlrpc_rset);
452
453         obd->u.filter.fo_fl_oss_capa = 0;
454         CFS_INIT_LIST_HEAD(&obd->u.filter.fo_capa_keys);
455         obd->u.filter.fo_capa_hash = init_capa_hash();
456         if (obd->u.filter.fo_capa_hash == NULL)
457                 RETURN(-ENOMEM);
458
459         m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
460         m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
461         /* set this lu_device to obd, because error handling need it */
462         obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
463
464         rc = ofd_procfs_init(m);
465         if (rc) {
466                 CERROR("Can't init ofd lprocfs, rc %d\n", rc);
467                 RETURN(rc);
468         }
469
470         /* No connection accepted until configurations will finish */
471         obd->obd_no_conn = 1;
472         obd->obd_replayable = 1;
473         if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
474                 char *str = lustre_cfg_string(cfg, 4);
475
476                 if (strchr(str, 'n')) {
477                         CWARN("%s: recovery disabled\n", obd->obd_name);
478                         obd->obd_replayable = 0;
479                 }
480         }
481
482         info = ofd_info_init(env, NULL);
483         if (info == NULL)
484                 RETURN(-EFAULT);
485
486         rc = lu_site_init(&m->ofd_site, &m->ofd_dt_dev.dd_lu_dev);
487         if (rc)
488                 GOTO(err_fini_proc, rc);
489         m->ofd_site.ls_top_dev = &m->ofd_dt_dev.dd_lu_dev;
490
491         rc = ofd_stack_init(env, m, cfg);
492         if (rc) {
493                 CERROR("Can't init device stack, rc %d\n", rc);
494                 GOTO(err_lu_site, rc);
495         }
496
497         /* populate cached statfs data */
498         osfs = &ofd_info(env)->fti_u.osfs;
499         rc = ofd_statfs_internal(env, m, osfs, 0, NULL);
500         if (rc != 0) {
501                 CERROR("%s: can't get statfs data, rc %d\n", obd->obd_name, rc);
502                 GOTO(err_fini_stack, rc);
503         }
504         if (!IS_PO2(osfs->os_bsize)) {
505                 CERROR("%s: blocksize (%d) is not a power of 2\n",
506                                 obd->obd_name, osfs->os_bsize);
507                 GOTO(err_fini_stack, rc = -EPROTO);
508         }
509         m->ofd_blockbits = cfs_fls(osfs->os_bsize) - 1;
510
511         snprintf(info->fti_u.name, sizeof(info->fti_u.name), "filter-%p", m);
512         m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name,
513                                               LDLM_NAMESPACE_SERVER,
514                                               LDLM_NAMESPACE_GREEDY,
515                                               LDLM_NS_TYPE_OST);
516         if (m->ofd_namespace == NULL)
517                 GOTO(err_fini_stack, rc = -ENOMEM);
518         /* set obd_namespace for compatibility with old code */
519         obd->obd_namespace = m->ofd_namespace;
520
521         dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf);
522
523         /* Allow at most ddp_grant_reserved% of the available filesystem space
524          * to be granted to clients, so that any errors in the grant overhead
525          * calculations do not allow granting more space to clients than can be
526          * written. Assumes that in aggregate the grant overhead calculations do
527          * not have more than ddp_grant_reserved% estimation error in them. */
528         m->ofd_grant_ratio =
529                 ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved);
530
531         rc = ofd_start(env, &m->ofd_dt_dev.dd_lu_dev);
532         if (rc)
533                 GOTO(err_fini_stack, rc);
534
535         rc = lut_init(env, &m->ofd_lut, obd, m->ofd_osd);
536         if (rc)
537                 GOTO(err_free_ns, rc);
538
539         rc = ofd_fs_setup(env, m, obd);
540         if (rc)
541                 GOTO(err_fini_lut, rc);
542
543         target_recovery_init(&m->ofd_lut, ost_handle);
544
545         rc = lu_site_init_finish(&m->ofd_site);
546         if (rc)
547                 GOTO(err_fs_cleanup, rc);
548
549         RETURN(0);
550 err_fs_cleanup:
551         target_recovery_fini(obd);
552         ofd_fs_cleanup(env, m);
553 err_fini_lut:
554         lut_fini(env, &m->ofd_lut);
555 err_free_ns:
556         ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force);
557         obd->obd_namespace = m->ofd_namespace = NULL;
558 err_fini_stack:
559         ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev);
560 err_lu_site:
561         lu_site_fini(&m->ofd_site);
562 err_fini_proc:
563         ofd_procfs_fini(m);
564         return rc;
565 }
566
567 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
568 {
569         struct obd_device *obd = ofd_obd(m);
570         struct lu_device  *d = &m->ofd_dt_dev.dd_lu_dev;
571
572         target_recovery_fini(obd);
573         obd_exports_barrier(obd);
574         obd_zombie_barrier();
575
576         lut_fini(env, &m->ofd_lut);
577         ofd_fs_cleanup(env, m);
578
579         ofd_free_capa_keys(m);
580         cleanup_capa_hash(obd->u.filter.fo_capa_hash);
581
582         if (m->ofd_namespace != NULL) {
583                 ldlm_namespace_free(m->ofd_namespace, NULL,
584                                     d->ld_obd->obd_force);
585                 d->ld_obd->obd_namespace = m->ofd_namespace = NULL;
586         }
587
588         ofd_stack_fini(env, m, m->ofd_site.ls_top_dev);
589         lu_site_fini(&m->ofd_site);
590         ofd_procfs_fini(m);
591         LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
592         EXIT;
593 }
594
595 static struct lu_device *ofd_device_fini(const struct lu_env *env,
596                                          struct lu_device *d)
597 {
598         ENTRY;
599         ofd_fini(env, ofd_dev(d));
600         RETURN(NULL);
601 }
602
603 static struct lu_device *ofd_device_free(const struct lu_env *env,
604                                          struct lu_device *d)
605 {
606         struct ofd_device *m = ofd_dev(d);
607
608         dt_device_fini(&m->ofd_dt_dev);
609         OBD_FREE_PTR(m);
610         RETURN(NULL);
611 }
612
613 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
614                                           struct lu_device_type *t,
615                                           struct lustre_cfg *cfg)
616 {
617         struct ofd_device *m;
618         struct lu_device  *l;
619         int                rc;
620
621         OBD_ALLOC_PTR(m);
622         if (m == NULL)
623                 return ERR_PTR(-ENOMEM);
624
625         l = &m->ofd_dt_dev.dd_lu_dev;
626         dt_device_init(&m->ofd_dt_dev, t);
627         rc = ofd_init0(env, m, t, cfg);
628         if (rc != 0) {
629                 ofd_device_free(env, l);
630                 l = ERR_PTR(rc);
631         }
632
633         return l;
634 }
635
636 /* thread context key constructor/destructor */
637 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
638
639 static void ofd_key_exit(const struct lu_context *ctx,
640                          struct lu_context_key *key, void *data)
641 {
642         struct ofd_thread_info *info = data;
643
644         info->fti_env = NULL;
645         info->fti_exp = NULL;
646 }
647
648 struct lu_context_key ofd_thread_key = {
649         .lct_tags = LCT_DT_THREAD,
650         .lct_init = ofd_key_init,
651         .lct_fini = ofd_key_fini,
652         .lct_exit = ofd_key_exit
653 };
654
655 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
656 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
657
658 static struct lu_device_type_operations ofd_device_type_ops = {
659         .ldto_init              = ofd_type_init,
660         .ldto_fini              = ofd_type_fini,
661
662         .ldto_start             = ofd_type_start,
663         .ldto_stop              = ofd_type_stop,
664
665         .ldto_device_alloc      = ofd_device_alloc,
666         .ldto_device_free       = ofd_device_free,
667         .ldto_device_fini       = ofd_device_fini
668 };
669
670 static struct lu_device_type ofd_device_type = {
671         .ldt_tags       = LU_DEVICE_DT,
672         .ldt_name       = LUSTRE_OST_NAME,
673         .ldt_ops        = &ofd_device_type_ops,
674         .ldt_ctx_tags   = LCT_DT_THREAD
675 };
676
677 int __init ofd_init(void)
678 {
679         struct lprocfs_static_vars      lvars;
680         int                             rc;
681
682         rc = lu_kmem_init(ofd_caches);
683         if (rc)
684                 return rc;
685
686         rc = ofd_fmd_init();
687         if (rc) {
688                 lu_kmem_fini(ofd_caches);
689                 return(rc);
690         }
691
692         lprocfs_ofd_init_vars(&lvars);
693
694         rc = class_register_type(&ofd_obd_ops, NULL, lvars.module_vars,
695                                  LUSTRE_OST_NAME, &ofd_device_type);
696         return rc;
697 }
698
699 void __exit ofd_exit(void)
700 {
701         ofd_fmd_exit();
702         lu_kmem_fini(ofd_caches);
703         class_unregister_type(LUSTRE_OST_NAME);
704 }
705
706 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
707 MODULE_DESCRIPTION("Lustre Object Filtering Device");
708 MODULE_LICENSE("GPL");
709
710 module_init(ofd_init);
711 module_exit(ofd_exit);