0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "dlm_internal.h"
0013 #include "midcomms.h"
0014 #include "lowcomms.h"
0015 #include "config.h"
0016 #include "memory.h"
0017
0018 static struct kmem_cache *writequeue_cache;
0019 static struct kmem_cache *mhandle_cache;
0020 static struct kmem_cache *msg_cache;
0021 static struct kmem_cache *lkb_cache;
0022 static struct kmem_cache *rsb_cache;
0023
0024
0025 int __init dlm_memory_init(void)
0026 {
0027 writequeue_cache = dlm_lowcomms_writequeue_cache_create();
0028 if (!writequeue_cache)
0029 goto out;
0030
0031 mhandle_cache = dlm_midcomms_cache_create();
0032 if (!mhandle_cache)
0033 goto mhandle;
0034
0035 lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
0036 __alignof__(struct dlm_lkb), 0, NULL);
0037 if (!lkb_cache)
0038 goto lkb;
0039
0040 msg_cache = dlm_lowcomms_msg_cache_create();
0041 if (!msg_cache)
0042 goto msg;
0043
0044 rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
0045 __alignof__(struct dlm_rsb), 0, NULL);
0046 if (!rsb_cache)
0047 goto rsb;
0048
0049 return 0;
0050
0051 rsb:
0052 kmem_cache_destroy(msg_cache);
0053 msg:
0054 kmem_cache_destroy(lkb_cache);
0055 lkb:
0056 kmem_cache_destroy(mhandle_cache);
0057 mhandle:
0058 kmem_cache_destroy(writequeue_cache);
0059 out:
0060 return -ENOMEM;
0061 }
0062
0063 void dlm_memory_exit(void)
0064 {
0065 kmem_cache_destroy(writequeue_cache);
0066 kmem_cache_destroy(mhandle_cache);
0067 kmem_cache_destroy(msg_cache);
0068 kmem_cache_destroy(lkb_cache);
0069 kmem_cache_destroy(rsb_cache);
0070 }
0071
0072 char *dlm_allocate_lvb(struct dlm_ls *ls)
0073 {
0074 char *p;
0075
0076 p = kzalloc(ls->ls_lvblen, GFP_NOFS);
0077 return p;
0078 }
0079
0080 void dlm_free_lvb(char *p)
0081 {
0082 kfree(p);
0083 }
0084
0085 struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
0086 {
0087 struct dlm_rsb *r;
0088
0089 r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
0090 return r;
0091 }
0092
0093 void dlm_free_rsb(struct dlm_rsb *r)
0094 {
0095 if (r->res_lvbptr)
0096 dlm_free_lvb(r->res_lvbptr);
0097 kmem_cache_free(rsb_cache, r);
0098 }
0099
0100 struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
0101 {
0102 struct dlm_lkb *lkb;
0103
0104 lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
0105 return lkb;
0106 }
0107
0108 void dlm_free_lkb(struct dlm_lkb *lkb)
0109 {
0110 if (lkb->lkb_flags & DLM_IFL_USER) {
0111 struct dlm_user_args *ua;
0112 ua = lkb->lkb_ua;
0113 if (ua) {
0114 kfree(ua->lksb.sb_lvbptr);
0115 kfree(ua);
0116 }
0117 }
0118 kmem_cache_free(lkb_cache, lkb);
0119 }
0120
0121 struct dlm_mhandle *dlm_allocate_mhandle(void)
0122 {
0123 return kmem_cache_alloc(mhandle_cache, GFP_NOFS);
0124 }
0125
0126 void dlm_free_mhandle(struct dlm_mhandle *mhandle)
0127 {
0128 kmem_cache_free(mhandle_cache, mhandle);
0129 }
0130
0131 struct writequeue_entry *dlm_allocate_writequeue(void)
0132 {
0133 return kmem_cache_alloc(writequeue_cache, GFP_ATOMIC);
0134 }
0135
0136 void dlm_free_writequeue(struct writequeue_entry *writequeue)
0137 {
0138 kmem_cache_free(writequeue_cache, writequeue);
0139 }
0140
0141 struct dlm_msg *dlm_allocate_msg(gfp_t allocation)
0142 {
0143 return kmem_cache_alloc(msg_cache, allocation);
0144 }
0145
0146 void dlm_free_msg(struct dlm_msg *msg)
0147 {
0148 kmem_cache_free(msg_cache, msg);
0149 }