blob: 37be29f21d04df27c08840b6c7b45346834c006d [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{
Wen Yang4aec7a72018-11-28 15:25:00 +080041 kmem_cache_destroy(lkb_cache);
42 kmem_cache_destroy(rsb_cache);
David Teiglande7fd4172006-01-18 09:30:29 +000043}
44
David Teigland52bda2b2007-11-07 09:06:49 -060045char *dlm_allocate_lvb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000046{
47 char *p;
48
David Teigland573c24c2009-11-30 16:34:43 -060049 p = kzalloc(ls->ls_lvblen, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000050 return p;
51}
52
David Teigland52bda2b2007-11-07 09:06:49 -060053void dlm_free_lvb(char *p)
David Teiglande7fd4172006-01-18 09:30:29 +000054{
55 kfree(p);
56}
57
David Teigland3881ac02011-07-07 14:05:03 -050058struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000059{
60 struct dlm_rsb *r;
61
David Teigland3881ac02011-07-07 14:05:03 -050062 r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000063 return r;
64}
65
David Teigland52bda2b2007-11-07 09:06:49 -060066void dlm_free_rsb(struct dlm_rsb *r)
David Teiglande7fd4172006-01-18 09:30:29 +000067{
68 if (r->res_lvbptr)
David Teigland52bda2b2007-11-07 09:06:49 -060069 dlm_free_lvb(r->res_lvbptr);
David Teigland3881ac02011-07-07 14:05:03 -050070 kmem_cache_free(rsb_cache, r);
David Teiglande7fd4172006-01-18 09:30:29 +000071}
72
David Teigland52bda2b2007-11-07 09:06:49 -060073struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000074{
75 struct dlm_lkb *lkb;
76
David Teigland573c24c2009-11-30 16:34:43 -060077 lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000078 return lkb;
79}
80
David Teigland52bda2b2007-11-07 09:06:49 -060081void dlm_free_lkb(struct dlm_lkb *lkb)
David Teiglande7fd4172006-01-18 09:30:29 +000082{
David Teigland597d0ca2006-07-12 16:44:04 -050083 if (lkb->lkb_flags & DLM_IFL_USER) {
84 struct dlm_user_args *ua;
David Teiglandd292c0c2008-02-06 23:27:04 -060085 ua = lkb->lkb_ua;
David Teigland597d0ca2006-07-12 16:44:04 -050086 if (ua) {
Wen Yang4aec7a72018-11-28 15:25:00 +080087 kfree(ua->lksb.sb_lvbptr);
David Teigland597d0ca2006-07-12 16:44:04 -050088 kfree(ua);
89 }
90 }
David Teiglande7fd4172006-01-18 09:30:29 +000091 kmem_cache_free(lkb_cache, lkb);
92}
93