blob: 5918f4d395869b61da0f8562eb2084f88b061ce0 [file] [log] [blame]
Thomas Gleixner2522fe42019-05-28 09:57:20 -07001// SPDX-License-Identifier: GPL-2.0-only
David Teiglande7fd4172006-01-18 09:30:29 +00002/******************************************************************************
3*******************************************************************************
4**
5** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
David Teigland52bda2b2007-11-07 09:06:49 -06006** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00007**
David Teiglande7fd4172006-01-18 09:30:29 +00008**
9*******************************************************************************
10******************************************************************************/
11
12#include "dlm_internal.h"
13#include "config.h"
14#include "memory.h"
15
Christoph Lametere18b8902006-12-06 20:33:20 -080016static struct kmem_cache *lkb_cache;
David Teigland3881ac02011-07-07 14:05:03 -050017static struct kmem_cache *rsb_cache;
David Teiglande7fd4172006-01-18 09:30:29 +000018
19
Denis Cheng30727172008-02-02 01:53:46 +080020int __init dlm_memory_init(void)
David Teiglande7fd4172006-01-18 09:30:29 +000021{
David Teiglande7fd4172006-01-18 09:30:29 +000022 lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
Paul Mundt20c2df82007-07-20 10:11:58 +090023 __alignof__(struct dlm_lkb), 0, NULL);
David Teiglande7fd4172006-01-18 09:30:29 +000024 if (!lkb_cache)
Dan Carpenter75af271e2012-05-15 11:58:12 +030025 return -ENOMEM;
David Teigland3881ac02011-07-07 14:05:03 -050026
27 rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
28 __alignof__(struct dlm_rsb), 0, NULL);
29 if (!rsb_cache) {
30 kmem_cache_destroy(lkb_cache);
Dan Carpenter75af271e2012-05-15 11:58:12 +030031 return -ENOMEM;
David Teigland3881ac02011-07-07 14:05:03 -050032 }
33
Dan Carpenter75af271e2012-05-15 11:58:12 +030034 return 0;
David Teiglande7fd4172006-01-18 09:30:29 +000035}
36
37void dlm_memory_exit(void)
38{
Wen Yangf31a8962018-11-28 15:25:00 +080039 kmem_cache_destroy(lkb_cache);
40 kmem_cache_destroy(rsb_cache);
David Teiglande7fd4172006-01-18 09:30:29 +000041}
42
David Teigland52bda2b2007-11-07 09:06:49 -060043char *dlm_allocate_lvb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000044{
45 char *p;
46
David Teigland573c24c2009-11-30 16:34:43 -060047 p = kzalloc(ls->ls_lvblen, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000048 return p;
49}
50
David Teigland52bda2b2007-11-07 09:06:49 -060051void dlm_free_lvb(char *p)
David Teiglande7fd4172006-01-18 09:30:29 +000052{
53 kfree(p);
54}
55
David Teigland3881ac02011-07-07 14:05:03 -050056struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000057{
58 struct dlm_rsb *r;
59
David Teigland3881ac02011-07-07 14:05:03 -050060 r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000061 return r;
62}
63
David Teigland52bda2b2007-11-07 09:06:49 -060064void dlm_free_rsb(struct dlm_rsb *r)
David Teiglande7fd4172006-01-18 09:30:29 +000065{
66 if (r->res_lvbptr)
David Teigland52bda2b2007-11-07 09:06:49 -060067 dlm_free_lvb(r->res_lvbptr);
David Teigland3881ac02011-07-07 14:05:03 -050068 kmem_cache_free(rsb_cache, r);
David Teiglande7fd4172006-01-18 09:30:29 +000069}
70
David Teigland52bda2b2007-11-07 09:06:49 -060071struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000072{
73 struct dlm_lkb *lkb;
74
David Teigland573c24c2009-11-30 16:34:43 -060075 lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000076 return lkb;
77}
78
David Teigland52bda2b2007-11-07 09:06:49 -060079void dlm_free_lkb(struct dlm_lkb *lkb)
David Teiglande7fd4172006-01-18 09:30:29 +000080{
David Teigland597d0ca2006-07-12 16:44:04 -050081 if (lkb->lkb_flags & DLM_IFL_USER) {
82 struct dlm_user_args *ua;
David Teiglandd292c0c2008-02-06 23:27:04 -060083 ua = lkb->lkb_ua;
David Teigland597d0ca2006-07-12 16:44:04 -050084 if (ua) {
Wen Yangf31a8962018-11-28 15:25:00 +080085 kfree(ua->lksb.sb_lvbptr);
David Teigland597d0ca2006-07-12 16:44:04 -050086 kfree(ua);
87 }
88 }
David Teiglande7fd4172006-01-18 09:30:29 +000089 kmem_cache_free(lkb_cache, lkb);
90}
91