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, 2017, 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 <uapi/linux/lustre/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;
130 if (!fid_is_sane(fid)) {
131 CERROR("%s: invalid FID "DFID"\n", lod2obd(lod)->obd_name,
136 if (fid_is_idif(fid)) {
137 *tgt = fid_idif_ost_idx(fid);
138 *type = LU_SEQ_RANGE_OST;
142 if (fid_is_update_log(fid) || fid_is_update_log_dir(fid)) {
144 *type = LU_SEQ_RANGE_MDT;
148 if (!lod->lod_initialized || (!fid_seq_in_fldb(fid_seq(fid)))) {
149 LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
151 *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
152 *type = LU_SEQ_RANGE_MDT;
156 server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
160 fld_range_set_type(&range, *type);
161 rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
165 *tgt = range.lsr_index;
166 *type = range.lsr_flags;
168 CDEBUG(D_INFO, "%s: got tgt %x for sequence: %#llx\n",
169 lod2obd(lod)->obd_name, *tgt, fid_seq(fid));
174 /* Slab for OSD object allocation */
175 struct kmem_cache *lod_object_kmem;
177 /* Slab for dt_txn_callback */
178 struct kmem_cache *lod_txn_callback_kmem;
179 static struct lu_kmem_descr lod_caches[] = {
181 .ckd_cache = &lod_object_kmem,
182 .ckd_name = "lod_obj",
183 .ckd_size = sizeof(struct lod_object)
186 .ckd_cache = &lod_txn_callback_kmem,
187 .ckd_name = "lod_txn_callback",
188 .ckd_size = sizeof(struct dt_txn_callback)
195 static struct lu_device *lod_device_fini(const struct lu_env *env,
196 struct lu_device *d);
199 * Implementation of lu_device_operations::ldo_object_alloc() for LOD
201 * Allocates and initializes LOD's slice in the given object.
203 * see include/lu_object.h for the details.
205 static struct lu_object *lod_object_alloc(const struct lu_env *env,
206 const struct lu_object_header *hdr,
207 struct lu_device *dev)
209 struct lod_object *lod_obj;
210 struct lu_object *lu_obj;
214 OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, GFP_NOFS);
216 RETURN(ERR_PTR(-ENOMEM));
218 mutex_init(&lod_obj->ldo_layout_mutex);
219 lu_obj = lod2lu_obj(lod_obj);
220 dt_object_init(&lod_obj->ldo_obj, NULL, dev);
221 lod_obj->ldo_obj.do_ops = &lod_obj_ops;
222 lu_obj->lo_ops = &lod_lu_obj_ops;
228 * Process the config log for all sub device.
230 * The function goes through all the targets in the given table
231 * and apply given configuration command on to the targets.
232 * Used to cleanup the targets at unmount.
234 * \param[in] env LU environment provided by the caller
235 * \param[in] lod lod device
236 * \param[in] ltd target's table to go through
237 * \param[in] lcfg configuration command to apply
239 * \retval 0 on success
240 * \retval negative negated errno on error
242 static int lod_sub_process_config(const struct lu_env *env,
243 struct lod_device *lod,
244 struct lod_tgt_descs *ltd,
245 struct lustre_cfg *lcfg)
247 struct lu_device *next;
248 struct lu_tgt_desc *tgt;
252 ltd_foreach_tgt(ltd, tgt) {
255 LASSERT(tgt && tgt->ltd_tgt);
256 next = &tgt->ltd_tgt->dd_lu_dev;
257 rc1 = next->ld_ops->ldo_process_config(env, next, lcfg);
259 CERROR("%s: error cleaning up LOD index %u: cmd %#x : rc = %d\n",
260 lod2obd(lod)->obd_name, tgt->ltd_index,
261 lcfg->lcfg_command, rc1);
265 lod_putref(lod, ltd);
269 struct lod_recovery_data {
270 struct lod_device *lrd_lod;
271 struct lod_tgt_desc *lrd_ltd;
272 struct ptlrpc_thread *lrd_thread;
278 * process update recovery record
280 * Add the update recovery recode to the update recovery list in
281 * lod_recovery_data. Then the recovery thread (target_recovery_thread)
282 * will redo these updates.
284 * \param[in]env execution environment
285 * \param[in]llh log handle of update record
286 * \param[in]rec update record to be replayed
287 * \param[in]data update recovery data which holds the necessary
288 * arguments for recovery (see struct lod_recovery_data)
290 * \retval 0 if the record is processed successfully.
291 * \retval negative errno if the record processing fails.
293 static int lod_process_recovery_updates(const struct lu_env *env,
294 struct llog_handle *llh,
295 struct llog_rec_hdr *rec,
298 struct lod_recovery_data *lrd = data;
299 struct llog_cookie *cookie = &lod_env_info(env)->lti_cookie;
300 struct lu_target *lut;
308 rc = lodname2mdt_index(lod2obd(lrd->lrd_lod)->obd_name, &index);
312 index = lrd->lrd_ltd->ltd_index;
316 llog_update_record_size((struct llog_update_record *)rec)) {
317 CERROR("%s: broken update record! index %u "DFID".%u: rc = %d\n",
318 lod2obd(lrd->lrd_lod)->obd_name, index,
319 PFID(&llh->lgh_id.lgl_oi.oi_fid), rec->lrh_index, -EIO);
323 cookie->lgc_lgl = llh->lgh_id;
324 cookie->lgc_index = rec->lrh_index;
325 cookie->lgc_subsys = LLOG_UPDATELOG_ORIG_CTXT;
327 CDEBUG(D_HA, "%s: process recovery updates "DFID".%u\n",
328 lod2obd(lrd->lrd_lod)->obd_name,
329 PFID(&llh->lgh_id.lgl_oi.oi_fid), rec->lrh_index);
330 lut = lod2lu_dev(lrd->lrd_lod)->ld_site->ls_tgt;
332 if (lut->lut_obd->obd_stopping ||
333 lut->lut_obd->obd_abort_recovery)
336 return insert_update_records_to_replay_list(lut->lut_tdtd,
337 (struct llog_update_record *)rec,
342 * recovery thread for update log
344 * Start recovery thread and prepare the sub llog, then it will retrieve
345 * the update records from the correpondent MDT and do recovery.
347 * \param[in] arg pointer to the recovery data
349 * \retval 0 if recovery succeeds
350 * \retval negative errno if recovery failed.
352 static int lod_sub_recovery_thread(void *arg)
354 struct lod_recovery_data *lrd = arg;
355 struct lod_device *lod = lrd->lrd_lod;
356 struct dt_device *dt;
357 struct ptlrpc_thread *thread = lrd->lrd_thread;
358 struct llog_ctxt *ctxt = NULL;
360 struct lu_target *lut;
361 struct lu_tgt_desc *mdt = NULL;
368 thread->t_flags = SVC_RUNNING;
369 wake_up(&thread->t_ctl_waitq);
371 rc = lu_env_init(&env, LCT_LOCAL | LCT_MD_THREAD);
374 CERROR("%s: can't initialize env: rc = %d\n",
375 lod2obd(lod)->obd_name, rc);
379 lut = lod2lu_dev(lod)->ld_site->ls_tgt;
380 atomic_inc(&lut->lut_tdtd->tdtd_recovery_threads_count);
384 dt = lrd->lrd_ltd->ltd_tgt;
386 start = ktime_get_real_seconds();
390 if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_TGT_RECOVERY_CONNECT)) &&
392 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_RECOVERY_CONNECT, cfs_fail_val);
395 rc = lod_sub_prep_llog(&env, lod, dt, lrd->lrd_idx);
397 if (!rc && !lod->lod_child->dd_rdonly) {
398 /* Process the recovery record */
399 ctxt = llog_get_context(dt->dd_lu_dev.ld_obd,
400 LLOG_UPDATELOG_ORIG_CTXT);
401 LASSERT(ctxt != NULL);
402 LASSERT(ctxt->loc_handle != NULL);
404 rc = llog_cat_process(&env, ctxt->loc_handle,
405 lod_process_recovery_updates, lrd, 0, 0);
409 struct lu_device *top_device;
411 top_device = lod->lod_dt_dev.dd_lu_dev.ld_site->ls_top_dev;
413 * Because the remote target might failover at the same time,
416 if ((rc == -ETIMEDOUT || rc == -EAGAIN || rc == -EIO) &&
417 dt != lod->lod_child &&
418 !top_device->ld_obd->obd_abort_recovery &&
419 !top_device->ld_obd->obd_stopping) {
421 if (ctxt->loc_handle)
427 CDEBUG(D_HA, "%s get update log failed %d, retry\n",
428 dt->dd_lu_dev.ld_obd->obd_name, rc);
432 CERROR("%s get update log failed: rc = %d\n",
433 dt->dd_lu_dev.ld_obd->obd_name, rc);
436 spin_lock(&top_device->ld_obd->obd_dev_lock);
437 if (!top_device->ld_obd->obd_abort_recovery &&
438 !top_device->ld_obd->obd_stopping)
439 top_device->ld_obd->obd_abort_recovery = 1;
440 spin_unlock(&top_device->ld_obd->obd_dev_lock);
446 CDEBUG(D_HA, "%s retrieved update log, duration %lld, retries %d\n",
447 dt->dd_lu_dev.ld_obd->obd_name, ktime_get_real_seconds() - start,
450 spin_lock(&lod->lod_lock);
452 lod->lod_child_got_update_log = 1;
454 lrd->lrd_ltd->ltd_got_update_log = 1;
456 if (!lod->lod_child_got_update_log) {
457 spin_unlock(&lod->lod_lock);
461 lod_foreach_mdt(lod, mdt) {
462 if (!mdt->ltd_got_update_log) {
463 spin_unlock(&lod->lod_lock);
467 lut->lut_tdtd->tdtd_replay_ready = 1;
468 spin_unlock(&lod->lod_lock);
470 CDEBUG(D_HA, "%s got update logs from all MDTs.\n",
471 lut->lut_obd->obd_name);
472 wake_up(&lut->lut_obd->obd_next_transno_waitq);
477 thread->t_flags = SVC_STOPPED;
478 atomic_dec(&lut->lut_tdtd->tdtd_recovery_threads_count);
479 wake_up(&lut->lut_tdtd->tdtd_recovery_threads_waitq);
480 wake_up(&thread->t_ctl_waitq);
486 * finish sub llog context
488 * Stop update recovery thread for the sub device, then cleanup the
489 * correspondent llog ctxt.
491 * \param[in] env execution environment
492 * \param[in] lod lod device to do update recovery
493 * \param[in] thread recovery thread on this sub device
495 void lod_sub_fini_llog(const struct lu_env *env,
496 struct dt_device *dt, struct ptlrpc_thread *thread)
498 struct obd_device *obd;
499 struct llog_ctxt *ctxt;
503 obd = dt->dd_lu_dev.ld_obd;
504 CDEBUG(D_INFO, "%s: finish sub llog\n", obd->obd_name);
505 /* Stop recovery thread first */
506 if (thread && thread->t_flags & SVC_RUNNING) {
507 thread->t_flags = SVC_STOPPING;
508 wake_up(&thread->t_ctl_waitq);
509 wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
512 ctxt = llog_get_context(obd, LLOG_UPDATELOG_ORIG_CTXT);
516 if (ctxt->loc_handle)
517 llog_cat_close(env, ctxt->loc_handle);
519 llog_cleanup(env, ctxt);
525 * Extract MDT target index from a device name.
527 * a helper function to extract index from the given device name
528 * like "fsname-MDTxxxx-mdtlov"
530 * \param[in] lodname device name
531 * \param[out] mdt_index extracted index
533 * \retval 0 on success
534 * \retval -EINVAL if the name is invalid
536 int lodname2mdt_index(char *lodname, u32 *mdt_index)
539 const char *ptr, *tmp;
542 /* 1.8 configs don't have "-MDT0000" at the end */
543 ptr = strstr(lodname, "-MDT");
549 ptr = strrchr(lodname, '-');
552 CERROR("invalid MDT index in '%s': rc = %d\n", lodname, rc);
556 if (strncmp(ptr, "-mdtlov", 7) != 0) {
558 CERROR("invalid MDT index in '%s': rc = %d\n", lodname, rc);
562 if ((unsigned long)ptr - (unsigned long)lodname <= 8) {
564 CERROR("invalid MDT index in '%s': rc = %d\n", lodname, rc);
568 if (strncmp(ptr - 8, "-MDT", 4) != 0) {
570 CERROR("invalid MDT index in '%s': rc = %d\n", lodname, rc);
574 rc = target_name2index(ptr - 7, &index, &tmp);
575 if (rc < 0 || rc & LDD_F_SV_ALL || *tmp != '-') {
577 CERROR("invalid MDT index in '%s': rc = %d\n", lodname, rc);
585 * Init sub llog context
587 * Setup update llog ctxt for update recovery threads, then start the
588 * recovery thread (lod_sub_recovery_thread) to read update llog from
589 * the correspondent MDT to do update recovery.
591 * \param[in] env execution environment
592 * \param[in] lod lod device to do update recovery
593 * \param[in] dt sub dt device for which the recovery thread is
595 * \retval 0 if initialization succeeds.
596 * \retval negative errno if initialization fails.
598 int lod_sub_init_llog(const struct lu_env *env, struct lod_device *lod,
599 struct dt_device *dt)
601 struct obd_device *obd;
602 struct lod_recovery_data *lrd = NULL;
603 struct ptlrpc_thread *thread;
604 struct task_struct *task;
605 struct lod_tgt_desc *subtgt = NULL;
612 rc = lodname2mdt_index(lod2obd(lod)->obd_name, &master_index);
620 if (lod->lod_child == dt) {
621 thread = &lod->lod_child_recovery_thread;
622 index = master_index;
624 struct lu_tgt_desc *mdt;
626 lod_foreach_mdt(lod, mdt) {
627 if (mdt->ltd_tgt == dt) {
628 index = mdt->ltd_index;
633 LASSERT(subtgt != NULL);
634 OBD_ALLOC_PTR(subtgt->ltd_recovery_thread);
635 if (!subtgt->ltd_recovery_thread)
636 GOTO(free_lrd, rc = -ENOMEM);
638 thread = subtgt->ltd_recovery_thread;
641 CDEBUG(D_INFO, "%s init sub log %s\n", lod2obd(lod)->obd_name,
642 dt->dd_lu_dev.ld_obd->obd_name);
644 lrd->lrd_ltd = subtgt;
645 lrd->lrd_thread = thread;
646 lrd->lrd_idx = index;
647 init_waitqueue_head(&thread->t_ctl_waitq);
649 obd = dt->dd_lu_dev.ld_obd;
650 obd->obd_lvfs_ctxt.dt = dt;
651 rc = llog_setup(env, obd, &obd->obd_olg, LLOG_UPDATELOG_ORIG_CTXT,
652 NULL, &llog_common_cat_ops);
654 CERROR("%s: cannot setup updatelog llog: rc = %d\n",
656 GOTO(free_thread, rc);
659 /* Start the recovery thread */
660 task = kthread_run(lod_sub_recovery_thread, lrd, "lod%04x_rec%04x",
661 master_index, index);
664 CERROR("%s: cannot start recovery thread: rc = %d\n",
669 wait_event_idle(thread->t_ctl_waitq, thread->t_flags & SVC_RUNNING ||
670 thread->t_flags & SVC_STOPPED);
674 lod_sub_fini_llog(env, dt, thread);
676 if (lod->lod_child != dt) {
677 OBD_FREE_PTR(subtgt->ltd_recovery_thread);
678 subtgt->ltd_recovery_thread = NULL;
686 * Stop sub recovery thread
688 * Stop sub recovery thread on all subs.
690 * \param[in] env execution environment
691 * \param[in] lod lod device to do update recovery
693 static void lod_sub_stop_recovery_threads(const struct lu_env *env,
694 struct lod_device *lod)
696 struct ptlrpc_thread *thread;
697 struct lu_tgt_desc *mdt;
700 * Stop the update log commit cancel threads and finish master
703 thread = &lod->lod_child_recovery_thread;
704 /* Stop recovery thread first */
705 if (thread && thread->t_flags & SVC_RUNNING) {
706 thread->t_flags = SVC_STOPPING;
707 wake_up(&thread->t_ctl_waitq);
708 wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
711 lod_getref(&lod->lod_mdt_descs);
712 lod_foreach_mdt(lod, mdt) {
713 thread = mdt->ltd_recovery_thread;
714 if (thread && thread->t_flags & SVC_RUNNING) {
715 thread->t_flags = SVC_STOPPING;
716 wake_up(&thread->t_ctl_waitq);
717 wait_event(thread->t_ctl_waitq,
718 thread->t_flags & SVC_STOPPED);
719 OBD_FREE_PTR(mdt->ltd_recovery_thread);
720 mdt->ltd_recovery_thread = NULL;
723 lod_putref(lod, &lod->lod_mdt_descs);
727 * finish all sub llog
729 * cleanup all of sub llog ctxt on the LOD.
731 * \param[in] env execution environment
732 * \param[in] lod lod device to do update recovery
734 static void lod_sub_fini_all_llogs(const struct lu_env *env,
735 struct lod_device *lod)
737 struct lu_tgt_desc *mdt;
740 * Stop the update log commit cancel threads and finish master
743 lod_sub_fini_llog(env, lod->lod_child,
744 &lod->lod_child_recovery_thread);
745 lod_getref(&lod->lod_mdt_descs);
746 lod_foreach_mdt(lod, mdt)
747 lod_sub_fini_llog(env, mdt->ltd_tgt,
748 mdt->ltd_recovery_thread);
749 lod_putref(lod, &lod->lod_mdt_descs);
752 static char *lod_show_update_logs_retrievers(void *data, int *size, int *count)
754 struct lod_device *lod = (struct lod_device *)data;
755 struct lu_target *lut = lod2lu_dev(lod)->ld_site->ls_tgt;
756 struct lu_tgt_desc *mdt = NULL;
762 *count = atomic_read(&lut->lut_tdtd->tdtd_recovery_threads_count);
768 *size = 5 * *count + 1;
769 OBD_ALLOC(buf, *size);
774 memset(buf, 0, *size);
776 if (!lod->lod_child_got_update_log) {
777 rc = lodname2mdt_index(lod2obd(lod)->obd_name, &i);
778 LASSERTF(rc == 0, "Fail to parse target index: rc = %d\n", rc);
780 rc = scnprintf(buf + len, *size - len, " %04x", i);
787 lod_foreach_mdt(lod, mdt) {
788 if (!mdt->ltd_got_update_log) {
789 rc = scnprintf(buf + len, *size - len, " %04x",
791 if (unlikely(rc <= 0))
803 * Prepare distribute txn
805 * Prepare distribute txn structure for LOD
807 * \param[in] env execution environment
808 * \param[in] lod_device LOD device
810 * \retval 0 if preparation succeeds.
811 * \retval negative errno if preparation fails.
813 static int lod_prepare_distribute_txn(const struct lu_env *env,
814 struct lod_device *lod)
816 struct target_distribute_txn_data *tdtd;
817 struct lu_target *lut;
822 /* Init update recovery data */
827 lut = lod2lu_dev(lod)->ld_site->ls_tgt;
828 tdtd->tdtd_dt = &lod->lod_dt_dev;
829 rc = distribute_txn_init(env, lut, tdtd,
830 lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id);
833 CERROR("%s: cannot init distribute txn: rc = %d\n",
834 lod2obd(lod)->obd_name, rc);
839 tdtd->tdtd_show_update_logs_retrievers =
840 lod_show_update_logs_retrievers;
841 tdtd->tdtd_show_retrievers_cbdata = lod;
843 lut->lut_tdtd = tdtd;
849 * Finish distribute txn
851 * Release the resource holding by distribute txn, i.e. stop distribute
854 * \param[in] env execution environment
855 * \param[in] lod lod device
857 static void lod_fini_distribute_txn(const struct lu_env *env,
858 struct lod_device *lod)
860 struct lu_target *lut;
862 lut = lod2lu_dev(lod)->ld_site->ls_tgt;
863 target_recovery_fini(lut->lut_obd);
867 distribute_txn_fini(env, lut->lut_tdtd);
869 OBD_FREE_PTR(lut->lut_tdtd);
870 lut->lut_tdtd = NULL;
874 * Implementation of lu_device_operations::ldo_process_config() for LOD
876 * The method is called by the configuration subsystem during setup,
877 * cleanup and when the configuration changes. The method processes
878 * few specific commands like adding/removing the targets, changing
879 * the runtime parameters.
881 * \param[in] env LU environment provided by the caller
882 * \param[in] dev lod device
883 * \param[in] lcfg configuration command to apply
885 * \retval 0 on success
886 * \retval negative negated errno on error
888 * The examples are below.
890 * Add osc config log:
891 * marker 20 (flags=0x01, v2.2.49.56) lustre-OST0001 'add osc'
892 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nidxxx
893 * attach 0:lustre-OST0001-osc-MDT0001 1:osc 2:lustre-MDT0001-mdtlov_UUID
894 * setup 0:lustre-OST0001-osc-MDT0001 1:lustre-OST0001_UUID 2:nid
895 * lov_modify_tgts add 0:lustre-MDT0001-mdtlov 1:lustre-OST0001_UUID 2:1 3:1
896 * marker 20 (flags=0x02, v2.2.49.56) lustre-OST0001 'add osc'
898 * Add mdc config log:
899 * marker 10 (flags=0x01, v2.2.49.56) lustre-MDT0000 'add osp'
900 * add_uuid nid=192.168.122.162@tcp(0x20000c0a87aa2) 0: 1:nid
901 * attach 0:lustre-MDT0000-osp-MDT0001 1:osp 2:lustre-MDT0001-mdtlov_UUID
902 * setup 0:lustre-MDT0000-osp-MDT0001 1:lustre-MDT0000_UUID 2:nid
903 * modify_mdc_tgts add 0:lustre-MDT0001 1:lustre-MDT0000_UUID 2:0 3:1
904 * marker 10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID 'add osp'
906 static int lod_process_config(const struct lu_env *env,
907 struct lu_device *dev,
908 struct lustre_cfg *lcfg)
910 struct lod_device *lod = lu2lod_dev(dev);
911 struct lu_device *next = &lod->lod_child->dd_lu_dev;
917 switch (lcfg->lcfg_command) {
918 case LCFG_LOV_DEL_OBD:
919 case LCFG_LOV_ADD_INA:
920 case LCFG_LOV_ADD_OBD:
926 * lov_modify_tgts add 0:lov_mdsA 1:osp 2:0 3:1
927 * modify_mdc_tgts add 0:lustre-MDT0001
928 * 1:lustre-MDT0001-mdc0002
931 arg1 = lustre_cfg_string(lcfg, 1);
933 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
934 GOTO(out, rc = -EINVAL);
935 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
936 GOTO(out, rc = -EINVAL);
938 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD) {
941 rc = lodname2mdt_index(lustre_cfg_string(lcfg, 0),
946 rc = lod_add_device(env, lod, arg1, index, gen,
947 mdt_index, LUSTRE_OSC_NAME, 1);
948 } else if (lcfg->lcfg_command == LCFG_ADD_MDC) {
950 rc = lod_add_device(env, lod, arg1, index, gen,
951 mdt_index, LUSTRE_MDC_NAME, 1);
952 } else if (lcfg->lcfg_command == LCFG_LOV_ADD_INA) {
953 /*FIXME: Add mdt_index for LCFG_LOV_ADD_INA*/
955 rc = lod_add_device(env, lod, arg1, index, gen,
956 mdt_index, LUSTRE_OSC_NAME, 0);
958 rc = lod_del_device(env, lod, &lod->lod_ost_descs,
966 struct obd_device *obd;
971 * Check if it is activate/deactivate mdc
972 * lustre-MDTXXXX-osp-MDTXXXX.active=1
974 param = lustre_cfg_buf(lcfg, 1);
975 if (strstr(param, "osp") && strstr(param, ".active=")) {
976 struct lod_tgt_desc *sub_tgt = NULL;
977 struct lu_tgt_desc *mdt;
981 ptr = strstr(param, ".");
983 obd = class_name2obd(param);
985 CERROR("%s: can not find %s: rc = %d\n",
986 lod2obd(lod)->obd_name, param, -EINVAL);
991 lod_foreach_mdt(lod, mdt) {
992 if (mdt->ltd_tgt->dd_lu_dev.ld_obd == obd) {
999 CERROR("%s: can not find %s: rc = %d\n",
1000 lod2obd(lod)->obd_name, param, -EINVAL);
1006 tmp = strstr(param, "=");
1009 struct llog_ctxt *ctxt;
1011 obd = sub_tgt->ltd_tgt->dd_lu_dev.ld_obd;
1012 ctxt = llog_get_context(obd,
1013 LLOG_UPDATELOG_ORIG_CTXT);
1015 rc = llog_setup(env, obd, &obd->obd_olg,
1016 LLOG_UPDATELOG_ORIG_CTXT,
1017 NULL, &llog_common_cat_ops);
1021 llog_ctxt_put(ctxt);
1023 rc = lod_sub_prep_llog(env, lod,
1025 sub_tgt->ltd_index);
1027 sub_tgt->ltd_active = 1;
1029 lod_sub_fini_llog(env, sub_tgt->ltd_tgt,
1031 sub_tgt->ltd_active = 0;
1037 if (strstr(param, PARAM_LOD) != NULL)
1038 count = class_modify_config(lcfg, PARAM_LOD,
1039 &lod->lod_dt_dev.dd_kobj);
1041 count = class_modify_config(lcfg, PARAM_LOV,
1042 &lod->lod_dt_dev.dd_kobj);
1043 rc = count > 0 ? 0 : count;
1046 case LCFG_PRE_CLEANUP: {
1047 lod_sub_process_config(env, lod, &lod->lod_mdt_descs, lcfg);
1048 lod_sub_process_config(env, lod, &lod->lod_ost_descs, lcfg);
1049 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_RECOVERY_CONNECT, cfs_fail_val * 2);
1050 next = &lod->lod_child->dd_lu_dev;
1051 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
1053 CDEBUG(D_HA, "%s: can't process %u: %d\n",
1054 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
1056 lod_sub_stop_recovery_threads(env, lod);
1057 lod_fini_distribute_txn(env, lod);
1058 lod_sub_fini_all_llogs(env, lod);
1061 case LCFG_CLEANUP: {
1062 if (lod->lod_md_root) {
1063 dt_object_put(env, &lod->lod_md_root->ldo_obj);
1064 lod->lod_md_root = NULL;
1068 * do cleanup on underlying storage only when
1069 * all OSPs are cleaned up, as they use that OSD as well
1071 lu_dev_del_linkage(dev->ld_site, dev);
1072 lod_sub_process_config(env, lod, &lod->lod_mdt_descs, lcfg);
1073 lod_sub_process_config(env, lod, &lod->lod_ost_descs, lcfg);
1074 next = &lod->lod_child->dd_lu_dev;
1075 rc = next->ld_ops->ldo_process_config(env, next, lcfg);
1077 CERROR("%s: can't process %u: rc = %d\n",
1078 lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
1080 rc = obd_disconnect(lod->lod_child_exp);
1082 CERROR("error in disconnect from storage: rc = %d\n",
1087 CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
1088 lcfg->lcfg_command);
1098 * Implementation of lu_device_operations::ldo_recovery_complete() for LOD
1100 * The method is called once the recovery is complete. This implementation
1101 * distributes the notification to all the known targets.
1103 * see include/lu_object.h for the details
1105 static int lod_recovery_complete(const struct lu_env *env,
1106 struct lu_device *dev)
1108 struct lod_device *lod = lu2lod_dev(dev);
1109 struct lu_device *next = &lod->lod_child->dd_lu_dev;
1110 struct lod_tgt_desc *tgt;
1115 LASSERT(lod->lod_recovery_completed == 0);
1116 lod->lod_recovery_completed = 1;
1118 rc = next->ld_ops->ldo_recovery_complete(env, next);
1120 lod_getref(&lod->lod_ost_descs);
1121 if (lod->lod_ost_descs.ltd_tgts_size > 0) {
1122 lod_foreach_ost(lod, tgt) {
1123 LASSERT(tgt && tgt->ltd_tgt);
1124 next = &tgt->ltd_tgt->dd_lu_dev;
1125 rc = next->ld_ops->ldo_recovery_complete(env, next);
1127 CERROR("%s: can't complete recovery on #%d: rc = %d\n",
1128 lod2obd(lod)->obd_name, tgt->ltd_index,
1132 lod_putref(lod, &lod->lod_ost_descs);
1137 * Init update logs on all sub device
1139 * LOD initialize update logs on all of sub devices. Because the initialization
1140 * process might need FLD lookup, see llog_osd_open()->dt_locate()->...->
1141 * lod_object_init(), this API has to be called after LOD is initialized.
1142 * \param[in] env execution environment
1143 * \param[in] lod lod device
1145 * \retval 0 if update log is initialized successfully.
1146 * \retval negative errno if initialization fails.
1148 static int lod_sub_init_llogs(const struct lu_env *env, struct lod_device *lod)
1150 struct lu_tgt_desc *mdt;
1156 * llog must be setup after LOD is initialized, because llog
1157 * initialization include FLD lookup
1159 LASSERT(lod->lod_initialized);
1161 /* Init the llog in its own stack */
1162 rc = lod_sub_init_llog(env, lod, lod->lod_child);
1166 lod_foreach_mdt(lod, mdt) {
1167 rc = lod_sub_init_llog(env, lod, mdt->ltd_tgt);
1176 * Implementation of lu_device_operations::ldo_prepare() for LOD
1178 * see include/lu_object.h for the details.
1180 static int lod_prepare(const struct lu_env *env, struct lu_device *pdev,
1181 struct lu_device *cdev)
1183 struct lod_device *lod = lu2lod_dev(cdev);
1184 struct lu_device *next = &lod->lod_child->dd_lu_dev;
1185 struct lu_fid *fid = &lod_env_info(env)->lti_fid;
1187 struct dt_object *root;
1188 struct dt_object *dto;
1193 rc = next->ld_ops->ldo_prepare(env, pdev, next);
1195 CERROR("%s: prepare bottom error: rc = %d\n",
1196 lod2obd(lod)->obd_name, rc);
1200 lod->lod_initialized = 1;
1202 rc = dt_root_get(env, lod->lod_child, fid);
1206 root = dt_locate(env, lod->lod_child, fid);
1208 RETURN(PTR_ERR(root));
1210 /* Create update log object */
1211 index = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
1212 lu_update_log_fid(fid, index);
1214 dto = local_file_find_or_create_with_fid(env, lod->lod_child,
1216 lod_update_log_name,
1219 GOTO(out_put, rc = PTR_ERR(dto));
1221 dt_object_put(env, dto);
1223 /* Create update log dir */
1224 lu_update_log_dir_fid(fid, index);
1225 dto = local_file_find_or_create_with_fid(env, lod->lod_child,
1227 lod_update_log_dir_name,
1230 GOTO(out_put, rc = PTR_ERR(dto));
1232 dt_object_put(env, dto);
1234 rc = lod_prepare_distribute_txn(env, lod);
1238 rc = lod_sub_init_llogs(env, lod);
1243 dt_object_put(env, root);
1248 const struct lu_device_operations lod_lu_ops = {
1249 .ldo_object_alloc = lod_object_alloc,
1250 .ldo_process_config = lod_process_config,
1251 .ldo_recovery_complete = lod_recovery_complete,
1252 .ldo_prepare = lod_prepare,
1256 * Implementation of dt_device_operations::dt_root_get() for LOD
1258 * see include/dt_object.h for the details.
1260 static int lod_root_get(const struct lu_env *env,
1261 struct dt_device *dev, struct lu_fid *f)
1263 return dt_root_get(env, dt2lod_dev(dev)->lod_child, f);
1266 static void lod_statfs_sum(struct obd_statfs *sfs,
1267 struct obd_statfs *ost_sfs, int *bs)
1269 while (ost_sfs->os_bsize < *bs) {
1271 sfs->os_bsize >>= 1;
1272 sfs->os_bavail <<= 1;
1273 sfs->os_blocks <<= 1;
1274 sfs->os_bfree <<= 1;
1275 sfs->os_granted <<= 1;
1277 while (ost_sfs->os_bsize > *bs) {
1278 ost_sfs->os_bsize >>= 1;
1279 ost_sfs->os_bavail <<= 1;
1280 ost_sfs->os_blocks <<= 1;
1281 ost_sfs->os_bfree <<= 1;
1282 ost_sfs->os_granted <<= 1;
1284 sfs->os_bavail += ost_sfs->os_bavail;
1285 sfs->os_blocks += ost_sfs->os_blocks;
1286 sfs->os_bfree += ost_sfs->os_bfree;
1287 sfs->os_granted += ost_sfs->os_granted;
1291 * Implementation of dt_device_operations::dt_statfs() for LOD
1293 * see include/dt_object.h for the details.
1295 static int lod_statfs(const struct lu_env *env, struct dt_device *dev,
1296 struct obd_statfs *sfs, struct obd_statfs_info *info)
1298 struct lod_device *lod = dt2lod_dev(dev);
1299 struct lu_tgt_desc *tgt;
1300 struct obd_statfs ost_sfs;
1305 rc = dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs);
1314 sfs->os_granted = 0;
1316 lod_getref(&lod->lod_mdt_descs);
1317 lod_foreach_mdt(lod, tgt) {
1318 rc = dt_statfs(env, tgt->ltd_tgt, &ost_sfs);
1322 sfs->os_files += ost_sfs.os_files;
1323 sfs->os_ffree += ost_sfs.os_ffree;
1324 lod_statfs_sum(sfs, &ost_sfs, &bs);
1326 lod_putref(lod, &lod->lod_mdt_descs);
1329 * at some point we can check whether DoM is enabled and
1330 * decide how to account MDT space. for simplicity let's
1331 * just fallback to pre-DoM policy if any OST is alive
1333 lod_getref(&lod->lod_ost_descs);
1334 lod_foreach_ost(lod, tgt) {
1335 rc = dt_statfs(env, tgt->ltd_tgt, &ost_sfs);
1337 if (rc || ost_sfs.os_bsize == 0)
1341 * if only MDTs with DoM then report only MDT blocks,
1342 * otherwise show only OST blocks, and DoM is "free"
1347 sfs->os_granted = 0;
1349 ost_files += ost_sfs.os_files;
1350 ost_ffree += ost_sfs.os_ffree;
1351 ost_sfs.os_bavail += ost_sfs.os_granted;
1352 lod_statfs_sum(sfs, &ost_sfs, &bs);
1353 LASSERTF(bs == ost_sfs.os_bsize, "%d != %d\n",
1354 (int)sfs->os_bsize, (int)ost_sfs.os_bsize);
1356 lod_putref(lod, &lod->lod_ost_descs);
1357 sfs->os_state |= OS_STATE_SUM;
1359 /* If we have _some_ OSTs, but don't have as many free objects on the
1360 * OSTs as inodes on the MDTs, reduce the reported number of inodes
1361 * to compensate, so that the "inodes in use" number is correct.
1362 * This should be kept in sync with ll_statfs_internal().
1364 if (ost_files && ost_ffree < sfs->os_ffree) {
1365 sfs->os_files = (sfs->os_files - sfs->os_ffree) + ost_ffree;
1366 sfs->os_ffree = ost_ffree;
1369 /* a single successful statfs should be enough */
1377 * Implementation of dt_device_operations::dt_trans_create() for LOD
1379 * Creates a transaction using local (to this node) OSD.
1381 * see include/dt_object.h for the details.
1383 static struct thandle *lod_trans_create(const struct lu_env *env,
1384 struct dt_device *dt)
1388 th = top_trans_create(env, dt2lod_dev(dt)->lod_child);
1398 * Implementation of dt_device_operations::dt_trans_start() for LOD
1400 * Starts the set of local transactions using the targets involved
1401 * in declare phase. Initial support for the distributed transactions.
1403 * see include/dt_object.h for the details.
1405 static int lod_trans_start(const struct lu_env *env, struct dt_device *dt,
1408 return top_trans_start(env, dt2lod_dev(dt)->lod_child, th);
1411 static int lod_trans_cb_add(struct thandle *th,
1412 struct dt_txn_commit_cb *dcb)
1414 struct top_thandle *top_th = container_of(th, struct top_thandle,
1416 return dt_trans_cb_add(top_th->tt_master_sub_thandle, dcb);
1420 * add noop update to the update records
1422 * Add noop updates to the update records, which is only used in
1425 * \param[in] env execution environment
1426 * \param[in] dt dt device of lod
1427 * \param[in] th thandle
1428 * \param[in] count the count of update records to be added.
1430 * \retval 0 if adding succeeds.
1431 * \retval negative errno if adding fails.
1433 static int lod_add_noop_records(const struct lu_env *env,
1434 struct dt_device *dt, struct thandle *th,
1437 struct top_thandle *top_th;
1438 struct lu_fid *fid = &lod_env_info(env)->lti_fid;
1442 top_th = container_of(th, struct top_thandle, tt_super);
1443 if (!top_th->tt_multiple_thandle)
1447 for (i = 0; i < count; i++) {
1448 rc = update_record_pack(noop, th, fid);
1456 * Implementation of dt_device_operations::dt_trans_stop() for LOD
1458 * Stops the set of local transactions using the targets involved
1459 * in declare phase. Initial support for the distributed transactions.
1461 * see include/dt_object.h for the details.
1463 static int lod_trans_stop(const struct lu_env *env, struct dt_device *dt,
1466 if (OBD_FAIL_CHECK(OBD_FAIL_SPLIT_UPDATE_REC)) {
1469 rc = lod_add_noop_records(env, dt, th, 5000);
1473 return top_trans_stop(env, dt2lod_dev(dt)->lod_child, th);
1477 * Implementation of dt_device_operations::dt_conf_get() for LOD
1479 * Currently returns the configuration provided by the local OSD.
1481 * see include/dt_object.h for the details.
1483 static void lod_conf_get(const struct lu_env *env,
1484 const struct dt_device *dev,
1485 struct dt_device_param *param)
1487 dt_conf_get(env, dt2lod_dev((struct dt_device *)dev)->lod_child, param);
1491 * Implementation of dt_device_operations::dt_sync() for LOD
1493 * Syncs all known OST targets. Very very expensive and used
1494 * rarely by LFSCK now. Should not be used in general.
1496 * see include/dt_object.h for the details.
1498 static int lod_sync(const struct lu_env *env, struct dt_device *dev)
1500 struct lod_device *lod = dt2lod_dev(dev);
1501 struct lu_tgt_desc *tgt;
1506 lod_getref(&lod->lod_ost_descs);
1507 lod_foreach_ost(lod, tgt) {
1508 if (!tgt->ltd_active)
1510 rc = dt_sync(env, tgt->ltd_tgt);
1512 if (rc != -ENOTCONN) {
1513 CERROR("%s: can't sync ost %u: rc = %d\n",
1514 lod2obd(lod)->obd_name, tgt->ltd_index,
1521 lod_putref(lod, &lod->lod_ost_descs);
1526 lod_getref(&lod->lod_mdt_descs);
1527 lod_foreach_mdt(lod, tgt) {
1528 if (!tgt->ltd_active)
1530 rc = dt_sync(env, tgt->ltd_tgt);
1532 if (rc != -ENOTCONN) {
1533 CERROR("%s: can't sync mdt %u: rc = %d\n",
1534 lod2obd(lod)->obd_name, tgt->ltd_index,
1541 lod_putref(lod, &lod->lod_mdt_descs);
1544 rc = dt_sync(env, lod->lod_child);
1550 * Implementation of dt_device_operations::dt_ro() for LOD
1552 * Turns local OSD read-only, used for the testing only.
1554 * see include/dt_object.h for the details.
1556 static int lod_ro(const struct lu_env *env, struct dt_device *dev)
1558 return dt_ro(env, dt2lod_dev(dev)->lod_child);
1562 * Implementation of dt_device_operations::dt_commit_async() for LOD
1564 * Asks local OSD to commit sooner.
1566 * see include/dt_object.h for the details.
1568 static int lod_commit_async(const struct lu_env *env, struct dt_device *dev)
1570 return dt_commit_async(env, dt2lod_dev(dev)->lod_child);
1573 static const struct dt_device_operations lod_dt_ops = {
1574 .dt_root_get = lod_root_get,
1575 .dt_statfs = lod_statfs,
1576 .dt_trans_create = lod_trans_create,
1577 .dt_trans_start = lod_trans_start,
1578 .dt_trans_stop = lod_trans_stop,
1579 .dt_conf_get = lod_conf_get,
1580 .dt_sync = lod_sync,
1582 .dt_commit_async = lod_commit_async,
1583 .dt_trans_cb_add = lod_trans_cb_add,
1587 * Connect to a local OSD.
1589 * Used to connect to the local OSD at mount. OSD name is taken from the
1590 * configuration command passed. This connection is used to identify LU
1591 * site and pin the OSD from early removal.
1593 * \param[in] env LU environment provided by the caller
1594 * \param[in] lod lod device
1595 * \param[in] cfg configuration command to apply
1597 * \retval 0 on success
1598 * \retval negative negated errno on error
1600 static int lod_connect_to_osd(const struct lu_env *env, struct lod_device *lod,
1601 struct lustre_cfg *cfg)
1603 struct obd_connect_data *data = NULL;
1604 struct obd_device *obd;
1605 char *nextdev = NULL, *p, *s;
1611 LASSERT(lod->lod_child_exp == NULL);
1614 * compatibility hack: we still use old config logs
1615 * which specify LOV, but we need to learn underlying
1616 * OSD device, which is supposed to be:
1617 * <fsname>-MDTxxxx-osd
1619 * 2.x MGS generates lines like the following:
1620 * #03 (176)lov_setup 0:lustre-MDT0000-mdtlov 1:(struct lov_desc)
1621 * 1.8 MGS generates lines like the following:
1622 * #03 (168)lov_setup 0:lustre-mdtlov 1:(struct lov_desc)
1624 * we use "-MDT" to differentiate 2.x from 1.8
1626 p = lustre_cfg_string(cfg, 0);
1627 if (p && strstr(p, "-mdtlov")) {
1628 len = strlen(p) + 6;
1629 OBD_ALLOC(nextdev, len);
1631 GOTO(out, rc = -ENOMEM);
1634 s = strstr(nextdev, "-mdtlov");
1636 CERROR("%s: unable to parse device name: rc = %d\n",
1637 lustre_cfg_string(cfg, 0), -EINVAL);
1638 GOTO(out, rc = -EINVAL);
1641 if (strstr(nextdev, "-MDT")) {
1646 strcpy(s, "-MDT0000-osd");
1649 CERROR("%s: unable to parse device name: rc = %d\n",
1650 lustre_cfg_string(cfg, 0), -EINVAL);
1651 GOTO(out, rc = -EINVAL);
1654 OBD_ALLOC_PTR(data);
1656 GOTO(out, rc = -ENOMEM);
1658 obd = class_name2obd(nextdev);
1660 CERROR("%s: can not locate next device: rc = %d\n",
1661 nextdev, -ENOTCONN);
1662 GOTO(out, rc = -ENOTCONN);
1665 data->ocd_connect_flags = OBD_CONNECT_VERSION;
1666 data->ocd_version = LUSTRE_VERSION_CODE;
1668 rc = obd_connect(env, &lod->lod_child_exp, obd, &obd->obd_uuid,
1671 CERROR("%s: cannot connect to next dev: rc = %d\n",
1676 lod->lod_dt_dev.dd_lu_dev.ld_site =
1677 lod->lod_child_exp->exp_obd->obd_lu_dev->ld_site;
1678 LASSERT(lod->lod_dt_dev.dd_lu_dev.ld_site);
1679 lod->lod_child = lu2dt_dev(lod->lod_child_exp->exp_obd->obd_lu_dev);
1685 OBD_FREE(nextdev, len);
1690 * Initialize LOD device at setup.
1692 * Initializes the given LOD device using the original configuration command.
1693 * The function initiates a connection to the local OSD and initializes few
1694 * internal structures like pools, target tables, etc.
1696 * \param[in] env LU environment provided by the caller
1697 * \param[in] lod lod device
1698 * \param[in] ldt not used
1699 * \param[in] cfg configuration command
1701 * \retval 0 on success
1702 * \retval negative negated errno on error
1704 static int lod_init0(const struct lu_env *env, struct lod_device *lod,
1705 struct lu_device_type *ldt, struct lustre_cfg *cfg)
1707 struct dt_device_param ddp;
1708 struct obd_device *obd;
1713 obd = class_name2obd(lustre_cfg_string(cfg, 0));
1716 CERROR("Cannot find obd with name '%s': rc = %d\n",
1717 lustre_cfg_string(cfg, 0), rc);
1721 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
1722 lod->lod_dt_dev.dd_lu_dev.ld_obd = obd;
1723 lod->lod_dt_dev.dd_lu_dev.ld_ops = &lod_lu_ops;
1724 lod->lod_dt_dev.dd_ops = &lod_dt_ops;
1726 rc = lod_connect_to_osd(env, lod, cfg);
1730 dt_conf_get(env, &lod->lod_dt_dev, &ddp);
1731 lod->lod_osd_max_easize = ddp.ddp_max_ea_size;
1732 lod->lod_dom_max_stripesize = (1ULL << 20); /* 1Mb as default value */
1734 /* setup obd to be used with old lov code */
1735 rc = lod_pools_init(lod, cfg);
1737 GOTO(out_disconnect, rc);
1739 rc = lod_procfs_init(lod);
1741 GOTO(out_pools, rc);
1743 spin_lock_init(&lod->lod_lock);
1744 spin_lock_init(&lod->lod_connects_lock);
1745 lu_tgt_descs_init(&lod->lod_mdt_descs, true);
1746 lu_tgt_descs_init(&lod->lod_ost_descs, false);
1751 lod_pools_fini(lod);
1753 obd_disconnect(lod->lod_child_exp);
1758 * Implementation of lu_device_type_operations::ldto_device_free() for LOD
1760 * Releases the memory allocated for LOD device.
1762 * see include/lu_object.h for the details.
1764 static struct lu_device *lod_device_free(const struct lu_env *env,
1765 struct lu_device *lu)
1767 struct lod_device *lod = lu2lod_dev(lu);
1768 struct lu_device *next = &lod->lod_child->dd_lu_dev;
1772 if (atomic_read(&lu->ld_ref) > 0 &&
1773 !cfs_hash_is_empty(lu->ld_site->ls_obj_hash)) {
1774 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
1775 lu_site_print(env, lu->ld_site, &msgdata, lu_cdebug_printer);
1777 LASSERTF(atomic_read(&lu->ld_ref) == 0, "lu is %p\n", lu);
1778 dt_device_fini(&lod->lod_dt_dev);
1784 * Implementation of lu_device_type_operations::ldto_device_alloc() for LOD
1786 * Allocates LOD device and calls the helpers to initialize it.
1788 * see include/lu_object.h for the details.
1790 static struct lu_device *lod_device_alloc(const struct lu_env *env,
1791 struct lu_device_type *type,
1792 struct lustre_cfg *lcfg)
1794 struct lod_device *lod;
1795 struct lu_device *lu_dev;
1799 lu_dev = ERR_PTR(-ENOMEM);
1803 lu_dev = lod2lu_dev(lod);
1804 dt_device_init(&lod->lod_dt_dev, type);
1805 rc = lod_init0(env, lod, type, lcfg);
1807 lod_device_free(env, lu_dev);
1808 lu_dev = ERR_PTR(rc);
1815 static void lod_avoid_guide_fini(struct lod_avoid_guide *lag)
1817 if (lag->lag_oss_avoid_array)
1818 OBD_FREE(lag->lag_oss_avoid_array,
1819 sizeof(u32) * lag->lag_oaa_size);
1820 if (lag->lag_ost_avoid_bitmap)
1821 CFS_FREE_BITMAP(lag->lag_ost_avoid_bitmap);
1825 * Implementation of lu_device_type_operations::ldto_device_fini() for LOD
1827 * Releases the internal resources used by LOD device.
1829 * see include/lu_object.h for the details.
1831 static struct lu_device *lod_device_fini(const struct lu_env *env,
1832 struct lu_device *d)
1834 struct lod_device *lod = lu2lod_dev(d);
1839 lod_pools_fini(lod);
1841 lod_procfs_fini(lod);
1843 rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs);
1845 CERROR("%s: can not fini ost descriptors: rc = %d\n",
1846 lod2obd(lod)->obd_name, rc);
1848 rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs);
1850 CERROR("%s: can not fini mdt descriptors: rc = %d\n",
1851 lod2obd(lod)->obd_name, rc);
1857 * Implementation of obd_ops::o_connect() for LOD
1859 * Used to track all the users of this specific LOD device,
1860 * so the device stays up until the last user disconnected.
1862 * \param[in] env LU environment provided by the caller
1863 * \param[out] exp export the caller will be using to access LOD
1864 * \param[in] obd OBD device representing LOD device
1865 * \param[in] cluuid unique identifier of the caller
1866 * \param[in] data not used
1867 * \param[in] localdata not used
1869 * \retval 0 on success
1870 * \retval negative negated errno on error
1872 static int lod_obd_connect(const struct lu_env *env, struct obd_export **exp,
1873 struct obd_device *obd, struct obd_uuid *cluuid,
1874 struct obd_connect_data *data, void *localdata)
1876 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
1877 struct lustre_handle conn;
1882 CDEBUG(D_CONFIG, "connect #%d\n", lod->lod_connects);
1884 rc = class_connect(&conn, obd, cluuid);
1888 *exp = class_conn2export(&conn);
1890 spin_lock(&lod->lod_connects_lock);
1891 lod->lod_connects++;
1892 /* at the moment we expect the only user */
1893 LASSERT(lod->lod_connects == 1);
1894 spin_unlock(&lod->lod_connects_lock);
1901 * Implementation of obd_ops::o_disconnect() for LOD
1903 * When the caller doesn't need to use this LOD instance, it calls
1904 * obd_disconnect() and LOD releases corresponding export/reference count.
1905 * Once all the users gone, LOD device is released.
1907 * \param[in] exp export provided to the caller in obd_connect()
1909 * \retval 0 on success
1910 * \retval negative negated errno on error
1912 static int lod_obd_disconnect(struct obd_export *exp)
1914 struct obd_device *obd = exp->exp_obd;
1915 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
1916 int rc, release = 0;
1920 /* Only disconnect the underlying layers on the final disconnect. */
1921 spin_lock(&lod->lod_connects_lock);
1922 lod->lod_connects--;
1923 if (lod->lod_connects != 0) {
1924 /* why should there be more than 1 connect? */
1925 spin_unlock(&lod->lod_connects_lock);
1926 CERROR("%s: disconnect #%d\n", exp->exp_obd->obd_name,
1930 spin_unlock(&lod->lod_connects_lock);
1932 /* the last user of lod has gone, let's release the device */
1936 rc = class_disconnect(exp); /* bz 9811 */
1938 if (rc == 0 && release)
1939 class_manual_cleanup(obd);
1943 LU_KEY_INIT(lod, struct lod_thread_info);
1945 static void lod_key_fini(const struct lu_context *ctx,
1946 struct lu_context_key *key, void *data)
1948 struct lod_thread_info *info = data;
1949 struct lod_layout_component *lds =
1950 info->lti_def_striping.lds_def_comp_entries;
1953 * allocated in lod_get_lov_ea
1954 * XXX: this is overload, a tread may have such store but used only
1955 * once. Probably better would be pool of such stores per LOD.
1957 if (info->lti_ea_store) {
1958 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
1959 info->lti_ea_store = NULL;
1960 info->lti_ea_store_size = 0;
1962 lu_buf_free(&info->lti_linkea_buf);
1965 lod_free_def_comp_entries(&info->lti_def_striping);
1967 if (info->lti_comp_size > 0)
1968 OBD_FREE(info->lti_comp_idx,
1969 info->lti_comp_size * sizeof(u32));
1971 lod_avoid_guide_fini(&info->lti_avoid);
1976 /* context key: lod_thread_key */
1977 LU_CONTEXT_KEY_DEFINE(lod, LCT_MD_THREAD);
1979 LU_TYPE_INIT_FINI(lod, &lod_thread_key);
1981 static struct lu_device_type_operations lod_device_type_ops = {
1982 .ldto_init = lod_type_init,
1983 .ldto_fini = lod_type_fini,
1985 .ldto_start = lod_type_start,
1986 .ldto_stop = lod_type_stop,
1988 .ldto_device_alloc = lod_device_alloc,
1989 .ldto_device_free = lod_device_free,
1991 .ldto_device_fini = lod_device_fini
1994 static struct lu_device_type lod_device_type = {
1995 .ldt_tags = LU_DEVICE_DT,
1996 .ldt_name = LUSTRE_LOD_NAME,
1997 .ldt_ops = &lod_device_type_ops,
1998 .ldt_ctx_tags = LCT_MD_THREAD,
2002 * Implementation of obd_ops::o_get_info() for LOD
2004 * Currently, there is only one supported key: KEY_OSP_CONNECTED , to provide
2005 * the caller binary status whether LOD has seen connection to any OST target.
2006 * It will also check if the MDT update log context being initialized (if
2009 * \param[in] env LU environment provided by the caller
2010 * \param[in] exp export of the caller
2011 * \param[in] keylen len of the key
2012 * \param[in] key the key
2013 * \param[in] vallen not used
2014 * \param[in] val not used
2016 * \retval 0 if a connection was seen
2017 * \retval -EAGAIN if LOD isn't running yet or no
2018 * connection has been seen yet
2019 * \retval -EINVAL if not supported key is requested
2021 static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp,
2022 u32 keylen, void *key, u32 *vallen, void *val)
2026 if (KEY_IS(KEY_OSP_CONNECTED)) {
2027 struct obd_device *obd = exp->exp_obd;
2028 struct lod_device *d;
2029 struct lod_tgt_desc *tgt;
2032 if (!obd->obd_set_up || obd->obd_stopping)
2035 d = lu2lod_dev(obd->obd_lu_dev);
2036 lod_getref(&d->lod_ost_descs);
2037 lod_foreach_ost(d, tgt) {
2038 rc = obd_get_info(env, tgt->ltd_exp, keylen, key,
2040 /* one healthy device is enough */
2044 lod_putref(d, &d->lod_ost_descs);
2046 lod_getref(&d->lod_mdt_descs);
2047 lod_foreach_mdt(d, tgt) {
2048 struct llog_ctxt *ctxt;
2050 if (!tgt->ltd_active)
2053 ctxt = llog_get_context(tgt->ltd_tgt->dd_lu_dev.ld_obd,
2054 LLOG_UPDATELOG_ORIG_CTXT);
2056 CDEBUG(D_INFO, "%s: %s is not ready.\n",
2058 tgt->ltd_tgt->dd_lu_dev.ld_obd->obd_name);
2062 if (!ctxt->loc_handle) {
2063 CDEBUG(D_INFO, "%s: %s is not ready.\n",
2065 tgt->ltd_tgt->dd_lu_dev.ld_obd->obd_name);
2067 llog_ctxt_put(ctxt);
2070 llog_ctxt_put(ctxt);
2072 lod_putref(d, &d->lod_mdt_descs);
2080 static int lod_obd_set_info_async(const struct lu_env *env,
2081 struct obd_export *exp,
2082 u32 keylen, void *key,
2083 u32 vallen, void *val,
2084 struct ptlrpc_request_set *set)
2086 struct obd_device *obd = class_exp2obd(exp);
2087 struct lod_device *d;
2088 struct lod_tgt_desc *tgt;
2096 set = ptlrpc_prep_set();
2101 d = lu2lod_dev(obd->obd_lu_dev);
2102 lod_getref(&d->lod_ost_descs);
2103 lod_foreach_ost(d, tgt) {
2104 if (!tgt->ltd_active)
2107 rc2 = obd_set_info_async(env, tgt->ltd_exp, keylen, key,
2109 if (rc2 != 0 && rc == 0)
2112 lod_putref(d, &d->lod_ost_descs);
2114 lod_getref(&d->lod_mdt_descs);
2115 lod_foreach_mdt(d, tgt) {
2116 if (!tgt->ltd_active)
2118 rc2 = obd_set_info_async(env, tgt->ltd_exp, keylen, key,
2120 if (rc2 != 0 && rc == 0)
2123 lod_putref(d, &d->lod_mdt_descs);
2127 rc2 = ptlrpc_set_wait(env, set);
2128 if (rc2 == 0 && rc == 0)
2130 ptlrpc_set_destroy(set);
2135 static const struct obd_ops lod_obd_device_ops = {
2136 .o_owner = THIS_MODULE,
2137 .o_connect = lod_obd_connect,
2138 .o_disconnect = lod_obd_disconnect,
2139 .o_get_info = lod_obd_get_info,
2140 .o_set_info_async = lod_obd_set_info_async,
2141 .o_pool_new = lod_pool_new,
2142 .o_pool_rem = lod_pool_remove,
2143 .o_pool_add = lod_pool_add,
2144 .o_pool_del = lod_pool_del,
2147 static int __init lod_init(void)
2149 struct obd_type *sym;
2152 rc = lu_kmem_init(lod_caches);
2156 rc = class_register_type(&lod_obd_device_ops, NULL, true, NULL,
2157 LUSTRE_LOD_NAME, &lod_device_type);
2159 lu_kmem_fini(lod_caches);
2163 /* create "lov" entry for compatibility purposes */
2164 sym = class_add_symlinks(LUSTRE_LOV_NAME, true);
2167 /* does real "lov" already exist ? */
2175 static void __exit lod_exit(void)
2177 struct obd_type *sym = class_search_type(LUSTRE_LOV_NAME);
2179 /* if this was never fully initialized by the lov layer
2180 * then we are responsible for freeing this obd_type
2183 /* final put if we manage this obd type */
2184 if (sym->typ_sym_filter)
2185 kobject_put(&sym->typ_kobj);
2186 /* put reference taken by class_search_type */
2187 kobject_put(&sym->typ_kobj);
2190 class_unregister_type(LUSTRE_LOD_NAME);
2191 lu_kmem_fini(lod_caches);
2194 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2195 MODULE_DESCRIPTION("Lustre Logical Object Device ("LUSTRE_LOD_NAME")");
2196 MODULE_VERSION(LUSTRE_VERSION_STRING);
2197 MODULE_LICENSE("GPL");
2199 module_init(lod_init);
2200 module_exit(lod_exit);