Lines Matching +full:lock +full:- +full:- +full:- +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * underlying calls for lock conversion
37 * needs a spinlock held on entry (res->spinlock) and it is the
38 * only one that holds a lock on exit (res->spinlock).
43 struct dlm_lock *lock, int flags,
48 struct dlm_lock *lock, int flags, int type);
55 * taken: takes and drops res->spinlock
61 struct dlm_lock *lock, int flags, int type) in dlmconvert_master() argument
66 spin_lock(&res->spinlock); in dlmconvert_master()
70 res->state |= DLM_LOCK_RES_IN_PROGRESS; in dlmconvert_master()
72 status = __dlmconvert_master(dlm, res, lock, flags, type, in dlmconvert_master()
75 res->state &= ~DLM_LOCK_RES_IN_PROGRESS; in dlmconvert_master()
76 spin_unlock(&res->spinlock); in dlmconvert_master()
77 wake_up(&res->wq); in dlmconvert_master()
83 dlm_queue_ast(dlm, lock); in dlmconvert_master()
93 /* performs lock conversion at the lockres master site
95 * caller needs: res->spinlock
96 * taken: takes and drops lock->spinlock
97 * held on exit: res->spinlock
99 * call_ast: whether ast should be called for this lock
104 struct dlm_lock *lock, int flags, in __dlmconvert_master() argument
111 assert_spin_locked(&res->spinlock); in __dlmconvert_master()
114 lock->ml.type, lock->ml.convert_type, type); in __dlmconvert_master()
116 spin_lock(&lock->spinlock); in __dlmconvert_master()
119 if (lock->ml.convert_type != LKM_IVMODE) { in __dlmconvert_master()
120 mlog(ML_ERROR, "attempted to convert a lock with a lock " in __dlmconvert_master()
127 if (!dlm_lock_on_list(&res->granted, lock)) { in __dlmconvert_master()
128 mlog(ML_ERROR, "attempted to convert a lock not on grant " in __dlmconvert_master()
135 switch (lock->ml.type) { in __dlmconvert_master()
138 mlog(0, "will set lvb: converting %s->%s\n", in __dlmconvert_master()
139 dlm_lock_mode_name(lock->ml.type), in __dlmconvert_master()
141 lock->lksb->flags |= DLM_LKSB_PUT_LVB; in __dlmconvert_master()
148 "lvb: converting %s->%s\n", in __dlmconvert_master()
149 dlm_lock_mode_name(lock->ml.type), in __dlmconvert_master()
151 lock->lksb->flags |= DLM_LKSB_GET_LVB; in __dlmconvert_master()
154 "into lvb: converting %s->%s\n", in __dlmconvert_master()
155 dlm_lock_mode_name(lock->ml.type), in __dlmconvert_master()
164 /* in-place downconvert? */ in __dlmconvert_master()
165 if (type <= lock->ml.type) in __dlmconvert_master()
170 list_for_each_entry(tmplock, &res->granted, list) { in __dlmconvert_master()
171 if (tmplock == lock) in __dlmconvert_master()
173 if (!dlm_lock_compatible(tmplock->ml.type, type)) in __dlmconvert_master()
177 list_for_each_entry(tmplock, &res->converting, list) { in __dlmconvert_master()
178 if (!dlm_lock_compatible(tmplock->ml.type, type)) in __dlmconvert_master()
181 if (!dlm_lock_compatible(tmplock->ml.convert_type, type)) in __dlmconvert_master()
188 mlog(0, "res %.*s, granting %s lock\n", res->lockname.len, in __dlmconvert_master()
189 res->lockname.name, dlm_lock_mode_name(type)); in __dlmconvert_master()
190 /* immediately grant the new lock type */ in __dlmconvert_master()
191 lock->lksb->status = DLM_NORMAL; in __dlmconvert_master()
192 if (lock->ml.node == dlm->node_num) in __dlmconvert_master()
193 mlog(0, "doing in-place convert for nonlocal lock\n"); in __dlmconvert_master()
194 lock->ml.type = type; in __dlmconvert_master()
195 if (lock->lksb->flags & DLM_LKSB_PUT_LVB) in __dlmconvert_master()
196 memcpy(res->lvb, lock->lksb->lvb, DLM_LVB_LEN); in __dlmconvert_master()
199 * Move the lock to the tail because it may be the only lock which has in __dlmconvert_master()
202 list_move_tail(&lock->list, &res->granted); in __dlmconvert_master()
210 mlog(0, "failed to convert NOQUEUE lock %.*s from " in __dlmconvert_master()
211 "%d to %d...\n", res->lockname.len, res->lockname.name, in __dlmconvert_master()
212 lock->ml.type, type); in __dlmconvert_master()
216 mlog(0, "res %.*s, queueing...\n", res->lockname.len, in __dlmconvert_master()
217 res->lockname.name); in __dlmconvert_master()
219 lock->ml.convert_type = type; in __dlmconvert_master()
220 /* do not alter lock refcount. switching lists. */ in __dlmconvert_master()
221 list_move_tail(&lock->list, &res->converting); in __dlmconvert_master()
224 spin_unlock(&lock->spinlock); in __dlmconvert_master()
234 struct dlm_lock *lock) in dlm_revert_pending_convert() argument
236 /* do not alter lock refcount. switching lists. */ in dlm_revert_pending_convert()
237 list_move_tail(&lock->list, &res->granted); in dlm_revert_pending_convert()
238 lock->ml.convert_type = LKM_IVMODE; in dlm_revert_pending_convert()
239 lock->lksb->flags &= ~(DLM_LKSB_GET_LVB|DLM_LKSB_PUT_LVB); in dlm_revert_pending_convert()
242 /* messages the master site to do lock conversion
245 * taken: takes and drops res->spinlock, uses DLM_LOCK_RES_IN_PROGRESS
251 struct dlm_lock *lock, int flags, int type) in dlmconvert_remote() argument
255 mlog(0, "type=%d, convert_type=%d, busy=%d\n", lock->ml.type, in dlmconvert_remote()
256 lock->ml.convert_type, res->state & DLM_LOCK_RES_IN_PROGRESS); in dlmconvert_remote()
258 spin_lock(&res->spinlock); in dlmconvert_remote()
259 if (res->state & DLM_LOCK_RES_RECOVERING) { in dlmconvert_remote()
269 if (lock->ml.convert_type != LKM_IVMODE) { in dlmconvert_remote()
271 mlog(ML_ERROR, "converting a remote lock that is already " in dlmconvert_remote()
273 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)), in dlmconvert_remote()
274 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)), in dlmconvert_remote()
275 lock->ml.convert_type); in dlmconvert_remote()
280 if (lock->ml.type == type && lock->ml.convert_type == LKM_IVMODE) { in dlmconvert_remote()
284 res->lockname.len, res->lockname.name, in dlmconvert_remote()
285 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)), in dlmconvert_remote()
286 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)), in dlmconvert_remote()
287 lock->ml.type, lock->ml.convert_type); in dlmconvert_remote()
292 res->state |= DLM_LOCK_RES_IN_PROGRESS; in dlmconvert_remote()
293 /* move lock to local convert queue */ in dlmconvert_remote()
294 /* do not alter lock refcount. switching lists. */ in dlmconvert_remote()
295 list_move_tail(&lock->list, &res->converting); in dlmconvert_remote()
296 lock->convert_pending = 1; in dlmconvert_remote()
297 lock->ml.convert_type = type; in dlmconvert_remote()
300 if (lock->ml.type == LKM_EXMODE) { in dlmconvert_remote()
302 lock->lksb->flags |= DLM_LKSB_PUT_LVB; in dlmconvert_remote()
304 if (lock->ml.convert_type == LKM_NLMODE) in dlmconvert_remote()
308 lock->lksb->flags |= DLM_LKSB_GET_LVB; in dlmconvert_remote()
312 spin_unlock(&res->spinlock); in dlmconvert_remote()
316 status = dlm_send_remote_convert_request(dlm, res, lock, flags, type); in dlmconvert_remote()
318 spin_lock(&res->spinlock); in dlmconvert_remote()
319 res->state &= ~DLM_LOCK_RES_IN_PROGRESS; in dlmconvert_remote()
327 dlm_revert_pending_convert(res, lock); in dlmconvert_remote()
328 } else if (!lock->convert_pending) { in dlmconvert_remote()
329 mlog(0, "%s: res %.*s, owner died and lock has been moved back " in dlmconvert_remote()
331 dlm->name, res->lockname.len, res->lockname.name); in dlmconvert_remote()
335 lock->convert_pending = 0; in dlmconvert_remote()
337 spin_unlock(&res->spinlock); in dlmconvert_remote()
341 wake_up(&res->wq); in dlmconvert_remote()
355 struct dlm_lock *lock, int flags, int type) in dlm_send_remote_convert_request() argument
364 mlog(0, "%.*s\n", res->lockname.len, res->lockname.name); in dlm_send_remote_convert_request()
367 convert.node_idx = dlm->node_num; in dlm_send_remote_convert_request()
369 convert.cookie = lock->ml.cookie; in dlm_send_remote_convert_request()
370 convert.namelen = res->lockname.len; in dlm_send_remote_convert_request()
372 memcpy(convert.name, res->lockname.name, convert.namelen); in dlm_send_remote_convert_request()
380 vec[1].iov_base = lock->lksb->lvb; in dlm_send_remote_convert_request()
384 tmpret = o2net_send_message_vec(DLM_CONVERT_LOCK_MSG, dlm->key, in dlm_send_remote_convert_request()
385 vec, veclen, res->owner, &status); in dlm_send_remote_convert_request()
391 "message!\n", res->owner); in dlm_send_remote_convert_request()
394 "message!\n", res->owner); in dlm_send_remote_convert_request()
397 "message!\n", res->owner); in dlm_send_remote_convert_request()
402 "node %u\n", tmpret, DLM_CONVERT_LOCK_MSG, dlm->key, in dlm_send_remote_convert_request()
403 res->owner); in dlm_send_remote_convert_request()
408 dlm_wait_for_node_death(dlm, res->owner, in dlm_send_remote_convert_request()
412 "from convert message!\n", res->owner); in dlm_send_remote_convert_request()
424 * taken: takes and drop res->spinlock
433 struct dlm_convert_lock *cnv = (struct dlm_convert_lock *)msg->buf; in dlm_convert_lock_handler()
435 struct dlm_lock *lock = NULL; in dlm_convert_lock_handler() local
448 "Domain %s not fully joined!\n", dlm->name); in dlm_convert_lock_handler()
450 if (cnv->namelen > DLM_LOCKID_NAME_MAX) { in dlm_convert_lock_handler()
456 flags = be32_to_cpu(cnv->flags); in dlm_convert_lock_handler()
469 res = dlm_lookup_lockres(dlm, cnv->name, cnv->namelen); in dlm_convert_lock_handler()
475 spin_lock(&res->spinlock); in dlm_convert_lock_handler()
478 spin_unlock(&res->spinlock); in dlm_convert_lock_handler()
482 list_for_each_entry(tmp_lock, &res->granted, list) { in dlm_convert_lock_handler()
483 if (tmp_lock->ml.cookie == cnv->cookie && in dlm_convert_lock_handler()
484 tmp_lock->ml.node == cnv->node_idx) { in dlm_convert_lock_handler()
485 lock = tmp_lock; in dlm_convert_lock_handler()
486 dlm_lock_get(lock); in dlm_convert_lock_handler()
490 spin_unlock(&res->spinlock); in dlm_convert_lock_handler()
491 if (!lock) { in dlm_convert_lock_handler()
493 mlog(ML_ERROR, "did not find lock to convert on grant queue! " in dlm_convert_lock_handler()
495 dlm_get_lock_cookie_node(be64_to_cpu(cnv->cookie)), in dlm_convert_lock_handler()
496 dlm_get_lock_cookie_seq(be64_to_cpu(cnv->cookie))); in dlm_convert_lock_handler()
501 /* found the lock */ in dlm_convert_lock_handler()
502 lksb = lock->lksb; in dlm_convert_lock_handler()
506 BUG_ON(lksb->flags & (DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB)); in dlm_convert_lock_handler()
507 lksb->flags |= DLM_LKSB_PUT_LVB; in dlm_convert_lock_handler()
508 memcpy(&lksb->lvb[0], &cnv->lvb[0], DLM_LVB_LEN); in dlm_convert_lock_handler()
510 BUG_ON(lksb->flags & (DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB)); in dlm_convert_lock_handler()
511 lksb->flags |= DLM_LKSB_GET_LVB; in dlm_convert_lock_handler()
514 spin_lock(&res->spinlock); in dlm_convert_lock_handler()
519 res->state |= DLM_LOCK_RES_IN_PROGRESS; in dlm_convert_lock_handler()
520 status = __dlmconvert_master(dlm, res, lock, flags, in dlm_convert_lock_handler()
521 cnv->requested_type, in dlm_convert_lock_handler()
523 res->state &= ~DLM_LOCK_RES_IN_PROGRESS; in dlm_convert_lock_handler()
526 spin_unlock(&res->spinlock); in dlm_convert_lock_handler()
528 wake_up(&res->wq); in dlm_convert_lock_handler()
533 lksb->flags &= ~(DLM_LKSB_GET_LVB|DLM_LKSB_PUT_LVB); in dlm_convert_lock_handler()
537 if (lock) in dlm_convert_lock_handler()
538 dlm_lock_put(lock); in dlm_convert_lock_handler()
542 dlm_queue_ast(dlm, lock); in dlm_convert_lock_handler()