4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2013, Intel Corporation.
30 * This file is part of Lustre, http://www.lustre.org/
31 * Lustre is a trademark of Sun Microsystems, Inc.
33 * lustre/lod/lod_dev.c
35 * Lustre Logical Object Device
37 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
38 * Author: Mikhail Pershin <mike.pershin@intel.com>
42 # define EXPORT_SYMTAB
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include <obd_class.h>
47 #include <md_object.h>
48 #include <lustre_fid.h>
49 #include <lustre_param.h>
50 #include <lustre_update.h>
52 #include "lod_internal.h"
55 * Lookup MDT/OST index \a tgt by FID \a fid.
57 * \param lod LOD to be lookup at.
58 * \param fid FID of object to find MDT/OST.
59 * \param tgt MDT/OST index to return.
60 * \param type indidcate the FID is on MDS or OST.
62 int lod_fld_lookup(const struct lu_env *env, struct lod_device *lod,
63 const struct lu_fid *fid, __u32 *tgt, int type)
65 struct lu_seq_range range = { 0 };
66 struct lu_server_fld *server_fld;
70 LASSERTF(fid_is_sane(fid), "Invalid FID "DFID"\n", PFID(fid));
71 if (fid_is_idif(fid)) {
72 *tgt = fid_idif_ost_idx(fid);
76 if (!lod->lod_initialized || (!fid_seq_in_fldb(fid_seq(fid)))) {
77 LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
78 *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
82 server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
83 fld_range_set_type(&range, type);
84 rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
88 *tgt = range.lsr_index;
90 CDEBUG(D_INFO, "LOD: got tgt %x for sequence: "
91 LPX64"\n", *tgt, fid_seq(fid));
96 extern struct lu_object_operations lod_lu_obj_ops;
97 extern struct lu_object_operations lod_lu_robj_ops;
98 extern struct dt_object_operations lod_obj_ops;
100 /* Slab for OSD object allocation */
101 cfs_mem_cache_t *lod_object_kmem;
103 static struct lu_kmem_descr lod_caches[] = {
105 .ckd_cache = &lod_object_kmem,
106 .ckd_name = "lod_obj",
107 .ckd_size = sizeof(struct lod_object)
114 static struct lu_device *lod_device_fini(const struct lu_env *env,
115 struct lu_device *d);
117 struct lu_object *lod_object_alloc(const struct lu_env *env,
118 const struct lu_object_header *hdr,
119 struct lu_device *dev)
121 struct lod_object *lod_obj;
122 struct lu_object *lu_obj;
123 const struct lu_fid *fid = &hdr->loh_fid;
128 OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, CFS_ALLOC_IO);
130 RETURN(ERR_PTR(-ENOMEM));
132 rc = lod_fld_lookup(env, lu2lod_dev(dev), fid, &mds, LU_SEQ_RANGE_MDT);
134 OBD_SLAB_FREE_PTR(lod_obj, lod_object_kmem);
138 lod_obj->ldo_mds_num = mds;
139 lu_obj = lod2lu_obj(lod_obj);
140 dt_object_init(&lod_obj->ldo_obj, NULL, dev);
141 lod_obj->ldo_obj.do_ops = &lod_obj_ops;
142 if (likely(mds == lu_site2seq(dev->ld_site)->ss_node_id))
143 lu_obj->lo_ops = &lod_lu_obj_ops;
145 lu_obj->lo_ops = &lod_lu_robj_ops;
149 static int lod_cleanup_desc_tgts(const struct lu_env *env,
150 struct lod_device *lod,
151 struct lod_tgt_descs *ltd,
152 struct lustre_cfg *lcfg)
154 struct lu_device *next;
159 if (ltd->ltd_tgts_size <= 0) {
160 lod_putref(lod, ltd);
163 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
164 struct lod_tgt_desc *tgt;
167 tgt = LTD_TGT(ltd, i);
168 LASSERT(tgt && tgt->ltd_tgt);
169 next = &tgt->ltd_tgt->dd_lu_dev;
170 rc1 = next->ld_ops->ldo_process_config(env, next, lcfg);
172 CERROR("%s: error cleaning up LOD index %u: cmd %#x"
173 ": rc = %d\n", lod2obd(lod)->obd_name, i,
174 lcfg->lcfg_command, rc1);
178 lod_putref(lod, ltd);
182 static int lodname2mdt_index(char *lodname, int *index)
186 /* The lodname suppose to be fsname-MDTxxxx-mdtlov */
187 ptr = strrchr(lodname, '-');
189 CERROR("invalid MDT index in '%s'\n", lodname);
193 if (strncmp(ptr, "-mdtlov", 7) != 0) {
194 CERROR("invalid MDT index in '%s'\n", lodname);
198 if ((unsigned long)ptr - (unsigned long)lodname <= 8) {
199 CERROR("invalid MDT index in '%s'\n", lodname);
203 if (strncmp(ptr - 8, "-MDT", 4) != 0) {
204 CERROR("invalid MDT index in '%s'\n", lodname);
208 *index = simple_strtol(ptr - 4, &tmp, 16);
209 if (*tmp != '-' || *index > INT_MAX || *index < 0) {
210 CERROR("invalid MDT index in '%s'\n", lodname);
217 * Init client sequence manager which is used by local MDS to talk to sequence
218 * controller on remote node.
220 static int lod_seq_init_cli(const struct lu_env *env,
221 struct lod_device *lod,
222 char *tgtuuid, int index)
224 struct seq_server_site *ss;
225 struct obd_device *osp;
228 struct obd_uuid obd_uuid;
231 ss = lu_site2seq(lod2lu_dev(lod)->ld_site);
234 /* check if this is adding the first MDC and controller is not yet
236 if (index != 0 || ss->ss_client_seq)
239 obd_str2uuid(&obd_uuid, tgtuuid);
240 osp = class_find_client_obd(&obd_uuid, LUSTRE_OSP_NAME,
241 &lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_uuid);
243 CERROR("%s: can't find %s device\n",
244 lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_name,
249 if (!osp->obd_set_up) {
250 CERROR("target %s not set up\n", osp->obd_name);
254 LASSERT(ss->ss_control_exp);
255 OBD_ALLOC_PTR(ss->ss_client_seq);
256 if (ss->ss_client_seq == NULL)
259 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
261 OBD_FREE_PTR(ss->ss_client_seq);
262 ss->ss_client_seq = NULL;
266 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s", osp->obd_name);
267 rc = seq_client_init(ss->ss_client_seq, ss->ss_control_exp,
268 LUSTRE_SEQ_METADATA, prefix, NULL);
269 OBD_FREE(prefix, MAX_OBD_NAME + 5);
271 OBD_FREE_PTR(ss->ss_client_seq);
272 ss->ss_client_seq = NULL;
276 LASSERT(ss->ss_server_seq != NULL);
277 rc = seq_server_set_cli(ss->ss_server_seq, ss->ss_client_seq,
283 static void lod_seq_fini_cli(struct lod_device *lod)
285 struct seq_server_site *ss;
289 ss = lu_site2seq(lod2lu_dev(lod)->ld_site);
295 if (ss->ss_server_seq)
296 seq_server_set_cli(ss->ss_server_seq,
299 if (ss->ss_control_exp) {
300 class_export_put(ss->ss_control_exp);
301 ss->ss_control_exp = NULL;
309 * Procss config log on LOD
310 * \param env environment info
311 * \param dev lod device
312 * \param lcfg config log
314 * Add osc config log,
315 * marker 20 (flags=0x01, v2.2.49.56) lustre-OST0001 'add osc'
316 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nidxxx
317 * attach 0:lustre-OST0001-osc-MDT0001 1:osc 2:lustre-MDT0001-mdtlov_UUID
318 * setup 0:lustre-OST0001-osc-MDT0001 1:lustre-OST0001_UUID 2:nid
319 * lov_modify_tgts add 0:lustre-MDT0001-mdtlov 1:lustre-OST0001_UUID 2:1 3:1
320 * marker 20 (flags=0x02, v2.2.49.56) lustre-OST0001 'add osc'
323 * marker 10 (flags=0x01, v2.2.49.56) lustre-MDT0000 'add osp'
324 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nid
325 * attach 0:lustre-MDT0000-osp-MDT0001 1:osp 2:lustre-MDT0001-mdtlov_UUID
326 * setup 0:lustre-MDT0000-osp-MDT0001 1:lustre-MDT0000_UUID 2:nid
327 * modify_mdc_tgts add 0:lustre-MDT0001 1:lustre-MDT0000_UUID 2:0 3:1
328 * marker 10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID 'add osp'
330 static int lod_process_config(const struct lu_env *env,
331 struct lu_device *dev,
332 struct lustre_cfg *lcfg)
334 struct lod_device *lod = lu2lod_dev(dev);
335 struct lu_device *next = &lod->lod_child->dd_lu_dev;
340 switch(lcfg->lcfg_command) {
341 case LCFG_LOV_DEL_OBD:
342 case LCFG_LOV_ADD_INA:
343 case LCFG_LOV_ADD_OBD:
348 /* lov_modify_tgts add 0:lov_mdsA 1:osp 2:0 3:1
349 * modify_mdc_tgts add 0:lustre-MDT0001
350 * 1:lustre-MDT0001-mdc0002
352 arg1 = lustre_cfg_string(lcfg, 1);
354 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
355 GOTO(out, rc = -EINVAL);
356 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
357 GOTO(out, rc = -EINVAL);
359 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD) {
361 mdt = strstr(lustre_cfg_string(lcfg, 0), "-MDT");
362 /* 1.8 configs don't have "-MDT0000" at the end */
366 rc = lodname2mdt_index(
367 lustre_cfg_string(lcfg, 0), &mdt_index);
371 rc = lod_add_device(env, lod, arg1, index, gen,
372 mdt_index, LUSTRE_OSC_NAME, 1);
373 } else if (lcfg->lcfg_command == LCFG_ADD_MDC) {
375 rc = lod_add_device(env, lod, arg1, index, gen,
376 mdt_index, LUSTRE_MDC_NAME, 1);
378 rc = lod_seq_init_cli(env, lod, arg1,
380 } else if (lcfg->lcfg_command == LCFG_LOV_ADD_INA) {
381 /*FIXME: Add mdt_index for LCFG_LOV_ADD_INA*/
383 rc = lod_add_device(env, lod, arg1, index, gen,
384 mdt_index, LUSTRE_OSC_NAME, 0);
386 rc = lod_del_device(env, lod,
395 struct lprocfs_static_vars v = { 0 };
396 struct obd_device *obd = lod2obd(lod);
398 lprocfs_lod_init_vars(&v);
400 rc = class_process_proc_param(PARAM_LOV, v.obd_vars, lcfg, obd);
406 case LCFG_PRE_CLEANUP: {
407 lu_dev_del_linkage(dev->ld_site, dev);
408 lod_cleanup_desc_tgts(env, lod, &lod->lod_mdt_descs, lcfg);
409 lod_cleanup_desc_tgts(env, lod, &lod->lod_ost_descs, lcfg);
411 lod_seq_fini_cli(lod);
413 if (lcfg->lcfg_command == LCFG_PRE_CLEANUP)
416 * do cleanup on underlying storage only when
417 * all OSPs are cleaned up, as they use that OSD as well
419 next = &lod->lod_child->dd_lu_dev;
420 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
422 CERROR("%s: can't process %u: %d\n",
423 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
425 rc = obd_disconnect(lod->lod_child_exp);
427 CERROR("error in disconnect from storage: %d\n", rc);
431 CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
441 static int lod_recovery_complete(const struct lu_env *env,
442 struct lu_device *dev)
444 struct lod_device *lod = lu2lod_dev(dev);
445 struct lu_device *next = &lod->lod_child->dd_lu_dev;
449 LASSERT(lod->lod_recovery_completed == 0);
450 lod->lod_recovery_completed = 1;
452 rc = next->ld_ops->ldo_recovery_complete(env, next);
454 lod_getref(&lod->lod_ost_descs);
455 if (lod->lod_osts_size > 0) {
456 cfs_foreach_bit(lod->lod_ost_bitmap, i) {
457 struct lod_tgt_desc *tgt;
458 tgt = OST_TGT(lod, i);
459 LASSERT(tgt && tgt->ltd_tgt);
460 next = &tgt->ltd_ost->dd_lu_dev;
461 rc = next->ld_ops->ldo_recovery_complete(env, next);
463 CERROR("%s: can't complete recovery on #%d:"
464 "%d\n", lod2obd(lod)->obd_name, i, rc);
467 lod_putref(lod, &lod->lod_ost_descs);
471 static int lod_prepare(const struct lu_env *env, struct lu_device *pdev,
472 struct lu_device *cdev)
474 struct lod_device *lod = lu2lod_dev(cdev);
475 struct lu_device *next = &lod->lod_child->dd_lu_dev;
479 rc = next->ld_ops->ldo_prepare(env, pdev, next);
481 CERROR("%s: prepare bottom error: rc = %d\n",
482 lod2obd(lod)->obd_name, rc);
486 lod->lod_initialized = 1;
491 const struct lu_device_operations lod_lu_ops = {
492 .ldo_object_alloc = lod_object_alloc,
493 .ldo_process_config = lod_process_config,
494 .ldo_recovery_complete = lod_recovery_complete,
495 .ldo_prepare = lod_prepare,
498 static int lod_root_get(const struct lu_env *env,
499 struct dt_device *dev, struct lu_fid *f)
501 return dt_root_get(env, dt2lod_dev(dev)->lod_child, f);
504 static int lod_statfs(const struct lu_env *env,
505 struct dt_device *dev, struct obd_statfs *sfs)
507 return dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs);
510 static struct thandle *lod_trans_create(const struct lu_env *env,
511 struct dt_device *dev)
515 th = dt_trans_create(env, dt2lod_dev(dev)->lod_child);
519 CFS_INIT_LIST_HEAD(&th->th_remote_update_list);
523 static int lod_remote_sync(const struct lu_env *env, struct dt_device *dev,
526 struct update_request *update;
530 if (cfs_list_empty(&th->th_remote_update_list))
533 cfs_list_for_each_entry(update, &th->th_remote_update_list,
535 /* In DNE phase I, there should be only one OSP
536 * here, so we will do send/receive one by one,
537 * instead of sending them parallel, will fix this
539 th->th_current_request = update;
540 rc = dt_trans_start(env, update->ur_dt, th);
542 /* FIXME how to revert the partial results
543 * once error happened? Resolved by 2 Phase commit */
552 static int lod_trans_start(const struct lu_env *env, struct dt_device *dev,
555 struct lod_device *lod = dt2lod_dev((struct dt_device *) dev);
558 rc = lod_remote_sync(env, dev, th);
562 return dt_trans_start(env, lod->lod_child, th);
565 static int lod_trans_stop(const struct lu_env *env, struct thandle *th)
567 struct update_request *update;
568 struct update_request *tmp;
572 cfs_list_for_each_entry_safe(update, tmp,
573 &th->th_remote_update_list,
575 th->th_current_request = update;
576 rc2 = dt_trans_stop(env, update->ur_dt, th);
577 if (unlikely(rc2 != 0 && rc == 0))
581 rc2 = dt_trans_stop(env, th->th_dev, th);
583 return rc2 != 0 ? rc2 : rc;
586 static void lod_conf_get(const struct lu_env *env,
587 const struct dt_device *dev,
588 struct dt_device_param *param)
590 dt_conf_get(env, dt2lod_dev((struct dt_device *)dev)->lod_child, param);
593 static int lod_sync(const struct lu_env *env, struct dt_device *dev)
595 struct lod_device *lod = dt2lod_dev(dev);
596 struct lod_ost_desc *ost;
600 lod_getref(&lod->lod_ost_descs);
601 lod_foreach_ost(lod, i) {
602 ost = OST_TGT(lod, i);
603 LASSERT(ost && ost->ltd_ost);
604 rc = dt_sync(env, ost->ltd_ost);
606 CERROR("%s: can't sync %u: %d\n",
607 lod2obd(lod)->obd_name, i, rc);
611 lod_putref(lod, &lod->lod_ost_descs);
613 rc = dt_sync(env, lod->lod_child);
618 static int lod_ro(const struct lu_env *env, struct dt_device *dev)
620 return dt_ro(env, dt2lod_dev(dev)->lod_child);
623 static int lod_commit_async(const struct lu_env *env, struct dt_device *dev)
625 return dt_commit_async(env, dt2lod_dev(dev)->lod_child);
628 static int lod_init_capa_ctxt(const struct lu_env *env, struct dt_device *dev,
629 int mode, unsigned long timeout,
630 __u32 alg, struct lustre_capa_key *keys)
632 struct dt_device *next = dt2lod_dev(dev)->lod_child;
633 return dt_init_capa_ctxt(env, next, mode, timeout, alg, keys);
636 static const struct dt_device_operations lod_dt_ops = {
637 .dt_root_get = lod_root_get,
638 .dt_statfs = lod_statfs,
639 .dt_trans_create = lod_trans_create,
640 .dt_trans_start = lod_trans_start,
641 .dt_trans_stop = lod_trans_stop,
642 .dt_conf_get = lod_conf_get,
645 .dt_commit_async = lod_commit_async,
646 .dt_init_capa_ctxt = lod_init_capa_ctxt,
649 static int lod_connect_to_osd(const struct lu_env *env, struct lod_device *lod,
650 struct lustre_cfg *cfg)
652 struct obd_connect_data *data = NULL;
653 struct obd_device *obd;
654 char *nextdev = NULL, *p, *s;
659 LASSERT(lod->lod_child_exp == NULL);
661 /* compatibility hack: we still use old config logs
662 * which specify LOV, but we need to learn underlying
663 * OSD device, which is supposed to be:
664 * <fsname>-MDTxxxx-osd
666 * 2.x MGS generates lines like the following:
667 * #03 (176)lov_setup 0:lustre-MDT0000-mdtlov 1:(struct lov_desc)
668 * 1.8 MGS generates lines like the following:
669 * #03 (168)lov_setup 0:lustre-mdtlov 1:(struct lov_desc)
671 * we use "-MDT" to differentiate 2.x from 1.8 */
673 if ((p = lustre_cfg_string(cfg, 0)) && strstr(p, "-mdtlov")) {
675 OBD_ALLOC(nextdev, len);
677 GOTO(out, rc = -ENOMEM);
680 s = strstr(nextdev, "-mdtlov");
681 if (unlikely(s == NULL)) {
682 CERROR("unable to parse device name %s\n",
683 lustre_cfg_string(cfg, 0));
684 GOTO(out, rc = -EINVAL);
687 if (strstr(nextdev, "-MDT")) {
692 strcpy(s, "-MDT0000-osd");
695 CERROR("unable to parse device name %s\n",
696 lustre_cfg_string(cfg, 0));
697 GOTO(out, rc = -EINVAL);
702 GOTO(out, rc = -ENOMEM);
704 obd = class_name2obd(nextdev);
706 CERROR("can not locate next device: %s\n", nextdev);
707 GOTO(out, rc = -ENOTCONN);
710 data->ocd_connect_flags = OBD_CONNECT_VERSION;
711 data->ocd_version = LUSTRE_VERSION_CODE;
713 rc = obd_connect(env, &lod->lod_child_exp, obd, &obd->obd_uuid,
716 CERROR("cannot connect to next dev %s (%d)\n", nextdev, rc);
720 lod->lod_dt_dev.dd_lu_dev.ld_site =
721 lod->lod_child_exp->exp_obd->obd_lu_dev->ld_site;
722 LASSERT(lod->lod_dt_dev.dd_lu_dev.ld_site);
723 lod->lod_child = lu2dt_dev(lod->lod_child_exp->exp_obd->obd_lu_dev);
729 OBD_FREE(nextdev, len);
733 static int lod_tgt_desc_init(struct lod_tgt_descs *ltd)
735 mutex_init(<d->ltd_mutex);
736 init_rwsem(<d->ltd_rw_sem);
738 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
739 * added to the LOD, see lod_add_device() */
740 ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(32);
741 if (ltd->ltd_tgt_bitmap == NULL)
744 ltd->ltd_tgts_size = 32;
747 ltd->ltd_death_row = 0;
748 ltd->ltd_refcount = 0;
752 static int lod_init0(const struct lu_env *env, struct lod_device *lod,
753 struct lu_device_type *ldt, struct lustre_cfg *cfg)
755 struct dt_device_param ddp;
756 struct obd_device *obd;
760 obd = class_name2obd(lustre_cfg_string(cfg, 0));
762 CERROR("Cannot find obd with name %s\n",
763 lustre_cfg_string(cfg, 0));
767 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
768 lod->lod_dt_dev.dd_lu_dev.ld_obd = obd;
769 lod->lod_dt_dev.dd_lu_dev.ld_ops = &lod_lu_ops;
770 lod->lod_dt_dev.dd_ops = &lod_dt_ops;
772 rc = lod_connect_to_osd(env, lod, cfg);
776 dt_conf_get(env, &lod->lod_dt_dev, &ddp);
777 lod->lod_osd_max_easize = ddp.ddp_max_ea_size;
779 /* setup obd to be used with old lov code */
780 rc = lod_pools_init(lod, cfg);
782 GOTO(out_disconnect, rc);
784 rc = lod_procfs_init(lod);
788 spin_lock_init(&lod->lod_desc_lock);
789 spin_lock_init(&lod->lod_connects_lock);
790 lod_tgt_desc_init(&lod->lod_mdt_descs);
791 lod_tgt_desc_init(&lod->lod_ost_descs);
798 obd_disconnect(lod->lod_child_exp);
802 static struct lu_device *lod_device_free(const struct lu_env *env,
803 struct lu_device *lu)
805 struct lod_device *lod = lu2lod_dev(lu);
806 struct lu_device *next = &lod->lod_child->dd_lu_dev;
809 LASSERT(cfs_atomic_read(&lu->ld_ref) == 0);
810 dt_device_fini(&lod->lod_dt_dev);
815 static struct lu_device *lod_device_alloc(const struct lu_env *env,
816 struct lu_device_type *type,
817 struct lustre_cfg *lcfg)
819 struct lod_device *lod;
820 struct lu_device *lu_dev;
824 lu_dev = ERR_PTR(-ENOMEM);
828 lu_dev = lod2lu_dev(lod);
829 dt_device_init(&lod->lod_dt_dev, type);
830 rc = lod_init0(env, lod, type, lcfg);
832 lod_device_free(env, lu_dev);
833 lu_dev = ERR_PTR(rc);
840 static struct lu_device *lod_device_fini(const struct lu_env *env,
843 struct lod_device *lod = lu2lod_dev(d);
849 lod_procfs_fini(lod);
851 rc = lod_fini_tgt(lod, &lod->lod_ost_descs);
853 CERROR("%s:can not fini ost descs %d\n",
854 lod2obd(lod)->obd_name, rc);
856 rc = lod_fini_tgt(lod, &lod->lod_mdt_descs);
858 CERROR("%s:can not fini mdt descs %d\n",
859 lod2obd(lod)->obd_name, rc);
865 * we use exports to track all LOD users
867 static int lod_obd_connect(const struct lu_env *env, struct obd_export **exp,
868 struct obd_device *obd, struct obd_uuid *cluuid,
869 struct obd_connect_data *data, void *localdata)
871 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
872 struct lustre_handle conn;
876 CDEBUG(D_CONFIG, "connect #%d\n", lod->lod_connects);
878 rc = class_connect(&conn, obd, cluuid);
882 *exp = class_conn2export(&conn);
884 spin_lock(&lod->lod_connects_lock);
886 /* at the moment we expect the only user */
887 LASSERT(lod->lod_connects == 1);
888 spin_unlock(&lod->lod_connects_lock);
894 * once last export (we don't count self-export) disappeared
895 * lod can be released
897 static int lod_obd_disconnect(struct obd_export *exp)
899 struct obd_device *obd = exp->exp_obd;
900 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
904 /* Only disconnect the underlying layers on the final disconnect. */
905 spin_lock(&lod->lod_connects_lock);
907 if (lod->lod_connects != 0) {
908 /* why should there be more than 1 connect? */
909 spin_unlock(&lod->lod_connects_lock);
910 CERROR("%s: disconnect #%d\n", exp->exp_obd->obd_name,
914 spin_unlock(&lod->lod_connects_lock);
916 /* the last user of lod has gone, let's release the device */
920 rc = class_disconnect(exp); /* bz 9811 */
922 if (rc == 0 && release)
923 class_manual_cleanup(obd);
927 LU_KEY_INIT(lod, struct lod_thread_info);
929 static void lod_key_fini(const struct lu_context *ctx,
930 struct lu_context_key *key, void *data)
932 struct lod_thread_info *info = data;
933 /* allocated in lod_get_lov_ea
934 * XXX: this is overload, a tread may have such store but used only
935 * once. Probably better would be pool of such stores per LOD.
937 if (info->lti_ea_store) {
938 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
939 info->lti_ea_store = NULL;
940 info->lti_ea_store_size = 0;
945 /* context key: lod_thread_key */
946 LU_CONTEXT_KEY_DEFINE(lod, LCT_MD_THREAD);
948 LU_TYPE_INIT_FINI(lod, &lod_thread_key);
950 static struct lu_device_type_operations lod_device_type_ops = {
951 .ldto_init = lod_type_init,
952 .ldto_fini = lod_type_fini,
954 .ldto_start = lod_type_start,
955 .ldto_stop = lod_type_stop,
957 .ldto_device_alloc = lod_device_alloc,
958 .ldto_device_free = lod_device_free,
960 .ldto_device_fini = lod_device_fini
963 static struct lu_device_type lod_device_type = {
964 .ldt_tags = LU_DEVICE_DT,
965 .ldt_name = LUSTRE_LOD_NAME,
966 .ldt_ops = &lod_device_type_ops,
967 .ldt_ctx_tags = LCT_MD_THREAD,
970 static int lod_obd_health_check(const struct lu_env *env,
971 struct obd_device *obd)
973 struct lod_device *d = lu2lod_dev(obd->obd_lu_dev);
974 struct lod_ost_desc *ost;
979 lod_getref(&d->lod_ost_descs);
980 lod_foreach_ost(d, i) {
982 LASSERT(ost && ost->ltd_ost);
983 rc = obd_health_check(env, ost->ltd_exp->exp_obd);
984 /* one healthy device is enough */
988 lod_putref(d, &d->lod_ost_descs);
992 static struct obd_ops lod_obd_device_ops = {
993 .o_owner = THIS_MODULE,
994 .o_connect = lod_obd_connect,
995 .o_disconnect = lod_obd_disconnect,
996 .o_health_check = lod_obd_health_check,
997 .o_pool_new = lod_pool_new,
998 .o_pool_rem = lod_pool_remove,
999 .o_pool_add = lod_pool_add,
1000 .o_pool_del = lod_pool_del,
1003 static int __init lod_mod_init(void)
1005 struct lprocfs_static_vars lvars = { 0 };
1006 cfs_proc_dir_entry_t *lov_proc_dir;
1009 rc = lu_kmem_init(lod_caches);
1013 lprocfs_lod_init_vars(&lvars);
1015 rc = class_register_type(&lod_obd_device_ops, NULL, lvars.module_vars,
1016 LUSTRE_LOD_NAME, &lod_device_type);
1018 lu_kmem_fini(lod_caches);
1022 /* create "lov" entry in procfs for compatibility purposes */
1023 lov_proc_dir = lprocfs_srch(proc_lustre_root, "lov");
1024 if (lov_proc_dir == NULL) {
1025 lov_proc_dir = lprocfs_register("lov", proc_lustre_root,
1027 if (IS_ERR(lov_proc_dir))
1028 CERROR("lod: can't create compat entry \"lov\": %d\n",
1029 (int)PTR_ERR(lov_proc_dir));
1035 static void __exit lod_mod_exit(void)
1038 lprocfs_try_remove_proc_entry("lov", proc_lustre_root);
1040 class_unregister_type(LUSTRE_LOD_NAME);
1041 lu_kmem_fini(lod_caches);
1044 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
1045 MODULE_DESCRIPTION("Lustre Logical Object Device ("LUSTRE_LOD_NAME")");
1046 MODULE_LICENSE("GPL");
1048 module_init(lod_mod_init);
1049 module_exit(lod_mod_exit);