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, 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 <lustre_fid.h>
48 #include <lustre_param.h>
50 #include "lod_internal.h"
53 * Lookup MDT/OST index \a tgt by FID \a fid.
55 * \param lod LOD to be lookup at.
56 * \param fid FID of object to find MDT/OST.
57 * \param tgt MDT/OST index to return.
58 * \param flags indidcate the FID is on MDS or OST.
60 int lod_fld_lookup(const struct lu_env *env, struct lod_device *lod,
61 const struct lu_fid *fid, __u32 *tgt, int flags)
63 struct lu_seq_range range;
64 struct lu_server_fld *server_fld;
68 LASSERTF(fid_is_sane(fid), "Invalid FID "DFID"\n", PFID(fid));
69 if (fid_is_idif(fid)) {
70 *tgt = fid_idif_ost_idx(fid);
74 if (!lod->lod_initialized || !fid_is_norm(fid)) {
75 LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
76 *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
80 server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
81 range.lsr_flags = flags;
82 rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
84 CERROR("%s: Can't find tgt by seq "LPX64", rc %d\n",
85 lod2obd(lod)->obd_name, fid_seq(fid), rc);
89 *tgt = range.lsr_index;
91 CDEBUG(D_INFO, "LOD: got tgt %x for sequence: "
92 LPX64"\n", *tgt, fid_seq(fid));
97 extern struct lu_object_operations lod_lu_obj_ops;
98 extern struct lu_object_operations lod_lu_robj_ops;
99 extern struct dt_object_operations lod_obj_ops;
101 /* Slab for OSD object allocation */
102 cfs_mem_cache_t *lod_object_kmem;
104 static struct lu_kmem_descr lod_caches[] = {
106 .ckd_cache = &lod_object_kmem,
107 .ckd_name = "lod_obj",
108 .ckd_size = sizeof(struct lod_object)
115 static struct lu_device *lod_device_fini(const struct lu_env *env,
116 struct lu_device *d);
118 struct lu_object *lod_object_alloc(const struct lu_env *env,
119 const struct lu_object_header *hdr,
120 struct lu_device *dev)
122 struct lod_object *lod_obj;
123 struct lu_object *lu_obj;
124 const struct lu_fid *fid = &hdr->loh_fid;
129 OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, CFS_ALLOC_IO);
131 RETURN(ERR_PTR(-ENOMEM));
133 rc = lod_fld_lookup(env, lu2lod_dev(dev), fid, &mds, LU_SEQ_RANGE_MDT);
135 OBD_SLAB_FREE_PTR(lod_obj, lod_object_kmem);
139 lod_obj->ldo_mds_num = mds;
140 lu_obj = lod2lu_obj(lod_obj);
141 dt_object_init(&lod_obj->ldo_obj, NULL, dev);
142 lod_obj->ldo_obj.do_ops = &lod_obj_ops;
143 if (likely(mds == lu_site2seq(dev->ld_site)->ss_node_id))
144 lu_obj->lo_ops = &lod_lu_obj_ops;
146 lu_obj->lo_ops = &lod_lu_robj_ops;
150 static int lod_cleanup_desc_tgts(const struct lu_env *env,
151 struct lod_device *lod,
152 struct lod_tgt_descs *ltd,
153 struct lustre_cfg *lcfg)
155 struct lu_device *next;
160 if (ltd->ltd_tgts_size <= 0) {
161 lod_putref(lod, ltd);
164 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
165 struct lod_tgt_desc *tgt;
168 tgt = LTD_TGT(ltd, i);
169 LASSERT(tgt && tgt->ltd_tgt);
170 next = &tgt->ltd_tgt->dd_lu_dev;
171 rc1 = next->ld_ops->ldo_process_config(env, next, lcfg);
173 CERROR("%s: error cleaning up LOD index %u: cmd %#x"
174 ": rc = %d\n", lod2obd(lod)->obd_name, i,
175 lcfg->lcfg_command, rc1);
179 lod_putref(lod, ltd);
183 static int lodname2mdt_index(char *lodname, int *index)
187 /* The lodname suppose to be fsname-MDTxxxx-mdtlov */
188 ptr = strrchr(lodname, '-');
190 CERROR("invalid MDT index in '%s'\n", lodname);
194 if (strncmp(ptr, "-mdtlov", 7) != 0) {
195 CERROR("invalid MDT index in '%s'\n", lodname);
199 if ((unsigned long)ptr - (unsigned long)lodname <= 8) {
200 CERROR("invalid MDT index in '%s'\n", lodname);
204 if (strncmp(ptr - 8, "-MDT", 4) != 0) {
205 CERROR("invalid MDT index in '%s'\n", lodname);
209 *index = simple_strtol(ptr - 4, &tmp, 16);
210 if (*tmp != '-' || *index > INT_MAX || *index < 0) {
211 CERROR("invalid MDT index in '%s'\n", lodname);
218 * Init client sequence manager which is used by local MDS to talk to sequence
219 * controller on remote node.
221 static int lod_seq_init_cli(const struct lu_env *env,
222 struct lod_device *lod,
223 char *tgtuuid, int index)
225 struct seq_server_site *ss;
226 struct obd_device *osp;
229 struct obd_uuid obd_uuid;
232 ss = lu_site2seq(lod2lu_dev(lod)->ld_site);
235 /* check if this is adding the first MDC and controller is not yet
237 if (index != 0 || ss->ss_client_seq)
240 obd_str2uuid(&obd_uuid, tgtuuid);
241 osp = class_find_client_obd(&obd_uuid, LUSTRE_OSP_NAME,
242 &lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_uuid);
244 CERROR("%s: can't find %s device\n",
245 lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_name,
250 if (!osp->obd_set_up) {
251 CERROR("target %s not set up\n", osp->obd_name);
255 LASSERT(ss->ss_control_exp);
256 OBD_ALLOC_PTR(ss->ss_client_seq);
257 if (ss->ss_client_seq == NULL)
260 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
262 OBD_FREE_PTR(ss->ss_client_seq);
263 ss->ss_client_seq = NULL;
267 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s", osp->obd_name);
268 rc = seq_client_init(ss->ss_client_seq, ss->ss_control_exp,
269 LUSTRE_SEQ_METADATA, prefix, NULL);
270 OBD_FREE(prefix, MAX_OBD_NAME + 5);
272 OBD_FREE_PTR(ss->ss_client_seq);
273 ss->ss_client_seq = NULL;
277 LASSERT(ss->ss_server_seq != NULL);
278 rc = seq_server_set_cli(ss->ss_server_seq, ss->ss_client_seq,
284 static void lod_seq_fini_cli(struct lod_device *lod)
286 struct seq_server_site *ss;
290 ss = lu_site2seq(lod2lu_dev(lod)->ld_site);
296 if (ss->ss_server_seq)
297 seq_server_set_cli(ss->ss_server_seq,
300 if (ss->ss_control_exp) {
301 class_export_put(ss->ss_control_exp);
302 ss->ss_control_exp = NULL;
310 * Procss config log on LOD
311 * \param env environment info
312 * \param dev lod device
313 * \param lcfg config log
315 * Add osc config log,
316 * marker 20 (flags=0x01, v2.2.49.56) lustre-OST0001 'add osc'
317 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nidxxx
318 * attach 0:lustre-OST0001-osc-MDT0001 1:osc 2:lustre-MDT0001-mdtlov_UUID
319 * setup 0:lustre-OST0001-osc-MDT0001 1:lustre-OST0001_UUID 2:nid
320 * lov_modify_tgts add 0:lustre-MDT0001-mdtlov 1:lustre-OST0001_UUID 2:1 3:1
321 * marker 20 (flags=0x02, v2.2.49.56) lustre-OST0001 'add osc'
324 * marker 10 (flags=0x01, v2.2.49.56) lustre-MDT0000 'add osp'
325 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nid
326 * attach 0:lustre-MDT0000-osp-MDT0001 1:osp 2:lustre-MDT0001-mdtlov_UUID
327 * setup 0:lustre-MDT0000-osp-MDT0001 1:lustre-MDT0000_UUID 2:nid
328 * modify_mdc_tgts add 0:lustre-MDT0001 1:lustre-MDT0000_UUID 2:0 3:1
329 * marker 10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID 'add osp'
331 static int lod_process_config(const struct lu_env *env,
332 struct lu_device *dev,
333 struct lustre_cfg *lcfg)
335 struct lod_device *lod = lu2lod_dev(dev);
336 struct lu_device *next = &lod->lod_child->dd_lu_dev;
341 switch(lcfg->lcfg_command) {
342 case LCFG_LOV_DEL_OBD:
343 case LCFG_LOV_ADD_INA:
344 case LCFG_LOV_ADD_OBD:
349 /* lov_modify_tgts add 0:lov_mdsA 1:osp 2:0 3:1
350 * modify_mdc_tgts add 0:lustre-MDT0001
351 * 1:lustre-MDT0001-mdc0002
353 arg1 = lustre_cfg_string(lcfg, 1);
355 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
356 GOTO(out, rc = -EINVAL);
357 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
358 GOTO(out, rc = -EINVAL);
360 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD) {
362 mdt = strstr(lustre_cfg_string(lcfg, 0), "-MDT");
363 /* 1.8 configs don't have "-MDT0000" at the end */
367 rc = lodname2mdt_index(
368 lustre_cfg_string(lcfg, 0), &mdt_index);
372 rc = lod_add_device(env, lod, arg1, index, gen,
373 mdt_index, LUSTRE_OSC_NAME, 1);
374 } else if (lcfg->lcfg_command == LCFG_ADD_MDC) {
376 rc = lod_add_device(env, lod, arg1, index, gen,
377 mdt_index, LUSTRE_MDC_NAME, 1);
379 rc = lod_seq_init_cli(env, lod, arg1,
381 } else if (lcfg->lcfg_command == LCFG_LOV_ADD_INA) {
382 /*FIXME: Add mdt_index for LCFG_LOV_ADD_INA*/
384 rc = lod_add_device(env, lod, arg1, index, gen,
385 mdt_index, LUSTRE_OSC_NAME, 0);
387 rc = lod_del_device(env, lod,
396 struct lprocfs_static_vars v = { 0 };
397 struct obd_device *obd = lod2obd(lod);
399 lprocfs_lod_init_vars(&v);
401 rc = class_process_proc_param(PARAM_LOV, v.obd_vars, lcfg, obd);
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 * do cleanup on underlying storage only when
414 * all OSPs are cleaned up, as they use that OSD as well
416 next = &lod->lod_child->dd_lu_dev;
417 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
419 CERROR("%s: can't process %u: %d\n",
420 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
422 rc = obd_disconnect(lod->lod_child_exp);
424 CERROR("error in disconnect from storage: %d\n", rc);
428 CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
438 static int lod_recovery_complete(const struct lu_env *env,
439 struct lu_device *dev)
441 struct lod_device *lod = lu2lod_dev(dev);
442 struct lu_device *next = &lod->lod_child->dd_lu_dev;
446 LASSERT(lod->lod_recovery_completed == 0);
447 lod->lod_recovery_completed = 1;
449 rc = next->ld_ops->ldo_recovery_complete(env, next);
451 lod_getref(&lod->lod_ost_descs);
452 if (lod->lod_osts_size > 0) {
453 cfs_foreach_bit(lod->lod_ost_bitmap, i) {
454 struct lod_tgt_desc *tgt;
455 tgt = OST_TGT(lod, i);
456 LASSERT(tgt && tgt->ltd_tgt);
457 next = &tgt->ltd_ost->dd_lu_dev;
458 rc = next->ld_ops->ldo_recovery_complete(env, next);
460 CERROR("%s: can't complete recovery on #%d:"
461 "%d\n", lod2obd(lod)->obd_name, i, rc);
464 lod_putref(lod, &lod->lod_ost_descs);
468 static int lod_prepare(const struct lu_env *env, struct lu_device *pdev,
469 struct lu_device *cdev)
471 struct lod_device *lod = lu2lod_dev(cdev);
472 struct lu_device *next = &lod->lod_child->dd_lu_dev;
476 rc = next->ld_ops->ldo_prepare(env, pdev, next);
478 CERROR("%s: prepare bottom error: rc = %d\n",
479 lod2obd(lod)->obd_name, rc);
483 lod->lod_initialized = 1;
488 const struct lu_device_operations lod_lu_ops = {
489 .ldo_object_alloc = lod_object_alloc,
490 .ldo_process_config = lod_process_config,
491 .ldo_recovery_complete = lod_recovery_complete,
492 .ldo_prepare = lod_prepare,
495 static int lod_root_get(const struct lu_env *env,
496 struct dt_device *dev, struct lu_fid *f)
498 return dt_root_get(env, dt2lod_dev(dev)->lod_child, f);
501 static int lod_statfs(const struct lu_env *env,
502 struct dt_device *dev, struct obd_statfs *sfs)
504 return dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs);
507 static struct thandle *lod_trans_create(const struct lu_env *env,
508 struct dt_device *dev)
510 return dt_trans_create(env, dt2lod_dev(dev)->lod_child);
513 static int lod_trans_start(const struct lu_env *env, struct dt_device *dev,
516 return dt_trans_start(env, dt2lod_dev(dev)->lod_child, th);
519 static int lod_trans_stop(const struct lu_env *env, struct thandle *th)
521 /* XXX: we don't know next device, will be fixed with DNE */
522 return dt_trans_stop(env, th->th_dev, th);
525 static void lod_conf_get(const struct lu_env *env,
526 const struct dt_device *dev,
527 struct dt_device_param *param)
529 dt_conf_get(env, dt2lod_dev((struct dt_device *)dev)->lod_child, param);
532 static int lod_sync(const struct lu_env *env, struct dt_device *dev)
534 struct lod_device *lod = dt2lod_dev(dev);
535 struct lod_ost_desc *ost;
539 lod_getref(&lod->lod_ost_descs);
540 lod_foreach_ost(lod, i) {
541 ost = OST_TGT(lod, i);
542 LASSERT(ost && ost->ltd_ost);
543 rc = dt_sync(env, ost->ltd_ost);
545 CERROR("%s: can't sync %u: %d\n",
546 lod2obd(lod)->obd_name, i, rc);
550 lod_putref(lod, &lod->lod_ost_descs);
552 rc = dt_sync(env, lod->lod_child);
557 static int lod_ro(const struct lu_env *env, struct dt_device *dev)
559 return dt_ro(env, dt2lod_dev(dev)->lod_child);
562 static int lod_commit_async(const struct lu_env *env, struct dt_device *dev)
564 return dt_commit_async(env, dt2lod_dev(dev)->lod_child);
567 static int lod_init_capa_ctxt(const struct lu_env *env, struct dt_device *dev,
568 int mode, unsigned long timeout,
569 __u32 alg, struct lustre_capa_key *keys)
571 struct dt_device *next = dt2lod_dev(dev)->lod_child;
572 return dt_init_capa_ctxt(env, next, mode, timeout, alg, keys);
575 static const struct dt_device_operations lod_dt_ops = {
576 .dt_root_get = lod_root_get,
577 .dt_statfs = lod_statfs,
578 .dt_trans_create = lod_trans_create,
579 .dt_trans_start = lod_trans_start,
580 .dt_trans_stop = lod_trans_stop,
581 .dt_conf_get = lod_conf_get,
584 .dt_commit_async = lod_commit_async,
585 .dt_init_capa_ctxt = lod_init_capa_ctxt,
588 static int lod_connect_to_osd(const struct lu_env *env, struct lod_device *lod,
589 struct lustre_cfg *cfg)
591 struct obd_connect_data *data = NULL;
592 struct obd_device *obd;
593 char *nextdev = NULL, *p, *s;
598 LASSERT(lod->lod_child_exp == NULL);
600 /* compatibility hack: we still use old config logs
601 * which specify LOV, but we need to learn underlying
602 * OSD device, which is supposed to be:
603 * <fsname>-MDTxxxx-osd
605 * 2.x MGS generates lines like the following:
606 * #03 (176)lov_setup 0:lustre-MDT0000-mdtlov 1:(struct lov_desc)
607 * 1.8 MGS generates lines like the following:
608 * #03 (168)lov_setup 0:lustre-mdtlov 1:(struct lov_desc)
610 * we use "-MDT" to differentiate 2.x from 1.8 */
612 if ((p = lustre_cfg_string(cfg, 0)) && strstr(p, "-mdtlov")) {
614 OBD_ALLOC(nextdev, len);
616 GOTO(out, rc = -ENOMEM);
619 s = strstr(nextdev, "-mdtlov");
620 if (unlikely(s == NULL)) {
621 CERROR("unable to parse device name %s\n",
622 lustre_cfg_string(cfg, 0));
623 GOTO(out, rc = -EINVAL);
626 if (strstr(nextdev, "-MDT")) {
631 strcpy(s, "-MDT0000-osd");
634 CERROR("unable to parse device name %s\n",
635 lustre_cfg_string(cfg, 0));
636 GOTO(out, rc = -EINVAL);
641 GOTO(out, rc = -ENOMEM);
643 obd = class_name2obd(nextdev);
645 CERROR("can not locate next device: %s\n", nextdev);
646 GOTO(out, rc = -ENOTCONN);
649 data->ocd_connect_flags = OBD_CONNECT_VERSION;
650 data->ocd_version = LUSTRE_VERSION_CODE;
652 rc = obd_connect(env, &lod->lod_child_exp, obd, &obd->obd_uuid,
655 CERROR("cannot connect to next dev %s (%d)\n", nextdev, rc);
659 lod->lod_dt_dev.dd_lu_dev.ld_site =
660 lod->lod_child_exp->exp_obd->obd_lu_dev->ld_site;
661 LASSERT(lod->lod_dt_dev.dd_lu_dev.ld_site);
662 lod->lod_child = lu2dt_dev(lod->lod_child_exp->exp_obd->obd_lu_dev);
668 OBD_FREE(nextdev, len);
672 static int lod_tgt_desc_init(struct lod_tgt_descs *ltd)
674 mutex_init(<d->ltd_mutex);
675 init_rwsem(<d->ltd_rw_sem);
677 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
678 * added to the LOD, see lod_add_device() */
679 ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(32);
680 if (ltd->ltd_tgt_bitmap == NULL)
683 ltd->ltd_tgts_size = 32;
686 ltd->ltd_death_row = 0;
687 ltd->ltd_refcount = 0;
691 static int lod_init0(const struct lu_env *env, struct lod_device *lod,
692 struct lu_device_type *ldt, struct lustre_cfg *cfg)
694 struct dt_device_param ddp;
695 struct obd_device *obd;
699 obd = class_name2obd(lustre_cfg_string(cfg, 0));
701 CERROR("Cannot find obd with name %s\n",
702 lustre_cfg_string(cfg, 0));
706 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
707 lod->lod_dt_dev.dd_lu_dev.ld_obd = obd;
708 lod->lod_dt_dev.dd_lu_dev.ld_ops = &lod_lu_ops;
709 lod->lod_dt_dev.dd_ops = &lod_dt_ops;
711 rc = lod_connect_to_osd(env, lod, cfg);
715 dt_conf_get(env, &lod->lod_dt_dev, &ddp);
716 lod->lod_osd_max_easize = ddp.ddp_max_ea_size;
718 /* setup obd to be used with old lov code */
719 rc = lod_pools_init(lod, cfg);
721 GOTO(out_disconnect, rc);
723 rc = lod_procfs_init(lod);
727 spin_lock_init(&lod->lod_desc_lock);
728 spin_lock_init(&lod->lod_connects_lock);
729 lod_tgt_desc_init(&lod->lod_mdt_descs);
730 lod_tgt_desc_init(&lod->lod_ost_descs);
737 obd_disconnect(lod->lod_child_exp);
741 static struct lu_device *lod_device_free(const struct lu_env *env,
742 struct lu_device *lu)
744 struct lod_device *lod = lu2lod_dev(lu);
745 struct lu_device *next = &lod->lod_child->dd_lu_dev;
748 LASSERT(cfs_atomic_read(&lu->ld_ref) == 0);
749 dt_device_fini(&lod->lod_dt_dev);
754 static struct lu_device *lod_device_alloc(const struct lu_env *env,
755 struct lu_device_type *type,
756 struct lustre_cfg *lcfg)
758 struct lod_device *lod;
759 struct lu_device *lu_dev;
763 lu_dev = ERR_PTR(-ENOMEM);
767 lu_dev = lod2lu_dev(lod);
768 dt_device_init(&lod->lod_dt_dev, type);
769 rc = lod_init0(env, lod, type, lcfg);
771 lod_device_free(env, lu_dev);
772 lu_dev = ERR_PTR(rc);
779 static struct lu_device *lod_device_fini(const struct lu_env *env,
782 struct lod_device *lod = lu2lod_dev(d);
788 lod_procfs_fini(lod);
790 rc = lod_fini_tgt(lod, &lod->lod_ost_descs);
792 CERROR("%s:can not fini ost descs %d\n",
793 lod2obd(lod)->obd_name, rc);
795 rc = lod_fini_tgt(lod, &lod->lod_mdt_descs);
797 CERROR("%s:can not fini mdt descs %d\n",
798 lod2obd(lod)->obd_name, rc);
804 * we use exports to track all LOD users
806 static int lod_obd_connect(const struct lu_env *env, struct obd_export **exp,
807 struct obd_device *obd, struct obd_uuid *cluuid,
808 struct obd_connect_data *data, void *localdata)
810 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
811 struct lustre_handle conn;
815 CDEBUG(D_CONFIG, "connect #%d\n", lod->lod_connects);
817 rc = class_connect(&conn, obd, cluuid);
821 *exp = class_conn2export(&conn);
823 spin_lock(&lod->lod_connects_lock);
825 /* at the moment we expect the only user */
826 LASSERT(lod->lod_connects == 1);
827 spin_unlock(&lod->lod_connects_lock);
833 * once last export (we don't count self-export) disappeared
834 * lod can be released
836 static int lod_obd_disconnect(struct obd_export *exp)
838 struct obd_device *obd = exp->exp_obd;
839 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
843 /* Only disconnect the underlying layers on the final disconnect. */
844 spin_lock(&lod->lod_connects_lock);
846 if (lod->lod_connects != 0) {
847 /* why should there be more than 1 connect? */
848 spin_unlock(&lod->lod_connects_lock);
849 CERROR("%s: disconnect #%d\n", exp->exp_obd->obd_name,
853 spin_unlock(&lod->lod_connects_lock);
855 /* the last user of lod has gone, let's release the device */
859 rc = class_disconnect(exp); /* bz 9811 */
861 if (rc == 0 && release)
862 class_manual_cleanup(obd);
866 LU_KEY_INIT(lod, struct lod_thread_info);
868 static void lod_key_fini(const struct lu_context *ctx,
869 struct lu_context_key *key, void *data)
871 struct lod_thread_info *info = data;
872 /* allocated in lod_get_lov_ea
873 * XXX: this is overload, a tread may have such store but used only
874 * once. Probably better would be pool of such stores per LOD.
876 if (info->lti_ea_store) {
877 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
878 info->lti_ea_store = NULL;
879 info->lti_ea_store_size = 0;
884 /* context key: lod_thread_key */
885 LU_CONTEXT_KEY_DEFINE(lod, LCT_MD_THREAD);
887 LU_TYPE_INIT_FINI(lod, &lod_thread_key);
889 static struct lu_device_type_operations lod_device_type_ops = {
890 .ldto_init = lod_type_init,
891 .ldto_fini = lod_type_fini,
893 .ldto_start = lod_type_start,
894 .ldto_stop = lod_type_stop,
896 .ldto_device_alloc = lod_device_alloc,
897 .ldto_device_free = lod_device_free,
899 .ldto_device_fini = lod_device_fini
902 static struct lu_device_type lod_device_type = {
903 .ldt_tags = LU_DEVICE_DT,
904 .ldt_name = LUSTRE_LOD_NAME,
905 .ldt_ops = &lod_device_type_ops,
906 .ldt_ctx_tags = LCT_MD_THREAD,
909 static int lod_obd_health_check(const struct lu_env *env,
910 struct obd_device *obd)
912 struct lod_device *d = lu2lod_dev(obd->obd_lu_dev);
913 struct lod_ost_desc *ost;
918 lod_getref(&d->lod_ost_descs);
919 lod_foreach_ost(d, i) {
921 LASSERT(ost && ost->ltd_ost);
922 rc = obd_health_check(env, ost->ltd_exp->exp_obd);
923 /* one healthy device is enough */
927 lod_putref(d, &d->lod_ost_descs);
931 static struct obd_ops lod_obd_device_ops = {
932 .o_owner = THIS_MODULE,
933 .o_connect = lod_obd_connect,
934 .o_disconnect = lod_obd_disconnect,
935 .o_health_check = lod_obd_health_check,
936 .o_pool_new = lod_pool_new,
937 .o_pool_rem = lod_pool_remove,
938 .o_pool_add = lod_pool_add,
939 .o_pool_del = lod_pool_del,
942 static int __init lod_mod_init(void)
944 struct lprocfs_static_vars lvars = { 0 };
945 cfs_proc_dir_entry_t *lov_proc_dir;
948 rc = lu_kmem_init(lod_caches);
952 lprocfs_lod_init_vars(&lvars);
954 rc = class_register_type(&lod_obd_device_ops, NULL, lvars.module_vars,
955 LUSTRE_LOD_NAME, &lod_device_type);
957 lu_kmem_fini(lod_caches);
961 /* create "lov" entry in procfs for compatibility purposes */
962 lov_proc_dir = lprocfs_srch(proc_lustre_root, "lov");
963 if (lov_proc_dir == NULL) {
964 lov_proc_dir = lprocfs_register("lov", proc_lustre_root,
966 if (IS_ERR(lov_proc_dir))
967 CERROR("lod: can't create compat entry \"lov\": %d\n",
968 (int)PTR_ERR(lov_proc_dir));
974 static void __exit lod_mod_exit(void)
977 lprocfs_try_remove_proc_entry("lov", proc_lustre_root);
979 class_unregister_type(LUSTRE_LOD_NAME);
980 lu_kmem_fini(lod_caches);
983 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
984 MODULE_DESCRIPTION("Lustre Logical Object Device ("LUSTRE_LOD_NAME")");
985 MODULE_LICENSE("GPL");
987 module_init(lod_mod_init);
988 module_exit(lod_mod_exit);