Blame view

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