These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / lustre / lustre / obdecho / echo_client.c
index d542e06..a4a9a76 100644 (file)
@@ -98,7 +98,6 @@ static int echo_client_setup(const struct lu_env *env,
                             struct lustre_cfg *lcfg);
 static int echo_client_cleanup(struct obd_device *obddev);
 
-
 /** \defgroup echo_helpers Helper functions
  * @{
  */
@@ -323,6 +322,7 @@ static const struct cl_page_operations echo_page_ops = {
                }
        }
 };
+
 /** @} echo_page */
 
 /** \defgroup echo_lock Locking
@@ -337,7 +337,7 @@ static void echo_lock_fini(const struct lu_env *env,
        struct echo_lock *ecl = cl2echo_lock(slice);
 
        LASSERT(list_empty(&ecl->el_chain));
-       OBD_SLAB_FREE_PTR(ecl, echo_lock_kmem);
+       kmem_cache_free(echo_lock_kmem, ecl);
 }
 
 static void echo_lock_delete(const struct lu_env *env,
@@ -396,7 +396,7 @@ static int echo_lock_init(const struct lu_env *env,
 {
        struct echo_lock *el;
 
-       OBD_SLAB_ALLOC_PTR_GFP(el, echo_lock_kmem, GFP_NOFS);
+       el = kmem_cache_alloc(echo_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (el != NULL) {
                cl_lock_slice_add(lock, &el->el_cl, obj, &echo_lock_ops);
                el->el_object = cl2echo_obj(obj);
@@ -418,6 +418,7 @@ static const struct cl_object_operations echo_cl_obj_ops = {
        .coo_io_init   = echo_io_init,
        .coo_conf_set  = echo_conf_set
 };
+
 /** @} echo_cl_ops */
 
 /** \defgroup echo_lu_ops lu_object operations
@@ -479,13 +480,13 @@ static int echo_alloc_memmd(struct echo_device *ed,
        lsm_size = lov_stripe_md_size(1);
 
        LASSERT(*lsmp == NULL);
-       OBD_ALLOC(*lsmp, lsm_size);
-       if (*lsmp == NULL)
+       *lsmp = kzalloc(lsm_size, GFP_NOFS);
+       if (!*lsmp)
                return -ENOMEM;
 
-       OBD_ALLOC((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
-       if ((*lsmp)->lsm_oinfo[0] == NULL) {
-               OBD_FREE(*lsmp, lsm_size);
+       (*lsmp)->lsm_oinfo[0] = kzalloc(sizeof(struct lov_oinfo), GFP_NOFS);
+       if (!(*lsmp)->lsm_oinfo[0]) {
+               kfree(*lsmp);
                return -ENOMEM;
        }
 
@@ -507,8 +508,8 @@ static int echo_free_memmd(struct echo_device *ed, struct lov_stripe_md **lsmp)
        lsm_size = lov_stripe_md_size(1);
 
        LASSERT(*lsmp != NULL);
-       OBD_FREE((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
-       OBD_FREE(*lsmp, lsm_size);
+       kfree((*lsmp)->lsm_oinfo[0]);
+       kfree(*lsmp);
        *lsmp = NULL;
        return 0;
 }
@@ -529,7 +530,7 @@ static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
 
        if (eco->eo_lsm)
                echo_free_memmd(eco->eo_dev, &eco->eo_lsm);
-       OBD_SLAB_FREE_PTR(eco, echo_object_kmem);
+       kmem_cache_free(echo_object_kmem, eco);
 }
 
 static int echo_object_print(const struct lu_env *env, void *cookie,
@@ -548,6 +549,7 @@ static const struct lu_object_operations echo_lu_obj_ops = {
        .loo_object_print     = echo_object_print,
        .loo_object_invariant = NULL
 };
+
 /** @} echo_lu_ops */
 
 /** \defgroup echo_lu_dev_ops  lu_device operations
@@ -565,7 +567,7 @@ static struct lu_object *echo_object_alloc(const struct lu_env *env,
 
        /* we're the top dev. */
        LASSERT(hdr == NULL);
