Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dlm: remove callback reference counting

Get rid of the unnecessary refcounting on callback structs.
Copy interesting callback info into the lkb struct rather
than maintaining pointers to callback structs from the lkb.
This goes back to the way things were done prior to
commit 61bed0baa4db ("fs: dlm: use a non-static queue for callbacks").

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>

authored by

Alexander Aring and committed by
David Teigland
2bec1bbd 986ae3c2

+28 -55
+17 -39
fs/dlm/ast.c
··· 18 18 #include "user.h" 19 19 #include "ast.h" 20 20 21 - void dlm_release_callback(struct kref *ref) 22 - { 23 - struct dlm_callback *cb = container_of(ref, struct dlm_callback, ref); 24 - 25 - dlm_free_cb(cb); 26 - } 27 - 28 - void dlm_callback_set_last_ptr(struct dlm_callback **from, 29 - struct dlm_callback *to) 30 - { 31 - if (*from) 32 - kref_put(&(*from)->ref, dlm_release_callback); 33 - 34 - if (to) 35 - kref_get(&to->ref); 36 - 37 - *from = to; 38 - } 39 - 40 21 static void dlm_callback_work(struct work_struct *work) 41 22 { 42 23 struct dlm_callback *cb = container_of(work, struct dlm_callback, work); ··· 34 53 cb->astfn(cb->astparam); 35 54 } 36 55 37 - kref_put(&cb->ref, dlm_release_callback); 56 + dlm_free_cb(cb); 38 57 } 39 58 40 59 int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode, ··· 51 70 /* if cb is a bast, it should be skipped if the blocking mode is 52 71 * compatible with the last granted mode 53 72 */ 54 - if (lkb->lkb_last_cast) { 55 - if (dlm_modes_compat(mode, lkb->lkb_last_cast->mode)) { 73 + if (lkb->lkb_last_cast_cb_mode != -1) { 74 + if (dlm_modes_compat(mode, lkb->lkb_last_cast_cb_mode)) { 56 75 log_debug(ls, "skip %x bast mode %d for cast mode %d", 57 76 lkb->lkb_id, mode, 58 - lkb->lkb_last_cast->mode); 77 + lkb->lkb_last_cast_cb_mode); 59 78 goto out; 60 79 } 61 80 } ··· 66 85 * is a bast for the same mode or a more restrictive mode. 67 86 * (the addional > PR check is needed for PR/CW inversion) 68 87 */ 69 - if (lkb->lkb_last_cb && lkb->lkb_last_cb->flags & DLM_CB_BAST) { 70 - prev_mode = lkb->lkb_last_cb->mode; 88 + if (lkb->lkb_last_cb_mode != -1 && 89 + lkb->lkb_last_cb_flags & DLM_CB_BAST) { 90 + prev_mode = lkb->lkb_last_cb_mode; 71 91 72 92 if ((prev_mode == mode) || 73 93 (prev_mode > mode && prev_mode > DLM_LOCK_PR)) { ··· 77 95 goto out; 78 96 } 79 97 } 98 + 99 + lkb->lkb_last_bast_time = ktime_get(); 100 + lkb->lkb_last_bast_cb_mode = mode; 80 101 } else if (flags & DLM_CB_CAST) { 81 102 if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) { 82 - if (lkb->lkb_last_cast) 83 - prev_mode = lkb->lkb_last_cb->mode; 84 - else 85 - prev_mode = -1; 103 + prev_mode = lkb->lkb_last_cast_cb_mode; 86 104 87 105 if (!status && lkb->lkb_lksb->sb_lvbptr && 88 106 dlm_lvb_operations[prev_mode + 1][mode + 1]) 89 107 copy_lvb = 1; 90 108 } 109 + 110 + lkb->lkb_last_cast_cb_mode = mode; 111 + lkb->lkb_last_cast_time = ktime_get(); 91 112 } 113 + 114 + lkb->lkb_last_cb_mode = mode; 115 + lkb->lkb_last_cb_flags = flags; 92 116 93 117 *cb = dlm_allocate_cb(); 94 118 if (!*cb) { ··· 114 126 (*cb)->sb_flags = (sbflags & 0x000000FF); 115 127 (*cb)->copy_lvb = copy_lvb; 116 128 (*cb)->lkb_lksb = lkb->lkb_lksb; 117 - kref_init(&(*cb)->ref); 118 129 119 - if (flags & DLM_CB_BAST) { 120 - lkb->lkb_last_bast_time = ktime_get(); 121 - lkb->lkb_last_bast_mode = mode; 122 - } else if (flags & DLM_CB_CAST) { 123 - dlm_callback_set_last_ptr(&lkb->lkb_last_cast, *cb); 124 - lkb->lkb_last_cast_time = ktime_get(); 125 - } 126 - 127 - dlm_callback_set_last_ptr(&lkb->lkb_last_cb, *cb); 128 130 rv = DLM_ENQUEUE_CALLBACK_NEED_SCHED; 129 131 130 132 out:
-3
fs/dlm/ast.h
··· 19 19 struct dlm_callback **cb); 20 20 void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status, 21 21 uint32_t sbflags); 22 - void dlm_callback_set_last_ptr(struct dlm_callback **from, 23 - struct dlm_callback *to); 24 22 25 - void dlm_release_callback(struct kref *ref); 26 23 int dlm_callback_start(struct dlm_ls *ls); 27 24 void dlm_callback_stop(struct dlm_ls *ls); 28 25 void dlm_callback_suspend(struct dlm_ls *ls);
+1 -1
fs/dlm/debug_fs.c
··· 247 247 lkb->lkb_status, 248 248 lkb->lkb_grmode, 249 249 lkb->lkb_rqmode, 250 - lkb->lkb_last_bast_mode, 250 + lkb->lkb_last_bast_cb_mode, 251 251 rsb_lookup, 252 252 lkb->lkb_wait_type, 253 253 lkb->lkb_lvbseq,
+4 -4
fs/dlm/dlm_internal.h
··· 258 258 uint32_t lkb_id; 259 259 260 260 struct list_head list; 261 - struct kref ref; 262 261 }; 263 262 264 263 struct dlm_lkb { ··· 288 289 struct list_head lkb_ownqueue; /* list of locks for a process */ 289 290 ktime_t lkb_timestamp; 290 291 291 - struct dlm_callback *lkb_last_cast; 292 - struct dlm_callback *lkb_last_cb; 293 - int lkb_last_bast_mode; 292 + int8_t lkb_last_cast_cb_mode; 293 + int8_t lkb_last_bast_cb_mode; 294 + int8_t lkb_last_cb_mode; 295 + uint8_t lkb_last_cb_flags; 294 296 ktime_t lkb_last_cast_time; /* for debugging */ 295 297 ktime_t lkb_last_bast_time; /* for debugging */ 296 298
+5 -3
fs/dlm/lock.c
··· 1197 1197 if (!lkb) 1198 1198 return -ENOMEM; 1199 1199 1200 - lkb->lkb_last_bast_mode = -1; 1200 + lkb->lkb_last_bast_cb_mode = DLM_LOCK_IV; 1201 + lkb->lkb_last_cast_cb_mode = DLM_LOCK_IV; 1202 + lkb->lkb_last_cb_mode = DLM_LOCK_IV; 1201 1203 lkb->lkb_nodeid = -1; 1202 1204 lkb->lkb_grmode = DLM_LOCK_IV; 1203 1205 kref_init(&lkb->lkb_ref); ··· 6033 6031 6034 6032 list_for_each_entry_safe(cb, cb_safe, &proc->asts, list) { 6035 6033 list_del(&cb->list); 6036 - kref_put(&cb->ref, dlm_release_callback); 6034 + dlm_free_cb(cb); 6037 6035 } 6038 6036 6039 6037 spin_unlock(&ls->ls_clear_proc_locks); ··· 6074 6072 spin_lock(&proc->asts_spin); 6075 6073 list_for_each_entry_safe(cb, cb_safe, &proc->asts, list) { 6076 6074 list_del(&cb->list); 6077 - kref_put(&cb->ref, dlm_release_callback); 6075 + dlm_free_cb(cb); 6078 6076 } 6079 6077 spin_unlock(&proc->asts_spin); 6080 6078 }
-4
fs/dlm/memory.c
··· 127 127 } 128 128 } 129 129 130 - /* drop references if they are set */ 131 - dlm_callback_set_last_ptr(&lkb->lkb_last_cast, NULL); 132 - dlm_callback_set_last_ptr(&lkb->lkb_last_cb, NULL); 133 - 134 130 kmem_cache_free(lkb_cache, lkb); 135 131 } 136 132
+1 -1
fs/dlm/user.c
··· 864 864 ret = copy_result_to_user(&cb->ua, 865 865 test_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags), 866 866 cb->flags, cb->mode, cb->copy_lvb, buf, count); 867 - kref_put(&cb->ref, dlm_release_callback); 867 + dlm_free_cb(cb); 868 868 return ret; 869 869 } 870 870