These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / lustre / lustre / lov / lov_obd.c
index 0278157..7abe484 100644 (file)
@@ -85,6 +85,7 @@ static void lov_putref(struct obd_device *obd)
                LIST_HEAD(kill);
                int i;
                struct lov_tgt_desc *tgt, *n;
+
                CDEBUG(D_CONFIG, "destroying %d lov targets\n",
                       lov->lov_death_row);
                for (i = 0; i < lov->desc.ld_tgt_count; i++) {
@@ -107,6 +108,10 @@ static void lov_putref(struct obd_device *obd)
                        /* Disconnect */
                        __lov_del_obd(obd, tgt);
                }
+
+               if (lov->lov_tgts_kobj)
+                       kobject_put(lov->lov_tgts_kobj);
+
        } else {
                mutex_unlock(&lov->lov_lock);
        }
@@ -117,7 +122,6 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                      enum obd_notify_event ev, void *data);
 
-
 #define MAX_STRING_SIZE 128
 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
                    struct obd_connect_data *data)
@@ -127,7 +131,6 @@ int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
        struct obd_device *tgt_obd;
        static struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
        struct obd_import *imp;
-       struct proc_dir_entry *lov_proc_dir;
        int rc;
 
        if (!lov->lov_tgts[index])
@@ -166,7 +169,6 @@ int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
                return rc;
        }
 
