1
2
3
4
5
6
7
8
9
10
11
12
13
14#include "dlm_internal.h"
15#include "config.h"
16#include "memory.h"
17
18static struct kmem_cache *lkb_cache;
19
20
21int __init dlm_memory_init(void)
22{
23 int ret = 0;
24
25 lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
26 __alignof__(struct dlm_lkb), 0, NULL);
27 if (!lkb_cache)
28 ret = -ENOMEM;
29 return ret;
30}
31
32void dlm_memory_exit(void)
33{
34 if (lkb_cache)
35 kmem_cache_destroy(lkb_cache);
36}
37
38char *dlm_allocate_lvb(struct dlm_ls *ls)
39{
40 char *p;
41
42 p = kzalloc(ls->ls_lvblen, GFP_NOFS);
43 return p;
44}
45
46void dlm_free_lvb(char *p)
47{
48 kfree(p);
49}
50
51
52
53
54struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls, int namelen)
55{
56 struct dlm_rsb *r;
57
58 DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,);
59
60 r = kzalloc(sizeof(*r) + namelen, GFP_NOFS);
61 return r;
62}
63
64void dlm_free_rsb(struct dlm_rsb *r)
65{
66 if (r->res_lvbptr)
67 dlm_free_lvb(r->res_lvbptr);
68 kfree(r);
69}
70
71struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
72{
73 struct dlm_lkb *lkb;
74
75 lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
76 return lkb;
77}
78
79void dlm_free_lkb(struct dlm_lkb *lkb)
80{
81 if (lkb->lkb_flags & DLM_IFL_USER) {
82 struct dlm_user_args *ua;
83 ua = lkb->lkb_ua;
84 if (ua) {
85 if (ua->lksb.sb_lvbptr)
86 kfree(ua->lksb.sb_lvbptr);
87 kfree(ua);
88 }
89 }
90 kmem_cache_free(lkb_cache, lkb);
91}
92
93