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);
183 /* For interoperability, see mdt_interop_param[]. */
184 static struct cfg_interop_param ofd_interop_param[] = {
185 { "ost.quota_type", NULL },
189 /* Some parameters were moved from ofd to osd and only their
190 * symlinks were kept in ofd by LU-3106. They are:
191 * -writehthrough_cache_enable
192 * -readcache_max_filese
195 * Since they are not included by the static lprocfs var list,
196 * a pre-check is added for them to avoid "unknown param" error
197 * message confuses the customer. If they are matched in this
198 * check, they will be passed to the osd directly.
200 static bool match_symlink_param(char *param)
205 if (class_match_param(param, PARAM_OST, ¶m) == 0) {
206 sval = strchr(param, '=');
208 paramlen = sval - param;
209 if (strncmp(param, "writethrough_cache_enable",
211 strncmp(param, "readcache_max_filesize",
213 strncmp(param, "read_cache_enable",
215 strncmp(param, "brw_stats", paramlen) == 0)
223 /* used by MGS to process specific configurations */
224 static int ofd_process_config(const struct lu_env *env, struct lu_device *d,
225 struct lustre_cfg *cfg)
227 struct ofd_device *m = ofd_dev(d);
228 struct dt_device *dt_next = m->ofd_osd;
229 struct lu_device *next = &dt_next->dd_lu_dev;
234 switch (cfg->lcfg_command) {
236 struct lprocfs_static_vars lvars;
238 /* For interoperability */
239 struct cfg_interop_param *ptr = NULL;
240 struct lustre_cfg *old_cfg = NULL;
243 param = lustre_cfg_string(cfg, 1);
245 CERROR("param is empty\n");
250 ptr = class_find_old_param(param, ofd_interop_param);
252 if (ptr->new_param == NULL) {
254 CWARN("For interoperability, skip this %s."
255 " It is obsolete.\n", ptr->old_param);
259 CWARN("Found old param %s, changed it to %s.\n",
260 ptr->old_param, ptr->new_param);
263 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
270 if (match_symlink_param(param)) {
271 rc = next->ld_ops->ldo_process_config(env, next, cfg);
275 lprocfs_ofd_init_vars(&lvars);
276 rc = class_process_proc_param(PARAM_OST, lvars.obd_vars, cfg,
278 if (rc > 0 || rc == -ENOSYS) {
279 CDEBUG(D_CONFIG, "pass param %s down the stack.\n",
281 /* we don't understand; pass it on */
282 rc = next->ld_ops->ldo_process_config(env, next, cfg);
286 case LCFG_SPTLRPC_CONF: {
291 /* others are passed further */
292 rc = next->ld_ops->ldo_process_config(env, next, cfg);
298 static int ofd_object_init(const struct lu_env *env, struct lu_object *o,
299 const struct lu_object_conf *conf)
301 struct ofd_device *d = ofd_dev(o->lo_dev);
302 struct lu_device *under;
303 struct lu_object *below;
308 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
309 PFID(lu_object_fid(o)));
311 under = &d->ofd_osd->dd_lu_dev;
312 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
314 lu_object_add(o, below);
321 static void ofd_object_free(const struct lu_env *env, struct lu_object *o)
323 struct ofd_object *of = ofd_obj(o);
324 struct lu_object_header *h;
329 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
330 PFID(lu_object_fid(o)));
333 lu_object_header_fini(h);
334 OBD_SLAB_FREE_PTR(of, ofd_object_kmem);
338 static int ofd_object_print(const struct lu_env *env, void *cookie,
339 lu_printer_t p, const struct lu_object *o)
341 return (*p)(env, cookie, LUSTRE_OST_NAME"-object@%p", o);
344 struct lu_object_operations ofd_obj_ops = {
345 .loo_object_init = ofd_object_init,
346 .loo_object_free = ofd_object_free,
347 .loo_object_print = ofd_object_print
350 static struct lu_object *ofd_object_alloc(const struct lu_env *env,
351 const struct lu_object_header *hdr,
354 struct ofd_object *of;
358 OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, GFP_NOFS);
361 struct lu_object_header *h;
363 o = &of->ofo_obj.do_lu;
365 lu_object_header_init(h);
366 lu_object_init(o, h, d);
367 lu_object_add_top(h, o);
368 o->lo_ops = &ofd_obj_ops;
375 extern int ost_handle(struct ptlrpc_request *req);
377 static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
378 struct lu_device *dev)
380 struct ofd_thread_info *info;
381 struct ofd_device *ofd = ofd_dev(dev);
382 struct obd_device *obd = ofd_obd(ofd);
383 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
384 struct lfsck_start_param lsp;
389 rc = lu_env_refill((struct lu_env *)env);
391 CERROR("Failure to refill session: '%d'\n", rc);
395 info = ofd_info_init(env, NULL);
399 /* initialize lower device */
400 rc = next->ld_ops->ldo_prepare(env, dev, next);
404 rc = lfsck_register(env, ofd->ofd_osd, &ofd->ofd_dt_dev, false);
406 CERROR("%s: failed to initialize lfsck: rc = %d\n",
411 lsp.lsp_start = NULL;
412 lsp.lsp_namespace = ofd->ofd_namespace;
413 rc = lfsck_start(env, ofd->ofd_osd, &lsp);
415 CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
420 target_recovery_init(&ofd->ofd_lut, ost_handle);
421 LASSERT(obd->obd_no_conn);
422 spin_lock(&obd->obd_dev_lock);
423 obd->obd_no_conn = 0;
424 spin_unlock(&obd->obd_dev_lock);
426 if (obd->obd_recovering == 0)
427 ofd_postrecov(env, ofd);
432 static int ofd_recovery_complete(const struct lu_env *env,
433 struct lu_device *dev)
435 struct ofd_device *ofd = ofd_dev(dev);
436 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
437 int rc = 0, max_precreate;
441 /* Grant space for object precreation on the self export.
442 * This initial reserved space (i.e. 10MB for zfs and 280KB for ldiskfs)
443 * is enough to create 10k objects. More space is then acquired for
444 * precreation in ofd_grant_create().
446 max_precreate = OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
447 ofd_grant_connect(env, dev->ld_obd->obd_self_export, max_precreate,
449 rc = next->ld_ops->ldo_recovery_complete(env, next);
453 static struct lu_device_operations ofd_lu_ops = {
454 .ldo_object_alloc = ofd_object_alloc,
455 .ldo_process_config = ofd_process_config,
456 .ldo_recovery_complete = ofd_recovery_complete,
457 .ldo_prepare = ofd_prepare,
460 static int ofd_procfs_init(struct ofd_device *ofd)
462 struct lprocfs_static_vars lvars;
463 struct obd_device *obd = ofd_obd(ofd);
464 cfs_proc_dir_entry_t *entry;
469 /* lprocfs must be setup before the ofd so state can be safely added
470 * to /proc incrementally as the ofd is setup */
471 lprocfs_ofd_init_vars(&lvars);
472 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
474 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
479 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_LAST);
481 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
483 GOTO(obd_cleanup, rc);
486 /* Init OFD private stats here */
487 lprocfs_counter_init(obd->obd_stats, LPROC_OFD_READ_BYTES,
488 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
489 lprocfs_counter_init(obd->obd_stats, LPROC_OFD_WRITE_BYTES,
490 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
492 obd->obd_uses_nid_stats = 1;
494 entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
497 CERROR("%s: error %d setting up lprocfs for %s\n",
498 obd->obd_name, rc, "exports");
499 GOTO(obd_cleanup, rc);
501 obd->obd_proc_exports_entry = entry;
503 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
504 lprocfs_nid_stats_clear_read,
505 lprocfs_nid_stats_clear_write, obd, NULL);
508 CERROR("%s: add proc entry 'clear' failed: %d.\n",
510 GOTO(obd_cleanup, rc);
513 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
514 ofd_stats_counter_init);
516 GOTO(remove_entry_clear, rc);
519 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
521 lprocfs_obd_cleanup(obd);
522 lprocfs_free_obd_stats(obd);
527 static void ofd_procfs_add_brw_stats_symlink(struct ofd_device *ofd)
529 struct obd_device *obd = ofd_obd(ofd);
530 struct obd_device *osd_obd = ofd->ofd_osd_exp->exp_obd;
531 cfs_proc_dir_entry_t *osd_root = osd_obd->obd_type->typ_procroot;
532 cfs_proc_dir_entry_t *osd_dir;
534 osd_dir = lprocfs_srch(osd_root, obd->obd_name);
538 if (lprocfs_srch(osd_dir, "brw_stats") != NULL)
539 lprocfs_add_symlink("brw_stats", obd->obd_proc_entry,
540 "../../%s/%s/brw_stats",
541 osd_root->name, osd_dir->name);
543 if (lprocfs_srch(osd_dir, "read_cache_enable") != NULL)
544 lprocfs_add_symlink("read_cache_enable", obd->obd_proc_entry,
545 "../../%s/%s/read_cache_enable",
546 osd_root->name, osd_dir->name);
548 if (lprocfs_srch(osd_dir, "readcache_max_filesize") != NULL)
549 lprocfs_add_symlink("readcache_max_filesize",
551 "../../%s/%s/readcache_max_filesize",
552 osd_root->name, osd_dir->name);
554 if (lprocfs_srch(osd_dir, "writethrough_cache_enable") != NULL)
555 lprocfs_add_symlink("writethrough_cache_enable",
557 "../../%s/%s/writethrough_cache_enable",
558 osd_root->name, osd_dir->name);
561 static void ofd_procfs_fini(struct ofd_device *ofd)
563 struct obd_device *obd = ofd_obd(ofd);
565 lprocfs_remove_proc_entry("writethrough_cache_enable",
566 obd->obd_proc_entry);
567 lprocfs_remove_proc_entry("readcache_max_filesize",
568 obd->obd_proc_entry);
569 lprocfs_remove_proc_entry("read_cache_enable", obd->obd_proc_entry);
570 lprocfs_remove_proc_entry("brw_stats", obd->obd_proc_entry);
571 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
572 lprocfs_free_per_client_stats(obd);
573 lprocfs_obd_cleanup(obd);
574 lprocfs_free_obd_stats(obd);
575 lprocfs_job_stats_fini(obd);
578 extern int ost_handle(struct ptlrpc_request *req);
580 int ofd_fid_fini(const struct lu_env *env, struct ofd_device *ofd)
582 return seq_site_fini(env, &ofd->ofd_seq_site);
585 int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd)
587 struct seq_server_site *ss = &ofd->ofd_seq_site;
588 struct lu_device *lu = &ofd->ofd_dt_dev.dd_lu_dev;
589 char *obd_name = ofd_name(ofd);
593 ss = &ofd->ofd_seq_site;
594 lu->ld_site->ld_seq_site = ss;
595 ss->ss_lu = lu->ld_site;
596 ss->ss_node_id = ofd->ofd_lut.lut_lsd.lsd_osd_index;
598 OBD_ALLOC_PTR(ss->ss_server_seq);
599 if (ss->ss_server_seq == NULL)
600 GOTO(out_free, rc = -ENOMEM);
602 OBD_ALLOC(name, strlen(obd_name) + 10);
604 OBD_FREE_PTR(ss->ss_server_seq);
605 ss->ss_server_seq = NULL;
606 GOTO(out_free, rc = -ENOMEM);
609 rc = seq_server_init(ss->ss_server_seq, ofd->ofd_osd, obd_name,
610 LUSTRE_SEQ_SERVER, ss, env);
612 CERROR("%s : seq server init error %d\n", obd_name, rc);
615 ss->ss_server_seq->lss_space.lsr_index = ss->ss_node_id;
617 OBD_ALLOC_PTR(ss->ss_client_seq);
618 if (ss->ss_client_seq == NULL)
619 GOTO(out_free, rc = -ENOMEM);
621 snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name);
622 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA,
625 CERROR("%s : seq client init error %d\n", obd_name, rc);
628 OBD_FREE(name, strlen(obd_name) + 10);
631 rc = seq_server_set_cli(ss->ss_server_seq, ss->ss_client_seq, env);
635 if (ss->ss_server_seq) {
636 seq_server_fini(ss->ss_server_seq, env);
637 OBD_FREE_PTR(ss->ss_server_seq);
638 ss->ss_server_seq = NULL;
641 if (ss->ss_client_seq) {
642 seq_client_fini(ss->ss_client_seq);
643 OBD_FREE_PTR(ss->ss_client_seq);
644 ss->ss_client_seq = NULL;
648 OBD_FREE(name, strlen(obd_name) + 10);
656 static struct tgt_opc_slice ofd_common_slice[] = {
658 .tos_opc_start = UPDATE_OBJ,
659 .tos_opc_end = UPDATE_LAST_OPC,
660 .tos_hs = tgt_out_handlers
663 .tos_opc_start = SEQ_FIRST_OPC,
664 .tos_opc_end = SEQ_LAST_OPC,
665 .tos_hs = seq_handlers
672 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
673 struct lu_device_type *ldt, struct lustre_cfg *cfg)
675 const char *dev = lustre_cfg_string(cfg, 0);
676 struct ofd_thread_info *info = NULL;
677 struct obd_device *obd;
678 struct obd_statfs *osfs;
683 obd = class_name2obd(dev);
685 CERROR("Cannot find obd with name %s\n", dev);
689 rc = lu_env_refill((struct lu_env *)env);
693 obd->u.obt.obt_magic = OBT_MAGIC;
695 m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT;
696 m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT;
698 spin_lock_init(&m->ofd_flags_lock);
699 m->ofd_raid_degraded = 0;
700 m->ofd_syncjournal = 0;
702 m->ofd_grant_compat_disable = 0;
705 spin_lock_init(&m->ofd_osfs_lock);
706 m->ofd_osfs_age = cfs_time_shift_64(-1000);
707 m->ofd_osfs_unstable = 0;
708 m->ofd_statfs_inflight = 0;
709 m->ofd_osfs_inflight = 0;
712 spin_lock_init(&m->ofd_grant_lock);
713 m->ofd_tot_dirty = 0;
714 m->ofd_tot_granted = 0;
715 m->ofd_tot_pending = 0;
716 m->ofd_seq_count = 0;
718 spin_lock_init(&m->ofd_batch_lock);
719 rwlock_init(&obd->u.filter.fo_sptlrpc_lock);
720 sptlrpc_rule_set_init(&obd->u.filter.fo_sptlrpc_rset);
722 obd->u.filter.fo_fl_oss_capa = 0;
723 CFS_INIT_LIST_HEAD(&obd->u.filter.fo_capa_keys);
724 obd->u.filter.fo_capa_hash = init_capa_hash();
725 if (obd->u.filter.fo_capa_hash == NULL)
728 m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
729 m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
730 /* set this lu_device to obd, because error handling need it */
731 obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
733 rc = ofd_procfs_init(m);
735 CERROR("Can't init ofd lprocfs, rc %d\n", rc);
739 /* No connection accepted until configurations will finish */
740 spin_lock(&obd->obd_dev_lock);
741 obd->obd_no_conn = 1;
742 spin_unlock(&obd->obd_dev_lock);
743 obd->obd_replayable = 1;
744 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
745 char *str = lustre_cfg_string(cfg, 4);
747 if (strchr(str, 'n')) {
748 CWARN("%s: recovery disabled\n", obd->obd_name);
749 obd->obd_replayable = 0;
753 info = ofd_info_init(env, NULL);
757 rc = ofd_stack_init(env, m, cfg);
759 CERROR("Can't init device stack, rc %d\n", rc);
760 GOTO(err_fini_proc, rc);
763 ofd_procfs_add_brw_stats_symlink(m);
765 /* populate cached statfs data */
766 osfs = &ofd_info(env)->fti_u.osfs;
767 rc = ofd_statfs_internal(env, m, osfs, 0, NULL);
769 CERROR("%s: can't get statfs data, rc %d\n", obd->obd_name, rc);
770 GOTO(err_fini_stack, rc);
772 if (!IS_PO2(osfs->os_bsize)) {
773 CERROR("%s: blocksize (%d) is not a power of 2\n",
774 obd->obd_name, osfs->os_bsize);
775 GOTO(err_fini_stack, rc = -EPROTO);
777 m->ofd_blockbits = fls(osfs->os_bsize) - 1;
779 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT;
780 if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS)
781 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_SMALL;
783 snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-%s",
784 "filter"/*LUSTRE_OST_NAME*/, obd->obd_uuid.uuid);
785 m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name,
786 LDLM_NAMESPACE_SERVER,
787 LDLM_NAMESPACE_GREEDY,
789 if (m->ofd_namespace == NULL)
790 GOTO(err_fini_stack, rc = -ENOMEM);
791 /* set obd_namespace for compatibility with old code */
792 obd->obd_namespace = m->ofd_namespace;
793 ldlm_register_intent(m->ofd_namespace, ofd_intent_policy);
794 m->ofd_namespace->ns_lvbo = &ofd_lvbo;
795 m->ofd_namespace->ns_lvbp = m;
797 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
798 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
800 dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf);
802 /* Allow at most ddp_grant_reserved% of the available filesystem space
803 * to be granted to clients, so that any errors in the grant overhead
804 * calculations do not allow granting more space to clients than can be
805 * written. Assumes that in aggregate the grant overhead calculations do
806 * not have more than ddp_grant_reserved% estimation error in them. */
808 ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved);
810 rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd, ofd_common_slice,
811 OBD_FAIL_OST_ALL_REQUEST_NET,
812 OBD_FAIL_OST_ALL_REPLY_NET);
814 GOTO(err_free_ns, rc);
816 rc = ofd_fs_setup(env, m, obd);
818 GOTO(err_fini_lut, rc);
822 tgt_fini(env, &m->ofd_lut);
824 ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force);
825 obd->obd_namespace = m->ofd_namespace = NULL;
827 ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev);
833 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
835 struct obd_device *obd = ofd_obd(m);
836 struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev;
838 lfsck_stop(env, m->ofd_osd, true);
839 lfsck_degister(env, m->ofd_osd);
840 target_recovery_fini(obd);
841 obd_exports_barrier(obd);
842 obd_zombie_barrier();
844 tgt_fini(env, &m->ofd_lut);
845 ofd_fs_cleanup(env, m);
847 ofd_free_capa_keys(m);
848 cleanup_capa_hash(obd->u.filter.fo_capa_hash);
850 if (m->ofd_namespace != NULL) {
851 ldlm_namespace_free(m->ofd_namespace, NULL,
852 d->ld_obd->obd_force);
853 d->ld_obd->obd_namespace = m->ofd_namespace = NULL;
856 ofd_stack_fini(env, m, &m->ofd_dt_dev.dd_lu_dev);
858 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
859 server_put_mount(obd->obd_name);
863 static struct lu_device *ofd_device_fini(const struct lu_env *env,
867 ofd_fini(env, ofd_dev(d));
871 static struct lu_device *ofd_device_free(const struct lu_env *env,
874 struct ofd_device *m = ofd_dev(d);
876 dt_device_fini(&m->ofd_dt_dev);
881 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
882 struct lu_device_type *t,
883 struct lustre_cfg *cfg)
885 struct ofd_device *m;
891 return ERR_PTR(-ENOMEM);
893 l = &m->ofd_dt_dev.dd_lu_dev;
894 dt_device_init(&m->ofd_dt_dev, t);
895 rc = ofd_init0(env, m, t, cfg);
897 ofd_device_free(env, l);
904 /* thread context key constructor/destructor */
905 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
907 static void ofd_key_exit(const struct lu_context *ctx,
908 struct lu_context_key *key, void *data)
910 struct ofd_thread_info *info = data;
912 info->fti_env = NULL;
913 info->fti_exp = NULL;
916 info->fti_transno = 0;
917 info->fti_pre_version = 0;
918 info->fti_obj = NULL;
919 info->fti_has_trans = 0;
920 info->fti_mult_trans = 0;
923 memset(&info->fti_attr, 0, sizeof info->fti_attr);
926 struct lu_context_key ofd_thread_key = {
927 .lct_tags = LCT_DT_THREAD,
928 .lct_init = ofd_key_init,
929 .lct_fini = ofd_key_fini,
930 .lct_exit = ofd_key_exit
933 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
934 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
936 static struct lu_device_type_operations ofd_device_type_ops = {
937 .ldto_init = ofd_type_init,
938 .ldto_fini = ofd_type_fini,
940 .ldto_start = ofd_type_start,
941 .ldto_stop = ofd_type_stop,
943 .ldto_device_alloc = ofd_device_alloc,
944 .ldto_device_free = ofd_device_free,
945 .ldto_device_fini = ofd_device_fini
948 static struct lu_device_type ofd_device_type = {
949 .ldt_tags = LU_DEVICE_DT,
950 .ldt_name = LUSTRE_OST_NAME,
951 .ldt_ops = &ofd_device_type_ops,
952 .ldt_ctx_tags = LCT_DT_THREAD
955 int __init ofd_init(void)
957 struct lprocfs_static_vars lvars;
960 rc = lu_kmem_init(ofd_caches);
966 lu_kmem_fini(ofd_caches);
970 lprocfs_ofd_init_vars(&lvars);
972 rc = class_register_type(&ofd_obd_ops, NULL, lvars.module_vars,
973 LUSTRE_OST_NAME, &ofd_device_type);
977 void __exit ofd_exit(void)
980 lu_kmem_fini(ofd_caches);
981 class_unregister_type(LUSTRE_OST_NAME);
984 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
985 MODULE_DESCRIPTION("Lustre Object Filtering Device");
986 MODULE_LICENSE("GPL");
988 module_init(ofd_init);
989 module_exit(ofd_exit);