Whamcloud - gitweb
lu_kmem_descr and its companion interface allow to create and destroy a number
authornikita <nikita>
Sat, 18 Oct 2008 17:20:41 +0000 (17:20 +0000)
committernikita <nikita>
Sat, 18 Oct 2008 17:20:41 +0000 (17:20 +0000)
of kmem caches at once.
b=16450

lustre/ChangeLog
lustre/include/lu_object.h
lustre/obdclass/lu_object.c

index ba2f2f2..8f7debb 100644 (file)
@@ -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>
index 138c586..64384b7 100644 (file)
@@ -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 */
index 5077327..1a36993 100644 (file)
@@ -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);
+