blob: da64df7576e18f5b5386aa3d9d5dde9465bba0be [file] [log] [blame]
David Teiglande7fd4172006-01-18 09:30:29 +00001/******************************************************************************
2*******************************************************************************
3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
David Teigland52bda2b2007-11-07 09:06:49 -06005** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00006**
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
Christoph Lametere18b8902006-12-06 20:33:20 -080018static struct kmem_cache *lkb_cache;
David Teigland3881ac02011-07-07 14:05:03 -050019static struct kmem_cache *rsb_cache;
David Teiglande7fd4172006-01-18 09:30:29 +000020
21
Denis Cheng30727172008-02-02 01:53:46 +080022int __init dlm_memory_init(void)
David Teiglande7fd4172006-01-18 09:30:29 +000023{
24 int ret = 0;
25
26 lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
Paul Mundt20c2df82007-07-20 10:11:58 +090027 __alignof__(struct dlm_lkb), 0, NULL);
David Teiglande7fd4172006-01-18 09:30:29 +000028 if (!lkb_cache)
29 ret = -ENOMEM;
David Teigland3881ac02011-07-07 14:05:03 -050030
31 rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
32 __alignof__(struct dlm_rsb), 0, NULL);
33 if (!rsb_cache) {
34 kmem_cache_destroy(lkb_cache);
35 ret = -ENOMEM;
36 }
37
David Teiglande7fd4172006-01-18 09:30:29 +000038 return ret;
39}
40
41void dlm_memory_exit(void)
42{
43 if (lkb_cache)
44 kmem_cache_destroy(lkb_cache);
David Teigland3881ac02011-07-07 14:05:03 -050045 if (rsb_cache)
46 kmem_cache_destroy(rsb_cache);
David Teiglande7fd4172006-01-18 09:30:29 +000047}
48
David Teigland52bda2b2007-11-07 09:06:49 -060049char *dlm_allocate_lvb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000050{
51 char *p;
52
David Teigland573c24c2009-11-30 16:34:43 -060053 p = kzalloc(ls->ls_lvblen, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000054 return p;
55}
56
David Teigland52bda2b2007-11-07 09:06:49 -060057void dlm_free_lvb(char *p)
David Teiglande7fd4172006-01-18 09:30:29 +000058{
59 kfree(p);
60}
61
David Teigland3881ac02011-07-07 14:05:03 -050062struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000063{
64 struct dlm_rsb *r;
65
David Teigland3881ac02011-07-07 14:05:03 -050066 r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000067 return r;
68}
69
David Teigland52bda2b2007-11-07 09:06:49 -060070void dlm_free_rsb(struct dlm_rsb *r)
David Teiglande7fd4172006-01-18 09:30:29 +000071{
72 if (r->res_lvbptr)
David Teigland52bda2b2007-11-07 09:06:49 -060073 dlm_free_lvb(r->res_lvbptr);
David Teigland3881ac02011-07-07 14:05:03 -050074 kmem_cache_free(rsb_cache, r);
David Teiglande7fd4172006-01-18 09:30:29 +000075}
76
David Teigland52bda2b2007-11-07 09:06:49 -060077struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000078{
79 struct dlm_lkb *lkb;
80
David Teigland573c24c2009-11-30 16:34:43 -060081 lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000082 return lkb;
83}
84
David Teigland52bda2b2007-11-07 09:06:49 -060085void dlm_free_lkb(struct dlm_lkb *lkb)
David Teiglande7fd4172006-01-18 09:30:29 +000086{
David Teigland597d0ca2006-07-12 16:44:04 -050087 if (lkb->lkb_flags & DLM_IFL_USER) {
88 struct dlm_user_args *ua;
David Teiglandd292c0c2008-02-06 23:27:04 -060089 ua = lkb->lkb_ua;
David Teigland597d0ca2006-07-12 16:44:04 -050090 if (ua) {
91 if (ua->lksb.sb_lvbptr)
92 kfree(ua->lksb.sb_lvbptr);
93 kfree(ua);
94 }
95 }
David Teiglande7fd4172006-01-18 09:30:29 +000096 kmem_cache_free(lkb_cache, lkb);
97}
98