Blame view
fs/dlm/memory.c
2.08 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 22 23 24 |
{ int ret = 0; lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb), |
20c2df83d
|
25 |
__alignof__(struct dlm_lkb), 0, NULL); |
e7fd41792
|
26 27 |
if (!lkb_cache) ret = -ENOMEM; |
3881ac04e
|
28 29 30 31 32 33 34 |
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); ret = -ENOMEM; } |
e7fd41792
|
35 36 37 38 39 40 41 |
return ret; } void dlm_memory_exit(void) { if (lkb_cache) kmem_cache_destroy(lkb_cache); |
3881ac04e
|
42 43 |
if (rsb_cache) kmem_cache_destroy(rsb_cache); |
e7fd41792
|
44 |
} |
52bda2b5b
|
45 |
char *dlm_allocate_lvb(struct dlm_ls *ls) |
e7fd41792
|
46 47 |
{ char *p; |
573c24c4a
|
48 |
p = kzalloc(ls->ls_lvblen, GFP_NOFS); |
e7fd41792
|
49 50 |
return p; } |
52bda2b5b
|
51 |
void dlm_free_lvb(char *p) |
e7fd41792
|
52 53 54 |
{ kfree(p); } |
3881ac04e
|
55 |
struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls) |
e7fd41792
|
56 57 |
{ struct dlm_rsb *r; |
3881ac04e
|
58 |
r = kmem_cache_zalloc(rsb_cache, GFP_NOFS); |
e7fd41792
|
59 60 |
return r; } |
52bda2b5b
|
61 |
void dlm_free_rsb(struct dlm_rsb *r) |
e7fd41792
|
62 63 |
{ if (r->res_lvbptr) |
52bda2b5b
|
64 |
dlm_free_lvb(r->res_lvbptr); |
3881ac04e
|
65 |
kmem_cache_free(rsb_cache, r); |
e7fd41792
|
66 |
} |
52bda2b5b
|
67 |
struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls) |
e7fd41792
|
68 69 |
{ struct dlm_lkb *lkb; |
573c24c4a
|
70 |
lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS); |
e7fd41792
|
71 72 |
return lkb; } |
52bda2b5b
|
73 |
void dlm_free_lkb(struct dlm_lkb *lkb) |
e7fd41792
|
74 |
{ |
597d0cae0
|
75 76 |
if (lkb->lkb_flags & DLM_IFL_USER) { struct dlm_user_args *ua; |
d292c0cc4
|
77 |
ua = lkb->lkb_ua; |
597d0cae0
|
78 79 80 81 82 83 |
if (ua) { if (ua->lksb.sb_lvbptr) kfree(ua->lksb.sb_lvbptr); kfree(ua); } } |
e7fd41792
|
84 85 |
kmem_cache_free(lkb_cache, lkb); } |