-
        if (imp->imp_invalid) {
                CDEBUG(D_CONFIG, "not connecting OSC %s; administratively disabled\n",
                       obd_uuid2str(tgt_uuid));
@@ -186,28 +188,10 @@ int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
        CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
               obd_uuid2str(tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
 
-       lov_proc_dir = obd->obd_proc_private;
-       if (lov_proc_dir) {
-               struct obd_device *osc_obd = lov->lov_tgts[index]->ltd_exp->exp_obd;
-               struct proc_dir_entry *osc_symlink;
-
-               LASSERT(osc_obd != NULL);
-               LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
-               LASSERT(osc_obd->obd_type->typ_name != NULL);
-
-               osc_symlink = lprocfs_add_symlink(osc_obd->obd_name,
-                                                 lov_proc_dir,
-                                                 "../../../%s/%s",
-                                                 osc_obd->obd_type->typ_name,
-                                                 osc_obd->obd_name);
-               if (osc_symlink == NULL) {
-                       CERROR("could not register LOV target /proc/fs/lustre/%s/%s/target_obds/%s.",
-                              obd->obd_type->typ_name, obd->obd_name,
-                              osc_obd->obd_name);
-                       lprocfs_remove(&lov_proc_dir);
-                       obd->obd_proc_private = NULL;
-               }
-       }
+       if (lov->lov_tgts_kobj)
+               /* Even if we failed, that's ok */
+               rc = sysfs_create_link(lov->lov_tgts_kobj, &tgt_obd->obd_kobj,
+                                      tgt_obd->obd_name);
 
        return 0;
 }
@@ -239,6 +223,10 @@ static int lov_connect(const struct lu_env *env,
                lov->lov_ocd = *data;
 
        obd_getref(obd);
+
+       lov->lov_tgts_kobj = kobject_create_and_add("target_obds",
+                                                   &obd->obd_kobj);
+
        for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                tgt = lov->lov_tgts[i];
                if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
@@ -268,7 +256,6 @@ static int lov_connect(const struct lu_env *env,
 
 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
 {
-       struct proc_dir_entry *lov_proc_dir;
        struct lov_obd *lov = &obd->u.lov;
        struct obd_device *osc_obd;
        int rc;
@@ -284,10 +271,10 @@ static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
        }
 
        if (osc_obd) {
-               lov_proc_dir = obd->obd_proc_private;
-               if (lov_proc_dir) {
-                       lprocfs_remove_proc_entry(osc_obd->obd_name, lov_proc_dir);
-               }
+               if (lov->lov_tgts_kobj)
+                       sysfs_remove_link(lov->lov_tgts_kobj,
+                                         osc_obd->obd_name);
+
                /* Pass it on to our clients.
                 * XXX This should be an argument to disconnect,
                 * XXX not a back-door flag on the OBD.  Ah well.
@@ -337,6 +324,7 @@ static int lov_disconnect(struct obd_export *exp)
                        lov_del_target(obd, i, NULL, lov->lov_tgts[i]->ltd_gen);
                }
        }
+
        obd_putref(obd);
 
 out:
@@ -554,7 +542,7 @@ static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
                newsize = max_t(__u32, lov->lov_tgt_size, 2);
                while (newsize < index + 1)
                        newsize <<= 1;
-               OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
+               newtgts = kcalloc(newsize, sizeof(*newtgts), GFP_NOFS);
                if (newtgts == NULL) {
                        mutex_unlock(&lov->lov_lock);
                        return -ENOMEM;
@@ -570,14 +558,13 @@ static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
                lov->lov_tgts = newtgts;
                lov->lov_tgt_size = newsize;
                smp_rmb();
-               if (old)
-                       OBD_FREE(old, sizeof(*old) * oldsize);
+               kfree(old);
 
                CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
                       lov->lov_tgts, lov->lov_tgt_size);
        }
 
-       OBD_ALLOC_PTR(tgt);
+       tgt = kzalloc(sizeof(*tgt), GFP_NOFS);
        if (!tgt) {
                mutex_unlock(&lov->lov_lock);
                return -ENOMEM;
@@ -586,7 +573,7 @@ static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
        rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
        if (rc) {
                mutex_unlock(&lov->lov_lock);
-               OBD_FREE_PTR(tgt);
+               kfree(tgt);
                return rc;
        }
 
@@ -712,7 +699,7 @@ static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
        if (tgt->ltd_exp)
                lov_disconnect_obd(obd, tgt);
 
-       OBD_FREE_PTR(tgt);
+       kfree(tgt);
 
        /* Manual cleanup - no cleanup logs to clean up the osc's.  We must
           do it ourselves. And we can't do it from lov_cleanup,
@@ -822,21 +809,16 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                goto out;
 
        lprocfs_lov_init_vars(&lvars);
-       lprocfs_obd_setup(obd, lvars.obd_vars);
-#if defined (CONFIG_PROC_FS)
-       {
-               int rc1;
+       lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars);
 
-               rc1 = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
-                                       0444, &lov_proc_target_fops, obd);
-               if (rc1)
-                       CWARN("Error adding the target_obd file\n");
-       }
-#endif
-       lov->lov_pool_proc_entry = lprocfs_register("pools",
-                                                   obd->obd_proc_entry,
-                                                   NULL, NULL);
+       rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "target_obd",
+                                0444, &lov_proc_target_fops, obd);
+       if (rc)
+               CWARN("Error adding the target_obd file\n");
 
+       lov->lov_pool_debugfs_entry = ldebugfs_register("pools",
+                                                    obd->obd_debugfs_entry,
+                                                    NULL, NULL);
        return 0;
 
 out:
@@ -850,6 +832,7 @@ static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
        switch (stage) {
        case OBD_CLEANUP_EARLY: {
                int i;
+
                for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                        if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
                                continue;
@@ -886,6 +869,7 @@ static int lov_cleanup(struct obd_device *obd)
        lprocfs_obd_cleanup(obd);
        if (lov->lov_tgts) {
                int i;
+
                obd_getref(obd);
                for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                        if (!lov->lov_tgts[i])
@@ -903,8 +887,7 @@ static int lov_cleanup(struct obd_device *obd)
                        lov_del_target(obd, i, NULL, 0);
                }
                obd_putref(obd);
-               OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
-                        lov->lov_tgt_size);
+               kfree(lov->lov_tgts);
                lov->lov_tgt_size = 0;
        }
        return 0;
@@ -931,14 +914,12 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
 
                obd_str2uuid(&obd_uuid,  lustre_cfg_buf(lcfg, 1));
 
-               if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1) {
-                       rc = -EINVAL;
+               rc = kstrtoint(lustre_cfg_buf(lcfg, 2), 10, indexp);
+               if (rc < 0)
                        goto out;
-               }
-               if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1) {
-                       rc = -EINVAL;
+               rc = kstrtoint(lustre_cfg_buf(lcfg, 3), 10, genp);
+               if (rc < 0)
                        goto out;
-               }
                index = *indexp;
                gen = *genp;
                if (cmd == LCFG_LOV_ADD_OBD)
@@ -994,8 +975,8 @@ static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
        LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
                src_oa->o_flags & OBD_FL_RECREATE_OBJS);
 
-       OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
-       if (obj_mdp == NULL)
+       obj_mdp = kzalloc(sizeof(*obj_mdp), GFP_NOFS);
+       if (!obj_mdp)
                return -ENOMEM;
 
        ost_idx = src_oa->o_nlink;
@@ -1032,7 +1013,7 @@ static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
        rc = obd_create(NULL, lov->lov_tgts[ost_idx]->ltd_exp,
                        src_oa, &obj_mdp, oti);
 out:
-       OBD_FREE(obj_mdp, sizeof(*obj_mdp));
+       kfree(obj_mdp);
        return rc;
 }
 
@@ -1079,8 +1060,7 @@ do {                                                                          \
 
 static int lov_destroy(const struct lu_env *env, struct obd_export *exp,
                       struct obdo *oa, struct lov_stripe_md *lsm,
-                      struct obd_trans_info *oti, struct obd_export *md_exp,
-                      void *capa)
+                      struct obd_trans_info *oti, struct obd_export *md_exp)
 {
        struct lov_request_set *set;
        struct obd_info oinfo;
@@ -1112,7 +1092,7 @@ static int lov_destroy(const struct lu_env *env, struct obd_export *exp,
                        oti->oti_logcookies = set->set_cookies + req->rq_stripe;
 
                err = obd_destroy(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
-                                 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
+                                 req->rq_oi.oi_oa, NULL, oti, NULL);
                err = lov_update_common_set(set, req, err);
                if (err) {
                        CERROR("%s: destroying objid "DOSTID" subobj "
@@ -1275,6 +1255,7 @@ static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
        /* If we are not waiting for responses on async requests, return. */
        if (rc || !rqset || list_empty(&rqset->set_requests)) {
                int err;
+
                if (rc)
                        atomic_set(&set->set_completes, 0);
                err = lov_fini_setattr_set(set);
@@ -1367,6 +1348,7 @@ static int lov_statfs_async(struct obd_export *exp, struct obd_info *oinfo,
 
        if (rc || list_empty(&rqset->set_requests)) {
                int err;
+
                if (rc)
                        atomic_set(&set->set_completes, 0);
                err = lov_fini_statfs_set(set);
@@ -1383,7 +1365,7 @@ static int lov_statfs(const struct lu_env *env, struct obd_export *exp,
                      struct obd_statfs *osfs, __u64 max_age, __u32 flags)
 {
        struct ptlrpc_request_set *set = NULL;
-       struct obd_info oinfo = { { { 0 } } };
+       struct obd_info oinfo = { };
        int rc = 0;
 
        /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
@@ -1419,7 +1401,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                __u32 flags;
 
                memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
-               if ((index >= count))
+               if (index >= count)
                        return -ENODEV;
 
                if (!lov->lov_tgts[index])
@@ -1458,7 +1440,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                __u32 *genp;
 
                len = 0;
-               if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
+               if (obd_ioctl_getdata(&buf, &len, uarg))
                        return -EINVAL;
 
                data = (struct obd_ioctl_data *)buf;
@@ -1491,7 +1473,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                        *genp = lov->lov_tgts[i]->ltd_gen;
                }
 
-               if (copy_to_user((void *)uarg, buf, len))
+               if (copy_to_user(uarg, buf, len))
                        rc = -EFAULT;
                obd_ioctl_freedata(buf, len);
                break;
@@ -1505,7 +1487,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                struct obd_quotactl *oqctl;
 
                if (qctl->qc_valid == QC_OSTIDX) {
-                       if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
+                       if (count <= qctl->qc_idx)
                                return -EINVAL;
 
                        tgt = lov->lov_tgts[qctl->qc_idx];
@@ -1532,7 +1514,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                        return -EAGAIN;
 
                LASSERT(tgt && tgt->ltd_exp);
-               OBD_ALLOC_PTR(oqctl);
+               oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
                if (!oqctl)
                        return -ENOMEM;
 
@@ -1543,7 +1525,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                        qctl->qc_valid = QC_OSTIDX;
                        qctl->obd_uuid = tgt->ltd_uuid;
                }
-               OBD_FREE_PTR(oqctl);
+               kfree(oqctl);
                break;
        }
        default: {
@@ -1690,7 +1672,7 @@ static int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, u64 fm_start,
                                break;
                }
                *stripe_count = j;
-               last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
+               last_stripe = (start_stripe + j - 1) % lsm->lsm_stripe_count;
        }
 
        return last_stripe;
@@ -1756,7 +1738,7 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
        if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
                buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
 
-       OBD_ALLOC_LARGE(fm_local, buffer_size);
+       fm_local = libcfs_kvzalloc(buffer_size, GFP_NOFS);
        if (fm_local == NULL) {
                rc = -ENOMEM;
                goto out;
@@ -1880,7 +1862,7 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
                        fm_local->fm_start = lun_start;
                        fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
                        memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
-                       *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
+                       *vallen = fiemap_count_to_size(fm_local->fm_extent_count);
                        rc = obd_get_info(NULL,
                                          lov->lov_tgts[ost_index]->ltd_exp,
                                          keylen, key, vallen, fm_local, lsm);
@@ -1962,7 +1944,7 @@ skip_last_device_calc:
        fiemap->fm_mapped_extents = current_extent;
 
 out:
-       OBD_FREE_LARGE(fm_local, buffer_size);
+       kvfree(fm_local);
        return rc;
 }
 
@@ -2085,7 +2067,7 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
        struct lov_tgt_desc *tgt;
        unsigned incr, check_uuid,
                 do_inactive, no_set;
-       unsigned next_id = 0,  mds_con = 0, capa = 0;
+       unsigned next_id = 0,  mds_con = 0;
 
        incr = check_uuid = do_inactive = no_set = 0;
        if (set == NULL) {
@@ -2110,8 +2092,6 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
                /* use defaults:  do_inactive = incr = 0; */
        } else if (KEY_IS(KEY_MDS_CONN)) {
                mds_con = 1;
-       } else if (KEY_IS(KEY_CAPA_KEY)) {
-               capa = 1;
        } else if (KEY_IS(KEY_CACHE_SET)) {
                LASSERT(lov->lov_cache == NULL);
                lov->lov_cache = val;
@@ -2119,11 +2099,10 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
        }
 
        for (i = 0; i < count; i++, val = (char *)val + incr) {
-               if (next_id) {
+               if (next_id)
                        tgt = lov->lov_tgts[((struct obd_id_info *)val)->idx];
-               } else {
+               else
                        tgt = lov->lov_tgts[i];
-               }
                /* OST was disconnected */
                if (!tgt || !tgt->ltd_exp)
                        continue;
@@ -2150,19 +2129,6 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
                        err = obd_set_info_async(env, tgt->ltd_exp,
                                         keylen, key, vallen,
                                         ((struct obd_id_info *)val)->data, set);
-               } else if (capa) {
-                       struct mds_capa_info *info = (struct mds_capa_info *)val;
-
-                       LASSERT(vallen == sizeof(*info));
-
-                        /* Only want a specific OSC */
-                       if (info->uuid &&
-                           !obd_uuid_equals(info->uuid, &tgt->ltd_uuid))
-                               continue;
-
-                       err = obd_set_info_async(env, tgt->ltd_exp, keylen,
-                                                key, sizeof(*info->capa),
-                                                info->capa, set);
                } else {
                        /* Only want a specific OSC */
                        if (check_uuid &&
@@ -2367,7 +2333,7 @@ static int __init lov_init(void)
        }
        lprocfs_lov_init_vars(&lvars);
 
-       rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
+       rc = class_register_type(&lov_obd_ops, NULL,
                                 LUSTRE_LOV_NAME, &lov_device_type);
 
        if (rc) {