12522fe45SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2e7fd4179SDavid Teigland /****************************************************************************** 3e7fd4179SDavid Teigland ******************************************************************************* 4e7fd4179SDavid Teigland ** 5e7fd4179SDavid Teigland ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 652bda2b5SDavid Teigland ** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 7e7fd4179SDavid Teigland ** 8e7fd4179SDavid Teigland ** 9e7fd4179SDavid Teigland ******************************************************************************* 10e7fd4179SDavid Teigland ******************************************************************************/ 11e7fd4179SDavid Teigland 12e7fd4179SDavid Teigland #include "dlm_internal.h" 13*6c547f26SAlexander Aring #include "midcomms.h" 14e7fd4179SDavid Teigland #include "config.h" 15e7fd4179SDavid Teigland #include "memory.h" 16e7fd4179SDavid Teigland 17*6c547f26SAlexander Aring static struct kmem_cache *mhandle_cache; 18e18b890bSChristoph Lameter static struct kmem_cache *lkb_cache; 193881ac04SDavid Teigland static struct kmem_cache *rsb_cache; 20e7fd4179SDavid Teigland 21e7fd4179SDavid Teigland 2230727174SDenis Cheng int __init dlm_memory_init(void) 23e7fd4179SDavid Teigland { 24*6c547f26SAlexander Aring mhandle_cache = dlm_midcomms_cache_create(); 25*6c547f26SAlexander Aring if (!mhandle_cache) 26*6c547f26SAlexander Aring goto out; 27*6c547f26SAlexander Aring 28e7fd4179SDavid Teigland lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb), 2920c2df83SPaul Mundt __alignof__(struct dlm_lkb), 0, NULL); 30e7fd4179SDavid Teigland if (!lkb_cache) 31*6c547f26SAlexander Aring goto lkb; 323881ac04SDavid Teigland 333881ac04SDavid Teigland rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb), 343881ac04SDavid Teigland __alignof__(struct dlm_rsb), 0, NULL); 35*6c547f26SAlexander Aring if (!rsb_cache) 36*6c547f26SAlexander Aring goto rsb; 373881ac04SDavid Teigland 3875af271eSDan Carpenter return 0; 39*6c547f26SAlexander Aring 40*6c547f26SAlexander Aring rsb: 41*6c547f26SAlexander Aring kmem_cache_destroy(lkb_cache); 42*6c547f26SAlexander Aring lkb: 43*6c547f26SAlexander Aring kmem_cache_destroy(mhandle_cache); 44*6c547f26SAlexander Aring out: 45*6c547f26SAlexander Aring return -ENOMEM; 46e7fd4179SDavid Teigland } 47e7fd4179SDavid Teigland 48e7fd4179SDavid Teigland void dlm_memory_exit(void) 49e7fd4179SDavid Teigland { 50*6c547f26SAlexander Aring kmem_cache_destroy(mhandle_cache); 51e7fd4179SDavid Teigland kmem_cache_destroy(lkb_cache); 523881ac04SDavid Teigland kmem_cache_destroy(rsb_cache); 53e7fd4179SDavid Teigland } 54e7fd4179SDavid Teigland 5552bda2b5SDavid Teigland char *dlm_allocate_lvb(struct dlm_ls *ls) 56e7fd4179SDavid Teigland { 57e7fd4179SDavid Teigland char *p; 58e7fd4179SDavid Teigland 59573c24c4SDavid Teigland p = kzalloc(ls->ls_lvblen, GFP_NOFS); 60e7fd4179SDavid Teigland return p; 61e7fd4179SDavid Teigland } 62e7fd4179SDavid Teigland 6352bda2b5SDavid Teigland void dlm_free_lvb(char *p) 64e7fd4179SDavid Teigland { 65e7fd4179SDavid Teigland kfree(p); 66e7fd4179SDavid Teigland } 67e7fd4179SDavid Teigland 683881ac04SDavid Teigland struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls) 69e7fd4179SDavid Teigland { 70e7fd4179SDavid Teigland struct dlm_rsb *r; 71e7fd4179SDavid Teigland 723881ac04SDavid Teigland r = kmem_cache_zalloc(rsb_cache, GFP_NOFS); 73e7fd4179SDavid Teigland return r; 74e7fd4179SDavid Teigland } 75e7fd4179SDavid Teigland 7652bda2b5SDavid Teigland void dlm_free_rsb(struct dlm_rsb *r) 77e7fd4179SDavid Teigland { 78e7fd4179SDavid Teigland if (r->res_lvbptr) 7952bda2b5SDavid Teigland dlm_free_lvb(r->res_lvbptr); 803881ac04SDavid Teigland kmem_cache_free(rsb_cache, r); 81e7fd4179SDavid Teigland } 82e7fd4179SDavid Teigland 8352bda2b5SDavid Teigland struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls) 84e7fd4179SDavid Teigland { 85e7fd4179SDavid Teigland struct dlm_lkb *lkb; 86e7fd4179SDavid Teigland 87573c24c4SDavid Teigland lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS); 88e7fd4179SDavid Teigland return lkb; 89e7fd4179SDavid Teigland } 90e7fd4179SDavid Teigland 9152bda2b5SDavid Teigland void dlm_free_lkb(struct dlm_lkb *lkb) 92e7fd4179SDavid Teigland { 93597d0caeSDavid Teigland if (lkb->lkb_flags & DLM_IFL_USER) { 94597d0caeSDavid Teigland struct dlm_user_args *ua; 95d292c0ccSDavid Teigland ua = lkb->lkb_ua; 96597d0caeSDavid Teigland if (ua) { 97597d0caeSDavid Teigland kfree(ua->lksb.sb_lvbptr); 98597d0caeSDavid Teigland kfree(ua); 99597d0caeSDavid Teigland } 100597d0caeSDavid Teigland } 101e7fd4179SDavid Teigland kmem_cache_free(lkb_cache, lkb); 102e7fd4179SDavid Teigland } 103e7fd4179SDavid Teigland 104*6c547f26SAlexander Aring struct dlm_mhandle *dlm_allocate_mhandle(void) 105*6c547f26SAlexander Aring { 106*6c547f26SAlexander Aring return kmem_cache_alloc(mhandle_cache, GFP_NOFS); 107*6c547f26SAlexander Aring } 108*6c547f26SAlexander Aring 109*6c547f26SAlexander Aring void dlm_free_mhandle(struct dlm_mhandle *mhandle) 110*6c547f26SAlexander Aring { 111*6c547f26SAlexander Aring kmem_cache_free(mhandle_cache, mhandle); 112*6c547f26SAlexander Aring } 113