From: nikita Date: Sat, 18 Oct 2008 17:20:41 +0000 (+0000) Subject: lu_kmem_descr and its companion interface allow to create and destroy a number X-Git-Tag: v1_9_90~60 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=9832985e363eb68ecfa904b274adedddb93becd7;p=fs%2Flustre-release.git lu_kmem_descr and its companion interface allow to create and destroy a number of kmem caches at once. b=16450 --- diff --git a/lustre/ChangeLog b/lustre/ChangeLog index ba2f2f2..8f7debb 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. diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 138c586..64384b7 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 5077327..1a36993 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); +