-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
*
* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2016, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include "lov_cl_internal.h"
-cfs_mem_cache_t *lov_page_kmem;
-cfs_mem_cache_t *lov_lock_kmem;
-cfs_mem_cache_t *lov_object_kmem;
-cfs_mem_cache_t *lov_thread_kmem;
-cfs_mem_cache_t *lov_session_kmem;
-cfs_mem_cache_t *lov_req_kmem;
+struct kmem_cache *lov_lock_kmem;
+struct kmem_cache *lov_object_kmem;
+struct kmem_cache *lov_thread_kmem;
+struct kmem_cache *lov_session_kmem;
-cfs_mem_cache_t *lovsub_page_kmem;
-cfs_mem_cache_t *lovsub_lock_kmem;
-cfs_mem_cache_t *lovsub_object_kmem;
-cfs_mem_cache_t *lovsub_req_kmem;
-
-cfs_mem_cache_t *lov_lock_link_kmem;
-
-/** Lock class of lov_device::ld_mutex. */
-struct lock_class_key cl_lov_device_mutex_class;
+struct kmem_cache *lovsub_lock_kmem;
+struct kmem_cache *lovsub_object_kmem;
struct lu_kmem_descr lov_caches[] = {
{
- .ckd_cache = &lov_page_kmem,
- .ckd_name = "lov_page_kmem",
- .ckd_size = sizeof (struct lov_page)
- },
- {
.ckd_cache = &lov_lock_kmem,
.ckd_name = "lov_lock_kmem",
.ckd_size = sizeof (struct lov_lock)
.ckd_size = sizeof (struct lov_session)
},
{
- .ckd_cache = &lov_req_kmem,
- .ckd_name = "lov_req_kmem",
- .ckd_size = sizeof (struct lov_req)
- },
- {
- .ckd_cache = &lovsub_page_kmem,
- .ckd_name = "lovsub_page_kmem",
- .ckd_size = sizeof (struct lovsub_page)
- },
- {
.ckd_cache = &lovsub_lock_kmem,
.ckd_name = "lovsub_lock_kmem",
.ckd_size = sizeof (struct lovsub_lock)
.ckd_size = sizeof (struct lovsub_object)
},
{
- .ckd_cache = &lovsub_req_kmem,
- .ckd_name = "lovsub_req_kmem",
- .ckd_size = sizeof (struct lovsub_req)
- },
- {
- .ckd_cache = &lov_lock_link_kmem,
- .ckd_name = "lov_lock_link_kmem",
- .ckd_size = sizeof (struct lov_lock_link)
- },
- {
.ckd_cache = NULL
}
};
/*****************************************************************************
*
- * Lov transfer operations.
- *
- */
-
-static void lov_req_completion(const struct lu_env *env,
- const struct cl_req_slice *slice, int ioret)
-{
- struct lov_req *lr;
-
- ENTRY;
- lr = cl2lov_req(slice);
- OBD_SLAB_FREE_PTR(lr, lov_req_kmem);
- EXIT;
-}
-
-static const struct cl_req_operations lov_req_ops = {
- .cro_completion = lov_req_completion
-};
-
-/*****************************************************************************
- *
* Lov device and device type functions.
*
*/
static void *lov_key_init(const struct lu_context *ctx,
- struct lu_context_key *key)
+ struct lu_context_key *key)
{
- struct lov_thread_info *info;
+ struct lov_thread_info *info;
- OBD_SLAB_ALLOC_PTR_GFP(info, lov_thread_kmem, CFS_ALLOC_IO);
- if (info != NULL)
- CFS_INIT_LIST_HEAD(&info->lti_closure.clc_list);
- else
- info = ERR_PTR(-ENOMEM);
- return info;
+ OBD_SLAB_ALLOC_PTR_GFP(info, lov_thread_kmem, GFP_NOFS);
+ if (info == NULL)
+ info = ERR_PTR(-ENOMEM);
+ return info;
}
static void lov_key_fini(const struct lu_context *ctx,
- struct lu_context_key *key, void *data)
+ struct lu_context_key *key, void *data)
{
- struct lov_thread_info *info = data;
- LINVRNT(list_empty(&info->lti_closure.clc_list));
- OBD_SLAB_FREE_PTR(info, lov_thread_kmem);
+ struct lov_thread_info *info = data;
+ OBD_SLAB_FREE_PTR(info, lov_thread_kmem);
}
struct lu_context_key lov_key = {
};
static void *lov_session_key_init(const struct lu_context *ctx,
- struct lu_context_key *key)
+ struct lu_context_key *key)
{
- struct lov_session *info;
+ struct lov_session *info;
- OBD_SLAB_ALLOC_PTR_GFP(info, lov_session_kmem, CFS_ALLOC_IO);
- if (info == NULL)
- info = ERR_PTR(-ENOMEM);
- return info;
+ OBD_SLAB_ALLOC_PTR_GFP(info, lov_session_kmem, GFP_NOFS);
+ if (info == NULL)
+ info = ERR_PTR(-ENOMEM);
+ return info;
}
static void lov_session_key_fini(const struct lu_context *ctx,
break;
}
lsd = cl2lovsub_dev(cl);
- lsd->acid_idx = i;
- lsd->acid_super = ld;
ld->ld_target[i] = lsd;
}
RETURN(rc);
}
-static int lov_req_init(const struct lu_env *env, struct cl_device *dev,
- struct cl_req *req)
-{
- struct lov_req *lr;
- int result;
-
- ENTRY;
- OBD_SLAB_ALLOC_PTR_GFP(lr, lov_req_kmem, CFS_ALLOC_IO);
- if (lr != NULL) {
- cl_req_slice_add(req, &lr->lr_cl, dev, &lov_req_ops);
- result = 0;
- } else
- result = -ENOMEM;
- RETURN(result);
-}
-
-static const struct cl_device_operations lov_cl_ops = {
- .cdo_req_init = lov_req_init
-};
-
-static void lov_emerg_free(struct lov_device_emerg **emrg, int nr)
-{
- int i;
-
- for (i = 0; i < nr; ++i) {
- struct lov_device_emerg *em;
-
- em = emrg[i];
- if (em != NULL) {
- LASSERT(em->emrg_page_list.pl_nr == 0);
- if (em->emrg_env != NULL)
- cl_env_put(em->emrg_env, &em->emrg_refcheck);
- OBD_FREE_PTR(em);
- }
- }
- OBD_FREE(emrg, nr * sizeof emrg[0]);
-}
-
+/* Free the lov specific data created for the back end lu_device. */
static struct lu_device *lov_device_free(const struct lu_env *env,
struct lu_device *d)
{
- struct lov_device *ld = lu2lov_dev(d);
- const int nr = ld->ld_target_nr;
-
- cl_device_fini(lu2cl_dev(d));
- if (ld->ld_target != NULL)
- OBD_FREE(ld->ld_target, nr * sizeof ld->ld_target[0]);
- if (ld->ld_emrg != NULL)
- lov_emerg_free(ld->ld_emrg, nr);
- OBD_FREE_PTR(ld);
- return NULL;
+ struct lov_device *ld = lu2lov_dev(d);
+ const int nr = ld->ld_target_nr;
+
+ cl_device_fini(lu2cl_dev(d));
+ if (ld->ld_target != NULL)
+ OBD_FREE(ld->ld_target, nr * sizeof ld->ld_target[0]);
+
+ OBD_FREE_PTR(ld);
+ return NULL;
}
static void lov_cl_del_target(const struct lu_env *env, struct lu_device *dev,
EXIT;
}
-static struct lov_device_emerg **lov_emerg_alloc(int nr)
-{
- struct lov_device_emerg **emerg;
- int i;
- int result;
-
- OBD_ALLOC(emerg, nr * sizeof emerg[0]);
- if (emerg == NULL)
- return ERR_PTR(-ENOMEM);
- for (result = i = 0; i < nr && result == 0; i++) {
- struct lov_device_emerg *em;
- void *cookie;
-
- OBD_ALLOC_PTR(em);
- if (em != NULL) {
- emerg[i] = em;
- cl_page_list_init(&em->emrg_page_list);
- cookie = cl_env_reenter();
- em->emrg_env = cl_env_alloc(&em->emrg_refcheck,
- LCT_REMEMBER|LCT_NOREF);
- cl_env_reexit(cookie);
- if (!IS_ERR(em->emrg_env))
- em->emrg_env->le_ctx.lc_cookie = 0x2;
- else {
- result = PTR_ERR(em->emrg_env);
- em->emrg_env = NULL;
- }
- } else
- result = -ENOMEM;
- }
- if (result != 0) {
- lov_emerg_free(emerg, nr);
- emerg = ERR_PTR(result);
- }
- return emerg;
-}
-
static int lov_expand_targets(const struct lu_env *env, struct lov_device *dev)
{
- int result;
- __u32 tgt_size;
- __u32 sub_size;
-
- ENTRY;
- result = 0;
- tgt_size = dev->ld_lov->lov_tgt_size;
- sub_size = dev->ld_target_nr;
- if (sub_size < tgt_size) {
- struct lovsub_device **newd;
- struct lov_device_emerg **emerg;
- const size_t sz = sizeof newd[0];
-
- emerg = lov_emerg_alloc(tgt_size);
- if (IS_ERR(emerg))
- RETURN(PTR_ERR(emerg));
-
- OBD_ALLOC(newd, tgt_size * sz);
- if (newd != NULL) {
- mutex_lock(&dev->ld_mutex);
- if (sub_size > 0) {
- memcpy(newd, dev->ld_target, sub_size * sz);
- OBD_FREE(dev->ld_target, sub_size * sz);
- }
- dev->ld_target = newd;
- dev->ld_target_nr = tgt_size;
-
- if (dev->ld_emrg != NULL)
- lov_emerg_free(dev->ld_emrg, sub_size);
- dev->ld_emrg = emerg;
- mutex_unlock(&dev->ld_mutex);
- } else {
- lov_emerg_free(emerg, tgt_size);
- result = -ENOMEM;
- }
- }
- RETURN(result);
+ int result;
+ __u32 tgt_size;
+ __u32 sub_size;
+
+ ENTRY;
+ result = 0;
+ tgt_size = dev->ld_lov->lov_tgt_size;
+ sub_size = dev->ld_target_nr;
+ if (sub_size < tgt_size) {
+ struct lovsub_device **newd;
+ const size_t sz = sizeof(newd[0]);
+
+ OBD_ALLOC(newd, tgt_size * sz);
+ if (newd != NULL) {
+ if (sub_size > 0) {
+ memcpy(newd, dev->ld_target, sub_size * sz);
+ OBD_FREE(dev->ld_target, sub_size * sz);
+ }
+
+ dev->ld_target = newd;
+ dev->ld_target_nr = tgt_size;
+ } else {
+ result = -ENOMEM;
+ }
+ }
+
+ RETURN(result);
}
static int lov_cl_add_target(const struct lu_env *env, struct lu_device *dev,
int rc;
ENTRY;
- lov_getref(obd);
+ obd_getref(obd);
tgt = obd->u.lov.lov_tgts[index];
LASSERT(tgt != NULL);
if (rc == 0 && ld->ld_flags & LOV_DEV_INITIALIZED) {
LASSERT(dev->ld_site != NULL);
- cl = cl_type_setup(env, dev->ld_site, &lovsub_device_type,
- tgt->ltd_obd->obd_lu_dev);
- if (!IS_ERR(cl)) {
- lsd = cl2lovsub_dev(cl);
- lsd->acid_idx = index;
- lsd->acid_super = ld;
- ld->ld_target[index] = lsd;
- } else {
- CERROR("add failed (%d), deleting %s\n", rc,
- obd_uuid2str(&tgt->ltd_uuid));
- lov_cl_del_target(env, dev, index);
- rc = PTR_ERR(cl);
- }
+ cl = cl_type_setup(env, dev->ld_site, &lovsub_device_type,
+ tgt->ltd_obd->obd_lu_dev);
+ if (!IS_ERR(cl)) {
+ lsd = cl2lovsub_dev(cl);
+ ld->ld_target[index] = lsd;
+ } else {
+ CERROR("add failed (%d), deleting %s\n", rc,
+ obd_uuid2str(&tgt->ltd_uuid));
+ lov_cl_del_target(env, dev, index);
+ rc = PTR_ERR(cl);
+ }
}
- lov_putref(obd);
+ obd_putref(obd);
RETURN(rc);
}
int gen;
__u32 index;
- lov_getref(obd);
+ obd_getref(obd);
cmd = cfg->lcfg_command;
rc = lov_process_config_base(d->ld_obd, cfg, &index, &gen);
case LCFG_LOV_ADD_INA:
rc = lov_cl_add_target(env, d, index);
if (rc != 0)
- lov_del_target(d->ld_obd, index, 0, 0);
+ lov_del_target(d->ld_obd, index, NULL, 0);
break;
case LCFG_LOV_DEL_OBD:
lov_cl_del_target(env, d, index);
break;
}
}
- lov_putref(obd);
+ obd_putref(obd);
RETURN(rc);
}
if (ld == NULL)
RETURN(ERR_PTR(-ENOMEM));
- cl_device_init(&ld->ld_cl, t);
- d = lov2lu_dev(ld);
- d->ld_ops = &lov_lu_ops;
- ld->ld_cl.cd_ops = &lov_cl_ops;
-
- mutex_init(&ld->ld_mutex);
- lockdep_set_class(&ld->ld_mutex, &cl_lov_device_mutex_class);
+ cl_device_init(&ld->ld_cl, t);
+ d = lov2lu_dev(ld);
+ d->ld_ops = &lov_lu_ops;
/* setup the LOV OBD */
obd = class_name2obd(lustre_cfg_string(cfg, 0));
.ldt_ops = &lov_device_type_ops,
.ldt_ctx_tags = LCT_CL_THREAD
};
-EXPORT_SYMBOL(lov_device_type);
/** @} lov */