aboutsummaryrefslogtreecommitdiffstats
path: root/fs/dlm/memory.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2006-01-18 04:30:29 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2006-01-18 04:30:29 -0500
commite7fd41792fc0ee52a05fcaac87511f118328d147 (patch)
treeeee5227088ba97daef795e385b7548d2a1cc4cb6 /fs/dlm/memory.c
parente47314207032cfd1157b8c377df162839b32ea6f (diff)
[DLM] The core of the DLM for GFS2/CLVM
This is the core of the distributed lock manager which is required to use GFS2 as a cluster filesystem. It is also used by CLVM and can be used as a standalone lock manager independantly of either of these two projects. It implements VAX-style locking modes. Signed-off-by: David Teigland <teigland@redhat.com> Signed-off-by: Steve Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/dlm/memory.c')
-rw-r--r--fs/dlm/memory.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c
new file mode 100644
index 000000000000..0b9851d0bdb2
--- /dev/null
+++ b/fs/dlm/memory.c
@@ -0,0 +1,122 @@
1/******************************************************************************
2*******************************************************************************
3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
6**
7** This copyrighted material is made available to anyone wishing to use,
8** modify, copy, or redistribute it subject to the terms and conditions
9** of the GNU General Public License v.2.
10**
11*******************************************************************************
12******************************************************************************/
13
14#include "dlm_internal.h"
15#include "config.h"
16#include "memory.h"
17
18static kmem_cache_t *lkb_cache;
19
20
21int 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, 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 *allocate_lvb(struct dlm_ls *ls)
39{
40 char *p;
41
42 p = kmalloc(ls->ls_lvblen, GFP_KERNEL);
43 if (p)
44 memset(p, 0, ls->ls_lvblen);
45 return p;
46}
47
48void free_lvb(char *p)
49{
50 kfree(p);
51}
52
53uint64_t *allocate_range(struct dlm_ls *ls)
54{
55 int ralen = 4*sizeof(uint64_t);
56 uint64_t *p;
57
58 p = kmalloc(ralen, GFP_KERNEL);
59 if (p)
60 memset(p, 0, ralen);
61 return p;
62}
63
64void free_range(uint64_t *p)
65{
66 kfree(p);
67}
68
69/* FIXME: have some minimal space built-in to rsb for the name and
70 kmalloc a separate name if needed, like dentries are done */
71
72struct dlm_rsb *allocate_rsb(struct dlm_ls *ls, int namelen)
73{
74 struct dlm_rsb *r;
75
76 DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,);
77
78 r = kmalloc(sizeof(*r) + namelen, GFP_KERNEL);
79 if (r)
80 memset(r, 0, sizeof(*r) + namelen);
81 return r;
82}
83
84void free_rsb(struct dlm_rsb *r)
85{
86 if (r->res_lvbptr)
87 free_lvb(r->res_lvbptr);
88 kfree(r);
89}
90
91struct dlm_lkb *allocate_lkb(struct dlm_ls *ls)
92{
93 struct dlm_lkb *lkb;
94
95 lkb = kmem_cache_alloc(lkb_cache, GFP_KERNEL);
96 if (lkb)
97 memset(lkb, 0, sizeof(*lkb));
98 return lkb;
99}
100
101void free_lkb(struct dlm_lkb *lkb)
102{
103 kmem_cache_free(lkb_cache, lkb);
104}
105
106struct dlm_direntry *allocate_direntry(struct dlm_ls *ls, int namelen)
107{
108 struct dlm_direntry *de;
109
110 DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,);
111
112 de = kmalloc(sizeof(*de) + namelen, GFP_KERNEL);
113 if (de)
114 memset(de, 0, sizeof(*de) + namelen);
115 return de;
116}
117
118void free_direntry(struct dlm_direntry *de)
119{
120 kfree(de);
121}
122