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 <linux/kthread.h>
93 #include <obd_class.h>
94 #include <md_object.h>
95 #include <lustre_fid.h>
96 #include <lustre_param.h>
97 #include <lustre_update.h>
98 #include <lustre_log.h>
100 #include "lod_internal.h"
102 static const char lod_update_log_name[] = "update_log";
103 static const char lod_update_log_dir_name[] = "update_log_dir";
106 * Lookup target by FID.
108 * Lookup MDT/OST target index by FID. Type of the target can be
111 * \param[in] env LU environment provided by the caller
112 * \param[in] lod lod device
114 * \param[out] tgt result target index
115 * \param[in] type expected type of the target:
116 * LU_SEQ_RANGE_{MDT,OST,ANY}
118 * \retval 0 on success
119 * \retval negative negated errno on error
121 int lod_fld_lookup(const struct lu_env *env, struct lod_device *lod,
122 const struct lu_fid *fid, __u32 *tgt, int *type)
124 struct lu_seq_range range = { 0 };
125 struct lu_server_fld *server_fld;
129 if (!fid_is_sane(fid)) {
130 CERROR("%s: invalid FID "DFID"\n", lod2obd(lod)->obd_name,
135 if (fid_is_idif(fid)) {
136 *tgt = fid_idif_ost_idx(fid);
137 *type = LU_SEQ_RANGE_OST;
141 if (fid_is_update_log(fid) || fid_is_update_log_dir(fid)) {
143 *type = LU_SEQ_RANGE_MDT;
147 if (!lod->lod_initialized || (!fid_seq_in_fldb(fid_seq(fid)))) {
148 LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
150 *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
151 *type = LU_SEQ_RANGE_MDT;
155 server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
156 if (server_fld == NULL)
159 fld_range_set_type(&range, *type);
160 rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
164 *tgt = range.lsr_index;
165 *type = range.lsr_flags;
167 CDEBUG(D_INFO, "%s: got tgt %x for sequence: "LPX64"\n",
168 lod2obd(lod)->obd_name, *tgt, fid_seq(fid));
173 /* Slab for OSD object allocation */
174 struct kmem_cache *lod_object_kmem;
176 /* Slab for dt_txn_callback */
177 struct kmem_cache *lod_txn_callback_kmem;
178 static struct lu_kmem_descr lod_caches[] = {
180 .ckd_cache = &lod_object_kmem,
181 .ckd_name = "lod_obj",
182 .ckd_size = sizeof(struct lod_object)
185 .ckd_cache = &lod_txn_callback_kmem,
186 .ckd_name = "lod_txn_callback",
187 .ckd_size = sizeof(struct dt_txn_callback)
194 static struct lu_device *lod_device_fini(const struct lu_env *env,
195 struct lu_device *d);
198 * Implementation of lu_device_operations::ldo_object_alloc() for LOD
200 * Allocates and initializes LOD's slice in the given object.
202 * see include/lu_object.h for the details.
204 static struct lu_object *lod_object_alloc(const struct lu_env *env,
205 const struct lu_object_header *hdr,
206 struct lu_device *dev)
208 struct lod_object *lod_obj;
209 struct lu_object *lu_obj;
212 OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, GFP_NOFS);
214 RETURN(ERR_PTR(-ENOMEM));
216 lu_obj = lod2lu_obj(lod_obj);
217 dt_object_init(&lod_obj->ldo_obj, NULL, dev);
218 lod_obj->ldo_obj.do_ops = &lod_obj_ops;
219 lu_obj->lo_ops = &lod_lu_obj_ops;
225 * Process the config log for all sub device.
227 * The function goes through all the targets in the given table
228 * and apply given configuration command on to the targets.
229 * Used to cleanup the targets at unmount.
231 * \param[in] env LU environment provided by the caller
232 * \param[in] lod lod device
233 * \param[in] ltd target's table to go through
234 * \param[in] lcfg configuration command to apply
236 * \retval 0 on success
237 * \retval negative negated errno on error
239 static int lod_sub_process_config(const struct lu_env *env,
240 struct lod_device *lod,
241 struct lod_tgt_descs *ltd,
242 struct lustre_cfg *lcfg)
244 struct lu_device *next;
249 if (ltd->ltd_tgts_size <= 0) {
250 lod_putref(lod, ltd);
253 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
254 struct lod_tgt_desc *tgt;
257 tgt = LTD_TGT(ltd, i);
258 LASSERT(tgt && tgt->ltd_tgt);
259 next = &tgt->ltd_tgt->dd_lu_dev;
260 rc1 = next->ld_ops->ldo_process_config(env, next, lcfg);
262 CERROR("%s: error cleaning up LOD index %u: cmd %#x"
263 ": rc = %d\n", lod2obd(lod)->obd_name, i,
264 lcfg->lcfg_command, rc1);
268 lod_putref(lod, ltd);
272 struct lod_recovery_data {
273 struct lod_device *lrd_lod;
274 struct lod_tgt_desc *lrd_ltd;
275 struct ptlrpc_thread *lrd_thread;
281 * process update recovery record
283 * Add the update recovery recode to the update recovery list in
284 * lod_recovery_data. Then the recovery thread (target_recovery_thread)
285 * will redo these updates.
287 * \param[in]env execution environment
288 * \param[in]llh log handle of update record
289 * \param[in]rec update record to be replayed
290 * \param[in]data update recovery data which holds the necessary
291 * arguments for recovery (see struct lod_recovery_data)
293 * \retval 0 if the record is processed successfully.
294 * \retval negative errno if the record processing fails.
296 static int lod_process_recovery_updates(const struct lu_env *env,
297 struct llog_handle *llh,
298 struct llog_rec_hdr *rec,
301 struct lod_recovery_data *lrd = data;
302 struct llog_cookie *cookie = &lod_env_info(env)->lti_cookie;
303 struct lu_target *lut;
307 if (lrd->lrd_ltd == NULL) {
310 rc = lodname2mdt_index(lod2obd(lrd->lrd_lod)->obd_name, &index);
314 index = lrd->lrd_ltd->ltd_index;
318 llog_update_record_size((struct llog_update_record *)rec)) {
319 CERROR("%s broken update record! index %u "DOSTID":%u :"
320 " rc = %d\n", lod2obd(lrd->lrd_lod)->obd_name, index,
321 POSTID(&llh->lgh_id.lgl_oi), rec->lrh_index, -EIO);
325 cookie->lgc_lgl = llh->lgh_id;
326 cookie->lgc_index = rec->lrh_index;
327 cookie->lgc_subsys = LLOG_UPDATELOG_ORIG_CTXT;
329 CDEBUG(D_HA, "%s: process recovery updates "DOSTID":%u\n",
330 lod2obd(lrd->lrd_lod)->obd_name,
331 POSTID(&llh->lgh_id.lgl_oi), rec->lrh_index);
332 lut = lod2lu_dev(lrd->lrd_lod)->ld_site->ls_tgt;
334 return insert_update_records_to_replay_list(lut->lut_tdtd,
335 (struct llog_update_record *)rec,
340 * recovery thread for update log
342 * Start recovery thread and prepare the sub llog, then it will retrieve
343 * the update records from the correpondent MDT and do recovery.
345 * \param[in] arg pointer to the recovery data
347 * \retval 0 if recovery succeeds
348 * \retval negative errno if recovery failed.
350 static int lod_sub_recovery_thread(void *arg)
352 struct lod_recovery_data *lrd = arg;
353 struct lod_device *lod = lrd->lrd_lod;
354 struct dt_device *dt;
355 struct ptlrpc_thread *thread = lrd->lrd_thread;
356 struct llog_ctxt *ctxt;
361 thread->t_flags = SVC_RUNNING;
362 wake_up(&thread->t_ctl_waitq);
364 rc = lu_env_init(&env, LCT_LOCAL | LCT_MD_THREAD);
367 CERROR("%s: can't initialize env: rc = %d\n",
368 lod2obd(lod)->obd_name, rc);
372 if (lrd->lrd_ltd == NULL)
375 dt = lrd->lrd_ltd->ltd_tgt;
377 rc = lod_sub_prep_llog(&env, lod, dt, lrd->lrd_idx);
381 /* Process the recovery record */
382 ctxt = llog_get_context(dt->dd_lu_dev.ld_obd, LLOG_UPDATELOG_ORIG_CTXT);
383 LASSERT(ctxt != NULL);
384 LASSERT(ctxt->loc_handle != NULL);
386 rc = llog_cat_process(&env, ctxt->loc_handle,
387 lod_process_recovery_updates, lrd, 0, 0);
391 CERROR("%s getting update log failed: rc = %d\n",
392 dt->dd_lu_dev.ld_obd->obd_name, rc);
396 CDEBUG(D_HA, "%s retrieve update log: rc = %d\n",
397 dt->dd_lu_dev.ld_obd->obd_name, rc);
399 if (lrd->lrd_ltd == NULL)
400 lod->lod_child_got_update_log = 1;
402 lrd->lrd_ltd->ltd_got_update_log = 1;
404 if (lod->lod_child_got_update_log) {
405 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
406 struct lod_tgt_desc *tgt = NULL;
407 bool all_got_log = true;
410 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
411 tgt = LTD_TGT(ltd, i);
412 if (!tgt->ltd_got_update_log) {
419 struct lu_target *lut;
421 lut = lod2lu_dev(lod)->ld_site->ls_tgt;
422 CDEBUG(D_HA, "%s got update logs from all MDTs.\n",
423 lut->lut_obd->obd_name);
424 lut->lut_tdtd->tdtd_replay_ready = 1;
425 wake_up(&lut->lut_obd->obd_next_transno_waitq);
431 thread->t_flags = SVC_STOPPED;
432 wake_up(&thread->t_ctl_waitq);
438 * finish sub llog context
440 * Stop update recovery thread for the sub device, then cleanup the
441 * correspondent llog ctxt.
443 * \param[in] env execution environment
444 * \param[in] lod lod device to do update recovery
445 * \param[in] thread recovery thread on this sub device
447 void lod_sub_fini_llog(const struct lu_env *env,
448 struct dt_device *dt, struct ptlrpc_thread *thread)
450 struct obd_device *obd;
451 struct llog_ctxt *ctxt;
454 obd = dt->dd_lu_dev.ld_obd;
455 CDEBUG(D_INFO, "%s: finish sub llog\n", obd->obd_name);
456 /* Stop recovery thread first */
457 if (thread != NULL && thread->t_flags & SVC_RUNNING) {
458 thread->t_flags = SVC_STOPPING;
459 wake_up(&thread->t_ctl_waitq);
460 wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
463 ctxt = llog_get_context(obd, LLOG_UPDATELOG_ORIG_CTXT);
467 if (ctxt->loc_handle != NULL)
468 llog_cat_close(env, ctxt->loc_handle);
470 llog_cleanup(env, ctxt);
476 * Extract MDT target index from a device name.
478 * a helper function to extract index from the given device name
479 * like "fsname-MDTxxxx-mdtlov"
481 * \param[in] lodname device name
482 * \param[out] mdt_index extracted index
484 * \retval 0 on success
485 * \retval -EINVAL if the name is invalid
487 int lodname2mdt_index(char *lodname, __u32 *mdt_index)
492 /* 1.8 configs don't have "-MDT0000" at the end */
493 ptr = strstr(lodname, "-MDT");
499 ptr = strrchr(lodname, '-');
501 CERROR("invalid MDT index in '%s'\n", lodname);
505 if (strncmp(ptr, "-mdtlov", 7) != 0) {
506 CERROR("invalid MDT index in '%s'\n", lodname);
510 if ((unsigned long)ptr - (unsigned long)lodname <= 8) {
511 CERROR("invalid MDT index in '%s'\n", lodname);
515 if (strncmp(ptr - 8, "-MDT", 4) != 0) {
516 CERROR("invalid MDT index in '%s'\n", lodname);
520 index = simple_strtol(ptr - 4, &tmp, 16);
521 if (*tmp != '-' || index > INT_MAX) {
522 CERROR("invalid MDT index in '%s'\n", lodname);
530 * Init sub llog context
532 * Setup update llog ctxt for update recovery threads, then start the
533 * recovery thread (lod_sub_recovery_thread) to read update llog from
534 * the correspondent MDT to do update recovery.
536 * \param[in] env execution environment
537 * \param[in] lod lod device to do update recovery
538 * \param[in] dt sub dt device for which the recovery thread is
540 * \retval 0 if initialization succeeds.
541 * \retval negative errno if initialization fails.
543 int lod_sub_init_llog(const struct lu_env *env, struct lod_device *lod,
544 struct dt_device *dt)
546 struct obd_device *obd;
547 struct lod_recovery_data *lrd = NULL;
548 struct ptlrpc_thread *thread;
549 struct task_struct *task;
550 struct l_wait_info lwi = { 0 };
551 struct lod_tgt_desc *sub_ltd = NULL;
557 rc = lodname2mdt_index(lod2obd(lod)->obd_name, &master_index);
565 if (lod->lod_child == dt) {
566 thread = &lod->lod_child_recovery_thread;
567 index = master_index;
569 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
570 struct lod_tgt_desc *tgt = NULL;
573 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
574 tgt = LTD_TGT(ltd, i);
575 if (tgt->ltd_tgt == dt) {
576 index = tgt->ltd_index;
581 LASSERT(sub_ltd != NULL);
582 OBD_ALLOC_PTR(sub_ltd->ltd_recovery_thread);
583 if (sub_ltd->ltd_recovery_thread == NULL)
584 GOTO(free_lrd, rc = -ENOMEM);
586 thread = sub_ltd->ltd_recovery_thread;
589 CDEBUG(D_INFO, "%s init sub log %s\n", lod2obd(lod)->obd_name,
590 dt->dd_lu_dev.ld_obd->obd_name);
592 lrd->lrd_ltd = sub_ltd;
593 lrd->lrd_thread = thread;
594 lrd->lrd_idx = index;
595 init_waitqueue_head(&thread->t_ctl_waitq);
597 obd = dt->dd_lu_dev.ld_obd;
598 obd->obd_lvfs_ctxt.dt = dt;
599 rc = llog_setup(env, obd, &obd->obd_olg, LLOG_UPDATELOG_ORIG_CTXT,
600 NULL, &llog_common_cat_ops);
602 CERROR("%s: cannot setup updatelog llog: rc = %d\n",
604 GOTO(free_thread, rc);
607 /* Start the recovery thread */
608 task = kthread_run(lod_sub_recovery_thread, lrd, "lod%04x_rec%04x",
609 master_index, index);
612 CERROR("%s: cannot start recovery thread: rc = %d\n",
617 l_wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_RUNNING ||
618 thread->t_flags & SVC_STOPPED, &lwi);
622 lod_sub_fini_llog(env, dt, thread);
624 if (lod->lod_child != dt) {
625 OBD_FREE_PTR(sub_ltd->ltd_recovery_thread);
626 sub_ltd->ltd_recovery_thread = NULL;
634 * Stop sub recovery thread
636 * Stop sub recovery thread on all subs.
638 * \param[in] env execution environment
639 * \param[in] lod lod device to do update recovery
641 static void lod_sub_stop_recovery_threads(const struct lu_env *env,
642 struct lod_device *lod)
644 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
645 struct ptlrpc_thread *thread;
648 /* Stop the update log commit cancel threads and finish master
650 thread = &lod->lod_child_recovery_thread;
651 /* Stop recovery thread first */
652 if (thread != NULL && thread->t_flags & SVC_RUNNING) {
653 thread->t_flags = SVC_STOPPING;
654 wake_up(&thread->t_ctl_waitq);
655 wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
659 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
660 struct lod_tgt_desc *tgt;
662 tgt = LTD_TGT(ltd, i);
663 thread = tgt->ltd_recovery_thread;
664 if (thread != NULL && thread->t_flags & SVC_RUNNING) {
665 thread->t_flags = SVC_STOPPING;
666 wake_up(&thread->t_ctl_waitq);
667 wait_event(thread->t_ctl_waitq,
668 thread->t_flags & SVC_STOPPED);
669 OBD_FREE_PTR(tgt->ltd_recovery_thread);
670 tgt->ltd_recovery_thread = NULL;
674 lod_putref(lod, ltd);
678 * finish all sub llog
680 * cleanup all of sub llog ctxt on the LOD.
682 * \param[in] env execution environment
683 * \param[in] lod lod device to do update recovery
685 static void lod_sub_fini_all_llogs(const struct lu_env *env,
686 struct lod_device *lod)
688 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
691 /* Stop the update log commit cancel threads and finish master
693 lod_sub_fini_llog(env, lod->lod_child,
694 &lod->lod_child_recovery_thread);
696 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
697 struct lod_tgt_desc *tgt;
699 tgt = LTD_TGT(ltd, i);
700 lod_sub_fini_llog(env, tgt->ltd_tgt,
701 tgt->ltd_recovery_thread);
704 lod_putref(lod, ltd);
708 * Prepare distribute txn
710 * Prepare distribute txn structure for LOD
712 * \param[in] env execution environment
713 * \param[in] lod_device LOD device
715 * \retval 0 if preparation succeeds.
716 * \retval negative errno if preparation fails.
718 static int lod_prepare_distribute_txn(const struct lu_env *env,
719 struct lod_device *lod)
721 struct target_distribute_txn_data *tdtd;
722 struct lu_target *lut;
726 /* Init update recovery data */
731 lut = lod2lu_dev(lod)->ld_site->ls_tgt;
733 rc = distribute_txn_init(env, lut, tdtd,
734 lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id);
737 CERROR("%s: cannot init distribute txn: rc = %d\n",
738 lod2obd(lod)->obd_name, rc);
743 tdtd->tdtd_dt = &lod->lod_dt_dev;
744 INIT_LIST_HEAD(&tdtd->tdtd_replay_list);
745 spin_lock_init(&tdtd->tdtd_replay_list_lock);
746 tdtd->tdtd_replay_handler = distribute_txn_replay_handle;
747 tdtd->tdtd_replay_ready = 0;
749 lut->lut_tdtd = tdtd;
755 * Finish distribute txn
757 * Release the resource holding by distribute txn, i.e. stop distribute
760 * \param[in] env execution environment
761 * \param[in] lod lod device
763 static void lod_fini_distribute_txn(const struct lu_env *env,
764 struct lod_device *lod)
766 struct lu_target *lut;
768 lut = lod2lu_dev(lod)->ld_site->ls_tgt;
769 if (lut->lut_tdtd == NULL)
772 distribute_txn_fini(env, lut->lut_tdtd);
774 OBD_FREE_PTR(lut->lut_tdtd);
775 lut->lut_tdtd = NULL;
779 * Implementation of lu_device_operations::ldo_process_config() for LOD
781 * The method is called by the configuration subsystem during setup,
782 * cleanup and when the configuration changes. The method processes
783 * few specific commands like adding/removing the targets, changing
784 * the runtime parameters.
786 * \param[in] env LU environment provided by the caller
787 * \param[in] dev lod device
788 * \param[in] lcfg configuration command to apply
790 * \retval 0 on success
791 * \retval negative negated errno on error
793 * The examples are below.
795 * Add osc config log:
796 * marker 20 (flags=0x01, v2.2.49.56) lustre-OST0001 'add osc'
797 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nidxxx
798 * attach 0:lustre-OST0001-osc-MDT0001 1:osc 2:lustre-MDT0001-mdtlov_UUID
799 * setup 0:lustre-OST0001-osc-MDT0001 1:lustre-OST0001_UUID 2:nid
800 * lov_modify_tgts add 0:lustre-MDT0001-mdtlov 1:lustre-OST0001_UUID 2:1 3:1
801 * marker 20 (flags=0x02, v2.2.49.56) lustre-OST0001 'add osc'
803 * Add mdc config log:
804 * marker 10 (flags=0x01, v2.2.49.56) lustre-MDT0000 'add osp'
805 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nid
806 * attach 0:lustre-MDT0000-osp-MDT0001 1:osp 2:lustre-MDT0001-mdtlov_UUID
807 * setup 0:lustre-MDT0000-osp-MDT0001 1:lustre-MDT0000_UUID 2:nid
808 * modify_mdc_tgts add 0:lustre-MDT0001 1:lustre-MDT0000_UUID 2:0 3:1
809 * marker 10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID 'add osp'
811 static int lod_process_config(const struct lu_env *env,
812 struct lu_device *dev,
813 struct lustre_cfg *lcfg)
815 struct lod_device *lod = lu2lod_dev(dev);
816 struct lu_device *next = &lod->lod_child->dd_lu_dev;
821 switch(lcfg->lcfg_command) {
822 case LCFG_LOV_DEL_OBD:
823 case LCFG_LOV_ADD_INA:
824 case LCFG_LOV_ADD_OBD:
829 /* lov_modify_tgts add 0:lov_mdsA 1:osp 2:0 3:1
830 * modify_mdc_tgts add 0:lustre-MDT0001
831 * 1:lustre-MDT0001-mdc0002
833 arg1 = lustre_cfg_string(lcfg, 1);
835 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
836 GOTO(out, rc = -EINVAL);
837 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
838 GOTO(out, rc = -EINVAL);
840 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD) {
843 rc = lodname2mdt_index(lustre_cfg_string(lcfg, 0),
848 rc = lod_add_device(env, lod, arg1, index, gen,
849 mdt_index, LUSTRE_OSC_NAME, 1);
850 } else if (lcfg->lcfg_command == LCFG_ADD_MDC) {
852 rc = lod_add_device(env, lod, arg1, index, gen,
853 mdt_index, LUSTRE_MDC_NAME, 1);
854 } else if (lcfg->lcfg_command == LCFG_LOV_ADD_INA) {
855 /*FIXME: Add mdt_index for LCFG_LOV_ADD_INA*/
857 rc = lod_add_device(env, lod, arg1, index, gen,
858 mdt_index, LUSTRE_OSC_NAME, 0);
860 rc = lod_del_device(env, lod,
862 arg1, index, gen, true);
869 struct obd_device *obd = lod2obd(lod);
871 rc = class_process_proc_param(PARAM_LOV, obd->obd_vars,
877 case LCFG_PRE_CLEANUP: {
878 lod_sub_process_config(env, lod, &lod->lod_mdt_descs, lcfg);
879 lod_sub_process_config(env, lod, &lod->lod_ost_descs, lcfg);
880 next = &lod->lod_child->dd_lu_dev;
881 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
883 CDEBUG(D_HA, "%s: can't process %u: %d\n",
884 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
886 lod_sub_stop_recovery_threads(env, lod);
887 lod_fini_distribute_txn(env, lod);
888 lod_sub_fini_all_llogs(env, lod);
893 * do cleanup on underlying storage only when
894 * all OSPs are cleaned up, as they use that OSD as well
896 lu_dev_del_linkage(dev->ld_site, dev);
897 lod_sub_process_config(env, lod, &lod->lod_mdt_descs, lcfg);
898 lod_sub_process_config(env, lod, &lod->lod_ost_descs, lcfg);
899 next = &lod->lod_child->dd_lu_dev;
900 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
902 CERROR("%s: can't process %u: %d\n",
903 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
905 rc = obd_disconnect(lod->lod_child_exp);
907 CERROR("error in disconnect from storage: %d\n", rc);
911 CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
922 * Implementation of lu_device_operations::ldo_recovery_complete() for LOD
924 * The method is called once the recovery is complete. This implementation
925 * distributes the notification to all the known targets.
927 * see include/lu_object.h for the details
929 static int lod_recovery_complete(const struct lu_env *env,
930 struct lu_device *dev)
932 struct lod_device *lod = lu2lod_dev(dev);
933 struct lu_device *next = &lod->lod_child->dd_lu_dev;
938 LASSERT(lod->lod_recovery_completed == 0);
939 lod->lod_recovery_completed = 1;
941 rc = next->ld_ops->ldo_recovery_complete(env, next);
943 lod_getref(&lod->lod_ost_descs);
944 if (lod->lod_osts_size > 0) {
945 cfs_foreach_bit(lod->lod_ost_bitmap, i) {
946 struct lod_tgt_desc *tgt;
947 tgt = OST_TGT(lod, i);
948 LASSERT(tgt && tgt->ltd_tgt);
949 next = &tgt->ltd_ost->dd_lu_dev;
950 rc = next->ld_ops->ldo_recovery_complete(env, next);
952 CERROR("%s: can't complete recovery on #%d:"
953 "%d\n", lod2obd(lod)->obd_name, i, rc);
956 lod_putref(lod, &lod->lod_ost_descs);
961 * Init update logs on all sub device
963 * LOD initialize update logs on all of sub devices. Because the initialization
964 * process might need FLD lookup, see llog_osd_open()->dt_locate()->...->
965 * lod_object_init(), this API has to be called after LOD is initialized.
966 * \param[in] env execution environment
967 * \param[in] lod lod device
969 * \retval 0 if update log is initialized successfully.
970 * \retval negative errno if initialization fails.
972 static int lod_sub_init_llogs(const struct lu_env *env, struct lod_device *lod)
974 struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
979 /* llog must be setup after LOD is initialized, because llog
980 * initialization include FLD lookup */
981 LASSERT(lod->lod_initialized);
983 /* Init the llog in its own stack */
984 rc = lod_sub_init_llog(env, lod, lod->lod_child);
988 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
989 struct lod_tgt_desc *tgt;
991 tgt = LTD_TGT(ltd, i);
992 rc = lod_sub_init_llog(env, lod, tgt->ltd_tgt);
1001 * Implementation of lu_device_operations::ldo_prepare() for LOD
1003 * see include/lu_object.h for the details.
1005 static int lod_prepare(const struct lu_env *env, struct lu_device *pdev,
1006 struct lu_device *cdev)
1008 struct lod_device *lod = lu2lod_dev(cdev);
1009 struct lu_device *next = &lod->lod_child->dd_lu_dev;
1010 struct lu_fid *fid = &lod_env_info(env)->lti_fid;
1012 struct dt_object *root;
1013 struct dt_object *dto;
1017 rc = next->ld_ops->ldo_prepare(env, pdev, next);
1019 CERROR("%s: prepare bottom error: rc = %d\n",
1020 lod2obd(lod)->obd_name, rc);
1024 lod->lod_initialized = 1;
1026 rc = dt_root_get(env, lod->lod_child, fid);
1030 root = dt_locate(env, lod->lod_child, fid);
1032 RETURN(PTR_ERR(root));
1034 /* Create update log object */
1035 index = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
1036 lu_update_log_fid(fid, index);
1038 dto = local_file_find_or_create_with_fid(env, lod->lod_child,
1040 lod_update_log_name,
1041 S_IFREG | S_IRUGO | S_IWUSR);
1043 GOTO(out_put, rc = PTR_ERR(dto));
1045 lu_object_put(env, &dto->do_lu);
1047 /* Create update log dir */
1048 lu_update_log_dir_fid(fid, index);
1049 dto = local_file_find_or_create_with_fid(env, lod->lod_child,
1051 lod_update_log_dir_name,
1052 S_IFDIR | S_IRUGO | S_IWUSR);
1054 GOTO(out_put, rc = PTR_ERR(dto));
1056 lu_object_put(env, &dto->do_lu);
1058 rc = lod_prepare_distribute_txn(env, lod);
1062 rc = lod_sub_init_llogs(env, lod);
1067 lu_object_put(env, &root->do_lu);
1072 const struct lu_device_operations lod_lu_ops = {
1073 .ldo_object_alloc = lod_object_alloc,
1074 .ldo_process_config = lod_process_config,
1075 .ldo_recovery_complete = lod_recovery_complete,
1076 .ldo_prepare = lod_prepare,
1080 * Implementation of dt_device_operations::dt_root_get() for LOD
1082 * see include/dt_object.h for the details.
1084 static int lod_root_get(const struct lu_env *env,
1085 struct dt_device *dev, struct lu_fid *f)
1087 return dt_root_get(env, dt2lod_dev(dev)->lod_child, f);
1091 * Implementation of dt_device_operations::dt_statfs() for LOD
1093 * see include/dt_object.h for the details.
1095 static int lod_statfs(const struct lu_env *env,
1096 struct dt_device *dev, struct obd_statfs *sfs)
1098 return dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs);
1102 * Implementation of dt_device_operations::dt_trans_create() for LOD
1104 * Creates a transaction using local (to this node) OSD.
1106 * see include/dt_object.h for the details.
1108 static struct thandle *lod_trans_create(const struct lu_env *env,
1109 struct dt_device *dt)
1113 th = top_trans_create(env, dt2lod_dev(dt)->lod_child);
1123 * Implementation of dt_device_operations::dt_trans_start() for LOD
1125 * Starts the set of local transactions using the targets involved
1126 * in declare phase. Initial support for the distributed transactions.
1128 * see include/dt_object.h for the details.
1130 static int lod_trans_start(const struct lu_env *env, struct dt_device *dt,
1133 return top_trans_start(env, dt2lod_dev(dt)->lod_child, th);
1136 static int lod_trans_cb_add(struct thandle *th,
1137 struct dt_txn_commit_cb *dcb)
1139 struct top_thandle *top_th = container_of(th, struct top_thandle,
1141 return dt_trans_cb_add(top_th->tt_master_sub_thandle, dcb);
1145 * add noop update to the update records
1147 * Add noop updates to the update records, which is only used in
1150 * \param[in] env execution environment
1151 * \param[in] dt dt device of lod
1152 * \param[in] th thandle
1153 * \param[in] count the count of update records to be added.
1155 * \retval 0 if adding succeeds.
1156 * \retval negative errno if adding fails.
1158 static int lod_add_noop_records(const struct lu_env *env,
1159 struct dt_device *dt, struct thandle *th,
1162 struct top_thandle *top_th;
1163 struct lu_fid *fid = &lod_env_info(env)->lti_fid;
1167 top_th = container_of(th, struct top_thandle, tt_super);
1168 if (top_th->tt_multiple_thandle == NULL)
1172 for (i = 0; i < count; i++) {
1173 rc = update_record_pack(noop, th, fid);
1181 * Implementation of dt_device_operations::dt_trans_stop() for LOD
1183 * Stops the set of local transactions using the targets involved
1184 * in declare phase. Initial support for the distributed transactions.
1186 * see include/dt_object.h for the details.
1188 static int lod_trans_stop(const struct lu_env *env, struct dt_device *dt,
1191 if (OBD_FAIL_CHECK(OBD_FAIL_SPLIT_UPDATE_REC)) {
1194 rc = lod_add_noop_records(env, dt, th, 5000);
1198 return top_trans_stop(env, dt2lod_dev(dt)->lod_child, th);
1202 * Implementation of dt_device_operations::dt_conf_get() for LOD
1204 * Currently returns the configuration provided by the local OSD.
1206 * see include/dt_object.h for the details.
1208 static void lod_conf_get(const struct lu_env *env,
1209 const struct dt_device *dev,
1210 struct dt_device_param *param)
1212 dt_conf_get(env, dt2lod_dev((struct dt_device *)dev)->lod_child, param);
1216 * Implementation of dt_device_operations::dt_sync() for LOD
1218 * Syncs all known OST targets. Very very expensive and used
1219 * rarely by LFSCK now. Should not be used in general.
1221 * see include/dt_object.h for the details.
1223 static int lod_sync(const struct lu_env *env, struct dt_device *dev)
1225 struct lod_device *lod = dt2lod_dev(dev);
1226 struct lod_ost_desc *ost;
1231 lod_getref(&lod->lod_ost_descs);
1232 lod_foreach_ost(lod, i) {
1233 ost = OST_TGT(lod, i);
1234 LASSERT(ost && ost->ltd_ost);
1235 rc = dt_sync(env, ost->ltd_ost);
1237 CERROR("%s: can't sync %u: %d\n",
1238 lod2obd(lod)->obd_name, i, rc);
1242 lod_putref(lod, &lod->lod_ost_descs);
1244 rc = dt_sync(env, lod->lod_child);
1250 * Implementation of dt_device_operations::dt_ro() for LOD
1252 * Turns local OSD read-only, used for the testing only.
1254 * see include/dt_object.h for the details.
1256 static int lod_ro(const struct lu_env *env, struct dt_device *dev)
1258 return dt_ro(env, dt2lod_dev(dev)->lod_child);
1262 * Implementation of dt_device_operations::dt_commit_async() for LOD
1264 * Asks local OSD to commit sooner.
1266 * see include/dt_object.h for the details.
1268 static int lod_commit_async(const struct lu_env *env, struct dt_device *dev)
1270 return dt_commit_async(env, dt2lod_dev(dev)->lod_child);
1273 static const struct dt_device_operations lod_dt_ops = {
1274 .dt_root_get = lod_root_get,
1275 .dt_statfs = lod_statfs,
1276 .dt_trans_create = lod_trans_create,
1277 .dt_trans_start = lod_trans_start,
1278 .dt_trans_stop = lod_trans_stop,
1279 .dt_conf_get = lod_conf_get,
1280 .dt_sync = lod_sync,
1282 .dt_commit_async = lod_commit_async,
1283 .dt_trans_cb_add = lod_trans_cb_add,
1287 * Connect to a local OSD.
1289 * Used to connect to the local OSD at mount. OSD name is taken from the
1290 * configuration command passed. This connection is used to identify LU
1291 * site and pin the OSD from early removal.
1293 * \param[in] env LU environment provided by the caller
1294 * \param[in] lod lod device
1295 * \param[in] cfg configuration command to apply
1297 * \retval 0 on success
1298 * \retval negative negated errno on error
1300 static int lod_connect_to_osd(const struct lu_env *env, struct lod_device *lod,
1301 struct lustre_cfg *cfg)
1303 struct obd_connect_data *data = NULL;
1304 struct obd_device *obd;
1305 char *nextdev = NULL, *p, *s;
1310 LASSERT(lod->lod_child_exp == NULL);
1312 /* compatibility hack: we still use old config logs
1313 * which specify LOV, but we need to learn underlying
1314 * OSD device, which is supposed to be:
1315 * <fsname>-MDTxxxx-osd
1317 * 2.x MGS generates lines like the following:
1318 * #03 (176)lov_setup 0:lustre-MDT0000-mdtlov 1:(struct lov_desc)
1319 * 1.8 MGS generates lines like the following:
1320 * #03 (168)lov_setup 0:lustre-mdtlov 1:(struct lov_desc)
1322 * we use "-MDT" to differentiate 2.x from 1.8 */
1324 if ((p = lustre_cfg_string(cfg, 0)) && strstr(p, "-mdtlov")) {
1325 len = strlen(p) + 6;
1326 OBD_ALLOC(nextdev, len);
1327 if (nextdev == NULL)
1328 GOTO(out, rc = -ENOMEM);
1331 s = strstr(nextdev, "-mdtlov");
1332 if (unlikely(s == NULL)) {
1333 CERROR("unable to parse device name %s\n",
1334 lustre_cfg_string(cfg, 0));
1335 GOTO(out, rc = -EINVAL);
1338 if (strstr(nextdev, "-MDT")) {
1343 strcpy(s, "-MDT0000-osd");
1346 CERROR("unable to parse device name %s\n",
1347 lustre_cfg_string(cfg, 0));
1348 GOTO(out, rc = -EINVAL);
1351 OBD_ALLOC_PTR(data);
1353 GOTO(out, rc = -ENOMEM);
1355 obd = class_name2obd(nextdev);
1357 CERROR("can not locate next device: %s\n", nextdev);
1358 GOTO(out, rc = -ENOTCONN);
1361 data->ocd_connect_flags = OBD_CONNECT_VERSION;
1362 data->ocd_version = LUSTRE_VERSION_CODE;
1364 rc = obd_connect(env, &lod->lod_child_exp, obd, &obd->obd_uuid,
1367 CERROR("cannot connect to next dev %s (%d)\n", nextdev, rc);
1371 lod->lod_dt_dev.dd_lu_dev.ld_site =
1372 lod->lod_child_exp->exp_obd->obd_lu_dev->ld_site;
1373 LASSERT(lod->lod_dt_dev.dd_lu_dev.ld_site);
1374 lod->lod_child = lu2dt_dev(lod->lod_child_exp->exp_obd->obd_lu_dev);
1380 OBD_FREE(nextdev, len);
1385 * Allocate and initialize target table.
1387 * A helper function to initialize the target table and allocate
1388 * a bitmap of the available targets.
1390 * \param[in] ltd target's table to initialize
1392 * \retval 0 on success
1393 * \retval negative negated errno on error
1395 static int lod_tgt_desc_init(struct lod_tgt_descs *ltd)
1397 mutex_init(<d->ltd_mutex);
1398 init_rwsem(<d->ltd_rw_sem);
1400 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
1401 * added to the LOD, see lod_add_device() */
1402 ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(32);
1403 if (ltd->ltd_tgt_bitmap == NULL)
1406 ltd->ltd_tgts_size = 32;
1409 ltd->ltd_death_row = 0;
1410 ltd->ltd_refcount = 0;
1415 * Initialize LOD device at setup.
1417 * Initializes the given LOD device using the original configuration command.
1418 * The function initiates a connection to the local OSD and initializes few
1419 * internal structures like pools, target tables, etc.
1421 * \param[in] env LU environment provided by the caller
1422 * \param[in] lod lod device
1423 * \param[in] ldt not used
1424 * \param[in] cfg configuration command
1426 * \retval 0 on success
1427 * \retval negative negated errno on error
1429 static int lod_init0(const struct lu_env *env, struct lod_device *lod,
1430 struct lu_device_type *ldt, struct lustre_cfg *cfg)
1432 struct dt_device_param ddp;
1433 struct obd_device *obd;
1437 obd = class_name2obd(lustre_cfg_string(cfg, 0));
1439 CERROR("Cannot find obd with name %s\n",
1440 lustre_cfg_string(cfg, 0));
1444 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
1445 lod->lod_dt_dev.dd_lu_dev.ld_obd = obd;
1446 lod->lod_dt_dev.dd_lu_dev.ld_ops = &lod_lu_ops;
1447 lod->lod_dt_dev.dd_ops = &lod_dt_ops;
1449 rc = lod_connect_to_osd(env, lod, cfg);
1453 dt_conf_get(env, &lod->lod_dt_dev, &ddp);
1454 lod->lod_osd_max_easize = ddp.ddp_max_ea_size;
1456 /* setup obd to be used with old lov code */
1457 rc = lod_pools_init(lod, cfg);
1459 GOTO(out_disconnect, rc);
1461 rc = lod_procfs_init(lod);
1463 GOTO(out_pools, rc);
1465 spin_lock_init(&lod->lod_desc_lock);
1466 spin_lock_init(&lod->lod_connects_lock);
1467 lod_tgt_desc_init(&lod->lod_mdt_descs);
1468 lod_tgt_desc_init(&lod->lod_ost_descs);
1473 lod_pools_fini(lod);
1475 obd_disconnect(lod->lod_child_exp);
1480 * Implementation of lu_device_type_operations::ldto_device_free() for LOD
1482 * Releases the memory allocated for LOD device.
1484 * see include/lu_object.h for the details.
1486 static struct lu_device *lod_device_free(const struct lu_env *env,
1487 struct lu_device *lu)
1489 struct lod_device *lod = lu2lod_dev(lu);
1490 struct lu_device *next = &lod->lod_child->dd_lu_dev;
1493 LASSERTF(atomic_read(&lu->ld_ref) == 0, "lu is %p\n", lu);
1494 dt_device_fini(&lod->lod_dt_dev);
1500 * Implementation of lu_device_type_operations::ldto_device_alloc() for LOD
1502 * Allocates LOD device and calls the helpers to initialize it.
1504 * see include/lu_object.h for the details.
1506 static struct lu_device *lod_device_alloc(const struct lu_env *env,
1507 struct lu_device_type *type,
1508 struct lustre_cfg *lcfg)
1510 struct lod_device *lod;
1511 struct lu_device *lu_dev;
1515 lu_dev = ERR_PTR(-ENOMEM);
1519 lu_dev = lod2lu_dev(lod);
1520 dt_device_init(&lod->lod_dt_dev, type);
1521 rc = lod_init0(env, lod, type, lcfg);
1523 lod_device_free(env, lu_dev);
1524 lu_dev = ERR_PTR(rc);
1532 * Implementation of lu_device_type_operations::ldto_device_fini() for LOD
1534 * Releases the internal resources used by LOD device.
1536 * see include/lu_object.h for the details.
1538 static struct lu_device *lod_device_fini(const struct lu_env *env,
1539 struct lu_device *d)
1541 struct lod_device *lod = lu2lod_dev(d);
1545 lod_pools_fini(lod);
1547 lod_procfs_fini(lod);
1549 rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs, true);
1551 CERROR("%s:can not fini ost descs %d\n",
1552 lod2obd(lod)->obd_name, rc);
1554 rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs, false);
1556 CERROR("%s:can not fini mdt descs %d\n",
1557 lod2obd(lod)->obd_name, rc);
1563 * Implementation of obd_ops::o_connect() for LOD
1565 * Used to track all the users of this specific LOD device,
1566 * so the device stays up until the last user disconnected.
1568 * \param[in] env LU environment provided by the caller
1569 * \param[out] exp export the caller will be using to access LOD
1570 * \param[in] obd OBD device representing LOD device
1571 * \param[in] cluuid unique identifier of the caller
1572 * \param[in] data not used
1573 * \param[in] localdata not used
1575 * \retval 0 on success
1576 * \retval negative negated errno on error
1578 static int lod_obd_connect(const struct lu_env *env, struct obd_export **exp,
1579 struct obd_device *obd, struct obd_uuid *cluuid,
1580 struct obd_connect_data *data, void *localdata)
1582 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
1583 struct lustre_handle conn;
1587 CDEBUG(D_CONFIG, "connect #%d\n", lod->lod_connects);
1589 rc = class_connect(&conn, obd, cluuid);
1593 *exp = class_conn2export(&conn);
1595 spin_lock(&lod->lod_connects_lock);
1596 lod->lod_connects++;
1597 /* at the moment we expect the only user */
1598 LASSERT(lod->lod_connects == 1);
1599 spin_unlock(&lod->lod_connects_lock);
1606 * Implementation of obd_ops::o_disconnect() for LOD
1608 * When the caller doesn't need to use this LOD instance, it calls
1609 * obd_disconnect() and LOD releases corresponding export/reference count.
1610 * Once all the users gone, LOD device is released.
1612 * \param[in] exp export provided to the caller in obd_connect()
1614 * \retval 0 on success
1615 * \retval negative negated errno on error
1617 static int lod_obd_disconnect(struct obd_export *exp)
1619 struct obd_device *obd = exp->exp_obd;
1620 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
1621 int rc, release = 0;
1624 /* Only disconnect the underlying layers on the final disconnect. */
1625 spin_lock(&lod->lod_connects_lock);
1626 lod->lod_connects--;
1627 if (lod->lod_connects != 0) {
1628 /* why should there be more than 1 connect? */
1629 spin_unlock(&lod->lod_connects_lock);
1630 CERROR("%s: disconnect #%d\n", exp->exp_obd->obd_name,
1634 spin_unlock(&lod->lod_connects_lock);
1636 /* the last user of lod has gone, let's release the device */
1640 rc = class_disconnect(exp); /* bz 9811 */
1642 if (rc == 0 && release)
1643 class_manual_cleanup(obd);
1647 LU_KEY_INIT(lod, struct lod_thread_info);
1649 static void lod_key_fini(const struct lu_context *ctx,
1650 struct lu_context_key *key, void *data)
1652 struct lod_thread_info *info = data;
1653 /* allocated in lod_get_lov_ea
1654 * XXX: this is overload, a tread may have such store but used only
1655 * once. Probably better would be pool of such stores per LOD.
1657 if (info->lti_ea_store) {
1658 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
1659 info->lti_ea_store = NULL;
1660 info->lti_ea_store_size = 0;
1662 lu_buf_free(&info->lti_linkea_buf);
1666 /* context key: lod_thread_key */
1667 LU_CONTEXT_KEY_DEFINE(lod, LCT_MD_THREAD);
1669 LU_TYPE_INIT_FINI(lod, &lod_thread_key);
1671 static struct lu_device_type_operations lod_device_type_ops = {
1672 .ldto_init = lod_type_init,
1673 .ldto_fini = lod_type_fini,
1675 .ldto_start = lod_type_start,
1676 .ldto_stop = lod_type_stop,
1678 .ldto_device_alloc = lod_device_alloc,
1679 .ldto_device_free = lod_device_free,
1681 .ldto_device_fini = lod_device_fini
1684 static struct lu_device_type lod_device_type = {
1685 .ldt_tags = LU_DEVICE_DT,
1686 .ldt_name = LUSTRE_LOD_NAME,
1687 .ldt_ops = &lod_device_type_ops,
1688 .ldt_ctx_tags = LCT_MD_THREAD,
1692 * Implementation of obd_ops::o_get_info() for LOD
1694 * Currently, there is only one supported key: KEY_OSP_CONNECTED , to provide
1695 * the caller binary status whether LOD has seen connection to any OST target.
1696 * It will also check if the MDT update log context being initialized (if
1699 * \param[in] env LU environment provided by the caller
1700 * \param[in] exp export of the caller
1701 * \param[in] keylen len of the key
1702 * \param[in] key the key
1703 * \param[in] vallen not used
1704 * \param[in] val not used
1706 * \retval 0 if a connection was seen
1707 * \retval -EAGAIN if LOD isn't running yet or no
1708 * connection has been seen yet
1709 * \retval -EINVAL if not supported key is requested
1711 static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp,
1712 __u32 keylen, void *key, __u32 *vallen, void *val)
1716 if (KEY_IS(KEY_OSP_CONNECTED)) {
1717 struct obd_device *obd = exp->exp_obd;
1718 struct lod_device *d;
1719 struct lod_tgt_desc *tgt;
1723 if (!obd->obd_set_up || obd->obd_stopping)
1726 d = lu2lod_dev(obd->obd_lu_dev);
1727 lod_getref(&d->lod_ost_descs);
1728 lod_foreach_ost(d, i) {
1729 tgt = OST_TGT(d, i);
1730 LASSERT(tgt && tgt->ltd_tgt);
1731 rc = obd_get_info(env, tgt->ltd_exp, keylen, key,
1733 /* one healthy device is enough */
1737 lod_putref(d, &d->lod_ost_descs);
1739 lod_getref(&d->lod_mdt_descs);
1740 lod_foreach_mdt(d, i) {
1741 struct llog_ctxt *ctxt;
1743 tgt = MDT_TGT(d, i);
1744 LASSERT(tgt != NULL);
1745 LASSERT(tgt->ltd_tgt != NULL);
1746 ctxt = llog_get_context(tgt->ltd_tgt->dd_lu_dev.ld_obd,
1747 LLOG_UPDATELOG_ORIG_CTXT);
1752 if (ctxt->loc_handle == NULL) {
1754 llog_ctxt_put(ctxt);
1757 llog_ctxt_put(ctxt);
1759 lod_putref(d, &d->lod_mdt_descs);
1767 static struct obd_ops lod_obd_device_ops = {
1768 .o_owner = THIS_MODULE,
1769 .o_connect = lod_obd_connect,
1770 .o_disconnect = lod_obd_disconnect,
1771 .o_get_info = lod_obd_get_info,
1772 .o_pool_new = lod_pool_new,
1773 .o_pool_rem = lod_pool_remove,
1774 .o_pool_add = lod_pool_add,
1775 .o_pool_del = lod_pool_del,
1778 static int __init lod_mod_init(void)
1780 struct obd_type *type;
1783 rc = lu_kmem_init(lod_caches);
1787 rc = class_register_type(&lod_obd_device_ops, NULL, true, NULL,
1788 LUSTRE_LOD_NAME, &lod_device_type);
1790 lu_kmem_fini(lod_caches);
1794 /* create "lov" entry in procfs for compatibility purposes */
1795 type = class_search_type(LUSTRE_LOV_NAME);
1796 if (type != NULL && type->typ_procroot != NULL)
1799 type = class_search_type(LUSTRE_LOD_NAME);
1800 type->typ_procsym = lprocfs_register("lov", proc_lustre_root,
1802 if (IS_ERR(type->typ_procsym)) {
1803 CERROR("lod: can't create compat entry \"lov\": %d\n",
1804 (int)PTR_ERR(type->typ_procsym));
1805 type->typ_procsym = NULL;
1810 static void __exit lod_mod_exit(void)
1812 class_unregister_type(LUSTRE_LOD_NAME);
1813 lu_kmem_fini(lod_caches);
1816 MODULE_AUTHOR("Intel Corporation. <https://wiki.hpdd.intel.com/>");
1817 MODULE_DESCRIPTION("Lustre Logical Object Device ("LUSTRE_LOD_NAME")");
1818 MODULE_LICENSE("GPL");
1820 module_init(lod_mod_init);
1821 module_exit(lod_mod_exit);