-       OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, GFP_NOFS);
+       eco = kmem_cache_alloc(echo_object_kmem, GFP_NOFS | __GFP_ZERO);
        if (eco != NULL) {
                struct cl_object_header *hdr = &eco->eo_hdr;
 
@@ -628,7 +630,7 @@ static void *echo_thread_key_init(const struct lu_context *ctx,
 {
        struct echo_thread_info *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(echo_thread_kmem, GFP_NOFS | __GFP_ZERO);
        if (info == NULL)
                info = ERR_PTR(-ENOMEM);
        return info;
@@ -639,7 +641,7 @@ static void echo_thread_key_fini(const struct lu_context *ctx,
 {
        struct echo_thread_info *info = data;
 
-       OBD_SLAB_FREE_PTR(info, echo_thread_kmem);
+       kmem_cache_free(echo_thread_kmem, info);
 }
 
 static void echo_thread_key_exit(const struct lu_context *ctx,
@@ -659,7 +661,7 @@ static void *echo_session_key_init(const struct lu_context *ctx,
 {
        struct echo_session_info *session;
 
-       OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, GFP_NOFS);
+       session = kmem_cache_alloc(echo_session_kmem, GFP_NOFS | __GFP_ZERO);
        if (session == NULL)
                session = ERR_PTR(-ENOMEM);
        return session;
@@ -670,7 +672,7 @@ static void echo_session_key_fini(const struct lu_context *ctx,
 {
        struct echo_session_info *session = data;
 
-       OBD_SLAB_FREE_PTR(session, echo_session_kmem);
+       kmem_cache_free(echo_session_kmem, session);
 }
 
 static void echo_session_key_exit(const struct lu_context *ctx,
@@ -700,8 +702,8 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
        int rc;
        int cleanup = 0;
 
-       OBD_ALLOC_PTR(ed);
-       if (ed == NULL) {
+       ed = kzalloc(sizeof(*ed), GFP_NOFS);
+       if (!ed) {
                rc = -ENOMEM;
                goto out;
        }
@@ -798,7 +800,7 @@ out:
        case 2:
                cl_device_fini(&ed->ed_cl);
        case 1:
-               OBD_FREE_PTR(ed);
+               kfree(ed);
        case 0:
        default:
                break;
@@ -895,7 +897,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
        LASSERT(ed->ed_site == lu2cl_site(d->ld_site));
        echo_site_fini(env, ed);
        cl_device_fini(&ed->ed_cl);
-       OBD_FREE_PTR(ed);
+       kfree(ed);
 
        return NULL;
 }
@@ -919,6 +921,7 @@ static struct lu_device_type echo_device_type = {
        .ldt_ops      = &echo_device_type_ops,
        .ldt_ctx_tags = LCT_CL_THREAD,
 };
+
 /** @} echo_init */
 
 /** \defgroup echo_exports Exported operations
@@ -1202,7 +1205,6 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset,
                goto out;
        LASSERT(rc == 0);
 
-
        rc = cl_echo_enqueue0(env, eco, offset,
                              offset + npages * PAGE_CACHE_SIZE - 1,
                              rw == READ ? LCK_PR : LCK_PW, &lh.cookie,
@@ -1259,8 +1261,8 @@ out:
        cl_env_put(env, &refcheck);
        return rc;
 }
-/** @} echo_exports */
 
+/** @} echo_exports */
 
 static u64 last_object_id;
 
@@ -1268,6 +1270,7 @@ static int
 echo_copyout_lsm(struct lov_stripe_md *lsm, void *_ulsm, int ulsm_nob)
 {
        struct lov_stripe_md *ulsm = _ulsm;
+       struct lov_oinfo **p;
        int nob, i;
 
        nob = offsetof(struct lov_stripe_md, lsm_oinfo[lsm->lsm_stripe_count]);
@@ -1277,9 +1280,10 @@ echo_copyout_lsm(struct lov_stripe_md *lsm, void *_ulsm, int ulsm_nob)
        if (copy_to_user(ulsm, lsm, sizeof(*ulsm)))
                return -EFAULT;
 
-       for (i = 0; i < lsm->lsm_stripe_count; i++) {
-               if (copy_to_user(ulsm->lsm_oinfo[i], lsm->lsm_oinfo[i],
-                                     sizeof(lsm->lsm_oinfo[0])))
+       for (i = 0, p = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++, p++) {
+               struct lov_oinfo __user *up;
+               if (get_user(up, ulsm->lsm_oinfo + i) ||
+                   copy_to_user(up, *p, sizeof(struct lov_oinfo)))
                        return -EFAULT;
        }
        return 0;
@@ -1287,9 +1291,10 @@ echo_copyout_lsm(struct lov_stripe_md *lsm, void *_ulsm, int ulsm_nob)
 
 static int
 echo_copyin_lsm(struct echo_device *ed, struct lov_stripe_md *lsm,
-                void *ulsm, int ulsm_nob)
+               struct lov_stripe_md __user *ulsm, int ulsm_nob)
 {
        struct echo_client_obd *ec = ed->ed_ec;
+       struct lov_oinfo **p;
        int                  i;
 
        if (ulsm_nob < sizeof(*lsm))
@@ -1304,12 +1309,10 @@ echo_copyin_lsm(struct echo_device *ed, struct lov_stripe_md *lsm,
            ((__u64)lsm->lsm_stripe_size * lsm->lsm_stripe_count > ~0UL))
                return -EINVAL;
 
-
-       for (i = 0; i < lsm->lsm_stripe_count; i++) {
-               if (copy_from_user(lsm->lsm_oinfo[i],
-                                      ((struct lov_stripe_md *)ulsm)-> \
-                                      lsm_oinfo[i],
-                                      sizeof(lsm->lsm_oinfo[0])))
+       for (i = 0, p = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++, p++) {
+               struct lov_oinfo __user *up;
+               if (get_user(up, ulsm->lsm_oinfo + i) ||
+                   copy_from_user(*p, up, sizeof(struct lov_oinfo)))
                        return -EFAULT;
        }
        return 0;
@@ -1400,7 +1403,7 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
 
  failed:
        if (created && rc)
-               obd_destroy(env, ec->ec_exp, oa, lsm, oti, NULL, NULL);
+               obd_destroy(env, ec->ec_exp, oa, lsm, oti, NULL);
        if (lsm)
                echo_free_memmd(ed, &lsm);
        if (rc)
@@ -1561,7 +1564,7 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                  (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
                  (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
 
-       gfp_mask = ((ostid_id(&oa->o_oi) & 2) == 0) ? GFP_IOFS : GFP_HIGHUSER;
+       gfp_mask = ((ostid_id(&oa->o_oi) & 2) == 0) ? GFP_KERNEL : GFP_HIGHUSER;
 
        LASSERT(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ);
        LASSERT(lsm != NULL);
@@ -1577,13 +1580,13 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
        if (rw == OBD_BRW_WRITE)
                brw_flags = OBD_BRW_ASYNC;
 
-       OBD_ALLOC(pga, npages * sizeof(*pga));
+       pga = kcalloc(npages, sizeof(*pga), GFP_NOFS);
        if (pga == NULL)
                return -ENOMEM;
 
-       OBD_ALLOC(pages, npages * sizeof(*pages));
+       pages = kcalloc(npages, sizeof(*pages), GFP_NOFS);
        if (pages == NULL) {
-               OBD_FREE(pga, npages * sizeof(*pga));
+               kfree(pga);
                return -ENOMEM;
        }
 
@@ -1594,7 +1597,7 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                LASSERT(pgp->pg == NULL);      /* for cleanup */
 
                rc = -ENOMEM;
-               OBD_PAGE_ALLOC(pgp->pg, gfp_mask);
+               pgp->pg = alloc_page(gfp_mask);
                if (pgp->pg == NULL)
                        goto out;
 
@@ -1630,10 +1633,10 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                        if (vrc != 0 && rc == 0)
                                rc = vrc;
                }
-               OBD_PAGE_FREE(pgp->pg);
+               __free_page(pgp->pg);
        }
-       OBD_FREE(pga, npages * sizeof(*pga));
-       OBD_FREE(pages, npages * sizeof(*pages));
+       kfree(pga);
+       kfree(pages);
        return rc;
 }
 
@@ -1659,8 +1662,8 @@ static int echo_client_prep_commit(const struct lu_env *env,
        npages = batch >> PAGE_CACHE_SHIFT;
        tot_pages = count >> PAGE_CACHE_SHIFT;
 
-       OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local));
-       OBD_ALLOC(rnb, npages * sizeof(struct niobuf_remote));
+       lnb = kcalloc(npages, sizeof(struct niobuf_local), GFP_NOFS);
+       rnb = kcalloc(npages, sizeof(struct niobuf_remote), GFP_NOFS);
 
        if (lnb == NULL || rnb == NULL) {
                ret = -ENOMEM;
@@ -1691,7 +1694,7 @@ static int echo_client_prep_commit(const struct lu_env *env,
 
                lpages = npages;
                ret = obd_preprw(env, rw, exp, oa, 1, &ioo, rnb, &lpages,
-                                lnb, oti, NULL);
+                                lnb, oti);
                if (ret != 0)
                        goto out;
                LASSERT(lpages == npages);
@@ -1737,10 +1740,8 @@ static int echo_client_prep_commit(const struct lu_env *env,
        }
 
 out:
-       if (lnb)
-               OBD_FREE(lnb, npages * sizeof(struct niobuf_local));
-       if (rnb)
-               OBD_FREE(rnb, npages * sizeof(struct niobuf_remote));
+       kfree(lnb);
+       kfree(rnb);
        return ret;
 }
 
@@ -1879,8 +1880,8 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
        if (rc < 0)
                return rc;
 
-       OBD_ALLOC_PTR(env);
-       if (env == NULL)
+       env = kzalloc(sizeof(*env), GFP_NOFS);
+       if (!env)
                return -ENOMEM;
 
        rc = lu_env_init(env, LCT_DT_THREAD);
@@ -1909,7 +1910,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                rc = echo_get_object(&eco, ed, oa);
                if (rc == 0) {
                        rc = obd_destroy(env, ec->ec_exp, oa, eco->eo_lsm,
-                                        &dummy_oti, NULL, NULL);
+                                        &dummy_oti, NULL);
                        if (rc == 0)
                                eco->eo_deleted = 1;
                        echo_put_object(eco);
@@ -1919,7 +1920,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
        case OBD_IOC_GETATTR:
                rc = echo_get_object(&eco, ed, oa);
                if (rc == 0) {
-                       struct obd_info oinfo = { { { 0 } } };
+                       struct obd_info oinfo = { };
 
                        oinfo.oi_md = eco->eo_lsm;
                        oinfo.oi_oa = oa;
@@ -1936,7 +1937,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
                rc = echo_get_object(&eco, ed, oa);
                if (rc == 0) {
-                       struct obd_info oinfo = { { { 0 } } };
+                       struct obd_info oinfo = { };
 
                        oinfo.oi_oa = oa;
                        oinfo.oi_md = eco->eo_lsm;
@@ -2010,7 +2011,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
 out:
        lu_env_fini(env);
-       OBD_FREE_PTR(env);
+       kfree(env);
 
        /* XXX this should be in a helper also called by target_send_reply */
        for (ack_lock = dummy_oti.oti_ack_locks, i = 0; i < 4;
@@ -2050,8 +2051,8 @@ static int echo_client_setup(const struct lu_env *env,
        ec->ec_unique = 0;
        ec->ec_nstripes = 0;
 
-       OBD_ALLOC(ocd, sizeof(*ocd));
-       if (ocd == NULL) {
+       ocd = kzalloc(sizeof(*ocd), GFP_NOFS);
+       if (!ocd) {
                CERROR("Can't alloc ocd connecting to %s\n",
                       lustre_cfg_string(lcfg, 1));
                return -ENOMEM;
@@ -2067,14 +2068,8 @@ static int echo_client_setup(const struct lu_env *env,
        ocd->ocd_group = FID_SEQ_ECHO;
 
        rc = obd_connect(env, &ec->ec_exp, tgt, &echo_uuid, ocd, NULL);
-       if (rc == 0) {
-               /* Turn off pinger because it connects to tgt obd directly. */
-               spin_lock(&tgt->obd_dev_lock);
-               list_del_init(&ec->ec_exp->exp_obd_chain_timed);
-               spin_unlock(&tgt->obd_dev_lock);
-       }
 
-       OBD_FREE(ocd, sizeof(*ocd));
+       kfree(ocd);
 
        if (rc != 0) {
                CERROR("fail to connect to device %s\n",
@@ -2141,17 +2136,13 @@ static struct obd_ops echo_client_obd_ops = {
        .o_disconnect  = echo_client_disconnect
 };
 
-int echo_client_init(void)
+static int echo_client_init(void)
 {
-       struct lprocfs_static_vars lvars = { NULL };
        int rc;
 
-       lprocfs_echo_init_vars(&lvars);
-
        rc = lu_kmem_init(echo_caches);
        if (rc == 0) {
                rc = class_register_type(&echo_client_obd_ops, NULL,
-                                        lvars.module_vars,
                                         LUSTRE_ECHO_CLIENT_NAME,
                                         &echo_device_type);
                if (rc)
@@ -2160,7 +2151,7 @@ int echo_client_init(void)
        return rc;
 }
 
-void echo_client_exit(void)
+static void echo_client_exit(void)
 {
        class_unregister_type(LUSTRE_ECHO_CLIENT_NAME);
        lu_kmem_fini(echo_caches);
@@ -2168,15 +2159,10 @@ void echo_client_exit(void)
 
 static int __init obdecho_init(void)
 {
-       struct lprocfs_static_vars lvars;
-
        LCONSOLE_INFO("Echo OBD driver; http://www.lustre.org/\n");
 
        LASSERT(PAGE_CACHE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
 
-       lprocfs_echo_init_vars(&lvars);
-
-
        return echo_client_init();
 }