Blame view

fs/dlm/memory.c 2.08 KB
e7fd41792   David Teigland   [DLM] The core of...
1
2
3
4
  /******************************************************************************
  *******************************************************************************
  **
  **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
52bda2b5b   David Teigland   dlm: use dlm pref...
5
  **  Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
e7fd41792   David Teigland   [DLM] The core of...
6
7
8
9
10
11
12
13
14
15
16
  **
  **  This copyrighted material is made available to anyone wishing to use,
  **  modify, copy, or redistribute it subject to the terms and conditions
  **  of the GNU General Public License v.2.
  **
  *******************************************************************************
  ******************************************************************************/
  
  #include "dlm_internal.h"
  #include "config.h"
  #include "memory.h"
e18b890bb   Christoph Lameter   [PATCH] slab: rem...
17
  static struct kmem_cache *lkb_cache;
3881ac04e   David Teigland   dlm: improve rsb ...
18
  static struct kmem_cache *rsb_cache;
e7fd41792   David Teigland   [DLM] The core of...
19

30727174b   Denis Cheng   dlm: add __init a...
20
  int __init dlm_memory_init(void)
e7fd41792   David Teigland   [DLM] The core of...
21
22
23
24
  {
  	int ret = 0;
  
  	lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
20c2df83d   Paul Mundt   mm: Remove slab d...
25
  				__alignof__(struct dlm_lkb), 0, NULL);
e7fd41792   David Teigland   [DLM] The core of...
26
27
  	if (!lkb_cache)
  		ret = -ENOMEM;
3881ac04e   David Teigland   dlm: improve rsb ...
28
29
30
31
32
33
34
  
  	rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
  				__alignof__(struct dlm_rsb), 0, NULL);
  	if (!rsb_cache) {
  		kmem_cache_destroy(lkb_cache);
  		ret = -ENOMEM;
  	}
e7fd41792   David Teigland   [DLM] The core of...
35
36
37
38
39
40
41
  	return ret;
  }
  
  void dlm_memory_exit(void)
  {
  	if (lkb_cache)
  		kmem_cache_destroy(lkb_cache);
3881ac04e   David Teigland   dlm: improve rsb ...
42
43
  	if (rsb_cache)
  		kmem_cache_destroy(rsb_cache);
e7fd41792   David Teigland   [DLM] The core of...
44
  }
52bda2b5b   David Teigland   dlm: use dlm pref...
45
  char *dlm_allocate_lvb(struct dlm_ls *ls)
e7fd41792   David Teigland   [DLM] The core of...
46
47
  {
  	char *p;
573c24c4a   David Teigland   dlm: always use G...
48
  	p = kzalloc(ls->ls_lvblen, GFP_NOFS);
e7fd41792   David Teigland   [DLM] The core of...
49
50
  	return p;
  }
52bda2b5b   David Teigland   dlm: use dlm pref...
51
  void dlm_free_lvb(char *p)
e7fd41792   David Teigland   [DLM] The core of...
52
53
54
  {
  	kfree(p);
  }
3881ac04e   David Teigland   dlm: improve rsb ...
55
  struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
e7fd41792   David Teigland   [DLM] The core of...
56
57
  {
  	struct dlm_rsb *r;
3881ac04e   David Teigland   dlm: improve rsb ...
58
  	r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
e7fd41792   David Teigland   [DLM] The core of...
59
60
  	return r;
  }
52bda2b5b   David Teigland   dlm: use dlm pref...
61
  void dlm_free_rsb(struct dlm_rsb *r)
e7fd41792   David Teigland   [DLM] The core of...
62
63
  {
  	if (r->res_lvbptr)
52bda2b5b   David Teigland   dlm: use dlm pref...
64
  		dlm_free_lvb(r->res_lvbptr);
3881ac04e   David Teigland   dlm: improve rsb ...
65
  	kmem_cache_free(rsb_cache, r);
e7fd41792   David Teigland   [DLM] The core of...
66
  }
52bda2b5b   David Teigland   dlm: use dlm pref...
67
  struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
e7fd41792   David Teigland   [DLM] The core of...
68
69
  {
  	struct dlm_lkb *lkb;
573c24c4a   David Teigland   dlm: always use G...
70
  	lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
e7fd41792   David Teigland   [DLM] The core of...
71
72
  	return lkb;
  }
52bda2b5b   David Teigland   dlm: use dlm pref...
73
  void dlm_free_lkb(struct dlm_lkb *lkb)
e7fd41792   David Teigland   [DLM] The core of...
74
  {
597d0cae0   David Teigland   [DLM] dlm: user l...
75
76
  	if (lkb->lkb_flags & DLM_IFL_USER) {
  		struct dlm_user_args *ua;
d292c0cc4   David Teigland   dlm: eliminate as...
77
  		ua = lkb->lkb_ua;
597d0cae0   David Teigland   [DLM] dlm: user l...
78
79
80
81
82
83
  		if (ua) {
  			if (ua->lksb.sb_lvbptr)
  				kfree(ua->lksb.sb_lvbptr);
  			kfree(ua);
  		}
  	}
e7fd41792   David Teigland   [DLM] The core of...
84
85
  	kmem_cache_free(lkb_cache, lkb);
  }