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));
68 if (fid_is_idif(fid)) {
69 *tgt = fid_idif_ost_idx(fid);
73 if (!lod->lod_initialized || (!fid_seq_in_fldb(fid_seq(fid)))) {
74 LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
75 *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
79 server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
80 fld_range_set_type(&range, type);
81 rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
85 *tgt = range.lsr_index;
87 CDEBUG(D_INFO, "LOD: got tgt %x for sequence: "
88 LPX64"\n", *tgt, fid_seq(fid));
93 extern struct lu_object_operations lod_lu_obj_ops;
94 extern struct lu_object_operations lod_lu_robj_ops;
95 extern struct dt_object_operations lod_obj_ops;
97 /* Slab for OSD object allocation */
98 struct kmem_cache *lod_object_kmem;
100 static struct lu_kmem_descr lod_caches[] = {
102 .ckd_cache = &lod_object_kmem,
103 .ckd_name = "lod_obj",
104 .ckd_size = sizeof(struct lod_object)
111 static struct lu_device *lod_device_fini(const struct lu_env *env,
112 struct lu_device *d);
114 struct lu_object *lod_object_alloc(const struct lu_env *env,
115 const struct lu_object_header *hdr,
116 struct lu_device *dev)
118 struct lod_object *lod_obj;
119 struct lu_object *lu_obj;
120 const struct lu_fid *fid = &hdr->loh_fid;
125 OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, __GFP_IO);
127 RETURN(ERR_PTR(-ENOMEM));
129 rc = lod_fld_lookup(env, lu2lod_dev(dev), fid, &mds, LU_SEQ_RANGE_MDT);
131 OBD_SLAB_FREE_PTR(lod_obj, lod_object_kmem);
135 lod_obj->ldo_mds_num = mds;
136 lu_obj = lod2lu_obj(lod_obj);
137 dt_object_init(&lod_obj->ldo_obj, NULL, dev);
138 lod_obj->ldo_obj.do_ops = &lod_obj_ops;
139 if (likely(mds == lu_site2seq(dev->ld_site)->ss_node_id))
140 lu_obj->lo_ops = &lod_lu_obj_ops;
142 lu_obj->lo_ops = &lod_lu_robj_ops;
146 static int lod_cleanup_desc_tgts(const struct lu_env *env,
147 struct lod_device *lod,
148 struct lod_tgt_descs *ltd,
149 struct lustre_cfg *lcfg)
151 struct lu_device *next;
156 if (ltd->ltd_tgts_size <= 0) {
157 lod_putref(lod, ltd);
160 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
161 struct lod_tgt_desc *tgt;
164 tgt = LTD_TGT(ltd, i);
165 LASSERT(tgt && tgt->ltd_tgt);
166 next = &tgt->ltd_tgt->dd_lu_dev;
167 rc1 = next->ld_ops->ldo_process_config(env, next, lcfg);
169 CERROR("%s: error cleaning up LOD index %u: cmd %#x"
170 ": rc = %d\n", lod2obd(lod)->obd_name, i,
171 lcfg->lcfg_command, rc1);
175 lod_putref(lod, ltd);
179 static int lodname2mdt_index(char *lodname, long *index)
183 /* The lodname suppose to be fsname-MDTxxxx-mdtlov */
184 ptr = strrchr(lodname, '-');
186 CERROR("invalid MDT index in '%s'\n", lodname);
190 if (strncmp(ptr, "-mdtlov", 7) != 0) {
191 CERROR("invalid MDT index in '%s'\n", lodname);
195 if ((unsigned long)ptr - (unsigned long)lodname <= 8) {
196 CERROR("invalid MDT index in '%s'\n", lodname);
200 if (strncmp(ptr - 8, "-MDT", 4) != 0) {
201 CERROR("invalid MDT index in '%s'\n", lodname);
205 *index = simple_strtol(ptr - 4, &tmp, 16);
206 if (*tmp != '-' || *index > INT_MAX || *index < 0) {
207 CERROR("invalid MDT index in '%s'\n", lodname);
214 * Procss config log on LOD
215 * \param env environment info
216 * \param dev lod device
217 * \param lcfg config log
219 * Add osc config log,
220 * marker 20 (flags=0x01, v2.2.49.56) lustre-OST0001 'add osc'
221 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nidxxx
222 * attach 0:lustre-OST0001-osc-MDT0001 1:osc 2:lustre-MDT0001-mdtlov_UUID
223 * setup 0:lustre-OST0001-osc-MDT0001 1:lustre-OST0001_UUID 2:nid
224 * lov_modify_tgts add 0:lustre-MDT0001-mdtlov 1:lustre-OST0001_UUID 2:1 3:1
225 * marker 20 (flags=0x02, v2.2.49.56) lustre-OST0001 'add osc'
228 * marker 10 (flags=0x01, v2.2.49.56) lustre-MDT0000 'add osp'
229 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nid
230 * attach 0:lustre-MDT0000-osp-MDT0001 1:osp 2:lustre-MDT0001-mdtlov_UUID
231 * setup 0:lustre-MDT0000-osp-MDT0001 1:lustre-MDT0000_UUID 2:nid
232 * modify_mdc_tgts add 0:lustre-MDT0001 1:lustre-MDT0000_UUID 2:0 3:1
233 * marker 10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID 'add osp'
235 static int lod_process_config(const struct lu_env *env,
236 struct lu_device *dev,
237 struct lustre_cfg *lcfg)
239 struct lod_device *lod = lu2lod_dev(dev);
240 struct lu_device *next = &lod->lod_child->dd_lu_dev;
245 switch(lcfg->lcfg_command) {
246 case LCFG_LOV_DEL_OBD:
247 case LCFG_LOV_ADD_INA:
248 case LCFG_LOV_ADD_OBD:
253 /* lov_modify_tgts add 0:lov_mdsA 1:osp 2:0 3:1
254 * modify_mdc_tgts add 0:lustre-MDT0001
255 * 1:lustre-MDT0001-mdc0002
257 arg1 = lustre_cfg_string(lcfg, 1);
259 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
260 GOTO(out, rc = -EINVAL);
261 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
262 GOTO(out, rc = -EINVAL);
264 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD) {
266 mdt = strstr(lustre_cfg_string(lcfg, 0), "-MDT");
267 /* 1.8 configs don't have "-MDT0000" at the end */
272 rc = lodname2mdt_index(
273 lustre_cfg_string(lcfg, 0),
277 mdt_index = long_index;
279 rc = lod_add_device(env, lod, arg1, index, gen,
280 mdt_index, LUSTRE_OSC_NAME, 1);
281 } else if (lcfg->lcfg_command == LCFG_ADD_MDC) {
283 rc = lod_add_device(env, lod, arg1, index, gen,
284 mdt_index, LUSTRE_MDC_NAME, 1);
285 } else if (lcfg->lcfg_command == LCFG_LOV_ADD_INA) {
286 /*FIXME: Add mdt_index for LCFG_LOV_ADD_INA*/
288 rc = lod_add_device(env, lod, arg1, index, gen,
289 mdt_index, LUSTRE_OSC_NAME, 0);
291 rc = lod_del_device(env, lod,
293 arg1, index, gen, true);
300 struct lprocfs_static_vars v = { 0 };
301 struct obd_device *obd = lod2obd(lod);
303 lprocfs_lod_init_vars(&v);
305 rc = class_process_proc_param(PARAM_LOV, v.obd_vars, lcfg, obd);
311 case LCFG_PRE_CLEANUP: {
312 lu_dev_del_linkage(dev->ld_site, dev);
313 lod_cleanup_desc_tgts(env, lod, &lod->lod_mdt_descs, lcfg);
314 lod_cleanup_desc_tgts(env, lod, &lod->lod_ost_descs, lcfg);
315 if (lcfg->lcfg_command == LCFG_PRE_CLEANUP)
318 * do cleanup on underlying storage only when
319 * all OSPs are cleaned up, as they use that OSD as well
321 next = &lod->lod_child->dd_lu_dev;
322 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
324 CERROR("%s: can't process %u: %d\n",
325 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
327 rc = obd_disconnect(lod->lod_child_exp);
329 CERROR("error in disconnect from storage: %d\n", rc);
333 CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
343 static int lod_recovery_complete(const struct lu_env *env,
344 struct lu_device *dev)
346 struct lod_device *lod = lu2lod_dev(dev);
347 struct lu_device *next = &lod->lod_child->dd_lu_dev;
351 LASSERT(lod->lod_recovery_completed == 0);
352 lod->lod_recovery_completed = 1;
354 rc = next->ld_ops->ldo_recovery_complete(env, next);
356 lod_getref(&lod->lod_ost_descs);
357 if (lod->lod_osts_size > 0) {
358 cfs_foreach_bit(lod->lod_ost_bitmap, i) {
359 struct lod_tgt_desc *tgt;
360 tgt = OST_TGT(lod, i);
361 LASSERT(tgt && tgt->ltd_tgt);
362 next = &tgt->ltd_ost->dd_lu_dev;
363 rc = next->ld_ops->ldo_recovery_complete(env, next);
365 CERROR("%s: can't complete recovery on #%d:"
366 "%d\n", lod2obd(lod)->obd_name, i, rc);
369 lod_putref(lod, &lod->lod_ost_descs);
373 static int lod_prepare(const struct lu_env *env, struct lu_device *pdev,
374 struct lu_device *cdev)
376 struct lod_device *lod = lu2lod_dev(cdev);
377 struct lu_device *next = &lod->lod_child->dd_lu_dev;
381 rc = next->ld_ops->ldo_prepare(env, pdev, next);
383 CERROR("%s: prepare bottom error: rc = %d\n",
384 lod2obd(lod)->obd_name, rc);
388 lod->lod_initialized = 1;
393 const struct lu_device_operations lod_lu_ops = {
394 .ldo_object_alloc = lod_object_alloc,
395 .ldo_process_config = lod_process_config,
396 .ldo_recovery_complete = lod_recovery_complete,
397 .ldo_prepare = lod_prepare,
400 static int lod_root_get(const struct lu_env *env,
401 struct dt_device *dev, struct lu_fid *f)
403 return dt_root_get(env, dt2lod_dev(dev)->lod_child, f);
406 static int lod_statfs(const struct lu_env *env,
407 struct dt_device *dev, struct obd_statfs *sfs)
409 return dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs);
412 static struct thandle *lod_trans_create(const struct lu_env *env,
413 struct dt_device *dev)
417 th = dt_trans_create(env, dt2lod_dev(dev)->lod_child);
421 CFS_INIT_LIST_HEAD(&th->th_remote_update_list);
425 static int lod_remote_sync(const struct lu_env *env, struct dt_device *dev,
428 struct update_request *update;
432 if (cfs_list_empty(&th->th_remote_update_list))
435 cfs_list_for_each_entry(update, &th->th_remote_update_list,
437 /* In DNE phase I, there should be only one OSP
438 * here, so we will do send/receive one by one,
439 * instead of sending them parallel, will fix this
441 th->th_current_request = update;
442 rc = dt_trans_start(env, update->ur_dt, th);
444 /* FIXME how to revert the partial results
445 * once error happened? Resolved by 2 Phase commit */
454 static int lod_trans_start(const struct lu_env *env, struct dt_device *dev,
457 struct lod_device *lod = dt2lod_dev((struct dt_device *) dev);
460 rc = lod_remote_sync(env, dev, th);
464 return dt_trans_start(env, lod->lod_child, th);
467 static int lod_trans_stop(const struct lu_env *env, struct thandle *th)
469 struct update_request *update;
470 struct update_request *tmp;
474 cfs_list_for_each_entry_safe(update, tmp,
475 &th->th_remote_update_list,
477 th->th_current_request = update;
478 rc2 = dt_trans_stop(env, update->ur_dt, th);
479 if (unlikely(rc2 != 0 && rc == 0))
483 rc2 = dt_trans_stop(env, th->th_dev, th);
485 return rc2 != 0 ? rc2 : rc;
488 static void lod_conf_get(const struct lu_env *env,
489 const struct dt_device *dev,
490 struct dt_device_param *param)
492 dt_conf_get(env, dt2lod_dev((struct dt_device *)dev)->lod_child, param);
495 static int lod_sync(const struct lu_env *env, struct dt_device *dev)
497 struct lod_device *lod = dt2lod_dev(dev);
498 struct lod_ost_desc *ost;
502 lod_getref(&lod->lod_ost_descs);
503 lod_foreach_ost(lod, i) {
504 ost = OST_TGT(lod, i);
505 LASSERT(ost && ost->ltd_ost);
506 rc = dt_sync(env, ost->ltd_ost);
508 CERROR("%s: can't sync %u: %d\n",
509 lod2obd(lod)->obd_name, i, rc);
513 lod_putref(lod, &lod->lod_ost_descs);
515 rc = dt_sync(env, lod->lod_child);
520 static int lod_ro(const struct lu_env *env, struct dt_device *dev)
522 return dt_ro(env, dt2lod_dev(dev)->lod_child);
525 static int lod_commit_async(const struct lu_env *env, struct dt_device *dev)
527 return dt_commit_async(env, dt2lod_dev(dev)->lod_child);
530 static int lod_init_capa_ctxt(const struct lu_env *env, struct dt_device *dev,
531 int mode, unsigned long timeout,
532 __u32 alg, struct lustre_capa_key *keys)
534 struct dt_device *next = dt2lod_dev(dev)->lod_child;
535 return dt_init_capa_ctxt(env, next, mode, timeout, alg, keys);
538 static const struct dt_device_operations lod_dt_ops = {
539 .dt_root_get = lod_root_get,
540 .dt_statfs = lod_statfs,
541 .dt_trans_create = lod_trans_create,
542 .dt_trans_start = lod_trans_start,
543 .dt_trans_stop = lod_trans_stop,
544 .dt_conf_get = lod_conf_get,
547 .dt_commit_async = lod_commit_async,
548 .dt_init_capa_ctxt = lod_init_capa_ctxt,
551 static int lod_connect_to_osd(const struct lu_env *env, struct lod_device *lod,
552 struct lustre_cfg *cfg)
554 struct obd_connect_data *data = NULL;
555 struct obd_device *obd;
556 char *nextdev = NULL, *p, *s;
561 LASSERT(lod->lod_child_exp == NULL);
563 /* compatibility hack: we still use old config logs
564 * which specify LOV, but we need to learn underlying
565 * OSD device, which is supposed to be:
566 * <fsname>-MDTxxxx-osd
568 * 2.x MGS generates lines like the following:
569 * #03 (176)lov_setup 0:lustre-MDT0000-mdtlov 1:(struct lov_desc)
570 * 1.8 MGS generates lines like the following:
571 * #03 (168)lov_setup 0:lustre-mdtlov 1:(struct lov_desc)
573 * we use "-MDT" to differentiate 2.x from 1.8 */
575 if ((p = lustre_cfg_string(cfg, 0)) && strstr(p, "-mdtlov")) {
577 OBD_ALLOC(nextdev, len);
579 GOTO(out, rc = -ENOMEM);
582 s = strstr(nextdev, "-mdtlov");
583 if (unlikely(s == NULL)) {
584 CERROR("unable to parse device name %s\n",
585 lustre_cfg_string(cfg, 0));
586 GOTO(out, rc = -EINVAL);
589 if (strstr(nextdev, "-MDT")) {
594 strcpy(s, "-MDT0000-osd");
597 CERROR("unable to parse device name %s\n",
598 lustre_cfg_string(cfg, 0));
599 GOTO(out, rc = -EINVAL);
604 GOTO(out, rc = -ENOMEM);
606 obd = class_name2obd(nextdev);
608 CERROR("can not locate next device: %s\n", nextdev);
609 GOTO(out, rc = -ENOTCONN);
612 data->ocd_connect_flags = OBD_CONNECT_VERSION;
613 data->ocd_version = LUSTRE_VERSION_CODE;
615 rc = obd_connect(env, &lod->lod_child_exp, obd, &obd->obd_uuid,
618 CERROR("cannot connect to next dev %s (%d)\n", nextdev, rc);
622 lod->lod_dt_dev.dd_lu_dev.ld_site =
623 lod->lod_child_exp->exp_obd->obd_lu_dev->ld_site;
624 LASSERT(lod->lod_dt_dev.dd_lu_dev.ld_site);
625 lod->lod_child = lu2dt_dev(lod->lod_child_exp->exp_obd->obd_lu_dev);
631 OBD_FREE(nextdev, len);
635 static int lod_tgt_desc_init(struct lod_tgt_descs *ltd)
637 mutex_init(<d->ltd_mutex);
638 init_rwsem(<d->ltd_rw_sem);
640 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
641 * added to the LOD, see lod_add_device() */
642 ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(32);
643 if (ltd->ltd_tgt_bitmap == NULL)
646 ltd->ltd_tgts_size = 32;
649 ltd->ltd_death_row = 0;
650 ltd->ltd_refcount = 0;
654 static int lod_init0(const struct lu_env *env, struct lod_device *lod,
655 struct lu_device_type *ldt, struct lustre_cfg *cfg)
657 struct dt_device_param ddp;
658 struct obd_device *obd;
662 obd = class_name2obd(lustre_cfg_string(cfg, 0));
664 CERROR("Cannot find obd with name %s\n",
665 lustre_cfg_string(cfg, 0));
669 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
670 lod->lod_dt_dev.dd_lu_dev.ld_obd = obd;
671 lod->lod_dt_dev.dd_lu_dev.ld_ops = &lod_lu_ops;
672 lod->lod_dt_dev.dd_ops = &lod_dt_ops;
674 rc = lod_connect_to_osd(env, lod, cfg);
678 dt_conf_get(env, &lod->lod_dt_dev, &ddp);
679 lod->lod_osd_max_easize = ddp.ddp_max_ea_size;
681 /* setup obd to be used with old lov code */
682 rc = lod_pools_init(lod, cfg);
684 GOTO(out_disconnect, rc);
686 rc = lod_procfs_init(lod);
690 spin_lock_init(&lod->lod_desc_lock);
691 spin_lock_init(&lod->lod_connects_lock);
692 lod_tgt_desc_init(&lod->lod_mdt_descs);
693 lod_tgt_desc_init(&lod->lod_ost_descs);
700 obd_disconnect(lod->lod_child_exp);
704 static struct lu_device *lod_device_free(const struct lu_env *env,
705 struct lu_device *lu)
707 struct lod_device *lod = lu2lod_dev(lu);
708 struct lu_device *next = &lod->lod_child->dd_lu_dev;
711 LASSERT(cfs_atomic_read(&lu->ld_ref) == 0);
712 dt_device_fini(&lod->lod_dt_dev);
717 static struct lu_device *lod_device_alloc(const struct lu_env *env,
718 struct lu_device_type *type,
719 struct lustre_cfg *lcfg)
721 struct lod_device *lod;
722 struct lu_device *lu_dev;
726 lu_dev = ERR_PTR(-ENOMEM);
730 lu_dev = lod2lu_dev(lod);
731 dt_device_init(&lod->lod_dt_dev, type);
732 rc = lod_init0(env, lod, type, lcfg);
734 lod_device_free(env, lu_dev);
735 lu_dev = ERR_PTR(rc);
742 static struct lu_device *lod_device_fini(const struct lu_env *env,
745 struct lod_device *lod = lu2lod_dev(d);
751 lod_procfs_fini(lod);
753 rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs, true);
755 CERROR("%s:can not fini ost descs %d\n",
756 lod2obd(lod)->obd_name, rc);
758 rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs, false);
760 CERROR("%s:can not fini mdt descs %d\n",
761 lod2obd(lod)->obd_name, rc);
767 * we use exports to track all LOD users
769 static int lod_obd_connect(const struct lu_env *env, struct obd_export **exp,
770 struct obd_device *obd, struct obd_uuid *cluuid,
771 struct obd_connect_data *data, void *localdata)
773 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
774 struct lustre_handle conn;
778 CDEBUG(D_CONFIG, "connect #%d\n", lod->lod_connects);
780 rc = class_connect(&conn, obd, cluuid);
784 *exp = class_conn2export(&conn);
786 spin_lock(&lod->lod_connects_lock);
788 /* at the moment we expect the only user */
789 LASSERT(lod->lod_connects == 1);
790 spin_unlock(&lod->lod_connects_lock);
796 * once last export (we don't count self-export) disappeared
797 * lod can be released
799 static int lod_obd_disconnect(struct obd_export *exp)
801 struct obd_device *obd = exp->exp_obd;
802 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
806 /* Only disconnect the underlying layers on the final disconnect. */
807 spin_lock(&lod->lod_connects_lock);
809 if (lod->lod_connects != 0) {
810 /* why should there be more than 1 connect? */
811 spin_unlock(&lod->lod_connects_lock);
812 CERROR("%s: disconnect #%d\n", exp->exp_obd->obd_name,
816 spin_unlock(&lod->lod_connects_lock);
818 /* the last user of lod has gone, let's release the device */
822 rc = class_disconnect(exp); /* bz 9811 */
824 if (rc == 0 && release)
825 class_manual_cleanup(obd);
829 LU_KEY_INIT(lod, struct lod_thread_info);
831 static void lod_key_fini(const struct lu_context *ctx,
832 struct lu_context_key *key, void *data)
834 struct lod_thread_info *info = data;
835 /* allocated in lod_get_lov_ea
836 * XXX: this is overload, a tread may have such store but used only
837 * once. Probably better would be pool of such stores per LOD.
839 if (info->lti_ea_store) {
840 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
841 info->lti_ea_store = NULL;
842 info->lti_ea_store_size = 0;
847 /* context key: lod_thread_key */
848 LU_CONTEXT_KEY_DEFINE(lod, LCT_MD_THREAD);
850 LU_TYPE_INIT_FINI(lod, &lod_thread_key);
852 static struct lu_device_type_operations lod_device_type_ops = {
853 .ldto_init = lod_type_init,
854 .ldto_fini = lod_type_fini,
856 .ldto_start = lod_type_start,
857 .ldto_stop = lod_type_stop,
859 .ldto_device_alloc = lod_device_alloc,
860 .ldto_device_free = lod_device_free,
862 .ldto_device_fini = lod_device_fini
865 static struct lu_device_type lod_device_type = {
866 .ldt_tags = LU_DEVICE_DT,
867 .ldt_name = LUSTRE_LOD_NAME,
868 .ldt_ops = &lod_device_type_ops,
869 .ldt_ctx_tags = LCT_MD_THREAD,
872 static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp,
873 __u32 keylen, void *key, __u32 *vallen, void *val,
874 struct lov_stripe_md *lsm)
878 if (KEY_IS(KEY_OSP_CONNECTED)) {
879 struct obd_device *obd = exp->exp_obd;
880 struct lod_device *d;
881 struct lod_ost_desc *ost;
884 if (!obd->obd_set_up || obd->obd_stopping)
887 d = lu2lod_dev(obd->obd_lu_dev);
888 lod_getref(&d->lod_ost_descs);
889 lod_foreach_ost(d, i) {
891 LASSERT(ost && ost->ltd_ost);
893 rc = obd_get_info(env, ost->ltd_exp, keylen, key,
895 /* one healthy device is enough */
899 lod_putref(d, &d->lod_ost_descs);
906 static struct obd_ops lod_obd_device_ops = {
907 .o_owner = THIS_MODULE,
908 .o_connect = lod_obd_connect,
909 .o_disconnect = lod_obd_disconnect,
910 .o_get_info = lod_obd_get_info,
911 .o_pool_new = lod_pool_new,
912 .o_pool_rem = lod_pool_remove,
913 .o_pool_add = lod_pool_add,
914 .o_pool_del = lod_pool_del,
917 static int __init lod_mod_init(void)
919 struct lprocfs_static_vars lvars = { 0 };
920 cfs_proc_dir_entry_t *lov_proc_dir;
923 rc = lu_kmem_init(lod_caches);
927 lprocfs_lod_init_vars(&lvars);
929 rc = class_register_type(&lod_obd_device_ops, NULL, NULL,
930 #ifndef HAVE_ONLY_PROCFS_SEQ
933 LUSTRE_LOD_NAME, &lod_device_type);
935 lu_kmem_fini(lod_caches);
939 /* create "lov" entry in procfs for compatibility purposes */
940 lov_proc_dir = lprocfs_srch(proc_lustre_root, "lov");
941 if (lov_proc_dir == NULL) {
942 lov_proc_dir = lprocfs_register("lov", proc_lustre_root,
944 if (IS_ERR(lov_proc_dir))
945 CERROR("lod: can't create compat entry \"lov\": %d\n",
946 (int)PTR_ERR(lov_proc_dir));
952 static void __exit lod_mod_exit(void)
955 lprocfs_try_remove_proc_entry("lov", proc_lustre_root);
957 class_unregister_type(LUSTRE_LOD_NAME);
958 lu_kmem_fini(lod_caches);
961 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
962 MODULE_DESCRIPTION("Lustre Logical Object Device ("LUSTRE_LOD_NAME")");
963 MODULE_LICENSE("GPL");
965 module_init(lod_mod_init);
966 module_exit(lod_mod_exit);