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, 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/lod/lod_dev.c
34 * Lustre Logical Object Device
36 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
37 * Author: Mikhail Pershin <mike.pershin@intel.com>
40 * The Logical Object Device (LOD) layer manages access to striped
41 * objects (both regular files and directories). It implements the DT
42 * device and object APIs and is responsible for creating, storing,
43 * and loading striping information as an extended attribute of the
44 * underlying OSD object. LOD is the server side analog of the LOV and
45 * LMV layers on the client side.
47 * Metadata LU object stack (layers of the same compound LU object,
48 * all have the same FID):
58 * During LOD object initialization the localness or remoteness of the
59 * object FID dictates the choice between OSD and OSP.
61 * An LOD object (file or directory) with N stripes (each has a
68 * S0 S1 S2 S3 S(N-1) OS[DP] objects, seen as DT objects by LOD
70 * When upper layers must access an object's stripes (which are
71 * themselves OST or MDT LU objects) LOD finds these objects by their
72 * FIDs and stores them as an array of DT object pointers on the
73 * object. Declarations and operations on LOD objects are received by
74 * LOD (as DT object operations) and performed on the underlying
75 * OS[DP] object and (as needed) on the stripes. From the perspective
76 * of LOD, a stripe-less file (created by mknod() or open with
77 * O_LOV_DELAY_CREATE) is an object which does not yet have stripes,
78 * while a non-striped directory (created by mkdir()) is an object
79 * which will never have stripes.
81 * The LOD layer also implements a small subset of the OBD device API
82 * to support MDT stack initialization and finalization (an MDD device
83 * connects and disconnects itself to and from the underlying LOD
84 * device), and pool management. In turn LOD uses the OBD device API
85 * to connect it self to the underlying OSD, and to connect itself to
86 * OSP devices representing the MDTs and OSTs that bear the stripes of
90 #define DEBUG_SUBSYSTEM S_MDS
92 #include <obd_class.h>
93 #include <md_object.h>
94 #include <lustre_fid.h>
95 #include <lustre_param.h>
96 #include <lustre_update.h>
98 #include "lod_internal.h"
101 * Lookup target by FID.
103 * Lookup MDT/OST target index by FID. Type of the target can be
106 * \param[in] env LU environment provided by the caller
107 * \param[in] lod lod device
109 * \param[out] tgt result target index
110 * \param[in] type expected type of the target:
111 * LU_SEQ_RANGE_{MDT,OST,ANY}
113 * \retval 0 on success
114 * \retval negative negated errno on error
116 int lod_fld_lookup(const struct lu_env *env, struct lod_device *lod,
117 const struct lu_fid *fid, __u32 *tgt, int *type)
119 struct lu_seq_range range = { 0 };
120 struct lu_server_fld *server_fld;
124 if (!fid_is_sane(fid)) {
125 CERROR("%s: invalid FID "DFID"\n", lod2obd(lod)->obd_name,
130 if (fid_is_idif(fid)) {
131 *tgt = fid_idif_ost_idx(fid);
132 *type = LU_SEQ_RANGE_OST;
136 if (!lod->lod_initialized || (!fid_seq_in_fldb(fid_seq(fid)))) {
137 LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
139 *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
140 *type = LU_SEQ_RANGE_MDT;
144 server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
145 fld_range_set_type(&range, *type);
146 rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
150 *tgt = range.lsr_index;
151 *type = range.lsr_flags;
153 CDEBUG(D_INFO, "%s: got tgt %x for sequence: "LPX64"\n",
154 lod2obd(lod)->obd_name, *tgt, fid_seq(fid));
159 /* Slab for OSD object allocation */
160 struct kmem_cache *lod_object_kmem;
162 static struct lu_kmem_descr lod_caches[] = {
164 .ckd_cache = &lod_object_kmem,
165 .ckd_name = "lod_obj",
166 .ckd_size = sizeof(struct lod_object)
173 static struct lu_device *lod_device_fini(const struct lu_env *env,
174 struct lu_device *d);
177 * Implementation of lu_device_operations::ldo_object_alloc() for LOD
179 * Allocates and initializes LOD's slice in the given object.
181 * see include/lu_object.h for the details.
183 static struct lu_object *lod_object_alloc(const struct lu_env *env,
184 const struct lu_object_header *hdr,
185 struct lu_device *dev)
187 struct lod_object *lod_obj;
188 struct lu_object *lu_obj;
191 OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, GFP_NOFS);
193 RETURN(ERR_PTR(-ENOMEM));
195 lu_obj = lod2lu_obj(lod_obj);
196 dt_object_init(&lod_obj->ldo_obj, NULL, dev);
197 lod_obj->ldo_obj.do_ops = &lod_obj_ops;
198 lu_obj->lo_ops = &lod_lu_obj_ops;
204 * Cleanup table of target's descriptors.
206 * The function goes through all the targets in the given table
207 * and apply given configuration command on to the targets.
208 * Used to cleanup the targets at unmount.
210 * \param[in] env LU environment provided by the caller
211 * \param[in] lod lod device
212 * \param[in] ltd target's table to go through
213 * \param[in] lcfg configuration command to apply
215 * \retval 0 on success
216 * \retval negative negated errno on error
218 static int lod_cleanup_desc_tgts(const struct lu_env *env,
219 struct lod_device *lod,
220 struct lod_tgt_descs *ltd,
221 struct lustre_cfg *lcfg)
223 struct lu_device *next;
228 if (ltd->ltd_tgts_size <= 0) {
229 lod_putref(lod, ltd);
232 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
233 struct lod_tgt_desc *tgt;
236 tgt = LTD_TGT(ltd, i);
237 LASSERT(tgt && tgt->ltd_tgt);
238 next = &tgt->ltd_tgt->dd_lu_dev;
239 rc1 = next->ld_ops->ldo_process_config(env, next, lcfg);
241 CERROR("%s: error cleaning up LOD index %u: cmd %#x"
242 ": rc = %d\n", lod2obd(lod)->obd_name, i,
243 lcfg->lcfg_command, rc1);
247 lod_putref(lod, ltd);
252 * Extract MDT target index from a device name.
254 * a helper function to extract index from the given device name
255 * like "fsname-MDTxxxx-mdtlov"
257 * \param[in] lodname device name
258 * \param[out] index extracted index
260 * \retval 0 on success
261 * \retval -EINVAL if the name is invalid
263 static int lodname2mdt_index(char *lodname, long *index)
267 ptr = strrchr(lodname, '-');
269 CERROR("invalid MDT index in '%s'\n", lodname);
273 if (strncmp(ptr, "-mdtlov", 7) != 0) {
274 CERROR("invalid MDT index in '%s'\n", lodname);
278 if ((unsigned long)ptr - (unsigned long)lodname <= 8) {
279 CERROR("invalid MDT index in '%s'\n", lodname);
283 if (strncmp(ptr - 8, "-MDT", 4) != 0) {
284 CERROR("invalid MDT index in '%s'\n", lodname);
288 *index = simple_strtol(ptr - 4, &tmp, 16);
289 if (*tmp != '-' || *index > INT_MAX || *index < 0) {
290 CERROR("invalid MDT index in '%s'\n", lodname);
297 * Implementation of lu_device_operations::ldo_process_config() for LOD
299 * The method is called by the configuration subsystem during setup,
300 * cleanup and when the configuration changes. The method processes
301 * few specific commands like adding/removing the targets, changing
302 * the runtime parameters.
304 * \param[in] env LU environment provided by the caller
305 * \param[in] dev lod device
306 * \param[in] lcfg configuration command to apply
308 * \retval 0 on success
309 * \retval negative negated errno on error
311 * The examples are below.
313 * Add osc config log:
314 * marker 20 (flags=0x01, v2.2.49.56) lustre-OST0001 'add osc'
315 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nidxxx
316 * attach 0:lustre-OST0001-osc-MDT0001 1:osc 2:lustre-MDT0001-mdtlov_UUID
317 * setup 0:lustre-OST0001-osc-MDT0001 1:lustre-OST0001_UUID 2:nid
318 * lov_modify_tgts add 0:lustre-MDT0001-mdtlov 1:lustre-OST0001_UUID 2:1 3:1
319 * marker 20 (flags=0x02, v2.2.49.56) lustre-OST0001 'add osc'
321 * Add mdc config log:
322 * marker 10 (flags=0x01, v2.2.49.56) lustre-MDT0000 'add osp'
323 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nid
324 * attach 0:lustre-MDT0000-osp-MDT0001 1:osp 2:lustre-MDT0001-mdtlov_UUID
325 * setup 0:lustre-MDT0000-osp-MDT0001 1:lustre-MDT0000_UUID 2:nid
326 * modify_mdc_tgts add 0:lustre-MDT0001 1:lustre-MDT0000_UUID 2:0 3:1
327 * marker 10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID 'add osp'
329 static int lod_process_config(const struct lu_env *env,
330 struct lu_device *dev,
331 struct lustre_cfg *lcfg)
333 struct lod_device *lod = lu2lod_dev(dev);
334 struct lu_device *next = &lod->lod_child->dd_lu_dev;
339 switch(lcfg->lcfg_command) {
340 case LCFG_LOV_DEL_OBD:
341 case LCFG_LOV_ADD_INA:
342 case LCFG_LOV_ADD_OBD:
347 /* lov_modify_tgts add 0:lov_mdsA 1:osp 2:0 3:1
348 * modify_mdc_tgts add 0:lustre-MDT0001
349 * 1:lustre-MDT0001-mdc0002
351 arg1 = lustre_cfg_string(lcfg, 1);
353 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
354 GOTO(out, rc = -EINVAL);
355 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
356 GOTO(out, rc = -EINVAL);
358 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD) {
360 mdt = strstr(lustre_cfg_string(lcfg, 0), "-MDT");
361 /* 1.8 configs don't have "-MDT0000" at the end */
366 rc = lodname2mdt_index(
367 lustre_cfg_string(lcfg, 0),
371 mdt_index = long_index;
373 rc = lod_add_device(env, lod, arg1, index, gen,
374 mdt_index, LUSTRE_OSC_NAME, 1);
375 } else if (lcfg->lcfg_command == LCFG_ADD_MDC) {
377 rc = lod_add_device(env, lod, arg1, index, gen,
378 mdt_index, LUSTRE_MDC_NAME, 1);
379 } else if (lcfg->lcfg_command == LCFG_LOV_ADD_INA) {
380 /*FIXME: Add mdt_index for LCFG_LOV_ADD_INA*/
382 rc = lod_add_device(env, lod, arg1, index, gen,
383 mdt_index, LUSTRE_OSC_NAME, 0);
385 rc = lod_del_device(env, lod,
387 arg1, index, gen, true);
394 struct obd_device *obd = lod2obd(lod);
396 rc = class_process_proc_param(PARAM_LOV, obd->obd_vars,
403 case LCFG_PRE_CLEANUP: {
404 lu_dev_del_linkage(dev->ld_site, dev);
405 lod_cleanup_desc_tgts(env, lod, &lod->lod_mdt_descs, lcfg);
406 lod_cleanup_desc_tgts(env, lod, &lod->lod_ost_descs, lcfg);
407 if (lcfg->lcfg_command == LCFG_PRE_CLEANUP)
410 * do cleanup on underlying storage only when
411 * all OSPs are cleaned up, as they use that OSD as well
413 next = &lod->lod_child->dd_lu_dev;
414 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
416 CERROR("%s: can't process %u: %d\n",
417 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
419 rc = obd_disconnect(lod->lod_child_exp);
421 CERROR("error in disconnect from storage: %d\n", rc);
425 CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
436 * Implementation of lu_device_operations::ldo_recovery_complete() for LOD
438 * The method is called once the recovery is complete. This implementation
439 * distributes the notification to all the known targets.
441 * see include/lu_object.h for the details
443 static int lod_recovery_complete(const struct lu_env *env,
444 struct lu_device *dev)
446 struct lod_device *lod = lu2lod_dev(dev);
447 struct lu_device *next = &lod->lod_child->dd_lu_dev;
452 LASSERT(lod->lod_recovery_completed == 0);
453 lod->lod_recovery_completed = 1;
455 rc = next->ld_ops->ldo_recovery_complete(env, next);
457 lod_getref(&lod->lod_ost_descs);
458 if (lod->lod_osts_size > 0) {
459 cfs_foreach_bit(lod->lod_ost_bitmap, i) {
460 struct lod_tgt_desc *tgt;
461 tgt = OST_TGT(lod, i);
462 LASSERT(tgt && tgt->ltd_tgt);
463 next = &tgt->ltd_ost->dd_lu_dev;
464 rc = next->ld_ops->ldo_recovery_complete(env, next);
466 CERROR("%s: can't complete recovery on #%d:"
467 "%d\n", lod2obd(lod)->obd_name, i, rc);
470 lod_putref(lod, &lod->lod_ost_descs);
475 * Implementation of lu_device_operations::ldo_prepare() for LOD
477 * see include/lu_object.h for the details.
479 static int lod_prepare(const struct lu_env *env, struct lu_device *pdev,
480 struct lu_device *cdev)
482 struct lod_device *lod = lu2lod_dev(cdev);
483 struct lu_device *next = &lod->lod_child->dd_lu_dev;
487 rc = next->ld_ops->ldo_prepare(env, pdev, next);
489 CERROR("%s: prepare bottom error: rc = %d\n",
490 lod2obd(lod)->obd_name, rc);
494 lod->lod_initialized = 1;
499 const struct lu_device_operations lod_lu_ops = {
500 .ldo_object_alloc = lod_object_alloc,
501 .ldo_process_config = lod_process_config,
502 .ldo_recovery_complete = lod_recovery_complete,
503 .ldo_prepare = lod_prepare,
507 * Implementation of dt_device_operations::dt_root_get() for LOD
509 * see include/dt_object.h for the details.
511 static int lod_root_get(const struct lu_env *env,
512 struct dt_device *dev, struct lu_fid *f)
514 return dt_root_get(env, dt2lod_dev(dev)->lod_child, f);
518 * Implementation of dt_device_operations::dt_statfs() for LOD
520 * see include/dt_object.h for the details.
522 static int lod_statfs(const struct lu_env *env,
523 struct dt_device *dev, struct obd_statfs *sfs)
525 return dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs);
529 * Implementation of dt_device_operations::dt_trans_create() for LOD
531 * Creates a transaction using local (to this node) OSD.
533 * see include/dt_object.h for the details.
535 static struct thandle *lod_trans_create(const struct lu_env *env,
536 struct dt_device *dt)
540 th = top_trans_create(env, dt2lod_dev(dt)->lod_child);
550 * Implementation of dt_device_operations::dt_trans_start() for LOD
552 * Starts the set of local transactions using the targets involved
553 * in declare phase. Initial support for the distributed transactions.
555 * see include/dt_object.h for the details.
557 static int lod_trans_start(const struct lu_env *env, struct dt_device *dt,
560 return top_trans_start(env, dt2lod_dev(dt)->lod_child, th);
564 * Implementation of dt_device_operations::dt_trans_stop() for LOD
566 * Stops the set of local transactions using the targets involved
567 * in declare phase. Initial support for the distributed transactions.
569 * see include/dt_object.h for the details.
571 static int lod_trans_stop(const struct lu_env *env, struct dt_device *dt,
574 return top_trans_stop(env, dt2lod_dev(dt)->lod_child, th);
578 * Implementation of dt_device_operations::dt_conf_get() for LOD
580 * Currently returns the configuration provided by the local OSD.
582 * see include/dt_object.h for the details.
584 static void lod_conf_get(const struct lu_env *env,
585 const struct dt_device *dev,
586 struct dt_device_param *param)
588 dt_conf_get(env, dt2lod_dev((struct dt_device *)dev)->lod_child, param);
592 * Implementation of dt_device_operations::dt_sync() for LOD
594 * Syncs all known OST targets. Very very expensive and used
595 * rarely by LFSCK now. Should not be used in general.
597 * see include/dt_object.h for the details.
599 static int lod_sync(const struct lu_env *env, struct dt_device *dev)
601 struct lod_device *lod = dt2lod_dev(dev);
602 struct lod_ost_desc *ost;
607 lod_getref(&lod->lod_ost_descs);
608 lod_foreach_ost(lod, i) {
609 ost = OST_TGT(lod, i);
610 LASSERT(ost && ost->ltd_ost);
611 rc = dt_sync(env, ost->ltd_ost);
613 CERROR("%s: can't sync %u: %d\n",
614 lod2obd(lod)->obd_name, i, rc);
618 lod_putref(lod, &lod->lod_ost_descs);
620 rc = dt_sync(env, lod->lod_child);
626 * Implementation of dt_device_operations::dt_ro() for LOD
628 * Turns local OSD read-only, used for the testing only.
630 * see include/dt_object.h for the details.
632 static int lod_ro(const struct lu_env *env, struct dt_device *dev)
634 return dt_ro(env, dt2lod_dev(dev)->lod_child);
638 * Implementation of dt_device_operations::dt_commit_async() for LOD
640 * Asks local OSD to commit sooner.
642 * see include/dt_object.h for the details.
644 static int lod_commit_async(const struct lu_env *env, struct dt_device *dev)
646 return dt_commit_async(env, dt2lod_dev(dev)->lod_child);
649 static const struct dt_device_operations lod_dt_ops = {
650 .dt_root_get = lod_root_get,
651 .dt_statfs = lod_statfs,
652 .dt_trans_create = lod_trans_create,
653 .dt_trans_start = lod_trans_start,
654 .dt_trans_stop = lod_trans_stop,
655 .dt_conf_get = lod_conf_get,
658 .dt_commit_async = lod_commit_async,
662 * Connect to a local OSD.
664 * Used to connect to the local OSD at mount. OSD name is taken from the
665 * configuration command passed. This connection is used to identify LU
666 * site and pin the OSD from early removal.
668 * \param[in] env LU environment provided by the caller
669 * \param[in] lod lod device
670 * \param[in] cfg configuration command to apply
672 * \retval 0 on success
673 * \retval negative negated errno on error
675 static int lod_connect_to_osd(const struct lu_env *env, struct lod_device *lod,
676 struct lustre_cfg *cfg)
678 struct obd_connect_data *data = NULL;
679 struct obd_device *obd;
680 char *nextdev = NULL, *p, *s;
685 LASSERT(lod->lod_child_exp == NULL);
687 /* compatibility hack: we still use old config logs
688 * which specify LOV, but we need to learn underlying
689 * OSD device, which is supposed to be:
690 * <fsname>-MDTxxxx-osd
692 * 2.x MGS generates lines like the following:
693 * #03 (176)lov_setup 0:lustre-MDT0000-mdtlov 1:(struct lov_desc)
694 * 1.8 MGS generates lines like the following:
695 * #03 (168)lov_setup 0:lustre-mdtlov 1:(struct lov_desc)
697 * we use "-MDT" to differentiate 2.x from 1.8 */
699 if ((p = lustre_cfg_string(cfg, 0)) && strstr(p, "-mdtlov")) {
701 OBD_ALLOC(nextdev, len);
703 GOTO(out, rc = -ENOMEM);
706 s = strstr(nextdev, "-mdtlov");
707 if (unlikely(s == NULL)) {
708 CERROR("unable to parse device name %s\n",
709 lustre_cfg_string(cfg, 0));
710 GOTO(out, rc = -EINVAL);
713 if (strstr(nextdev, "-MDT")) {
718 strcpy(s, "-MDT0000-osd");
721 CERROR("unable to parse device name %s\n",
722 lustre_cfg_string(cfg, 0));
723 GOTO(out, rc = -EINVAL);
728 GOTO(out, rc = -ENOMEM);
730 obd = class_name2obd(nextdev);
732 CERROR("can not locate next device: %s\n", nextdev);
733 GOTO(out, rc = -ENOTCONN);
736 data->ocd_connect_flags = OBD_CONNECT_VERSION;
737 data->ocd_version = LUSTRE_VERSION_CODE;
739 rc = obd_connect(env, &lod->lod_child_exp, obd, &obd->obd_uuid,
742 CERROR("cannot connect to next dev %s (%d)\n", nextdev, rc);
746 lod->lod_dt_dev.dd_lu_dev.ld_site =
747 lod->lod_child_exp->exp_obd->obd_lu_dev->ld_site;
748 LASSERT(lod->lod_dt_dev.dd_lu_dev.ld_site);
749 lod->lod_child = lu2dt_dev(lod->lod_child_exp->exp_obd->obd_lu_dev);
755 OBD_FREE(nextdev, len);
760 * Allocate and initialize target table.
762 * A helper function to initialize the target table and allocate
763 * a bitmap of the available targets.
765 * \param[in] ltd target's table to initialize
767 * \retval 0 on success
768 * \retval negative negated errno on error
770 static int lod_tgt_desc_init(struct lod_tgt_descs *ltd)
772 mutex_init(<d->ltd_mutex);
773 init_rwsem(<d->ltd_rw_sem);
775 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
776 * added to the LOD, see lod_add_device() */
777 ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(32);
778 if (ltd->ltd_tgt_bitmap == NULL)
781 ltd->ltd_tgts_size = 32;
784 ltd->ltd_death_row = 0;
785 ltd->ltd_refcount = 0;
790 * Initialize LOD device at setup.
792 * Initializes the given LOD device using the original configuration command.
793 * The function initiates a connection to the local OSD and initializes few
794 * internal structures like pools, target tables, etc.
796 * \param[in] env LU environment provided by the caller
797 * \param[in] lod lod device
798 * \param[in] ldt not used
799 * \param[in] cfg configuration command
801 * \retval 0 on success
802 * \retval negative negated errno on error
804 static int lod_init0(const struct lu_env *env, struct lod_device *lod,
805 struct lu_device_type *ldt, struct lustre_cfg *cfg)
807 struct dt_device_param ddp;
808 struct obd_device *obd;
812 obd = class_name2obd(lustre_cfg_string(cfg, 0));
814 CERROR("Cannot find obd with name %s\n",
815 lustre_cfg_string(cfg, 0));
819 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
820 lod->lod_dt_dev.dd_lu_dev.ld_obd = obd;
821 lod->lod_dt_dev.dd_lu_dev.ld_ops = &lod_lu_ops;
822 lod->lod_dt_dev.dd_ops = &lod_dt_ops;
824 rc = lod_connect_to_osd(env, lod, cfg);
828 dt_conf_get(env, &lod->lod_dt_dev, &ddp);
829 lod->lod_osd_max_easize = ddp.ddp_max_ea_size;
831 /* setup obd to be used with old lov code */
832 rc = lod_pools_init(lod, cfg);
834 GOTO(out_disconnect, rc);
836 rc = lod_procfs_init(lod);
840 spin_lock_init(&lod->lod_desc_lock);
841 spin_lock_init(&lod->lod_connects_lock);
842 lod_tgt_desc_init(&lod->lod_mdt_descs);
843 lod_tgt_desc_init(&lod->lod_ost_descs);
850 obd_disconnect(lod->lod_child_exp);
855 * Implementation of lu_device_type_operations::ldto_device_free() for LOD
857 * Releases the memory allocated for LOD device.
859 * see include/lu_object.h for the details.
861 static struct lu_device *lod_device_free(const struct lu_env *env,
862 struct lu_device *lu)
864 struct lod_device *lod = lu2lod_dev(lu);
865 struct lu_device *next = &lod->lod_child->dd_lu_dev;
868 LASSERT(atomic_read(&lu->ld_ref) == 0);
869 dt_device_fini(&lod->lod_dt_dev);
875 * Implementation of lu_device_type_operations::ldto_device_alloc() for LOD
877 * Allocates LOD device and calls the helpers to initialize it.
879 * see include/lu_object.h for the details.
881 static struct lu_device *lod_device_alloc(const struct lu_env *env,
882 struct lu_device_type *type,
883 struct lustre_cfg *lcfg)
885 struct lod_device *lod;
886 struct lu_device *lu_dev;
890 lu_dev = ERR_PTR(-ENOMEM);
894 lu_dev = lod2lu_dev(lod);
895 dt_device_init(&lod->lod_dt_dev, type);
896 rc = lod_init0(env, lod, type, lcfg);
898 lod_device_free(env, lu_dev);
899 lu_dev = ERR_PTR(rc);
907 * Implementation of lu_device_type_operations::ldto_device_fini() for LOD
909 * Releases the internal resources used by LOD device.
911 * see include/lu_object.h for the details.
913 static struct lu_device *lod_device_fini(const struct lu_env *env,
916 struct lod_device *lod = lu2lod_dev(d);
922 lod_procfs_fini(lod);
924 rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs, true);
926 CERROR("%s:can not fini ost descs %d\n",
927 lod2obd(lod)->obd_name, rc);
929 rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs, false);
931 CERROR("%s:can not fini mdt descs %d\n",
932 lod2obd(lod)->obd_name, rc);
938 * Implementation of obd_ops::o_connect() for LOD
940 * Used to track all the users of this specific LOD device,
941 * so the device stays up until the last user disconnected.
943 * \param[in] env LU environment provided by the caller
944 * \param[out] exp export the caller will be using to access LOD
945 * \param[in] obd OBD device representing LOD device
946 * \param[in] cluuid unique identifier of the caller
947 * \param[in] data not used
948 * \param[in] localdata not used
950 * \retval 0 on success
951 * \retval negative negated errno on error
953 static int lod_obd_connect(const struct lu_env *env, struct obd_export **exp,
954 struct obd_device *obd, struct obd_uuid *cluuid,
955 struct obd_connect_data *data, void *localdata)
957 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
958 struct lustre_handle conn;
962 CDEBUG(D_CONFIG, "connect #%d\n", lod->lod_connects);
964 rc = class_connect(&conn, obd, cluuid);
968 *exp = class_conn2export(&conn);
970 spin_lock(&lod->lod_connects_lock);
972 /* at the moment we expect the only user */
973 LASSERT(lod->lod_connects == 1);
974 spin_unlock(&lod->lod_connects_lock);
981 * Implementation of obd_ops::o_disconnect() for LOD
983 * When the caller doesn't need to use this LOD instance, it calls
984 * obd_disconnect() and LOD releases corresponding export/reference count.
985 * Once all the users gone, LOD device is released.
987 * \param[in] exp export provided to the caller in obd_connect()
989 * \retval 0 on success
990 * \retval negative negated errno on error
992 static int lod_obd_disconnect(struct obd_export *exp)
994 struct obd_device *obd = exp->exp_obd;
995 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
999 /* Only disconnect the underlying layers on the final disconnect. */
1000 spin_lock(&lod->lod_connects_lock);
1001 lod->lod_connects--;
1002 if (lod->lod_connects != 0) {
1003 /* why should there be more than 1 connect? */
1004 spin_unlock(&lod->lod_connects_lock);
1005 CERROR("%s: disconnect #%d\n", exp->exp_obd->obd_name,
1009 spin_unlock(&lod->lod_connects_lock);
1011 /* the last user of lod has gone, let's release the device */
1015 rc = class_disconnect(exp); /* bz 9811 */
1017 if (rc == 0 && release)
1018 class_manual_cleanup(obd);
1022 LU_KEY_INIT(lod, struct lod_thread_info);
1024 static void lod_key_fini(const struct lu_context *ctx,
1025 struct lu_context_key *key, void *data)
1027 struct lod_thread_info *info = data;
1028 /* allocated in lod_get_lov_ea
1029 * XXX: this is overload, a tread may have such store but used only
1030 * once. Probably better would be pool of such stores per LOD.
1032 if (info->lti_ea_store) {
1033 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
1034 info->lti_ea_store = NULL;
1035 info->lti_ea_store_size = 0;
1037 lu_buf_free(&info->lti_linkea_buf);
1041 /* context key: lod_thread_key */
1042 LU_CONTEXT_KEY_DEFINE(lod, LCT_MD_THREAD);
1044 LU_TYPE_INIT_FINI(lod, &lod_thread_key);
1046 static struct lu_device_type_operations lod_device_type_ops = {
1047 .ldto_init = lod_type_init,
1048 .ldto_fini = lod_type_fini,
1050 .ldto_start = lod_type_start,
1051 .ldto_stop = lod_type_stop,
1053 .ldto_device_alloc = lod_device_alloc,
1054 .ldto_device_free = lod_device_free,
1056 .ldto_device_fini = lod_device_fini
1059 static struct lu_device_type lod_device_type = {
1060 .ldt_tags = LU_DEVICE_DT,
1061 .ldt_name = LUSTRE_LOD_NAME,
1062 .ldt_ops = &lod_device_type_ops,
1063 .ldt_ctx_tags = LCT_MD_THREAD,
1067 * Implementation of obd_ops::o_get_info() for LOD
1069 * Currently, there is only one supported key: KEY_OSP_CONNECTED , to provide
1070 * the caller binary status whether LOD has seen connection to any OST target.
1072 * \param[in] env LU environment provided by the caller
1073 * \param[in] exp export of the caller
1074 * \param[in] keylen len of the key
1075 * \param[in] key the key
1076 * \param[in] vallen not used
1077 * \param[in] val not used
1079 * \retval 0 if a connection was seen
1080 * \retval -EAGAIN if LOD isn't running yet or no
1081 * connection has been seen yet
1082 * \retval -EINVAL if not supported key is requested
1084 static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp,
1085 __u32 keylen, void *key, __u32 *vallen, void *val)
1089 if (KEY_IS(KEY_OSP_CONNECTED)) {
1090 struct obd_device *obd = exp->exp_obd;
1091 struct lod_device *d;
1092 struct lod_ost_desc *ost;
1096 if (!obd->obd_set_up || obd->obd_stopping)
1099 d = lu2lod_dev(obd->obd_lu_dev);
1100 lod_getref(&d->lod_ost_descs);
1101 lod_foreach_ost(d, i) {
1102 ost = OST_TGT(d, i);
1103 LASSERT(ost && ost->ltd_ost);
1105 rc = obd_get_info(env, ost->ltd_exp, keylen, key,
1107 /* one healthy device is enough */
1111 lod_putref(d, &d->lod_ost_descs);
1118 static struct obd_ops lod_obd_device_ops = {
1119 .o_owner = THIS_MODULE,
1120 .o_connect = lod_obd_connect,
1121 .o_disconnect = lod_obd_disconnect,
1122 .o_get_info = lod_obd_get_info,
1123 .o_pool_new = lod_pool_new,
1124 .o_pool_rem = lod_pool_remove,
1125 .o_pool_add = lod_pool_add,
1126 .o_pool_del = lod_pool_del,
1129 static int __init lod_mod_init(void)
1131 struct obd_type *type;
1134 rc = lu_kmem_init(lod_caches);
1138 rc = class_register_type(&lod_obd_device_ops, NULL, true, NULL,
1139 LUSTRE_LOD_NAME, &lod_device_type);
1141 lu_kmem_fini(lod_caches);
1145 /* create "lov" entry in procfs for compatibility purposes */
1146 type = class_search_type(LUSTRE_LOV_NAME);
1147 if (type != NULL && type->typ_procroot != NULL)
1150 type = class_search_type(LUSTRE_LOD_NAME);
1151 type->typ_procsym = lprocfs_register("lov", proc_lustre_root,
1153 if (IS_ERR(type->typ_procsym)) {
1154 CERROR("lod: can't create compat entry \"lov\": %d\n",
1155 (int)PTR_ERR(type->typ_procsym));
1156 type->typ_procsym = NULL;
1161 static void __exit lod_mod_exit(void)
1163 class_unregister_type(LUSTRE_LOD_NAME);
1164 lu_kmem_fini(lod_caches);
1167 MODULE_AUTHOR("Intel Corporation. <https://wiki.hpdd.intel.com/>");
1168 MODULE_DESCRIPTION("Lustre Logical Object Device ("LUSTRE_LOD_NAME")");
1169 MODULE_LICENSE("GPL");
1171 module_init(lod_mod_init);
1172 module_exit(lod_mod_exit);