X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Flod%2Flod_dev.c;h=a857df1e43f93228a80baef8e430cc7990763460;hp=dc26c297ee49092db2c4084636a63f5ca12c3332;hb=45222b2ef279d62ac3aab0e7babc55d77e3c93a2;hpb=462d476d67903ae366d860f86cdf0ff9070ed167 diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index dc26c29..a857df1 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -244,27 +244,21 @@ static int lod_sub_process_config(const struct lu_env *env, struct lod_tgt_descs *ltd, struct lustre_cfg *lcfg) { - struct lu_device *next; + struct lu_device *next; + struct lu_tgt_desc *tgt; int rc = 0; - unsigned int i; lod_getref(ltd); - if (ltd->ltd_tgts_size <= 0) { - lod_putref(lod, ltd); - return 0; - } - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - struct lod_tgt_desc *tgt; + ltd_foreach_tgt(ltd, tgt) { int rc1; - tgt = LTD_TGT(ltd, i); LASSERT(tgt && tgt->ltd_tgt); next = &tgt->ltd_tgt->dd_lu_dev; rc1 = next->ld_ops->ldo_process_config(env, next, lcfg); if (rc1) { CERROR("%s: error cleaning up LOD index %u: cmd %#x : rc = %d\n", - lod2obd(lod)->obd_name, i, lcfg->lcfg_command, - rc1); + lod2obd(lod)->obd_name, tgt->ltd_index, + lcfg->lcfg_command, rc1); rc = rc1; } } @@ -364,11 +358,9 @@ static int lod_sub_recovery_thread(void *arg) struct llog_ctxt *ctxt = NULL; struct lu_env env; struct lu_target *lut; - struct lod_tgt_descs *ltd = &lod->lod_mdt_descs; - struct lod_tgt_desc *tgt = NULL; + struct lu_tgt_desc *mdt = NULL; time64_t start; int retries = 0; - int i; int rc; ENTRY; @@ -459,9 +451,8 @@ again: GOTO(out, rc = 0); } - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - tgt = LTD_TGT(ltd, i); - if (!tgt->ltd_got_update_log) { + lod_foreach_mdt(lod, mdt) { + if (!mdt->ltd_got_update_log) { spin_unlock(&lod->lod_lock); GOTO(out, rc = 0); } @@ -605,7 +596,7 @@ int lod_sub_init_llog(const struct lu_env *env, struct lod_device *lod, struct ptlrpc_thread *thread; struct task_struct *task; struct l_wait_info lwi = { 0 }; - struct lod_tgt_desc *sub_ltd = NULL; + struct lod_tgt_desc *subtgt = NULL; u32 index; u32 master_index; int rc; @@ -624,30 +615,27 @@ int lod_sub_init_llog(const struct lu_env *env, struct lod_device *lod, thread = &lod->lod_child_recovery_thread; index = master_index; } else { - struct lod_tgt_descs *ltd = &lod->lod_mdt_descs; - struct lod_tgt_desc *tgt = NULL; - unsigned int i; - - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - tgt = LTD_TGT(ltd, i); - if (tgt->ltd_tgt == dt) { - index = tgt->ltd_index; - sub_ltd = tgt; + struct lu_tgt_desc *mdt; + + lod_foreach_mdt(lod, mdt) { + if (mdt->ltd_tgt == dt) { + index = mdt->ltd_index; + subtgt = mdt; break; } } - LASSERT(sub_ltd != NULL); - OBD_ALLOC_PTR(sub_ltd->ltd_recovery_thread); - if (!sub_ltd->ltd_recovery_thread) + LASSERT(subtgt != NULL); + OBD_ALLOC_PTR(subtgt->ltd_recovery_thread); + if (!subtgt->ltd_recovery_thread) GOTO(free_lrd, rc = -ENOMEM); - thread = sub_ltd->ltd_recovery_thread; + thread = subtgt->ltd_recovery_thread; } CDEBUG(D_INFO, "%s init sub log %s\n", lod2obd(lod)->obd_name, dt->dd_lu_dev.ld_obd->obd_name); lrd->lrd_lod = lod; - lrd->lrd_ltd = sub_ltd; + lrd->lrd_ltd = subtgt; lrd->lrd_thread = thread; lrd->lrd_idx = index; init_waitqueue_head(&thread->t_ctl_waitq); @@ -680,8 +668,8 @@ out_llog: lod_sub_fini_llog(env, dt, thread); free_thread: if (lod->lod_child != dt) { - OBD_FREE_PTR(sub_ltd->ltd_recovery_thread); - sub_ltd->ltd_recovery_thread = NULL; + OBD_FREE_PTR(subtgt->ltd_recovery_thread); + subtgt->ltd_recovery_thread = NULL; } free_lrd: OBD_FREE_PTR(lrd); @@ -699,9 +687,8 @@ free_lrd: static void lod_sub_stop_recovery_threads(const struct lu_env *env, struct lod_device *lod) { - struct lod_tgt_descs *ltd = &lod->lod_mdt_descs; struct ptlrpc_thread *thread; - unsigned int i; + struct lu_tgt_desc *mdt; /* * Stop the update log commit cancel threads and finish master @@ -715,23 +702,19 @@ static void lod_sub_stop_recovery_threads(const struct lu_env *env, wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED); } - lod_getref(ltd); - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - struct lod_tgt_desc *tgt; - - tgt = LTD_TGT(ltd, i); - thread = tgt->ltd_recovery_thread; + lod_getref(&lod->lod_mdt_descs); + lod_foreach_mdt(lod, mdt) { + thread = mdt->ltd_recovery_thread; if (thread && thread->t_flags & SVC_RUNNING) { thread->t_flags = SVC_STOPPING; wake_up(&thread->t_ctl_waitq); wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED); - OBD_FREE_PTR(tgt->ltd_recovery_thread); - tgt->ltd_recovery_thread = NULL; + OBD_FREE_PTR(mdt->ltd_recovery_thread); + mdt->ltd_recovery_thread = NULL; } } - - lod_putref(lod, ltd); + lod_putref(lod, &lod->lod_mdt_descs); } /** @@ -745,8 +728,7 @@ static void lod_sub_stop_recovery_threads(const struct lu_env *env, static void lod_sub_fini_all_llogs(const struct lu_env *env, struct lod_device *lod) { - struct lod_tgt_descs *ltd = &lod->lod_mdt_descs; - unsigned int i; + struct lu_tgt_desc *mdt; /* * Stop the update log commit cancel threads and finish master @@ -754,24 +736,18 @@ static void lod_sub_fini_all_llogs(const struct lu_env *env, */ lod_sub_fini_llog(env, lod->lod_child, &lod->lod_child_recovery_thread); - lod_getref(ltd); - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - struct lod_tgt_desc *tgt; - - tgt = LTD_TGT(ltd, i); - lod_sub_fini_llog(env, tgt->ltd_tgt, - tgt->ltd_recovery_thread); - } - - lod_putref(lod, ltd); + lod_getref(&lod->lod_mdt_descs); + lod_foreach_mdt(lod, mdt) + lod_sub_fini_llog(env, mdt->ltd_tgt, + mdt->ltd_recovery_thread); + lod_putref(lod, &lod->lod_mdt_descs); } static char *lod_show_update_logs_retrievers(void *data, int *size, int *count) { struct lod_device *lod = (struct lod_device *)data; struct lu_target *lut = lod2lu_dev(lod)->ld_site->ls_tgt; - struct lod_tgt_descs *ltd = &lod->lod_mdt_descs; - struct lod_tgt_desc *tgt = NULL; + struct lu_tgt_desc *mdt = NULL; char *buf; int len = 0; int rc; @@ -802,10 +778,10 @@ static char *lod_show_update_logs_retrievers(void *data, int *size, int *count) (*count)++; } - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - tgt = LTD_TGT(ltd, i); - if (!tgt->ltd_got_update_log) { - rc = snprintf(buf + len, *size - len, " %04x", i); + lod_foreach_mdt(lod, mdt) { + if (!mdt->ltd_got_update_log) { + rc = snprintf(buf + len, *size - len, " %04x", + mdt->ltd_index); if (unlikely(rc <= 0)) break; @@ -973,9 +949,8 @@ static int lod_process_config(const struct lu_env *env, rc = lod_add_device(env, lod, arg1, index, gen, mdt_index, LUSTRE_OSC_NAME, 0); } else { - rc = lod_del_device(env, lod, - &lod->lod_ost_descs, - arg1, index, gen, true); + rc = lod_del_device(env, lod, &lod->lod_ost_descs, + arg1, index, gen); } break; @@ -992,11 +967,10 @@ static int lod_process_config(const struct lu_env *env, */ param = lustre_cfg_buf(lcfg, 1); if (strstr(param, "osp") && strstr(param, ".active=")) { - struct lod_tgt_descs *ltd = &lod->lod_mdt_descs; struct lod_tgt_desc *sub_tgt = NULL; + struct lu_tgt_desc *mdt; char *ptr; char *tmp; - int i; ptr = strstr(param, "."); *ptr = '\0'; @@ -1008,12 +982,9 @@ static int lod_process_config(const struct lu_env *env, GOTO(out, rc); } - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - struct lod_tgt_desc *tgt; - - tgt = LTD_TGT(ltd, i); - if (tgt->ltd_tgt->dd_lu_dev.ld_obd == obd) { - sub_tgt = tgt; + lod_foreach_mdt(lod, mdt) { + if (mdt->ltd_tgt->dd_lu_dev.ld_obd == obd) { + sub_tgt = mdt; break; } } @@ -1129,7 +1100,7 @@ static int lod_recovery_complete(const struct lu_env *env, { struct lod_device *lod = lu2lod_dev(dev); struct lu_device *next = &lod->lod_child->dd_lu_dev; - unsigned int i; + struct lod_tgt_desc *tgt; int rc; ENTRY; @@ -1140,17 +1111,15 @@ static int lod_recovery_complete(const struct lu_env *env, rc = next->ld_ops->ldo_recovery_complete(env, next); lod_getref(&lod->lod_ost_descs); - if (lod->lod_osts_size > 0) { - cfs_foreach_bit(lod->lod_ost_bitmap, i) { - struct lod_tgt_desc *tgt; - - tgt = OST_TGT(lod, i); + if (lod->lod_ost_descs.ltd_tgts_size > 0) { + lod_foreach_ost(lod, tgt) { LASSERT(tgt && tgt->ltd_tgt); - next = &tgt->ltd_ost->dd_lu_dev; + next = &tgt->ltd_tgt->dd_lu_dev; rc = next->ld_ops->ldo_recovery_complete(env, next); if (rc) CERROR("%s: can't complete recovery on #%d: rc = %d\n", - lod2obd(lod)->obd_name, i, rc); + lod2obd(lod)->obd_name, tgt->ltd_index, + rc); } } lod_putref(lod, &lod->lod_ost_descs); @@ -1171,9 +1140,8 @@ static int lod_recovery_complete(const struct lu_env *env, */ static int lod_sub_init_llogs(const struct lu_env *env, struct lod_device *lod) { - struct lod_tgt_descs *ltd = &lod->lod_mdt_descs; + struct lu_tgt_desc *mdt; int rc; - unsigned int i; ENTRY; @@ -1188,11 +1156,8 @@ static int lod_sub_init_llogs(const struct lu_env *env, struct lod_device *lod) if (rc < 0) RETURN(rc); - cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) { - struct lod_tgt_desc *tgt; - - tgt = LTD_TGT(ltd, i); - rc = lod_sub_init_llog(env, lod, tgt->ltd_tgt); + lod_foreach_mdt(lod, mdt) { + rc = lod_sub_init_llog(env, lod, mdt->ltd_tgt); if (rc != 0) break; } @@ -1320,16 +1285,15 @@ static void lod_statfs_sum(struct obd_statfs *sfs, * * see include/dt_object.h for the details. */ -static int lod_statfs(const struct lu_env *env, - struct dt_device *dev, struct obd_statfs *sfs) +static int lod_statfs(const struct lu_env *env, struct dt_device *dev, + struct obd_statfs *sfs, struct obd_statfs_info *info) { struct lod_device *lod = dt2lod_dev(dev); - struct lod_ost_desc *ost; - struct lod_mdt_desc *mdt; + struct lu_tgt_desc *tgt; struct obd_statfs ost_sfs; u64 ost_files = 0; u64 ost_ffree = 0; - int i, rc, bs; + int rc, bs; rc = dt_statfs(env, dt2lod_dev(dev)->lod_child, sfs); if (rc) @@ -1343,10 +1307,8 @@ static int lod_statfs(const struct lu_env *env, sfs->os_granted = 0; lod_getref(&lod->lod_mdt_descs); - lod_foreach_mdt(lod, i) { - mdt = MDT_TGT(lod, i); - LASSERT(mdt && mdt->ltd_mdt); - rc = dt_statfs(env, mdt->ltd_mdt, &ost_sfs); + lod_foreach_mdt(lod, tgt) { + rc = dt_statfs(env, tgt->ltd_tgt, &ost_sfs); /* ignore errors */ if (rc) continue; @@ -1362,10 +1324,8 @@ static int lod_statfs(const struct lu_env *env, * just fallback to pre-DoM policy if any OST is alive */ lod_getref(&lod->lod_ost_descs); - lod_foreach_ost(lod, i) { - ost = OST_TGT(lod, i); - LASSERT(ost && ost->ltd_ost); - rc = dt_statfs(env, ost->ltd_ost, &ost_sfs); + lod_foreach_ost(lod, tgt) { + rc = dt_statfs(env, tgt->ltd_tgt, &ost_sfs); /* ignore errors */ if (rc || ost_sfs.os_bsize == 0) continue; @@ -1531,24 +1491,21 @@ static void lod_conf_get(const struct lu_env *env, static int lod_sync(const struct lu_env *env, struct dt_device *dev) { struct lod_device *lod = dt2lod_dev(dev); - struct lod_ost_desc *ost; - struct lod_mdt_desc *mdt; - unsigned int i; + struct lu_tgt_desc *tgt; int rc = 0; ENTRY; lod_getref(&lod->lod_ost_descs); - lod_foreach_ost(lod, i) { - ost = OST_TGT(lod, i); - LASSERT(ost && ost->ltd_ost); - if (!ost->ltd_active) + lod_foreach_ost(lod, tgt) { + if (!tgt->ltd_active) continue; - rc = dt_sync(env, ost->ltd_ost); + rc = dt_sync(env, tgt->ltd_tgt); if (rc) { if (rc != -ENOTCONN) { CERROR("%s: can't sync ost %u: rc = %d\n", - lod2obd(lod)->obd_name, i, rc); + lod2obd(lod)->obd_name, tgt->ltd_index, + rc); break; } rc = 0; @@ -1560,16 +1517,15 @@ static int lod_sync(const struct lu_env *env, struct dt_device *dev) RETURN(rc); lod_getref(&lod->lod_mdt_descs); - lod_foreach_mdt(lod, i) { - mdt = MDT_TGT(lod, i); - LASSERT(mdt && mdt->ltd_mdt); - if (!mdt->ltd_active) + lod_foreach_mdt(lod, tgt) { + if (!tgt->ltd_active) continue; - rc = dt_sync(env, mdt->ltd_mdt); + rc = dt_sync(env, tgt->ltd_tgt); if (rc) { if (rc != -ENOTCONN) { CERROR("%s: can't sync mdt %u: rc = %d\n", - lod2obd(lod)->obd_name, i, rc); + lod2obd(lod)->obd_name, tgt->ltd_index, + rc); break; } rc = 0; @@ -1724,38 +1680,6 @@ out: } /** - * Allocate and initialize target table. - * - * A helper function to initialize the target table and allocate - * a bitmap of the available targets. - * - * \param[in] ltd target's table to initialize - * - * \retval 0 on success - * \retval negative negated errno on error - **/ -static int lod_tgt_desc_init(struct lod_tgt_descs *ltd) -{ - mutex_init(<d->ltd_mutex); - init_rwsem(<d->ltd_rw_sem); - - /* - * the OST array and bitmap are allocated/grown dynamically as OSTs are - * added to the LOD, see lod_add_device() - */ - ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(32); - if (!ltd->ltd_tgt_bitmap) - RETURN(-ENOMEM); - - ltd->ltd_tgts_size = 32; - ltd->ltd_tgtnr = 0; - - ltd->ltd_death_row = 0; - ltd->ltd_refcount = 0; - return 0; -} - -/** * Initialize LOD device at setup. * * Initializes the given LOD device using the original configuration command. @@ -1811,8 +1735,8 @@ static int lod_init0(const struct lu_env *env, struct lod_device *lod, spin_lock_init(&lod->lod_lock); spin_lock_init(&lod->lod_connects_lock); - lod_tgt_desc_init(&lod->lod_mdt_descs); - lod_tgt_desc_init(&lod->lod_ost_descs); + lu_tgt_descs_init(&lod->lod_mdt_descs, true); + lu_tgt_descs_init(&lod->lod_ost_descs, false); RETURN(0); @@ -1909,12 +1833,12 @@ static struct lu_device *lod_device_fini(const struct lu_env *env, lod_procfs_fini(lod); - rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs, true); + rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs); if (rc) CERROR("%s: can not fini ost descriptors: rc = %d\n", lod2obd(lod)->obd_name, rc); - rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs, false); + rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs); if (rc) CERROR("%s: can not fini mdt descriptors: rc = %d\n", lod2obd(lod)->obd_name, rc); @@ -2096,7 +2020,6 @@ static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp, struct obd_device *obd = exp->exp_obd; struct lod_device *d; struct lod_tgt_desc *tgt; - unsigned int i; int rc = 1; if (!obd->obd_set_up || obd->obd_stopping) @@ -2104,9 +2027,7 @@ static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp, d = lu2lod_dev(obd->obd_lu_dev); lod_getref(&d->lod_ost_descs); - lod_foreach_ost(d, i) { - tgt = OST_TGT(d, i); - LASSERT(tgt && tgt->ltd_tgt); + lod_foreach_ost(d, tgt) { rc = obd_get_info(env, tgt->ltd_exp, keylen, key, vallen, val); /* one healthy device is enough */ @@ -2116,12 +2037,9 @@ static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp, lod_putref(d, &d->lod_ost_descs); lod_getref(&d->lod_mdt_descs); - lod_foreach_mdt(d, i) { + lod_foreach_mdt(d, tgt) { struct llog_ctxt *ctxt; - tgt = MDT_TGT(d, i); - LASSERT(tgt != NULL); - LASSERT(tgt->ltd_tgt != NULL); if (!tgt->ltd_active) continue; @@ -2162,7 +2080,7 @@ static int lod_obd_set_info_async(const struct lu_env *env, struct lod_device *d; struct lod_tgt_desc *tgt; int no_set = 0; - int i, rc = 0, rc2; + int rc = 0, rc2; ENTRY; @@ -2175,9 +2093,7 @@ static int lod_obd_set_info_async(const struct lu_env *env, d = lu2lod_dev(obd->obd_lu_dev); lod_getref(&d->lod_ost_descs); - lod_foreach_ost(d, i) { - tgt = OST_TGT(d, i); - LASSERT(tgt && tgt->ltd_tgt); + lod_foreach_ost(d, tgt) { if (!tgt->ltd_active) continue; @@ -2189,9 +2105,7 @@ static int lod_obd_set_info_async(const struct lu_env *env, lod_putref(d, &d->lod_ost_descs); lod_getref(&d->lod_mdt_descs); - lod_foreach_mdt(d, i) { - tgt = MDT_TGT(d, i); - LASSERT(tgt && tgt->ltd_tgt); + lod_foreach_mdt(d, tgt) { if (!tgt->ltd_active) continue; rc2 = obd_set_info_async(env, tgt->ltd_exp, keylen, key, @@ -2223,10 +2137,9 @@ static struct obd_ops lod_obd_device_ops = { .o_pool_del = lod_pool_del, }; -static struct obd_type *sym; - static int __init lod_init(void) { + struct obd_type *sym; int rc; rc = lu_kmem_init(lod_caches); @@ -2254,10 +2167,19 @@ static int __init lod_init(void) static void __exit lod_exit(void) { - if (!IS_ERR_OR_NULL(sym)) { - ldebugfs_remove(&sym->typ_debugfs_entry); + struct obd_type *sym = class_search_type(LUSTRE_LOV_NAME); + + /* if this was never fully initialized by the lov layer + * then we are responsible for freeing this obd_type + */ + if (sym) { + /* final put if we manage this obd type */ + if (sym->typ_sym_filter) + kobject_put(&sym->typ_kobj); + /* put reference taken by class_search_type */ kobject_put(&sym->typ_kobj); } + class_unregister_type(LUSTRE_LOD_NAME); lu_kmem_fini(lod_caches); }