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, 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).
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
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
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39 * Author: Mike Pershin <tappro@whamcloud.com>
40 * Author: Johann Lombardi <johann@whamcloud.com>
43 #define DEBUG_SUBSYSTEM S_FILTER
45 #include <obd_class.h>
46 #include <lustre_param.h>
47 #include <lustre_fid.h>
48 #include <lustre_lfsck.h>
50 #include "ofd_internal.h"
52 /* Slab for OFD object allocation */
53 static struct kmem_cache *ofd_object_kmem;
55 static struct lu_kmem_descr ofd_caches[] = {
57 .ckd_cache = &ofd_object_kmem,
58 .ckd_name = "ofd_obj",
59 .ckd_size = sizeof(struct ofd_object)
66 static int ofd_connect_to_next(const struct lu_env *env, struct ofd_device *m,
67 const char *next, struct obd_export **exp)
69 struct obd_connect_data *data = NULL;
70 struct obd_device *obd;
76 GOTO(out, rc = -ENOMEM);
78 obd = class_name2obd(next);
80 CERROR("%s: can't locate next device: %s\n",
81 m->ofd_dt_dev.dd_lu_dev.ld_obd->obd_name, next);
82 GOTO(out, rc = -ENOTCONN);
85 data->ocd_connect_flags = OBD_CONNECT_VERSION;
86 data->ocd_version = LUSTRE_VERSION_CODE;
88 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
90 CERROR("%s: cannot connect to next dev %s: rc = %d\n",
91 m->ofd_dt_dev.dd_lu_dev.ld_obd->obd_name, next, rc);
95 m->ofd_dt_dev.dd_lu_dev.ld_site =
96 m->ofd_osd_exp->exp_obd->obd_lu_dev->ld_site;
97 LASSERT(m->ofd_dt_dev.dd_lu_dev.ld_site);
98 m->ofd_osd = lu2dt_dev(m->ofd_osd_exp->exp_obd->obd_lu_dev);
99 m->ofd_dt_dev.dd_lu_dev.ld_site->ls_top_dev = &m->ofd_dt_dev.dd_lu_dev;
107 static int ofd_stack_init(const struct lu_env *env,
108 struct ofd_device *m, struct lustre_cfg *cfg)
110 const char *dev = lustre_cfg_string(cfg, 0);
112 struct ofd_thread_info *info = ofd_info(env);
113 struct lustre_mount_info *lmi;
119 lmi = server_get_mount(dev);
121 CERROR("Cannot get mount info for %s!\n", dev);
125 /* find bottom osd */
126 OBD_ALLOC(osdname, MTI_NAME_MAXLEN);
130 snprintf(osdname, MTI_NAME_MAXLEN, "%s-osd", dev);
131 rc = ofd_connect_to_next(env, m, osdname, &m->ofd_osd_exp);
132 OBD_FREE(osdname, MTI_NAME_MAXLEN);
136 d = m->ofd_osd_exp->exp_obd->obd_lu_dev;
138 m->ofd_osd = lu2dt_dev(d);
140 snprintf(info->fti_u.name, sizeof(info->fti_u.name),
141 "%s-osd", lustre_cfg_string(cfg, 0));
146 static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m,
147 struct lu_device *top)
149 struct obd_device *obd = ofd_obd(m);
150 struct lustre_cfg_bufs bufs;
151 struct lustre_cfg *lcfg;
156 lu_site_purge(env, top->ld_site, ~0);
158 /* process cleanup, pass mdt obd name to get obd umount flags */
159 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
164 lustre_cfg_bufs_set_string(&bufs, 1, flags);
165 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
167 CERROR("Cannot alloc lcfg!\n");
172 top->ld_ops->ldo_process_config(env, top, lcfg);
173 lustre_cfg_free(lcfg);
175 lu_site_purge(env, top->ld_site, ~0);
177 LASSERT(m->ofd_osd_exp);
178 obd_disconnect(m->ofd_osd_exp);
184 /* For interoperability, see mdt_interop_param[]. */
185 static struct cfg_interop_param ofd_interop_param[] = {
186 { "ost.quota_type", NULL },
190 /* used by MGS to process specific configurations */
191 static int ofd_process_config(const struct lu_env *env, struct lu_device *d,
192 struct lustre_cfg *cfg)
194 struct ofd_device *m = ofd_dev(d);
195 struct dt_device *dt_next = m->ofd_osd;
196 struct lu_device *next = &dt_next->dd_lu_dev;
201 switch (cfg->lcfg_command) {
203 struct lprocfs_static_vars lvars;
205 /* For interoperability */
206 struct cfg_interop_param *ptr = NULL;
207 struct lustre_cfg *old_cfg = NULL;
210 param = lustre_cfg_string(cfg, 1);
212 CERROR("param is empty\n");
217 ptr = class_find_old_param(param, ofd_interop_param);
219 if (ptr->new_param == NULL) {
221 CWARN("For interoperability, skip this %s."
222 " It is obsolete.\n", ptr->old_param);
226 CWARN("Found old param %s, changed it to %s.\n",
227 ptr->old_param, ptr->new_param);
230 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
237 lprocfs_ofd_init_vars(&lvars);
238 rc = class_process_proc_param(PARAM_OST, lvars.obd_vars, cfg,
240 if (rc > 0 || rc == -ENOSYS)
241 /* we don't understand; pass it on */
242 rc = next->ld_ops->ldo_process_config(env, next, cfg);
245 case LCFG_SPTLRPC_CONF: {
250 /* others are passed further */
251 rc = next->ld_ops->ldo_process_config(env, next, cfg);
257 static int ofd_object_init(const struct lu_env *env, struct lu_object *o,
258 const struct lu_object_conf *conf)
260 struct ofd_device *d = ofd_dev(o->lo_dev);
261 struct lu_device *under;
262 struct lu_object *below;
267 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
268 PFID(lu_object_fid(o)));
270 under = &d->ofd_osd->dd_lu_dev;
271 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
273 lu_object_add(o, below);
280 static void ofd_object_free(const struct lu_env *env, struct lu_object *o)
282 struct ofd_object *of = ofd_obj(o);
283 struct lu_object_header *h;
288 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
289 PFID(lu_object_fid(o)));
292 lu_object_header_fini(h);
293 OBD_SLAB_FREE_PTR(of, ofd_object_kmem);
297 static int ofd_object_print(const struct lu_env *env, void *cookie,
298 lu_printer_t p, const struct lu_object *o)
300 return (*p)(env, cookie, LUSTRE_OST_NAME"-object@%p", o);
303 struct lu_object_operations ofd_obj_ops = {
304 .loo_object_init = ofd_object_init,
305 .loo_object_free = ofd_object_free,
306 .loo_object_print = ofd_object_print
309 static struct lu_object *ofd_object_alloc(const struct lu_env *env,
310 const struct lu_object_header *hdr,
313 struct ofd_object *of;
317 OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, __GFP_IO);
320 struct lu_object_header *h;
322 o = &of->ofo_obj.do_lu;
324 lu_object_header_init(h);
325 lu_object_init(o, h, d);
326 lu_object_add_top(h, o);
327 o->lo_ops = &ofd_obj_ops;
334 extern int ost_handle(struct ptlrpc_request *req);
336 static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
337 struct lu_device *dev)
339 struct ofd_thread_info *info;
340 struct ofd_device *ofd = ofd_dev(dev);
341 struct obd_device *obd = ofd_obd(ofd);
342 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
343 struct lfsck_start_param lsp;
348 rc = lu_env_refill((struct lu_env *)env);
350 CERROR("Failure to refill session: '%d'\n", rc);
354 info = ofd_info_init(env, NULL);
358 /* initialize lower device */
359 rc = next->ld_ops->ldo_prepare(env, dev, next);
363 rc = lfsck_register(env, ofd->ofd_osd, &ofd->ofd_dt_dev, false);
365 CERROR("%s: failed to initialize lfsck: rc = %d\n",
370 lsp.lsp_start = NULL;
371 lsp.lsp_namespace = ofd->ofd_namespace;
372 rc = lfsck_start(env, ofd->ofd_osd, &lsp);
374 CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
379 target_recovery_init(&ofd->ofd_lut, ost_handle);
380 LASSERT(obd->obd_no_conn);
381 spin_lock(&obd->obd_dev_lock);
382 obd->obd_no_conn = 0;
383 spin_unlock(&obd->obd_dev_lock);
385 if (obd->obd_recovering == 0)
386 ofd_postrecov(env, ofd);
391 static int ofd_recovery_complete(const struct lu_env *env,
392 struct lu_device *dev)
394 struct ofd_device *ofd = ofd_dev(dev);
395 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
396 int rc = 0, max_precreate;
400 /* Grant space for object precreation on the self export.
401 * This initial reserved space (i.e. 10MB for zfs and 280KB for ldiskfs)
402 * is enough to create 10k objects. More space is then acquired for
403 * precreation in ofd_grant_create().
405 max_precreate = OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
406 ofd_grant_connect(env, dev->ld_obd->obd_self_export, max_precreate,
408 rc = next->ld_ops->ldo_recovery_complete(env, next);
412 static struct lu_device_operations ofd_lu_ops = {
413 .ldo_object_alloc = ofd_object_alloc,
414 .ldo_process_config = ofd_process_config,
415 .ldo_recovery_complete = ofd_recovery_complete,
416 .ldo_prepare = ofd_prepare,
419 static int ofd_procfs_init(struct ofd_device *ofd)
421 struct lprocfs_static_vars lvars;
422 struct obd_device *obd = ofd_obd(ofd);
423 cfs_proc_dir_entry_t *entry;
428 /* lprocfs must be setup before the ofd so state can be safely added
429 * to /proc incrementally as the ofd is setup */
430 lprocfs_ofd_init_vars(&lvars);
431 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
433 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
438 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_LAST);
440 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
442 GOTO(obd_cleanup, rc);
445 /* Init OFD private stats here */
446 lprocfs_counter_init(obd->obd_stats, LPROC_OFD_READ_BYTES,
447 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
448 lprocfs_counter_init(obd->obd_stats, LPROC_OFD_WRITE_BYTES,
449 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
451 obd->obd_uses_nid_stats = 1;
453 entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
456 CERROR("%s: error %d setting up lprocfs for %s\n",
457 obd->obd_name, rc, "exports");
458 GOTO(obd_cleanup, rc);
460 obd->obd_proc_exports_entry = entry;
462 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
463 lprocfs_nid_stats_clear_read,
464 lprocfs_nid_stats_clear_write, obd, NULL);
467 CERROR("%s: add proc entry 'clear' failed: %d.\n",
469 GOTO(obd_cleanup, rc);
472 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
473 ofd_stats_counter_init);
475 GOTO(remove_entry_clear, rc);
478 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
480 lprocfs_obd_cleanup(obd);
481 lprocfs_free_obd_stats(obd);
486 static void ofd_procfs_add_brw_stats_symlink(struct ofd_device *ofd)
488 struct obd_device *obd = ofd_obd(ofd);
489 struct obd_device *osd_obd = ofd->ofd_osd_exp->exp_obd;
490 cfs_proc_dir_entry_t *osd_root = osd_obd->obd_type->typ_procroot;
491 cfs_proc_dir_entry_t *osd_dir;
493 osd_dir = lprocfs_srch(osd_root, obd->obd_name);
497 if (lprocfs_srch(osd_dir, "brw_stats") != NULL)
498 lprocfs_add_symlink("brw_stats", obd->obd_proc_entry,
499 "../../%s/%s/brw_stats",
500 osd_root->name, osd_dir->name);
502 if (lprocfs_srch(osd_dir, "read_cache_enable") != NULL)
503 lprocfs_add_symlink("read_cache_enable", obd->obd_proc_entry,
504 "../../%s/%s/read_cache_enable",
505 osd_root->name, osd_dir->name);
507 if (lprocfs_srch(osd_dir, "readcache_max_filesize") != NULL)
508 lprocfs_add_symlink("readcache_max_filesize",
510 "../../%s/%s/readcache_max_filesize",
511 osd_root->name, osd_dir->name);
513 if (lprocfs_srch(osd_dir, "writethrough_cache_enable") != NULL)
514 lprocfs_add_symlink("writethrough_cache_enable",
516 "../../%s/%s/writethrough_cache_enable",
517 osd_root->name, osd_dir->name);
520 static void ofd_procfs_fini(struct ofd_device *ofd)
522 struct obd_device *obd = ofd_obd(ofd);
524 lprocfs_remove_proc_entry("writethrough_cache_enable",
525 obd->obd_proc_entry);
526 lprocfs_remove_proc_entry("readcache_max_filesize",
527 obd->obd_proc_entry);
528 lprocfs_remove_proc_entry("read_cache_enable", obd->obd_proc_entry);
529 lprocfs_remove_proc_entry("brw_stats", obd->obd_proc_entry);
530 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
531 lprocfs_free_per_client_stats(obd);
532 lprocfs_obd_cleanup(obd);
533 lprocfs_free_obd_stats(obd);
534 lprocfs_job_stats_fini(obd);
537 extern int ost_handle(struct ptlrpc_request *req);
539 int ofd_fid_fini(const struct lu_env *env, struct ofd_device *ofd)
541 return seq_site_fini(env, &ofd->ofd_seq_site);
544 int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd)
546 struct seq_server_site *ss = &ofd->ofd_seq_site;
547 struct lu_device *lu = &ofd->ofd_dt_dev.dd_lu_dev;
548 char *obd_name = ofd_name(ofd);
552 ss = &ofd->ofd_seq_site;
553 lu->ld_site->ld_seq_site = ss;
554 ss->ss_lu = lu->ld_site;
555 ss->ss_node_id = ofd->ofd_lut.lut_lsd.lsd_osd_index;
557 OBD_ALLOC_PTR(ss->ss_server_seq);
558 if (ss->ss_server_seq == NULL)
559 GOTO(out_free, rc = -ENOMEM);
561 OBD_ALLOC(name, strlen(obd_name) + 10);
563 OBD_FREE_PTR(ss->ss_server_seq);
564 ss->ss_server_seq = NULL;
565 GOTO(out_free, rc = -ENOMEM);
568 rc = seq_server_init(ss->ss_server_seq, ofd->ofd_osd, obd_name,
569 LUSTRE_SEQ_SERVER, ss, env);
571 CERROR("%s : seq server init error %d\n", obd_name, rc);
574 ss->ss_server_seq->lss_space.lsr_index = ss->ss_node_id;
576 OBD_ALLOC_PTR(ss->ss_client_seq);
577 if (ss->ss_client_seq == NULL)
578 GOTO(out_free, rc = -ENOMEM);
580 snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name);
581 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA,
584 CERROR("%s : seq client init error %d\n", obd_name, rc);
587 OBD_FREE(name, strlen(obd_name) + 10);
590 rc = seq_server_set_cli(ss->ss_server_seq, ss->ss_client_seq, env);
594 if (ss->ss_server_seq) {
595 seq_server_fini(ss->ss_server_seq, env);
596 OBD_FREE_PTR(ss->ss_server_seq);
597 ss->ss_server_seq = NULL;
600 if (ss->ss_client_seq) {
601 seq_client_fini(ss->ss_client_seq);
602 OBD_FREE_PTR(ss->ss_client_seq);
603 ss->ss_client_seq = NULL;
607 OBD_FREE(name, strlen(obd_name) + 10);
615 static struct tgt_opc_slice ofd_common_slice[] = {
617 .tos_opc_start = UPDATE_OBJ,
618 .tos_opc_end = UPDATE_LAST_OPC,
619 .tos_hs = tgt_out_handlers
622 .tos_opc_start = SEQ_FIRST_OPC,
623 .tos_opc_end = SEQ_LAST_OPC,
624 .tos_hs = seq_handlers
631 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
632 struct lu_device_type *ldt, struct lustre_cfg *cfg)
634 const char *dev = lustre_cfg_string(cfg, 0);
635 struct ofd_thread_info *info = NULL;
636 struct obd_device *obd;
637 struct obd_statfs *osfs;
642 obd = class_name2obd(dev);
644 CERROR("Cannot find obd with name %s\n", dev);
648 rc = lu_env_refill((struct lu_env *)env);
652 obd->u.obt.obt_magic = OBT_MAGIC;
654 m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT;
655 m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT;
657 spin_lock_init(&m->ofd_flags_lock);
658 m->ofd_raid_degraded = 0;
659 m->ofd_syncjournal = 0;
661 m->ofd_grant_compat_disable = 0;
664 spin_lock_init(&m->ofd_osfs_lock);
665 m->ofd_osfs_age = cfs_time_shift_64(-1000);
666 m->ofd_osfs_unstable = 0;
667 m->ofd_statfs_inflight = 0;
668 m->ofd_osfs_inflight = 0;
671 spin_lock_init(&m->ofd_grant_lock);
672 m->ofd_tot_dirty = 0;
673 m->ofd_tot_granted = 0;
674 m->ofd_tot_pending = 0;
675 m->ofd_seq_count = 0;
677 spin_lock_init(&m->ofd_batch_lock);
678 rwlock_init(&obd->u.filter.fo_sptlrpc_lock);
679 sptlrpc_rule_set_init(&obd->u.filter.fo_sptlrpc_rset);
681 obd->u.filter.fo_fl_oss_capa = 0;
682 CFS_INIT_LIST_HEAD(&obd->u.filter.fo_capa_keys);
683 obd->u.filter.fo_capa_hash = init_capa_hash();
684 if (obd->u.filter.fo_capa_hash == NULL)
687 m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
688 m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
689 /* set this lu_device to obd, because error handling need it */
690 obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
692 rc = ofd_procfs_init(m);
694 CERROR("Can't init ofd lprocfs, rc %d\n", rc);
698 /* No connection accepted until configurations will finish */
699 spin_lock(&obd->obd_dev_lock);
700 obd->obd_no_conn = 1;
701 spin_unlock(&obd->obd_dev_lock);
702 obd->obd_replayable = 1;
703 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
704 char *str = lustre_cfg_string(cfg, 4);
706 if (strchr(str, 'n')) {
707 CWARN("%s: recovery disabled\n", obd->obd_name);
708 obd->obd_replayable = 0;
712 info = ofd_info_init(env, NULL);
716 rc = ofd_stack_init(env, m, cfg);
718 CERROR("Can't init device stack, rc %d\n", rc);
719 GOTO(err_fini_proc, rc);
722 ofd_procfs_add_brw_stats_symlink(m);
724 /* populate cached statfs data */
725 osfs = &ofd_info(env)->fti_u.osfs;
726 rc = ofd_statfs_internal(env, m, osfs, 0, NULL);
728 CERROR("%s: can't get statfs data, rc %d\n", obd->obd_name, rc);
729 GOTO(err_fini_stack, rc);
731 if (!IS_PO2(osfs->os_bsize)) {
732 CERROR("%s: blocksize (%d) is not a power of 2\n",
733 obd->obd_name, osfs->os_bsize);
734 GOTO(err_fini_stack, rc = -EPROTO);
736 m->ofd_blockbits = fls(osfs->os_bsize) - 1;
738 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT;
739 if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS)
740 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_SMALL;
742 snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-%s",
743 "filter"/*LUSTRE_OST_NAME*/, obd->obd_uuid.uuid);
744 m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name,
745 LDLM_NAMESPACE_SERVER,
746 LDLM_NAMESPACE_GREEDY,
748 if (m->ofd_namespace == NULL)
749 GOTO(err_fini_stack, rc = -ENOMEM);
750 /* set obd_namespace for compatibility with old code */
751 obd->obd_namespace = m->ofd_namespace;
752 ldlm_register_intent(m->ofd_namespace, ofd_intent_policy);
753 m->ofd_namespace->ns_lvbo = &ofd_lvbo;
754 m->ofd_namespace->ns_lvbp = m;
756 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
757 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
759 dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf);
761 /* Allow at most ddp_grant_reserved% of the available filesystem space
762 * to be granted to clients, so that any errors in the grant overhead
763 * calculations do not allow granting more space to clients than can be
764 * written. Assumes that in aggregate the grant overhead calculations do
765 * not have more than ddp_grant_reserved% estimation error in them. */
767 ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved);
769 rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd, ofd_common_slice,
770 OBD_FAIL_OST_ALL_REQUEST_NET,
771 OBD_FAIL_OST_ALL_REPLY_NET);
773 GOTO(err_free_ns, rc);
775 rc = ofd_fs_setup(env, m, obd);
777 GOTO(err_fini_lut, rc);
781 tgt_fini(env, &m->ofd_lut);
783 ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force);
784 obd->obd_namespace = m->ofd_namespace = NULL;
786 ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev);
792 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
794 struct obd_device *obd = ofd_obd(m);
795 struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev;
797 lfsck_stop(env, m->ofd_osd, true);
798 lfsck_degister(env, m->ofd_osd);
799 target_recovery_fini(obd);
800 obd_exports_barrier(obd);
801 obd_zombie_barrier();
803 tgt_fini(env, &m->ofd_lut);
804 ofd_fs_cleanup(env, m);
806 ofd_free_capa_keys(m);
807 cleanup_capa_hash(obd->u.filter.fo_capa_hash);
809 if (m->ofd_namespace != NULL) {
810 ldlm_namespace_free(m->ofd_namespace, NULL,
811 d->ld_obd->obd_force);
812 d->ld_obd->obd_namespace = m->ofd_namespace = NULL;
815 ofd_stack_fini(env, m, &m->ofd_dt_dev.dd_lu_dev);
817 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
818 server_put_mount(obd->obd_name, NULL);
822 static struct lu_device *ofd_device_fini(const struct lu_env *env,
826 ofd_fini(env, ofd_dev(d));
830 static struct lu_device *ofd_device_free(const struct lu_env *env,
833 struct ofd_device *m = ofd_dev(d);
835 dt_device_fini(&m->ofd_dt_dev);
840 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
841 struct lu_device_type *t,
842 struct lustre_cfg *cfg)
844 struct ofd_device *m;
850 return ERR_PTR(-ENOMEM);
852 l = &m->ofd_dt_dev.dd_lu_dev;
853 dt_device_init(&m->ofd_dt_dev, t);
854 rc = ofd_init0(env, m, t, cfg);
856 ofd_device_free(env, l);
863 /* thread context key constructor/destructor */
864 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
866 static void ofd_key_exit(const struct lu_context *ctx,
867 struct lu_context_key *key, void *data)
869 struct ofd_thread_info *info = data;
871 info->fti_env = NULL;
872 info->fti_exp = NULL;
875 info->fti_transno = 0;
876 info->fti_pre_version = 0;
877 info->fti_obj = NULL;
878 info->fti_has_trans = 0;
879 info->fti_mult_trans = 0;
882 memset(&info->fti_attr, 0, sizeof info->fti_attr);
885 struct lu_context_key ofd_thread_key = {
886 .lct_tags = LCT_DT_THREAD,
887 .lct_init = ofd_key_init,
888 .lct_fini = ofd_key_fini,
889 .lct_exit = ofd_key_exit
892 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
893 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
895 static struct lu_device_type_operations ofd_device_type_ops = {
896 .ldto_init = ofd_type_init,
897 .ldto_fini = ofd_type_fini,
899 .ldto_start = ofd_type_start,
900 .ldto_stop = ofd_type_stop,
902 .ldto_device_alloc = ofd_device_alloc,
903 .ldto_device_free = ofd_device_free,
904 .ldto_device_fini = ofd_device_fini
907 static struct lu_device_type ofd_device_type = {
908 .ldt_tags = LU_DEVICE_DT,
909 .ldt_name = LUSTRE_OST_NAME,
910 .ldt_ops = &ofd_device_type_ops,
911 .ldt_ctx_tags = LCT_DT_THREAD
914 int __init ofd_init(void)
916 struct lprocfs_static_vars lvars;
919 rc = lu_kmem_init(ofd_caches);
925 lu_kmem_fini(ofd_caches);
929 lprocfs_ofd_init_vars(&lvars);
931 rc = class_register_type(&ofd_obd_ops, NULL, lvars.module_vars,
932 LUSTRE_OST_NAME, &ofd_device_type);
936 void __exit ofd_exit(void)
939 lu_kmem_fini(ofd_caches);
940 class_unregister_type(LUSTRE_OST_NAME);
943 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
944 MODULE_DESCRIPTION("Lustre Object Filtering Device");
945 MODULE_LICENSE("GPL");
947 module_init(ofd_init);
948 module_exit(ofd_exit);