Blame view
fs/dlm/memory.c
2.06 KB
e7fd41792
|
1 2 3 4 |
/****************************************************************************** ******************************************************************************* ** ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
52bda2b5b
|
5 |
** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. |
e7fd41792
|
6 7 8 9 10 11 12 13 14 15 16 |
** ** This copyrighted material is made available to anyone wishing to use, ** modify, copy, or redistribute it subject to the terms and conditions ** of the GNU General Public License v.2. ** ******************************************************************************* ******************************************************************************/ #include "dlm_internal.h" #include "config.h" #include "memory.h" |
e18b890bb
|
17 |
static struct kmem_cache *lkb_cache; |
3881ac04e
|
18 |
static struct kmem_cache *rsb_cache; |
e7fd41792
|
19 |
|
30727174b
|
20 |
int __init dlm_memory_init(void) |
e7fd41792
|
21 |
{ |
e7fd41792
|
22 |
lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb), |
20c2df83d
|
23 |
__alignof__(struct dlm_lkb), 0, NULL); |
e7fd41792
|
24 |
if (!lkb_cache) |
75af271ed
|
25 |
return -ENOMEM; |
3881ac04e
|
26 27 28 29 30 |
rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb), __alignof__(struct dlm_rsb), 0, NULL); if (!rsb_cache) { kmem_cache_destroy(lkb_cache); |
75af271ed
|
31 |
return -ENOMEM; |
3881ac04e
|
32 |
} |
75af271ed
|
33 |
return 0; |
e7fd41792
|
34 35 36 37 38 39 |
} void dlm_memory_exit(void) { if (lkb_cache) kmem_cache_destroy(lkb_cache); |
3881ac04e
|
40 41 |
if (rsb_cache) kmem_cache_destroy(rsb_cache); |
e7fd41792
|
42 |
} |
52bda2b5b
|
43 |
char *dlm_allocate_lvb(struct dlm_ls *ls) |
e7fd41792
|
44 45 |
{ char *p; |
573c24c4a
|
46 |
p = kzalloc(ls->ls_lvblen, GFP_NOFS); |
e7fd41792
|
47 48 |
return p; } |
52bda2b5b
|
49 |
void dlm_free_lvb(char *p) |
e7fd41792
|
50 51 52 |
{ kfree(p); } |
3881ac04e
|
53 |
struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls) |
e7fd41792
|
54 55 |
{ struct dlm_rsb *r; |
3881ac04e
|
56 |
r = kmem_cache_zalloc(rsb_cache, GFP_NOFS); |
e7fd41792
|
57 58 |
return r; } |
52bda2b5b
|
59 |
void dlm_free_rsb(struct dlm_rsb *r) |
e7fd41792
|
60 61 |
{ if (r->res_lvbptr) |
52bda2b5b
|
62 |
dlm_free_lvb(r->res_lvbptr); |
3881ac04e
|
63 |
kmem_cache_free(rsb_cache, r); |
e7fd41792
|
64 |
} |
52bda2b5b
|
65 |
struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls) |
e7fd41792
|
66 67 |
{ struct dlm_lkb *lkb; |
573c24c4a
|
68 |
lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS); |
e7fd41792
|
69 70 |
return lkb; } |
52bda2b5b
|
71 |
void dlm_free_lkb(struct dlm_lkb *lkb) |
e7fd41792
|
72 |
{ |
597d0cae0
|
73 74 |
if (lkb->lkb_flags & DLM_IFL_USER) { struct dlm_user_args *ua; |
d292c0cc4
|
75 |
ua = lkb->lkb_ua; |
597d0cae0
|
76 77 78 79 80 81 |
if (ua) { if (ua->lksb.sb_lvbptr) kfree(ua->lksb.sb_lvbptr); kfree(ua); } } |
e7fd41792
|
82 83 |
kmem_cache_free(lkb_cache, lkb); } |