memory.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /******************************************************************************
  3. *******************************************************************************
  4. **
  5. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  6. ** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
  7. **
  8. **
  9. *******************************************************************************
  10. ******************************************************************************/
  11. #include "dlm_internal.h"
  12. #include "config.h"
  13. #include "memory.h"
  14. static struct kmem_cache *lkb_cache;
  15. static struct kmem_cache *rsb_cache;
  16. int __init dlm_memory_init(void)
  17. {
  18. lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
  19. __alignof__(struct dlm_lkb), 0, NULL);
  20. if (!lkb_cache)
  21. return -ENOMEM;
  22. rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
  23. __alignof__(struct dlm_rsb), 0, NULL);
  24. if (!rsb_cache) {
  25. kmem_cache_destroy(lkb_cache);
  26. return -ENOMEM;
  27. }
  28. return 0;
  29. }
  30. void dlm_memory_exit(void)
  31. {
  32. kmem_cache_destroy(lkb_cache);
  33. kmem_cache_destroy(rsb_cache);
  34. }
  35. char *dlm_allocate_lvb(struct dlm_ls *ls)
  36. {
  37. char *p;
  38. p = kzalloc(ls->ls_lvblen, GFP_NOFS);
  39. return p;
  40. }
  41. void dlm_free_lvb(char *p)
  42. {
  43. kfree(p);
  44. }
  45. struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
  46. {
  47. struct dlm_rsb *r;
  48. r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
  49. return r;
  50. }
  51. void dlm_free_rsb(struct dlm_rsb *r)
  52. {
  53. if (r->res_lvbptr)
  54. dlm_free_lvb(r->res_lvbptr);
  55. kmem_cache_free(rsb_cache, r);
  56. }
  57. struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
  58. {
  59. struct dlm_lkb *lkb;
  60. lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
  61. return lkb;
  62. }
  63. void dlm_free_lkb(struct dlm_lkb *lkb)
  64. {
  65. if (lkb->lkb_flags & DLM_IFL_USER) {
  66. struct dlm_user_args *ua;
  67. ua = lkb->lkb_ua;
  68. if (ua) {
  69. kfree(ua->lksb.sb_lvbptr);
  70. kfree(ua);
  71. }
  72. }
  73. kmem_cache_free(lkb_cache, lkb);
  74. }