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>
41 #define DEBUG_SUBSYSTEM S_MDS
43 #include <obd_class.h>
44 #include <md_object.h>
45 #include <lustre_fid.h>
46 #include <lustre_param.h>
47 #include <lustre_update.h>
49 #include "lod_internal.h"
52 * Lookup MDT/OST index \a tgt by FID \a fid.
54 * \param lod LOD to be lookup at.
55 * \param fid FID of object to find MDT/OST.
56 * \param tgt MDT/OST index to return.
57 * \param type indidcate the FID is on MDS or OST.
59 int lod_fld_lookup(const struct lu_env *env, struct lod_device *lod,
60 const struct lu_fid *fid, __u32 *tgt, int *type)
62 struct lu_seq_range range = { 0 };
63 struct lu_server_fld *server_fld;
67 LASSERTF(fid_is_sane(fid), "Invalid FID "DFID"\n", PFID(fid));
69 if (fid_is_idif(fid)) {
70 *tgt = fid_idif_ost_idx(fid);
71 *type = LU_SEQ_RANGE_OST;
75 if (!lod->lod_initialized || (!fid_seq_in_fldb(fid_seq(fid)))) {
76 LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
78 *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
79 *type = LU_SEQ_RANGE_MDT;
83 server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
84 fld_range_set_type(&range, *type);
85 rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
89 *tgt = range.lsr_index;
90 *type = range.lsr_flags;
92 CDEBUG(D_INFO, "LOD: got tgt %x for sequence: "
93 LPX64"\n", *tgt, fid_seq(fid));
98 extern struct lu_object_operations lod_lu_obj_ops;
99 extern struct dt_object_operations lod_obj_ops;
101 /* Slab for OSD object allocation */
102 struct kmem_cache *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;
126 OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, GFP_NOFS);
128 RETURN(ERR_PTR(-ENOMEM));
130 lu_obj = lod2lu_obj(lod_obj);
131 dt_object_init(&lod_obj->ldo_obj, NULL, dev);
132 lod_obj->ldo_obj.do_ops = &lod_obj_ops;
133 lu_obj->lo_ops = &lod_lu_obj_ops;
138 static int lod_cleanup_desc_tgts(const struct lu_env *env,
139 struct lod_device *lod,
140 struct lod_tgt_descs *ltd,
141 struct lustre_cfg *lcfg)
143 struct lu_device *next;
148 if (ltd->ltd_tgts_size <= 0) {
149 lod_putref(lod, ltd);
152 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
153 struct lod_tgt_desc *tgt;
156 tgt = LTD_TGT(ltd, i);
157 LASSERT(tgt && tgt->ltd_tgt);
158 next = &tgt->ltd_tgt->dd_lu_dev;
159 rc1 = next->ld_ops->ldo_process_config(env, next, lcfg);
161 CERROR("%s: error cleaning up LOD index %u: cmd %#x"
162 ": rc = %d\n", lod2obd(lod)->obd_name, i,
163 lcfg->lcfg_command, rc1);
167 lod_putref(lod, ltd);
171 static int lodname2mdt_index(char *lodname, long *index)
175 /* The lodname suppose to be fsname-MDTxxxx-mdtlov */
176 ptr = strrchr(lodname, '-');
178 CERROR("invalid MDT index in '%s'\n", lodname);
182 if (strncmp(ptr, "-mdtlov", 7) != 0) {
183 CERROR("invalid MDT index in '%s'\n", lodname);
187 if ((unsigned long)ptr - (unsigned long)lodname <= 8) {
188 CERROR("invalid MDT index in '%s'\n", lodname);
192 if (strncmp(ptr - 8, "-MDT", 4) != 0) {
193 CERROR("invalid MDT index in '%s'\n", lodname);
197 *index = simple_strtol(ptr - 4, &tmp, 16);
198 if (*tmp != '-' || *index > INT_MAX || *index < 0) {
199 CERROR("invalid MDT index in '%s'\n", lodname);
206 * Procss config log on LOD
207 * \param env environment info
208 * \param dev lod device
209 * \param lcfg config log
211 * Add osc config log,
212 * marker 20 (flags=0x01, v2.2.49.56) lustre-OST0001 'add osc'
213 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nidxxx
214 * attach 0:lustre-OST0001-osc-MDT0001 1:osc 2:lustre-MDT0001-mdtlov_UUID
215 * setup 0:lustre-OST0001-osc-MDT0001 1:lustre-OST0001_UUID 2:nid
216 * lov_modify_tgts add 0:lustre-MDT0001-mdtlov 1:lustre-OST0001_UUID 2:1 3:1
217 * marker 20 (flags=0x02, v2.2.49.56) lustre-OST0001 'add osc'
220 * marker 10 (flags=0x01, v2.2.49.56) lustre-MDT0000 'add osp'
221 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nid
222 * attach 0:lustre-MDT0000-osp-MDT0001 1:osp 2:lustre-MDT0001-mdtlov_UUID
223 * setup 0:lustre-MDT0000-osp-MDT0001 1:lustre-MDT0000_UUID 2:nid
224 * modify_mdc_tgts add 0:lustre-MDT0001 1:lustre-MDT0000_UUID 2:0 3:1
225 * marker 10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID 'add osp'
227 static int lod_process_config(const struct lu_env *env,
228 struct lu_device *dev,
229 struct lustre_cfg *lcfg)
231 struct lod_device *lod = lu2lod_dev(dev);
232 struct lu_device *next = &lod->lod_child->dd_lu_dev;
237 switch(lcfg->lcfg_command) {
238 case LCFG_LOV_DEL_OBD:
239 case LCFG_LOV_ADD_INA:
240 case LCFG_LOV_ADD_OBD:
245 /* lov_modify_tgts add 0:lov_mdsA 1:osp 2:0 3:1
246 * modify_mdc_tgts add 0:lustre-MDT0001
247 * 1:lustre-MDT0001-mdc0002
249 arg1 = lustre_cfg_string(lcfg, 1);
251 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
252 GOTO(out, rc = -EINVAL);
253 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
254 GOTO(out, rc = -EINVAL);
256 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD) {
258 mdt = strstr(lustre_cfg_string(lcfg, 0), "-MDT");
259 /* 1.8 configs don't have "-MDT0000" at the end */
264 rc = lodname2mdt_index(
265 lustre_cfg_string(lcfg, 0),
269 mdt_index = long_index;
271 rc = lod_add_device(env, lod, arg1, index, gen,
272 mdt_index, LUSTRE_OSC_NAME, 1);
273 } else if (lcfg->lcfg_command == LCFG_ADD_MDC) {
275 rc = lod_add_device(env, lod, arg1, index, gen,
276 mdt_index, LUSTRE_MDC_NAME, 1);
277 } else if (lcfg->lcfg_command == LCFG_LOV_ADD_INA) {
278 /*FIXME: Add mdt_index for LCFG_LOV_ADD_INA*/
280 rc = lod_add_device(env, lod, arg1, index, gen,
281 mdt_index, LUSTRE_OSC_NAME, 0);
283 rc = lod_del_device(env, lod,
285 arg1, index, gen, true);
292 struct lprocfs_static_vars v = { 0 };
293 struct obd_device *obd = lod2obd(lod);
295 lprocfs_lod_init_vars(&v);
297 rc = class_process_proc_param(PARAM_LOV, v.obd_vars, lcfg, obd);
303 case LCFG_PRE_CLEANUP: {
304 lu_dev_del_linkage(dev->ld_site, dev);
305 lod_cleanup_desc_tgts(env, lod, &lod->lod_mdt_descs, lcfg);
306 lod_cleanup_desc_tgts(env, lod, &lod->lod_ost_descs, lcfg);
307 if (lcfg->lcfg_command == LCFG_PRE_CLEANUP)
310 * do cleanup on underlying storage only when
311 * all OSPs are cleaned up, as they use that OSD as well
313 next = &lod->lod_child->dd_lu_dev;
314 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
316 CERROR("%s: can't process %u: %d\n",
317 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
319 rc = obd_disconnect(lod->lod_child_exp);
321 CERROR("error in disconnect from storage: %d\n", rc);
325 CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
335 static int lod_recovery_complete(const struct lu_env *env,
336 struct lu_device *dev)
338 struct lod_device *lod = lu2lod_dev(dev);
339 struct lu_device *next = &lod->lod_child->dd_lu_dev;
343 LASSERT(lod->lod_recovery_completed == 0);
344 lod->lod_recovery_completed = 1;
346 rc = next->ld_ops->ldo_recovery_complete(env, next);
348 lod_getref(&lod->lod_ost_descs);
349 if (lod->lod_osts_size > 0) {
350 cfs_foreach_bit(lod->lod_ost_bitmap, i) {
351 struct lod_tgt_desc *tgt;
352 tgt = OST_TGT(lod, i);
353 LASSERT(tgt && tgt->ltd_tgt);
354 next = &tgt->ltd_ost->dd_lu_dev;
355 rc = next->ld_ops->ldo_recovery_complete(env, next);
357 CERROR("%s: can't complete recovery on #%d:"
358 "%d\n", lod2obd(lod)->obd_name, i, rc);
361 lod_putref(lod, &lod->lod_ost_descs);
365 static int lod_prepare(const struct lu_env *env, struct lu_device *pdev,
366 struct lu_device *cdev)
368 struct lod_device *lod = lu2lod_dev(cdev);
369 struct lu_device *next = &lod->lod_child->dd_lu_dev;
373 rc = next->ld_ops->ldo_prepare(env, pdev, next);
375 CERROR("%s: prepare bottom error: rc = %d\n",
376 lod2obd(lod)->obd_name, rc);
380 lod->lod_initialized = 1;
385 const struct lu_device_operations lod_lu_ops = {
386 .ldo_object_alloc = lod_object_alloc,
387 .ldo_process_config = lod_process_config,
388 .ldo_recovery_complete = lod_recovery_complete,
389 .ldo_prepare = lod_prepare,
392 static int lod_root_get(const struct lu_env *env,
393 struct dt_device *dev, struct lu_fid *f)
395 return dt_root_get(env, dt2lod_dev(dev)->lod_child, f);
398 static int lod_statfs(const struct lu_env *env,
399 struct dt_device *dev, struct obd_statfs *sfs)
401 return dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs);
404 static struct thandle *lod_trans_create(const struct lu_env *env,
405 struct dt_device *dev)
409 th = dt_trans_create(env, dt2lod_dev(dev)->lod_child);
416 static int lod_trans_start(const struct lu_env *env, struct dt_device *dev,
419 struct lod_device *lod = dt2lod_dev((struct dt_device *) dev);
422 if (unlikely(th->th_update != NULL)) {
423 struct thandle_update *tu = th->th_update;
424 struct dt_update_request *update;
426 list_for_each_entry(update, &tu->tu_remote_update_list,
428 LASSERT(update->dur_dt != NULL);
429 rc = dt_trans_start(env, update->dur_dt, th);
434 return dt_trans_start(env, lod->lod_child, th);
437 static int lod_trans_stop(const struct lu_env *env, struct dt_device *dt,
440 struct thandle_update *tu = th->th_update;
441 struct dt_update_request *update;
442 struct dt_update_request *tmp;
447 rc = dt_trans_stop(env, th->th_dev, th);
448 if (likely(tu == NULL))
451 list_for_each_entry_safe(update, tmp,
452 &tu->tu_remote_update_list,
454 /* update will be freed inside dt_trans_stop */
455 rc2 = dt_trans_stop(env, update->dur_dt, th);
456 if (unlikely(rc2 != 0 && rc == 0))
463 static void lod_conf_get(const struct lu_env *env,
464 const struct dt_device *dev,
465 struct dt_device_param *param)
467 dt_conf_get(env, dt2lod_dev((struct dt_device *)dev)->lod_child, param);
470 static int lod_sync(const struct lu_env *env, struct dt_device *dev)
472 struct lod_device *lod = dt2lod_dev(dev);
473 struct lod_ost_desc *ost;
477 lod_getref(&lod->lod_ost_descs);
478 lod_foreach_ost(lod, i) {
479 ost = OST_TGT(lod, i);
480 LASSERT(ost && ost->ltd_ost);
481 rc = dt_sync(env, ost->ltd_ost);
483 CERROR("%s: can't sync %u: %d\n",
484 lod2obd(lod)->obd_name, i, rc);
488 lod_putref(lod, &lod->lod_ost_descs);
490 rc = dt_sync(env, lod->lod_child);
495 static int lod_ro(const struct lu_env *env, struct dt_device *dev)
497 return dt_ro(env, dt2lod_dev(dev)->lod_child);
500 static int lod_commit_async(const struct lu_env *env, struct dt_device *dev)
502 return dt_commit_async(env, dt2lod_dev(dev)->lod_child);
505 static int lod_init_capa_ctxt(const struct lu_env *env, struct dt_device *dev,
506 int mode, unsigned long timeout,
507 __u32 alg, struct lustre_capa_key *keys)
509 struct dt_device *next = dt2lod_dev(dev)->lod_child;
510 return dt_init_capa_ctxt(env, next, mode, timeout, alg, keys);
513 static const struct dt_device_operations lod_dt_ops = {
514 .dt_root_get = lod_root_get,
515 .dt_statfs = lod_statfs,
516 .dt_trans_create = lod_trans_create,
517 .dt_trans_start = lod_trans_start,
518 .dt_trans_stop = lod_trans_stop,
519 .dt_conf_get = lod_conf_get,
522 .dt_commit_async = lod_commit_async,
523 .dt_init_capa_ctxt = lod_init_capa_ctxt,
526 static int lod_connect_to_osd(const struct lu_env *env, struct lod_device *lod,
527 struct lustre_cfg *cfg)
529 struct obd_connect_data *data = NULL;
530 struct obd_device *obd;
531 char *nextdev = NULL, *p, *s;
536 LASSERT(lod->lod_child_exp == NULL);
538 /* compatibility hack: we still use old config logs
539 * which specify LOV, but we need to learn underlying
540 * OSD device, which is supposed to be:
541 * <fsname>-MDTxxxx-osd
543 * 2.x MGS generates lines like the following:
544 * #03 (176)lov_setup 0:lustre-MDT0000-mdtlov 1:(struct lov_desc)
545 * 1.8 MGS generates lines like the following:
546 * #03 (168)lov_setup 0:lustre-mdtlov 1:(struct lov_desc)
548 * we use "-MDT" to differentiate 2.x from 1.8 */
550 if ((p = lustre_cfg_string(cfg, 0)) && strstr(p, "-mdtlov")) {
552 OBD_ALLOC(nextdev, len);
554 GOTO(out, rc = -ENOMEM);
557 s = strstr(nextdev, "-mdtlov");
558 if (unlikely(s == NULL)) {
559 CERROR("unable to parse device name %s\n",
560 lustre_cfg_string(cfg, 0));
561 GOTO(out, rc = -EINVAL);
564 if (strstr(nextdev, "-MDT")) {
569 strcpy(s, "-MDT0000-osd");
572 CERROR("unable to parse device name %s\n",
573 lustre_cfg_string(cfg, 0));
574 GOTO(out, rc = -EINVAL);
579 GOTO(out, rc = -ENOMEM);
581 obd = class_name2obd(nextdev);
583 CERROR("can not locate next device: %s\n", nextdev);
584 GOTO(out, rc = -ENOTCONN);
587 data->ocd_connect_flags = OBD_CONNECT_VERSION;
588 data->ocd_version = LUSTRE_VERSION_CODE;
590 rc = obd_connect(env, &lod->lod_child_exp, obd, &obd->obd_uuid,
593 CERROR("cannot connect to next dev %s (%d)\n", nextdev, rc);
597 lod->lod_dt_dev.dd_lu_dev.ld_site =
598 lod->lod_child_exp->exp_obd->obd_lu_dev->ld_site;
599 LASSERT(lod->lod_dt_dev.dd_lu_dev.ld_site);
600 lod->lod_child = lu2dt_dev(lod->lod_child_exp->exp_obd->obd_lu_dev);
606 OBD_FREE(nextdev, len);
610 static int lod_tgt_desc_init(struct lod_tgt_descs *ltd)
612 mutex_init(<d->ltd_mutex);
613 init_rwsem(<d->ltd_rw_sem);
615 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
616 * added to the LOD, see lod_add_device() */
617 ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(32);
618 if (ltd->ltd_tgt_bitmap == NULL)
621 ltd->ltd_tgts_size = 32;
624 ltd->ltd_death_row = 0;
625 ltd->ltd_refcount = 0;
629 static int lod_init0(const struct lu_env *env, struct lod_device *lod,
630 struct lu_device_type *ldt, struct lustre_cfg *cfg)
632 struct dt_device_param ddp;
633 struct obd_device *obd;
637 obd = class_name2obd(lustre_cfg_string(cfg, 0));
639 CERROR("Cannot find obd with name %s\n",
640 lustre_cfg_string(cfg, 0));
644 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
645 lod->lod_dt_dev.dd_lu_dev.ld_obd = obd;
646 lod->lod_dt_dev.dd_lu_dev.ld_ops = &lod_lu_ops;
647 lod->lod_dt_dev.dd_ops = &lod_dt_ops;
649 rc = lod_connect_to_osd(env, lod, cfg);
653 dt_conf_get(env, &lod->lod_dt_dev, &ddp);
654 lod->lod_osd_max_easize = ddp.ddp_max_ea_size;
656 /* setup obd to be used with old lov code */
657 rc = lod_pools_init(lod, cfg);
659 GOTO(out_disconnect, rc);
661 rc = lod_procfs_init(lod);
665 spin_lock_init(&lod->lod_desc_lock);
666 spin_lock_init(&lod->lod_connects_lock);
667 lod_tgt_desc_init(&lod->lod_mdt_descs);
668 lod_tgt_desc_init(&lod->lod_ost_descs);
675 obd_disconnect(lod->lod_child_exp);
679 static struct lu_device *lod_device_free(const struct lu_env *env,
680 struct lu_device *lu)
682 struct lod_device *lod = lu2lod_dev(lu);
683 struct lu_device *next = &lod->lod_child->dd_lu_dev;
686 LASSERT(atomic_read(&lu->ld_ref) == 0);
687 dt_device_fini(&lod->lod_dt_dev);
692 static struct lu_device *lod_device_alloc(const struct lu_env *env,
693 struct lu_device_type *type,
694 struct lustre_cfg *lcfg)
696 struct lod_device *lod;
697 struct lu_device *lu_dev;
701 lu_dev = ERR_PTR(-ENOMEM);
705 lu_dev = lod2lu_dev(lod);
706 dt_device_init(&lod->lod_dt_dev, type);
707 rc = lod_init0(env, lod, type, lcfg);
709 lod_device_free(env, lu_dev);
710 lu_dev = ERR_PTR(rc);
717 static struct lu_device *lod_device_fini(const struct lu_env *env,
720 struct lod_device *lod = lu2lod_dev(d);
726 lod_procfs_fini(lod);
728 rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs, true);
730 CERROR("%s:can not fini ost descs %d\n",
731 lod2obd(lod)->obd_name, rc);
733 rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs, false);
735 CERROR("%s:can not fini mdt descs %d\n",
736 lod2obd(lod)->obd_name, rc);
742 * we use exports to track all LOD users
744 static int lod_obd_connect(const struct lu_env *env, struct obd_export **exp,
745 struct obd_device *obd, struct obd_uuid *cluuid,
746 struct obd_connect_data *data, void *localdata)
748 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
749 struct lustre_handle conn;
753 CDEBUG(D_CONFIG, "connect #%d\n", lod->lod_connects);
755 rc = class_connect(&conn, obd, cluuid);
759 *exp = class_conn2export(&conn);
761 spin_lock(&lod->lod_connects_lock);
763 /* at the moment we expect the only user */
764 LASSERT(lod->lod_connects == 1);
765 spin_unlock(&lod->lod_connects_lock);
771 * once last export (we don't count self-export) disappeared
772 * lod can be released
774 static int lod_obd_disconnect(struct obd_export *exp)
776 struct obd_device *obd = exp->exp_obd;
777 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
781 /* Only disconnect the underlying layers on the final disconnect. */
782 spin_lock(&lod->lod_connects_lock);
784 if (lod->lod_connects != 0) {
785 /* why should there be more than 1 connect? */
786 spin_unlock(&lod->lod_connects_lock);
787 CERROR("%s: disconnect #%d\n", exp->exp_obd->obd_name,
791 spin_unlock(&lod->lod_connects_lock);
793 /* the last user of lod has gone, let's release the device */
797 rc = class_disconnect(exp); /* bz 9811 */
799 if (rc == 0 && release)
800 class_manual_cleanup(obd);
804 LU_KEY_INIT(lod, struct lod_thread_info);
806 static void lod_key_fini(const struct lu_context *ctx,
807 struct lu_context_key *key, void *data)
809 struct lod_thread_info *info = data;
810 /* allocated in lod_get_lov_ea
811 * XXX: this is overload, a tread may have such store but used only
812 * once. Probably better would be pool of such stores per LOD.
814 if (info->lti_ea_store) {
815 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
816 info->lti_ea_store = NULL;
817 info->lti_ea_store_size = 0;
822 /* context key: lod_thread_key */
823 LU_CONTEXT_KEY_DEFINE(lod, LCT_MD_THREAD);
825 LU_TYPE_INIT_FINI(lod, &lod_thread_key);
827 static struct lu_device_type_operations lod_device_type_ops = {
828 .ldto_init = lod_type_init,
829 .ldto_fini = lod_type_fini,
831 .ldto_start = lod_type_start,
832 .ldto_stop = lod_type_stop,
834 .ldto_device_alloc = lod_device_alloc,
835 .ldto_device_free = lod_device_free,
837 .ldto_device_fini = lod_device_fini
840 static struct lu_device_type lod_device_type = {
841 .ldt_tags = LU_DEVICE_DT,
842 .ldt_name = LUSTRE_LOD_NAME,
843 .ldt_ops = &lod_device_type_ops,
844 .ldt_ctx_tags = LCT_MD_THREAD,
847 static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp,
848 __u32 keylen, void *key, __u32 *vallen, void *val,
849 struct lov_stripe_md *lsm)
853 if (KEY_IS(KEY_OSP_CONNECTED)) {
854 struct obd_device *obd = exp->exp_obd;
855 struct lod_device *d;
856 struct lod_ost_desc *ost;
859 if (!obd->obd_set_up || obd->obd_stopping)
862 d = lu2lod_dev(obd->obd_lu_dev);
863 lod_getref(&d->lod_ost_descs);
864 lod_foreach_ost(d, i) {
866 LASSERT(ost && ost->ltd_ost);
868 rc = obd_get_info(env, ost->ltd_exp, keylen, key,
870 /* one healthy device is enough */
874 lod_putref(d, &d->lod_ost_descs);
881 static struct obd_ops lod_obd_device_ops = {
882 .o_owner = THIS_MODULE,
883 .o_connect = lod_obd_connect,
884 .o_disconnect = lod_obd_disconnect,
885 .o_get_info = lod_obd_get_info,
886 .o_pool_new = lod_pool_new,
887 .o_pool_rem = lod_pool_remove,
888 .o_pool_add = lod_pool_add,
889 .o_pool_del = lod_pool_del,
892 static int __init lod_mod_init(void)
894 struct lprocfs_static_vars lvars = { 0 };
895 struct obd_type *type;
898 rc = lu_kmem_init(lod_caches);
902 lprocfs_lod_init_vars(&lvars);
904 rc = class_register_type(&lod_obd_device_ops, NULL, true, NULL,
905 #ifndef HAVE_ONLY_PROCFS_SEQ
908 LUSTRE_LOD_NAME, &lod_device_type);
910 lu_kmem_fini(lod_caches);
914 /* create "lov" entry in procfs for compatibility purposes */
915 type = class_search_type(LUSTRE_LOV_NAME);
916 if (type != NULL && type->typ_procroot != NULL)
919 type = class_search_type(LUSTRE_LOD_NAME);
920 type->typ_procsym = lprocfs_register("lov", proc_lustre_root,
922 if (IS_ERR(type->typ_procsym))
923 CERROR("lod: can't create compat entry \"lov\": %d\n",
924 (int)PTR_ERR(type->typ_procsym));
928 static void __exit lod_mod_exit(void)
930 lprocfs_try_remove_proc_entry("lov", proc_lustre_root);
932 class_unregister_type(LUSTRE_LOD_NAME);
933 lu_kmem_fini(lod_caches);
936 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
937 MODULE_DESCRIPTION("Lustre Logical Object Device ("LUSTRE_LOD_NAME")");
938 MODULE_LICENSE("GPL");
940 module_init(lod_mod_init);
941 module_exit(lod_mod_exit);