blob: 7cd24bccd4fe56aab54db611c4587a8bdc51a7e8 [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{
David Teiglande7fd4172006-01-18 09:30:29 +000024 lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
Paul Mundt20c2df82007-07-20 10:11:58 +090025 __alignof__(struct dlm_lkb), 0, NULL);
David Teiglande7fd4172006-01-18 09:30:29 +000026 if (!lkb_cache)
Dan Carpenter75af271e2012-05-15 11:58:12 +030027 return -ENOMEM;
David Teigland3881ac02011-07-07 14:05:03 -050028
29 rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
30 __alignof__(struct dlm_rsb), 0, NULL);
31 if (!rsb_cache) {
32 kmem_cache_destroy(lkb_cache);
Dan Carpenter75af271e2012-05-15 11:58:12 +030033 return -ENOMEM;
David Teigland3881ac02011-07-07 14:05:03 -050034 }
35
Dan Carpenter75af271e2012-05-15 11:58:12 +030036 return 0;
David Teiglande7fd4172006-01-18 09:30:29 +000037}
38
39void dlm_memory_exit(void)
40{
41 if (lkb_cache)
42 kmem_cache_destroy(lkb_cache);
David Teigland3881ac02011-07-07 14:05:03 -050043 if (rsb_cache)
44 kmem_cache_destroy(rsb_cache);
David Teiglande7fd4172006-01-18 09:30:29 +000045}
46
David Teigland52bda2b2007-11-07 09:06:49 -060047char *dlm_allocate_lvb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000048{
49 char *p;
50
David Teigland573c24c2009-11-30 16:34:43 -060051 p = kzalloc(ls->ls_lvblen, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000052 return p;
53}
54
David Teigland52bda2b2007-11-07 09:06:49 -060055void dlm_free_lvb(char *p)
David Teiglande7fd4172006-01-18 09:30:29 +000056{
57 kfree(p);
58}
59
David Teigland3881ac02011-07-07 14:05:03 -050060struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000061{
62 struct dlm_rsb *r;
63
David Teigland3881ac02011-07-07 14:05:03 -050064 r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000065 return r;
66}
67
David Teigland52bda2b2007-11-07 09:06:49 -060068void dlm_free_rsb(struct dlm_rsb *r)
David Teiglande7fd4172006-01-18 09:30:29 +000069{
70 if (r->res_lvbptr)
David Teigland52bda2b2007-11-07 09:06:49 -060071 dlm_free_lvb(r->res_lvbptr);
David Teigland3881ac02011-07-07 14:05:03 -050072 kmem_cache_free(rsb_cache, r);
David Teiglande7fd4172006-01-18 09:30:29 +000073}
74
David Teigland52bda2b2007-11-07 09:06:49 -060075struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000076{
77 struct dlm_lkb *lkb;
78
David Teigland573c24c2009-11-30 16:34:43 -060079 lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000080 return lkb;
81}
82
David Teigland52bda2b2007-11-07 09:06:49 -060083void dlm_free_lkb(struct dlm_lkb *lkb)
David Teiglande7fd4172006-01-18 09:30:29 +000084{
David Teigland597d0ca2006-07-12 16:44:04 -050085 if (lkb->lkb_flags & DLM_IFL_USER) {
86 struct dlm_user_args *ua;
David Teiglandd292c0c2008-02-06 23:27:04 -060087 ua = lkb->lkb_ua;
David Teigland597d0ca2006-07-12 16:44:04 -050088 if (ua) {
89 if (ua->lksb.sb_lvbptr)
90 kfree(ua->lksb.sb_lvbptr);
91 kfree(ua);
92 }
93 }
David Teiglande7fd4172006-01-18 09:30:29 +000094 kmem_cache_free(lkb_cache, lkb);
95}
96