Whamcloud - gitweb
LU-8066 obd_type: discard obd_types linked list.
[fs/lustre-release.git] / lustre / lod / lod_dev.c
index 8285524..99ccbb0 100644 (file)
@@ -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;
                }
        }
@@ -368,7 +362,6 @@ static int lod_sub_recovery_thread(void *arg)
        struct lod_tgt_desc *tgt = NULL;
        time64_t start;
        int retries = 0;
-       int i;
        int rc;
 
        ENTRY;
@@ -459,8 +452,7 @@ again:
                GOTO(out, rc = 0);
        }
 
-       cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
-               tgt = LTD_TGT(ltd, i);
+       ltd_foreach_tgt(ltd, tgt) {
                if (!tgt->ltd_got_update_log) {
                        spin_unlock(&lod->lod_lock);
                        GOTO(out, rc = 0);
@@ -605,7 +597,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 +616,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;
+               struct lu_tgt_desc *tgt;
 
-               cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
-                       tgt = LTD_TGT(ltd, i);
+               ltd_foreach_tgt(&lod->lod_mdt_descs, tgt) {
                        if (tgt->ltd_tgt == dt) {
                                index = tgt->ltd_index;
-                               sub_ltd = tgt;
+                               subtgt = tgt;
                                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 +669,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);
@@ -701,7 +690,7 @@ static void lod_sub_stop_recovery_threads(const struct lu_env *env,
 {
        struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
        struct ptlrpc_thread *thread;
-       unsigned int i;
+       struct lu_tgt_desc *tgt;
 
        /*
         * Stop the update log commit cancel threads and finish master
@@ -716,10 +705,7 @@ static void lod_sub_stop_recovery_threads(const struct lu_env *env,
        }
 
        lod_getref(ltd);
-       cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
-               struct lod_tgt_desc     *tgt;
-
-               tgt = LTD_TGT(ltd, i);
+       ltd_foreach_tgt(ltd, tgt) {
                thread = tgt->ltd_recovery_thread;
                if (thread && thread->t_flags & SVC_RUNNING) {
                        thread->t_flags = SVC_STOPPING;
@@ -746,7 +732,7 @@ 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 *tgt;
 
        /*
         * Stop the update log commit cancel threads and finish master
@@ -755,14 +741,9 @@ 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);
+       ltd_foreach_tgt(ltd, tgt)
                lod_sub_fini_llog(env, tgt->ltd_tgt,
                                  tgt->ltd_recovery_thread);
-       }
-
        lod_putref(lod, ltd);
 }
 
@@ -802,10 +783,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);
+       ltd_foreach_tgt(ltd, tgt) {
                if (!tgt->ltd_got_update_log) {
-                       rc = snprintf(buf + len, *size - len, " %04x", i);
+                       rc = snprintf(buf + len, *size - len, " %04x",
+                                     tgt->ltd_index);
                        if (unlikely(rc <= 0))
                                break;
 
@@ -994,9 +975,9 @@ static int lod_process_config(const struct lu_env *env,
                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 *tgt;
                        char *ptr;
                        char *tmp;
-                       int i;
 
                        ptr = strstr(param, ".");
                        *ptr = '\0';
@@ -1008,10 +989,7 @@ 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);
+                       ltd_foreach_tgt(ltd, tgt) {
                                if (tgt->ltd_tgt->dd_lu_dev.ld_obd == obd) {
                                        sub_tgt = tgt;
                                        break;
@@ -1172,8 +1150,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 *tgt;
        int rc;
-       unsigned int i;
 
        ENTRY;
 
@@ -1188,10 +1166,7 @@ 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);
+       ltd_foreach_tgt(ltd, tgt) {
                rc = lod_sub_init_llog(env, lod, tgt->ltd_tgt);
                if (rc != 0)
                        break;
@@ -1320,8 +1295,8 @@ 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;
@@ -1379,8 +1354,8 @@ static int lod_statfs(const struct lu_env *env,
                        sfs->os_bfree = 0;
                        sfs->os_granted = 0;
                }
-               ost_files += sfs->os_files;
-               ost_ffree += sfs->os_ffree;
+               ost_files += ost_sfs.os_files;
+               ost_ffree += ost_sfs.os_ffree;
                ost_sfs.os_bavail += ost_sfs.os_granted;
                lod_statfs_sum(sfs, &ost_sfs, &bs);
                LASSERTF(bs == ost_sfs.os_bsize, "%d != %d\n",
@@ -1724,38 +1699,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(&ltd->ltd_mutex);
-       init_rwsem(&ltd->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 +1754,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);
+       lu_tgt_descs_init(&lod->lod_ost_descs);
 
        RETURN(0);
 
@@ -2223,13 +2166,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 dentry *symlink;
-       struct obd_type *type;
-       struct qstr dname;
+       struct obd_type *sym;
        int rc;
 
        rc = lu_kmem_init(lod_caches);
@@ -2243,55 +2182,33 @@ static int __init lod_init(void)
                return rc;
        }
 
-       sym = class_setup_tunables(LUSTRE_LOV_NAME);
+       /* create "lov" entry for compatibility purposes */
+       sym = class_add_symlinks(LUSTRE_LOV_NAME, true);
        if (IS_ERR(sym)) {
                rc = PTR_ERR(sym);
                /* does real "lov" already exist ? */
                if (rc == -EEXIST)
-                       GOTO(try_proc, rc = 0);
-               GOTO(no_lov, rc);
-       }
-
-       /* create "lov" entry for compatibility purposes */
-       dname.name = "lov";
-       dname.len = strlen(dname.name);
-       dname.hash = ll_full_name_hash(debugfs_lustre_root, dname.name,
-                                      dname.len);
-       symlink = d_lookup(debugfs_lustre_root, &dname);
-       if (!symlink) {
-               symlink = debugfs_create_dir(dname.name, debugfs_lustre_root);
-               if (IS_ERR_OR_NULL(symlink)) {
-                       rc = symlink ? PTR_ERR(symlink) : -ENOMEM;
-                       GOTO(no_lov, rc);
-               }
-               sym->typ_debugfs_entry = symlink;
-       } else {
-               dput(symlink);
+                       rc = 0;
        }
 
-try_proc:
-       type = class_search_type(LUSTRE_LOV_NAME);
-       if (type && type->typ_procroot)
-               GOTO(no_lov, rc);
-
-       type = class_search_type(LUSTRE_LOD_NAME);
-       type->typ_procsym = lprocfs_register("lov", proc_lustre_root,
-                                            NULL, NULL);
-       if (IS_ERR(type->typ_procsym)) {
-               CERROR("lod: can't create compat entry \"lov\": %d\n",
-                      (int)PTR_ERR(type->typ_procsym));
-               type->typ_procsym = NULL;
-       }
-no_lov:
        return rc;
 }
 
 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);
 }