diff --git a/lustre/ChangeLog b/lustre/ChangeLog index ba2f2f2d52522bd25764f2706b6c2276a4685dcb..8f7debb6563b4d90d4597a9f0f6a5fa40a31c182 100644 --- a/lustre/ChangeLog +++ b/lustre/ChangeLog @@ -1621,6 +1621,12 @@ Description: Add lu_ref support to struct lu_device. Details : Add lu_ref support to lu_object and lu_device. lu_ref is used to track leaked references. +Severity : normal +Bugzilla : 16450 +Description: Introduce lu_kmem_descr. +Details : lu_kmem_descr and its companion interface allow to create + and destroy a number of kmem caches at once. + -------------------------------------------------------------------------------- 2007-08-10 Cluster File Systems, Inc. <info@clusterfs.com> diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 138c58669a9a00d3a6a7ce1cca24b0b30ab27605..64384b79a6eb8405be3d0ee64c92a11966e26725 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -1301,4 +1301,15 @@ enum { extern const char *lu_time_names[LU_TIME_NR]; +struct lu_kmem_descr { + cfs_mem_cache_t **ckd_cache; + const char *ckd_name; + const size_t ckd_size; +}; + +int lu_kmem_init(struct lu_kmem_descr *caches); +void lu_kmem_fini(struct lu_kmem_descr *caches); + +/** @} lu */ + #endif /* __LUSTRE_LU_OBJECT_H */ diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index 5077327efe8ee2954c0a1cc2321300db00ba8e8a..1a3699370c81d64252e6c8ec17f848ad53aa5ad7 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -1529,3 +1529,43 @@ const char *lu_time_names[LU_TIME_NR] = { [LU_TIME_FIND_INSERT] = "find_insert" }; EXPORT_SYMBOL(lu_time_names); + +/** + * Helper function to initialize a number of kmem slab caches at once. + */ +int lu_kmem_init(struct lu_kmem_descr *caches) +{ + int result; + + for (result = 0; caches->ckd_cache != NULL; ++caches) { + *caches->ckd_cache = cfs_mem_cache_create(caches->ckd_name, + caches->ckd_size, + 0, 0); + if (*caches->ckd_cache == NULL) { + result = -ENOMEM; + break; + } + } + return result; +} +EXPORT_SYMBOL(lu_kmem_init); + +/** + * Helper function to finalize a number of kmem slab cached at once. Dual to + * lu_kmem_init(). + */ +void lu_kmem_fini(struct lu_kmem_descr *caches) +{ + int rc; + + for (; caches->ckd_cache != NULL; ++caches) { + if (*caches->ckd_cache != NULL) { + rc = cfs_mem_cache_destroy(*caches->ckd_cache); + LASSERTF(rc == 0, "couldn't destroy %s slab\n", + caches->ckd_name); + *caches->ckd_cache = NULL; + } + } +} +EXPORT_SYMBOL(lu_kmem_fini); +