Lines Matching refs:lkb
77 static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb);
78 static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb);
79 static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb);
80 static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb);
81 static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb);
82 static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode);
83 static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb);
85 static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb);
86 static int _cancel_lock(struct dlm_rsb *r, struct dlm_lkb *lkb);
87 static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb,
91 static void del_timeout(struct dlm_lkb *lkb);
160 void dlm_print_lkb(struct dlm_lkb *lkb) in dlm_print_lkb() argument
164 lkb->lkb_nodeid, lkb->lkb_id, lkb->lkb_remid, lkb->lkb_exflags, in dlm_print_lkb()
165 lkb->lkb_flags, lkb->lkb_status, lkb->lkb_rqmode, in dlm_print_lkb()
166 lkb->lkb_grmode, lkb->lkb_wait_type); in dlm_print_lkb()
178 struct dlm_lkb *lkb; in dlm_dump_rsb() local
185 list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) in dlm_dump_rsb()
186 dlm_print_lkb(lkb); in dlm_dump_rsb()
188 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) in dlm_dump_rsb()
189 dlm_print_lkb(lkb); in dlm_dump_rsb()
191 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) in dlm_dump_rsb()
192 dlm_print_lkb(lkb); in dlm_dump_rsb()
194 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) in dlm_dump_rsb()
195 dlm_print_lkb(lkb); in dlm_dump_rsb()
215 static inline int can_be_queued(struct dlm_lkb *lkb) in can_be_queued() argument
217 return !(lkb->lkb_exflags & DLM_LKF_NOQUEUE); in can_be_queued()
220 static inline int force_blocking_asts(struct dlm_lkb *lkb) in force_blocking_asts() argument
222 return (lkb->lkb_exflags & DLM_LKF_NOQUEUEBAST); in force_blocking_asts()
225 static inline int is_demoted(struct dlm_lkb *lkb) in is_demoted() argument
227 return (lkb->lkb_sbflags & DLM_SBF_DEMOTED); in is_demoted()
230 static inline int is_altmode(struct dlm_lkb *lkb) in is_altmode() argument
232 return (lkb->lkb_sbflags & DLM_SBF_ALTMODE); in is_altmode()
235 static inline int is_granted(struct dlm_lkb *lkb) in is_granted() argument
237 return (lkb->lkb_status == DLM_LKSTS_GRANTED); in is_granted()
246 static inline int is_process_copy(struct dlm_lkb *lkb) in is_process_copy() argument
248 return (lkb->lkb_nodeid && !(lkb->lkb_flags & DLM_IFL_MSTCPY)); in is_process_copy()
251 static inline int is_master_copy(struct dlm_lkb *lkb) in is_master_copy() argument
253 if (lkb->lkb_flags & DLM_IFL_MSTCPY) in is_master_copy()
254 DLM_ASSERT(lkb->lkb_nodeid, dlm_print_lkb(lkb);); in is_master_copy()
255 return (lkb->lkb_flags & DLM_IFL_MSTCPY) ? 1 : 0; in is_master_copy()
258 static inline int middle_conversion(struct dlm_lkb *lkb) in middle_conversion() argument
260 if ((lkb->lkb_grmode==DLM_LOCK_PR && lkb->lkb_rqmode==DLM_LOCK_CW) || in middle_conversion()
261 (lkb->lkb_rqmode==DLM_LOCK_PR && lkb->lkb_grmode==DLM_LOCK_CW)) in middle_conversion()
266 static inline int down_conversion(struct dlm_lkb *lkb) in down_conversion() argument
268 return (!middle_conversion(lkb) && lkb->lkb_rqmode < lkb->lkb_grmode); in down_conversion()
271 static inline int is_overlap_unlock(struct dlm_lkb *lkb) in is_overlap_unlock() argument
273 return lkb->lkb_flags & DLM_IFL_OVERLAP_UNLOCK; in is_overlap_unlock()
276 static inline int is_overlap_cancel(struct dlm_lkb *lkb) in is_overlap_cancel() argument
278 return lkb->lkb_flags & DLM_IFL_OVERLAP_CANCEL; in is_overlap_cancel()
281 static inline int is_overlap(struct dlm_lkb *lkb) in is_overlap() argument
283 return (lkb->lkb_flags & (DLM_IFL_OVERLAP_UNLOCK | in is_overlap()
287 static void queue_cast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in queue_cast() argument
289 if (is_master_copy(lkb)) in queue_cast()
292 del_timeout(lkb); in queue_cast()
294 DLM_ASSERT(lkb->lkb_lksb, dlm_print_lkb(lkb);); in queue_cast()
298 if (rv == -DLM_ECANCEL && (lkb->lkb_flags & DLM_IFL_TIMEOUT_CANCEL)) { in queue_cast()
299 lkb->lkb_flags &= ~DLM_IFL_TIMEOUT_CANCEL; in queue_cast()
303 if (rv == -DLM_ECANCEL && (lkb->lkb_flags & DLM_IFL_DEADLOCK_CANCEL)) { in queue_cast()
304 lkb->lkb_flags &= ~DLM_IFL_DEADLOCK_CANCEL; in queue_cast()
308 dlm_add_ast(lkb, DLM_CB_CAST, lkb->lkb_grmode, rv, lkb->lkb_sbflags); in queue_cast()
311 static inline void queue_cast_overlap(struct dlm_rsb *r, struct dlm_lkb *lkb) in queue_cast_overlap() argument
313 queue_cast(r, lkb, in queue_cast_overlap()
314 is_overlap_unlock(lkb) ? -DLM_EUNLOCK : -DLM_ECANCEL); in queue_cast_overlap()
317 static void queue_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rqmode) in queue_bast() argument
319 if (is_master_copy(lkb)) { in queue_bast()
320 send_bast(r, lkb, rqmode); in queue_bast()
322 dlm_add_ast(lkb, DLM_CB_BAST, rqmode, 0, 0); in queue_bast()
567 static void attach_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) in attach_lkb() argument
570 lkb->lkb_resource = r; in attach_lkb()
573 static void detach_lkb(struct dlm_lkb *lkb) in detach_lkb() argument
575 if (lkb->lkb_resource) { in detach_lkb()
576 put_rsb(lkb->lkb_resource); in detach_lkb()
577 lkb->lkb_resource = NULL; in detach_lkb()
583 struct dlm_lkb *lkb, *tmp; in create_lkb() local
587 lkb = dlm_allocate_lkb(ls); in create_lkb()
588 if (!lkb) in create_lkb()
591 lkb->lkb_nodeid = -1; in create_lkb()
592 lkb->lkb_grmode = DLM_LOCK_IV; in create_lkb()
593 kref_init(&lkb->lkb_ref); in create_lkb()
594 INIT_LIST_HEAD(&lkb->lkb_ownqueue); in create_lkb()
595 INIT_LIST_HEAD(&lkb->lkb_rsb_lookup); in create_lkb()
596 INIT_LIST_HEAD(&lkb->lkb_time_list); in create_lkb()
597 INIT_LIST_HEAD(&lkb->lkb_astqueue); in create_lkb()
618 lkb->lkb_id = lkid; in create_lkb()
619 list_add(&lkb->lkb_idtbl_list, &ls->ls_lkbtbl[bucket].list); in create_lkb()
622 *lkb_ret = lkb; in create_lkb()
628 struct dlm_lkb *lkb; in __find_lkb() local
631 list_for_each_entry(lkb, &ls->ls_lkbtbl[bucket].list, lkb_idtbl_list) { in __find_lkb()
632 if (lkb->lkb_id == lkid) in __find_lkb()
633 return lkb; in __find_lkb()
640 struct dlm_lkb *lkb; in find_lkb() local
647 lkb = __find_lkb(ls, lkid); in find_lkb()
648 if (lkb) in find_lkb()
649 kref_get(&lkb->lkb_ref); in find_lkb()
652 *lkb_ret = lkb; in find_lkb()
653 return lkb ? 0 : -ENOENT; in find_lkb()
658 struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref); in kill_lkb() local
663 DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); in kill_lkb()
669 static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb) in __put_lkb() argument
671 uint16_t bucket = (lkb->lkb_id >> 16); in __put_lkb()
674 if (kref_put(&lkb->lkb_ref, kill_lkb)) { in __put_lkb()
675 list_del(&lkb->lkb_idtbl_list); in __put_lkb()
678 detach_lkb(lkb); in __put_lkb()
681 if (lkb->lkb_lvbptr && is_master_copy(lkb)) in __put_lkb()
682 dlm_free_lvb(lkb->lkb_lvbptr); in __put_lkb()
683 dlm_free_lkb(lkb); in __put_lkb()
691 int dlm_put_lkb(struct dlm_lkb *lkb) in dlm_put_lkb() argument
695 DLM_ASSERT(lkb->lkb_resource, dlm_print_lkb(lkb);); in dlm_put_lkb()
696 DLM_ASSERT(lkb->lkb_resource->res_ls, dlm_print_lkb(lkb);); in dlm_put_lkb()
698 ls = lkb->lkb_resource->res_ls; in dlm_put_lkb()
699 return __put_lkb(ls, lkb); in dlm_put_lkb()
705 static inline void hold_lkb(struct dlm_lkb *lkb) in hold_lkb() argument
707 kref_get(&lkb->lkb_ref); in hold_lkb()
715 static inline void unhold_lkb(struct dlm_lkb *lkb) in unhold_lkb() argument
718 rv = kref_put(&lkb->lkb_ref, kill_lkb); in unhold_lkb()
719 DLM_ASSERT(!rv, dlm_print_lkb(lkb);); in unhold_lkb()
725 struct dlm_lkb *lkb = NULL; in lkb_add_ordered() local
727 list_for_each_entry(lkb, head, lkb_statequeue) in lkb_add_ordered()
728 if (lkb->lkb_rqmode < mode) in lkb_add_ordered()
731 __list_add(new, lkb->lkb_statequeue.prev, &lkb->lkb_statequeue); in lkb_add_ordered()
736 static void add_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int status) in add_lkb() argument
738 kref_get(&lkb->lkb_ref); in add_lkb()
740 DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); in add_lkb()
742 lkb->lkb_timestamp = ktime_get(); in add_lkb()
744 lkb->lkb_status = status; in add_lkb()
748 if (lkb->lkb_exflags & DLM_LKF_HEADQUE) in add_lkb()
749 list_add(&lkb->lkb_statequeue, &r->res_waitqueue); in add_lkb()
751 list_add_tail(&lkb->lkb_statequeue, &r->res_waitqueue); in add_lkb()
755 lkb_add_ordered(&lkb->lkb_statequeue, &r->res_grantqueue, in add_lkb()
756 lkb->lkb_grmode); in add_lkb()
759 if (lkb->lkb_exflags & DLM_LKF_HEADQUE) in add_lkb()
760 list_add(&lkb->lkb_statequeue, &r->res_convertqueue); in add_lkb()
762 list_add_tail(&lkb->lkb_statequeue, in add_lkb()
766 DLM_ASSERT(0, dlm_print_lkb(lkb); printk("sts=%d\n", status);); in add_lkb()
770 static void del_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) in del_lkb() argument
772 lkb->lkb_status = 0; in del_lkb()
773 list_del(&lkb->lkb_statequeue); in del_lkb()
774 unhold_lkb(lkb); in del_lkb()
777 static void move_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int sts) in move_lkb() argument
779 hold_lkb(lkb); in move_lkb()
780 del_lkb(r, lkb); in move_lkb()
781 add_lkb(r, lkb, sts); in move_lkb()
782 unhold_lkb(lkb); in move_lkb()
805 static int add_to_waiters(struct dlm_lkb *lkb, int mstype) in add_to_waiters() argument
807 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in add_to_waiters()
812 if (is_overlap_unlock(lkb) || in add_to_waiters()
813 (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL))) { in add_to_waiters()
818 if (lkb->lkb_wait_type || is_overlap_cancel(lkb)) { in add_to_waiters()
821 lkb->lkb_flags |= DLM_IFL_OVERLAP_UNLOCK; in add_to_waiters()
824 lkb->lkb_flags |= DLM_IFL_OVERLAP_CANCEL; in add_to_waiters()
830 lkb->lkb_wait_count++; in add_to_waiters()
831 hold_lkb(lkb); in add_to_waiters()
834 lkb->lkb_id, lkb->lkb_wait_type, mstype, in add_to_waiters()
835 lkb->lkb_wait_count, lkb->lkb_flags); in add_to_waiters()
839 DLM_ASSERT(!lkb->lkb_wait_count, in add_to_waiters()
840 dlm_print_lkb(lkb); in add_to_waiters()
841 printk("wait_count %d\n", lkb->lkb_wait_count);); in add_to_waiters()
843 lkb->lkb_wait_count++; in add_to_waiters()
844 lkb->lkb_wait_type = mstype; in add_to_waiters()
845 hold_lkb(lkb); in add_to_waiters()
846 list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); in add_to_waiters()
850 lkb->lkb_id, error, lkb->lkb_flags, mstype, in add_to_waiters()
851 lkb->lkb_wait_type, lkb->lkb_resource->res_name); in add_to_waiters()
861 static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype, in _remove_from_waiters() argument
864 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in _remove_from_waiters()
867 if (is_overlap_unlock(lkb) && (mstype == DLM_MSG_UNLOCK_REPLY)) { in _remove_from_waiters()
868 log_debug(ls, "remwait %x unlock_reply overlap", lkb->lkb_id); in _remove_from_waiters()
869 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in _remove_from_waiters()
874 if (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL_REPLY)) { in _remove_from_waiters()
875 log_debug(ls, "remwait %x cancel_reply overlap", lkb->lkb_id); in _remove_from_waiters()
876 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in _remove_from_waiters()
885 (lkb->lkb_wait_type != DLM_MSG_CANCEL)) { in _remove_from_waiters()
887 lkb->lkb_id, lkb->lkb_wait_type); in _remove_from_waiters()
900 (lkb->lkb_wait_type == DLM_MSG_CONVERT) && in _remove_from_waiters()
901 is_overlap_cancel(lkb) && ms && !ms->m_result) { in _remove_from_waiters()
903 lkb->lkb_id); in _remove_from_waiters()
904 lkb->lkb_wait_type = 0; in _remove_from_waiters()
905 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in _remove_from_waiters()
906 lkb->lkb_wait_count--; in _remove_from_waiters()
913 if (lkb->lkb_wait_type) { in _remove_from_waiters()
914 lkb->lkb_wait_type = 0; in _remove_from_waiters()
919 lkb->lkb_id, mstype, lkb->lkb_flags); in _remove_from_waiters()
928 if (overlap_done && lkb->lkb_wait_type) { in _remove_from_waiters()
930 lkb->lkb_id, mstype, lkb->lkb_wait_type); in _remove_from_waiters()
931 lkb->lkb_wait_count--; in _remove_from_waiters()
932 lkb->lkb_wait_type = 0; in _remove_from_waiters()
935 DLM_ASSERT(lkb->lkb_wait_count, dlm_print_lkb(lkb);); in _remove_from_waiters()
937 lkb->lkb_flags &= ~DLM_IFL_RESEND; in _remove_from_waiters()
938 lkb->lkb_wait_count--; in _remove_from_waiters()
939 if (!lkb->lkb_wait_count) in _remove_from_waiters()
940 list_del_init(&lkb->lkb_wait_reply); in _remove_from_waiters()
941 unhold_lkb(lkb); in _remove_from_waiters()
945 static int remove_from_waiters(struct dlm_lkb *lkb, int mstype) in remove_from_waiters() argument
947 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in remove_from_waiters()
951 error = _remove_from_waiters(lkb, mstype, NULL); in remove_from_waiters()
959 static int remove_from_waiters_ms(struct dlm_lkb *lkb, struct dlm_message *ms) in remove_from_waiters_ms() argument
961 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in remove_from_waiters_ms()
966 error = _remove_from_waiters(lkb, ms->m_type, ms); in remove_from_waiters_ms()
1041 static void add_timeout(struct dlm_lkb *lkb) in add_timeout() argument
1043 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in add_timeout()
1045 if (is_master_copy(lkb)) in add_timeout()
1049 !(lkb->lkb_exflags & DLM_LKF_NODLCKWT)) { in add_timeout()
1050 lkb->lkb_flags |= DLM_IFL_WATCH_TIMEWARN; in add_timeout()
1053 if (lkb->lkb_exflags & DLM_LKF_TIMEOUT) in add_timeout()
1058 DLM_ASSERT(list_empty(&lkb->lkb_time_list), dlm_print_lkb(lkb);); in add_timeout()
1060 hold_lkb(lkb); in add_timeout()
1061 list_add_tail(&lkb->lkb_time_list, &ls->ls_timeout); in add_timeout()
1065 static void del_timeout(struct dlm_lkb *lkb) in del_timeout() argument
1067 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in del_timeout()
1070 if (!list_empty(&lkb->lkb_time_list)) { in del_timeout()
1071 list_del_init(&lkb->lkb_time_list); in del_timeout()
1072 unhold_lkb(lkb); in del_timeout()
1086 struct dlm_lkb *lkb; in dlm_scan_timeout() local
1097 list_for_each_entry(lkb, &ls->ls_timeout, lkb_time_list) { in dlm_scan_timeout()
1100 lkb->lkb_timestamp)); in dlm_scan_timeout()
1102 if ((lkb->lkb_exflags & DLM_LKF_TIMEOUT) && in dlm_scan_timeout()
1103 wait_us >= (lkb->lkb_timeout_cs * 10000)) in dlm_scan_timeout()
1106 if ((lkb->lkb_flags & DLM_IFL_WATCH_TIMEWARN) && in dlm_scan_timeout()
1112 hold_lkb(lkb); in dlm_scan_timeout()
1120 r = lkb->lkb_resource; in dlm_scan_timeout()
1126 lkb->lkb_flags &= ~DLM_IFL_WATCH_TIMEWARN; in dlm_scan_timeout()
1127 if (!(lkb->lkb_exflags & DLM_LKF_TIMEOUT)) in dlm_scan_timeout()
1128 del_timeout(lkb); in dlm_scan_timeout()
1129 dlm_timeout_warn(lkb); in dlm_scan_timeout()
1134 lkb->lkb_id, lkb->lkb_nodeid, r->res_name); in dlm_scan_timeout()
1135 lkb->lkb_flags &= ~DLM_IFL_WATCH_TIMEWARN; in dlm_scan_timeout()
1136 lkb->lkb_flags |= DLM_IFL_TIMEOUT_CANCEL; in dlm_scan_timeout()
1137 del_timeout(lkb); in dlm_scan_timeout()
1138 _cancel_lock(r, lkb); in dlm_scan_timeout()
1143 dlm_put_lkb(lkb); in dlm_scan_timeout()
1152 struct dlm_lkb *lkb; in dlm_adjust_timeouts() local
1157 list_for_each_entry(lkb, &ls->ls_timeout, lkb_time_list) in dlm_adjust_timeouts()
1158 lkb->lkb_timestamp = ktime_add_us(lkb->lkb_timestamp, adj_us); in dlm_adjust_timeouts()
1164 static void set_lvb_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_lvb_lock() argument
1172 b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; in set_lvb_lock()
1175 if (!lkb->lkb_lvbptr) in set_lvb_lock()
1178 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock()
1184 memcpy(lkb->lkb_lvbptr, r->res_lvbptr, len); in set_lvb_lock()
1185 lkb->lkb_lvbseq = r->res_lvbseq; in set_lvb_lock()
1188 if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { in set_lvb_lock()
1193 if (!lkb->lkb_lvbptr) in set_lvb_lock()
1196 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock()
1205 memcpy(r->res_lvbptr, lkb->lkb_lvbptr, len); in set_lvb_lock()
1207 lkb->lkb_lvbseq = r->res_lvbseq; in set_lvb_lock()
1212 lkb->lkb_sbflags |= DLM_SBF_VALNOTVALID; in set_lvb_lock()
1215 static void set_lvb_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_lvb_unlock() argument
1217 if (lkb->lkb_grmode < DLM_LOCK_PW) in set_lvb_unlock()
1220 if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { in set_lvb_unlock()
1225 if (!lkb->lkb_lvbptr) in set_lvb_unlock()
1228 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_unlock()
1237 memcpy(r->res_lvbptr, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); in set_lvb_unlock()
1244 static void set_lvb_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, in set_lvb_lock_pc() argument
1249 if (!lkb->lkb_lvbptr) in set_lvb_lock_pc()
1252 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock_pc()
1255 b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; in set_lvb_lock_pc()
1260 memcpy(lkb->lkb_lvbptr, ms->m_extra, len); in set_lvb_lock_pc()
1261 lkb->lkb_lvbseq = ms->m_lvbseq; in set_lvb_lock_pc()
1275 static void _remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _remove_lock() argument
1277 del_lkb(r, lkb); in _remove_lock()
1278 lkb->lkb_grmode = DLM_LOCK_IV; in _remove_lock()
1281 unhold_lkb(lkb); in _remove_lock()
1284 static void remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in remove_lock() argument
1286 set_lvb_unlock(r, lkb); in remove_lock()
1287 _remove_lock(r, lkb); in remove_lock()
1290 static void remove_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) in remove_lock_pc() argument
1292 _remove_lock(r, lkb); in remove_lock_pc()
1299 static int revert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in revert_lock() argument
1303 lkb->lkb_rqmode = DLM_LOCK_IV; in revert_lock()
1305 switch (lkb->lkb_status) { in revert_lock()
1309 move_lkb(r, lkb, DLM_LKSTS_GRANTED); in revert_lock()
1313 del_lkb(r, lkb); in revert_lock()
1314 lkb->lkb_grmode = DLM_LOCK_IV; in revert_lock()
1317 unhold_lkb(lkb); in revert_lock()
1321 log_print("invalid status for revert %d", lkb->lkb_status); in revert_lock()
1326 static int revert_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) in revert_lock_pc() argument
1328 return revert_lock(r, lkb); in revert_lock_pc()
1331 static void _grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _grant_lock() argument
1333 if (lkb->lkb_grmode != lkb->lkb_rqmode) { in _grant_lock()
1334 lkb->lkb_grmode = lkb->lkb_rqmode; in _grant_lock()
1335 if (lkb->lkb_status) in _grant_lock()
1336 move_lkb(r, lkb, DLM_LKSTS_GRANTED); in _grant_lock()
1338 add_lkb(r, lkb, DLM_LKSTS_GRANTED); in _grant_lock()
1341 lkb->lkb_rqmode = DLM_LOCK_IV; in _grant_lock()
1344 static void grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in grant_lock() argument
1346 set_lvb_lock(r, lkb); in grant_lock()
1347 _grant_lock(r, lkb); in grant_lock()
1348 lkb->lkb_highbast = 0; in grant_lock()
1351 static void grant_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, in grant_lock_pc() argument
1354 set_lvb_lock_pc(r, lkb, ms); in grant_lock_pc()
1355 _grant_lock(r, lkb); in grant_lock_pc()
1362 static void grant_lock_pending(struct dlm_rsb *r, struct dlm_lkb *lkb) in grant_lock_pending() argument
1364 grant_lock(r, lkb); in grant_lock_pending()
1365 if (is_master_copy(lkb)) in grant_lock_pending()
1366 send_grant(r, lkb); in grant_lock_pending()
1368 queue_cast(r, lkb, 0); in grant_lock_pending()
1379 static void munge_demoted(struct dlm_lkb *lkb, struct dlm_message *ms) in munge_demoted() argument
1383 lkb->lkb_id, ms->m_type); in munge_demoted()
1387 if (lkb->lkb_rqmode == DLM_LOCK_IV || lkb->lkb_grmode == DLM_LOCK_IV) { in munge_demoted()
1389 lkb->lkb_id, lkb->lkb_grmode, lkb->lkb_rqmode); in munge_demoted()
1393 lkb->lkb_grmode = DLM_LOCK_NL; in munge_demoted()
1396 static void munge_altmode(struct dlm_lkb *lkb, struct dlm_message *ms) in munge_altmode() argument
1401 lkb->lkb_id, ms->m_type); in munge_altmode()
1405 if (lkb->lkb_exflags & DLM_LKF_ALTPR) in munge_altmode()
1406 lkb->lkb_rqmode = DLM_LOCK_PR; in munge_altmode()
1407 else if (lkb->lkb_exflags & DLM_LKF_ALTCW) in munge_altmode()
1408 lkb->lkb_rqmode = DLM_LOCK_CW; in munge_altmode()
1410 log_print("munge_altmode invalid exflags %x", lkb->lkb_exflags); in munge_altmode()
1411 dlm_print_lkb(lkb); in munge_altmode()
1415 static inline int first_in_list(struct dlm_lkb *lkb, struct list_head *head) in first_in_list() argument
1419 if (lkb->lkb_id == first->lkb_id) in first_in_list()
1427 static int queue_conflict(struct list_head *head, struct dlm_lkb *lkb) in queue_conflict() argument
1432 if (this == lkb) in queue_conflict()
1434 if (!modes_compat(this, lkb)) in queue_conflict()
1517 static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) in _can_be_granted() argument
1519 int8_t conv = (lkb->lkb_grmode != DLM_LOCK_IV); in _can_be_granted()
1540 if (lkb->lkb_exflags & DLM_LKF_EXPEDITE) in _can_be_granted()
1548 if (queue_conflict(&r->res_grantqueue, lkb)) in _can_be_granted()
1557 if (queue_conflict(&r->res_convertqueue, lkb)) in _can_be_granted()
1583 if (now && conv && !(lkb->lkb_exflags & DLM_LKF_QUECVT)) in _can_be_granted()
1591 if (lkb->lkb_exflags & DLM_LKF_NOORDER) in _can_be_granted()
1600 if (!now && conv && first_in_list(lkb, &r->res_convertqueue)) in _can_be_granted()
1627 first_in_list(lkb, &r->res_waitqueue)) in _can_be_granted()
1633 static int can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now, in can_be_granted() argument
1637 int8_t alt = 0, rqmode = lkb->lkb_rqmode; in can_be_granted()
1638 int8_t is_convert = (lkb->lkb_grmode != DLM_LOCK_IV); in can_be_granted()
1643 rv = _can_be_granted(r, lkb, now); in can_be_granted()
1653 if (is_convert && can_be_queued(lkb) && in can_be_granted()
1654 conversion_deadlock_detect(r, lkb)) { in can_be_granted()
1655 if (lkb->lkb_exflags & DLM_LKF_CONVDEADLK) { in can_be_granted()
1656 lkb->lkb_grmode = DLM_LOCK_NL; in can_be_granted()
1657 lkb->lkb_sbflags |= DLM_SBF_DEMOTED; in can_be_granted()
1658 } else if (!(lkb->lkb_exflags & DLM_LKF_NODLCKWT)) { in can_be_granted()
1663 lkb->lkb_id, now); in can_be_granted()
1677 if (rqmode != DLM_LOCK_PR && (lkb->lkb_exflags & DLM_LKF_ALTPR)) in can_be_granted()
1679 else if (rqmode != DLM_LOCK_CW && (lkb->lkb_exflags & DLM_LKF_ALTCW)) in can_be_granted()
1683 lkb->lkb_rqmode = alt; in can_be_granted()
1684 rv = _can_be_granted(r, lkb, now); in can_be_granted()
1686 lkb->lkb_sbflags |= DLM_SBF_ALTMODE; in can_be_granted()
1688 lkb->lkb_rqmode = rqmode; in can_be_granted()
1706 struct dlm_lkb *lkb, *s; in grant_pending_convert() local
1716 list_for_each_entry_safe(lkb, s, &r->res_convertqueue, lkb_statequeue) { in grant_pending_convert()
1717 demoted = is_demoted(lkb); in grant_pending_convert()
1720 if (can_be_granted(r, lkb, 0, &deadlk)) { in grant_pending_convert()
1721 grant_lock_pending(r, lkb); in grant_pending_convert()
1726 if (!demoted && is_demoted(lkb)) { in grant_pending_convert()
1728 lkb->lkb_id, lkb->lkb_nodeid, r->res_name); in grant_pending_convert()
1735 lkb->lkb_id, lkb->lkb_nodeid, r->res_name); in grant_pending_convert()
1740 hi = max_t(int, lkb->lkb_rqmode, hi); in grant_pending_convert()
1742 if (cw && lkb->lkb_rqmode == DLM_LOCK_CW) in grant_pending_convert()
1758 struct dlm_lkb *lkb, *s; in grant_pending_wait() local
1760 list_for_each_entry_safe(lkb, s, &r->res_waitqueue, lkb_statequeue) { in grant_pending_wait()
1761 if (can_be_granted(r, lkb, 0, NULL)) in grant_pending_wait()
1762 grant_lock_pending(r, lkb); in grant_pending_wait()
1764 high = max_t(int, lkb->lkb_rqmode, high); in grant_pending_wait()
1765 if (lkb->lkb_rqmode == DLM_LOCK_CW) in grant_pending_wait()
1794 struct dlm_lkb *lkb, *s; in grant_pending_locks() local
1812 list_for_each_entry_safe(lkb, s, &r->res_grantqueue, lkb_statequeue) { in grant_pending_locks()
1813 if (lkb->lkb_bastfn && lock_requires_bast(lkb, high, cw)) { in grant_pending_locks()
1815 lkb->lkb_grmode == DLM_LOCK_PR) in grant_pending_locks()
1816 queue_bast(r, lkb, DLM_LOCK_CW); in grant_pending_locks()
1818 queue_bast(r, lkb, high); in grant_pending_locks()
1819 lkb->lkb_highbast = high; in grant_pending_locks()
1839 struct dlm_lkb *lkb) in send_bast_queue() argument
1845 if (gr == lkb) in send_bast_queue()
1847 if (gr->lkb_bastfn && modes_require_bast(gr, lkb)) { in send_bast_queue()
1848 queue_bast(r, gr, lkb->lkb_rqmode); in send_bast_queue()
1849 gr->lkb_highbast = lkb->lkb_rqmode; in send_bast_queue()
1854 static void send_blocking_asts(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_blocking_asts() argument
1856 send_bast_queue(r, &r->res_grantqueue, lkb); in send_blocking_asts()
1859 static void send_blocking_asts_all(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_blocking_asts_all() argument
1861 send_bast_queue(r, &r->res_grantqueue, lkb); in send_blocking_asts_all()
1862 send_bast_queue(r, &r->res_convertqueue, lkb); in send_blocking_asts_all()
1884 static int set_master(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_master() argument
1891 r->res_first_lkid = lkb->lkb_id; in set_master()
1892 lkb->lkb_nodeid = r->res_nodeid; in set_master()
1896 if (r->res_first_lkid && r->res_first_lkid != lkb->lkb_id) { in set_master()
1897 list_add_tail(&lkb->lkb_rsb_lookup, &r->res_lookup); in set_master()
1902 lkb->lkb_nodeid = 0; in set_master()
1907 lkb->lkb_nodeid = r->res_nodeid; in set_master()
1916 r->res_first_lkid = lkb->lkb_id; in set_master()
1917 send_lookup(r, lkb); in set_master()
1941 lkb->lkb_nodeid = 0; in set_master()
1943 r->res_first_lkid = lkb->lkb_id; in set_master()
1945 lkb->lkb_nodeid = ret_nodeid; in set_master()
1952 struct dlm_lkb *lkb, *safe; in process_lookup_list() local
1954 list_for_each_entry_safe(lkb, safe, &r->res_lookup, lkb_rsb_lookup) { in process_lookup_list()
1955 list_del_init(&lkb->lkb_rsb_lookup); in process_lookup_list()
1956 _request_lock(r, lkb); in process_lookup_list()
1965 struct dlm_lkb *lkb; in confirm_master() local
1987 lkb = list_entry(r->res_lookup.next, struct dlm_lkb, in confirm_master()
1989 list_del_init(&lkb->lkb_rsb_lookup); in confirm_master()
1990 r->res_first_lkid = lkb->lkb_id; in confirm_master()
1991 _request_lock(r, lkb); in confirm_master()
2080 static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in validate_lock_args() argument
2086 if (lkb->lkb_flags & DLM_IFL_MSTCPY) in validate_lock_args()
2090 !__quecvt_compat_matrix[lkb->lkb_grmode+1][args->mode+1]) in validate_lock_args()
2094 if (lkb->lkb_status != DLM_LKSTS_GRANTED) in validate_lock_args()
2097 if (lkb->lkb_wait_type) in validate_lock_args()
2100 if (is_overlap(lkb)) in validate_lock_args()
2104 lkb->lkb_exflags = args->flags; in validate_lock_args()
2105 lkb->lkb_sbflags = 0; in validate_lock_args()
2106 lkb->lkb_astfn = args->astfn; in validate_lock_args()
2107 lkb->lkb_astparam = args->astparam; in validate_lock_args()
2108 lkb->lkb_bastfn = args->bastfn; in validate_lock_args()
2109 lkb->lkb_rqmode = args->mode; in validate_lock_args()
2110 lkb->lkb_lksb = args->lksb; in validate_lock_args()
2111 lkb->lkb_lvbptr = args->lksb->sb_lvbptr; in validate_lock_args()
2112 lkb->lkb_ownpid = (int) current->pid; in validate_lock_args()
2113 lkb->lkb_timeout_cs = args->timeout; in validate_lock_args()
2118 rv, lkb->lkb_id, lkb->lkb_flags, args->flags, in validate_lock_args()
2119 lkb->lkb_status, lkb->lkb_wait_type, in validate_lock_args()
2120 lkb->lkb_resource->res_name); in validate_lock_args()
2131 static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) in validate_unlock_args() argument
2133 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in validate_unlock_args()
2136 if (lkb->lkb_flags & DLM_IFL_MSTCPY) { in validate_unlock_args()
2137 log_error(ls, "unlock on MSTCPY %x", lkb->lkb_id); in validate_unlock_args()
2138 dlm_print_lkb(lkb); in validate_unlock_args()
2146 if (lkb->lkb_flags & DLM_IFL_ENDOFLIFE) { in validate_unlock_args()
2147 log_debug(ls, "unlock on ENDOFLIFE %x", lkb->lkb_id); in validate_unlock_args()
2155 if (!list_empty(&lkb->lkb_rsb_lookup)) { in validate_unlock_args()
2157 log_debug(ls, "unlock on rsb_lookup %x", lkb->lkb_id); in validate_unlock_args()
2158 list_del_init(&lkb->lkb_rsb_lookup); in validate_unlock_args()
2159 queue_cast(lkb->lkb_resource, lkb, in validate_unlock_args()
2162 unhold_lkb(lkb); /* undoes create_lkb() */ in validate_unlock_args()
2172 if (lkb->lkb_exflags & DLM_LKF_CANCEL) in validate_unlock_args()
2175 if (is_overlap(lkb)) in validate_unlock_args()
2179 del_timeout(lkb); in validate_unlock_args()
2181 if (lkb->lkb_flags & DLM_IFL_RESEND) { in validate_unlock_args()
2182 lkb->lkb_flags |= DLM_IFL_OVERLAP_CANCEL; in validate_unlock_args()
2188 if (lkb->lkb_status == DLM_LKSTS_GRANTED && in validate_unlock_args()
2189 !lkb->lkb_wait_type) { in validate_unlock_args()
2194 switch (lkb->lkb_wait_type) { in validate_unlock_args()
2197 lkb->lkb_flags |= DLM_IFL_OVERLAP_CANCEL; in validate_unlock_args()
2213 if (lkb->lkb_exflags & DLM_LKF_FORCEUNLOCK) in validate_unlock_args()
2216 if (is_overlap_unlock(lkb)) in validate_unlock_args()
2220 del_timeout(lkb); in validate_unlock_args()
2222 if (lkb->lkb_flags & DLM_IFL_RESEND) { in validate_unlock_args()
2223 lkb->lkb_flags |= DLM_IFL_OVERLAP_UNLOCK; in validate_unlock_args()
2228 switch (lkb->lkb_wait_type) { in validate_unlock_args()
2231 lkb->lkb_flags |= DLM_IFL_OVERLAP_UNLOCK; in validate_unlock_args()
2243 if (lkb->lkb_wait_type || lkb->lkb_wait_count) in validate_unlock_args()
2248 lkb->lkb_exflags |= args->flags; in validate_unlock_args()
2249 lkb->lkb_sbflags = 0; in validate_unlock_args()
2250 lkb->lkb_astparam = args->astparam; in validate_unlock_args()
2255 lkb->lkb_id, lkb->lkb_flags, lkb->lkb_exflags, in validate_unlock_args()
2256 args->flags, lkb->lkb_wait_type, in validate_unlock_args()
2257 lkb->lkb_resource->res_name); in validate_unlock_args()
2268 static int do_request(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_request() argument
2272 if (can_be_granted(r, lkb, 1, NULL)) { in do_request()
2273 grant_lock(r, lkb); in do_request()
2274 queue_cast(r, lkb, 0); in do_request()
2278 if (can_be_queued(lkb)) { in do_request()
2280 add_lkb(r, lkb, DLM_LKSTS_WAITING); in do_request()
2281 add_timeout(lkb); in do_request()
2286 queue_cast(r, lkb, -EAGAIN); in do_request()
2291 static void do_request_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_request_effects() argument
2296 if (force_blocking_asts(lkb)) in do_request_effects()
2297 send_blocking_asts_all(r, lkb); in do_request_effects()
2300 send_blocking_asts(r, lkb); in do_request_effects()
2305 static int do_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_convert() argument
2312 if (can_be_granted(r, lkb, 1, &deadlk)) { in do_convert()
2313 grant_lock(r, lkb); in do_convert()
2314 queue_cast(r, lkb, 0); in do_convert()
2325 lkb->lkb_id, lkb->lkb_nodeid, lkb->lkb_status, in do_convert()
2326 lkb->lkb_grmode, lkb->lkb_rqmode, r->res_name); in do_convert()
2327 revert_lock(r, lkb); in do_convert()
2328 queue_cast(r, lkb, -EDEADLK); in do_convert()
2339 if (is_demoted(lkb)) { in do_convert()
2341 if (_can_be_granted(r, lkb, 1)) { in do_convert()
2342 grant_lock(r, lkb); in do_convert()
2343 queue_cast(r, lkb, 0); in do_convert()
2349 if (can_be_queued(lkb)) { in do_convert()
2351 del_lkb(r, lkb); in do_convert()
2352 add_lkb(r, lkb, DLM_LKSTS_CONVERT); in do_convert()
2353 add_timeout(lkb); in do_convert()
2358 queue_cast(r, lkb, -EAGAIN); in do_convert()
2363 static void do_convert_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_convert_effects() argument
2372 if (force_blocking_asts(lkb)) in do_convert_effects()
2373 send_blocking_asts_all(r, lkb); in do_convert_effects()
2376 send_blocking_asts(r, lkb); in do_convert_effects()
2381 static int do_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_unlock() argument
2383 remove_lock(r, lkb); in do_unlock()
2384 queue_cast(r, lkb, -DLM_EUNLOCK); in do_unlock()
2388 static void do_unlock_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_unlock_effects() argument
2396 static int do_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_cancel() argument
2400 error = revert_lock(r, lkb); in do_cancel()
2402 queue_cast(r, lkb, -DLM_ECANCEL); in do_cancel()
2408 static void do_cancel_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_cancel_effects() argument
2422 static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _request_lock() argument
2428 error = set_master(r, lkb); in _request_lock()
2438 error = send_request(r, lkb); in _request_lock()
2440 error = do_request(r, lkb); in _request_lock()
2443 do_request_effects(r, lkb, error); in _request_lock()
2451 static int _convert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _convert_lock() argument
2457 error = send_convert(r, lkb); in _convert_lock()
2459 error = do_convert(r, lkb); in _convert_lock()
2462 do_convert_effects(r, lkb, error); in _convert_lock()
2470 static int _unlock_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _unlock_lock() argument
2476 error = send_unlock(r, lkb); in _unlock_lock()
2478 error = do_unlock(r, lkb); in _unlock_lock()
2481 do_unlock_effects(r, lkb, error); in _unlock_lock()
2489 static int _cancel_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _cancel_lock() argument
2495 error = send_cancel(r, lkb); in _cancel_lock()
2497 error = do_cancel(r, lkb); in _cancel_lock()
2500 do_cancel_effects(r, lkb, error); in _cancel_lock()
2511 static int request_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, char *name, in request_lock() argument
2517 error = validate_lock_args(ls, lkb, args); in request_lock()
2527 attach_lkb(r, lkb); in request_lock()
2528 lkb->lkb_lksb->sb_lkid = lkb->lkb_id; in request_lock()
2530 error = _request_lock(r, lkb); in request_lock()
2539 static int convert_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in convert_lock() argument
2545 r = lkb->lkb_resource; in convert_lock()
2550 error = validate_lock_args(ls, lkb, args); in convert_lock()
2554 error = _convert_lock(r, lkb); in convert_lock()
2561 static int unlock_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in unlock_lock() argument
2567 r = lkb->lkb_resource; in unlock_lock()
2572 error = validate_unlock_args(lkb, args); in unlock_lock()
2576 error = _unlock_lock(r, lkb); in unlock_lock()
2583 static int cancel_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in cancel_lock() argument
2589 r = lkb->lkb_resource; in cancel_lock()
2594 error = validate_unlock_args(lkb, args); in cancel_lock()
2598 error = _cancel_lock(r, lkb); in cancel_lock()
2621 struct dlm_lkb *lkb; in dlm_lock() local
2632 error = find_lkb(ls, lksb->sb_lkid, &lkb); in dlm_lock()
2634 error = create_lkb(ls, &lkb); in dlm_lock()
2645 error = convert_lock(ls, lkb, &args); in dlm_lock()
2647 error = request_lock(ls, lkb, name, namelen, &args); in dlm_lock()
2653 __put_lkb(ls, lkb); in dlm_lock()
2669 struct dlm_lkb *lkb; in dlm_unlock() local
2679 error = find_lkb(ls, lkid, &lkb); in dlm_unlock()
2688 error = cancel_lock(ls, lkb, &args); in dlm_unlock()
2690 error = unlock_lock(ls, lkb, &args); in dlm_unlock()
2697 dlm_put_lkb(lkb); in dlm_unlock()
2760 static int create_message(struct dlm_rsb *r, struct dlm_lkb *lkb, in create_message() argument
2778 if (lkb && lkb->lkb_lvbptr) in create_message()
2797 static void send_args(struct dlm_rsb *r, struct dlm_lkb *lkb, in send_args() argument
2800 ms->m_nodeid = lkb->lkb_nodeid; in send_args()
2801 ms->m_pid = lkb->lkb_ownpid; in send_args()
2802 ms->m_lkid = lkb->lkb_id; in send_args()
2803 ms->m_remid = lkb->lkb_remid; in send_args()
2804 ms->m_exflags = lkb->lkb_exflags; in send_args()
2805 ms->m_sbflags = lkb->lkb_sbflags; in send_args()
2806 ms->m_flags = lkb->lkb_flags; in send_args()
2807 ms->m_lvbseq = lkb->lkb_lvbseq; in send_args()
2808 ms->m_status = lkb->lkb_status; in send_args()
2809 ms->m_grmode = lkb->lkb_grmode; in send_args()
2810 ms->m_rqmode = lkb->lkb_rqmode; in send_args()
2816 if (lkb->lkb_bastfn) in send_args()
2818 if (lkb->lkb_astfn) in send_args()
2834 if (!lkb->lkb_lvbptr) in send_args()
2836 memcpy(ms->m_extra, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); in send_args()
2841 static int send_common(struct dlm_rsb *r, struct dlm_lkb *lkb, int mstype) in send_common() argument
2847 error = add_to_waiters(lkb, mstype); in send_common()
2853 error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); in send_common()
2857 send_args(r, lkb, ms); in send_common()
2865 remove_from_waiters(lkb, msg_reply_type(mstype)); in send_common()
2869 static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_request() argument
2871 return send_common(r, lkb, DLM_MSG_REQUEST); in send_request()
2874 static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_convert() argument
2878 error = send_common(r, lkb, DLM_MSG_CONVERT); in send_convert()
2881 if (!error && down_conversion(lkb)) { in send_convert()
2882 remove_from_waiters(lkb, DLM_MSG_CONVERT_REPLY); in send_convert()
2885 r->res_ls->ls_stub_ms.m_flags = lkb->lkb_flags; in send_convert()
2886 __receive_convert_reply(r, lkb, &r->res_ls->ls_stub_ms); in send_convert()
2896 static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_unlock() argument
2898 return send_common(r, lkb, DLM_MSG_UNLOCK); in send_unlock()
2901 static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_cancel() argument
2903 return send_common(r, lkb, DLM_MSG_CANCEL); in send_cancel()
2906 static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_grant() argument
2912 to_nodeid = lkb->lkb_nodeid; in send_grant()
2914 error = create_message(r, lkb, to_nodeid, DLM_MSG_GRANT, &ms, &mh); in send_grant()
2918 send_args(r, lkb, ms); in send_grant()
2927 static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode) in send_bast() argument
2933 to_nodeid = lkb->lkb_nodeid; in send_bast()
2939 send_args(r, lkb, ms); in send_bast()
2948 static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_lookup() argument
2954 error = add_to_waiters(lkb, DLM_MSG_LOOKUP); in send_lookup()
2964 send_args(r, lkb, ms); in send_lookup()
2972 remove_from_waiters(lkb, DLM_MSG_LOOKUP_REPLY); in send_lookup()
2996 static int send_common_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, in send_common_reply() argument
3003 to_nodeid = lkb->lkb_nodeid; in send_common_reply()
3005 error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); in send_common_reply()
3009 send_args(r, lkb, ms); in send_common_reply()
3018 static int send_request_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_request_reply() argument
3020 return send_common_reply(r, lkb, DLM_MSG_REQUEST_REPLY, rv); in send_request_reply()
3023 static int send_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_convert_reply() argument
3025 return send_common_reply(r, lkb, DLM_MSG_CONVERT_REPLY, rv); in send_convert_reply()
3028 static int send_unlock_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_unlock_reply() argument
3030 return send_common_reply(r, lkb, DLM_MSG_UNLOCK_REPLY, rv); in send_unlock_reply()
3033 static int send_cancel_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_cancel_reply() argument
3035 return send_common_reply(r, lkb, DLM_MSG_CANCEL_REPLY, rv); in send_cancel_reply()
3063 static void receive_flags(struct dlm_lkb *lkb, struct dlm_message *ms) in receive_flags() argument
3065 lkb->lkb_exflags = ms->m_exflags; in receive_flags()
3066 lkb->lkb_sbflags = ms->m_sbflags; in receive_flags()
3067 lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | in receive_flags()
3071 static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in receive_flags_reply() argument
3073 lkb->lkb_sbflags = ms->m_sbflags; in receive_flags_reply()
3074 lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | in receive_flags_reply()
3083 static int receive_lvb(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_lvb() argument
3088 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_lvb()
3089 if (!lkb->lkb_lvbptr) in receive_lvb()
3090 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_lvb()
3091 if (!lkb->lkb_lvbptr) in receive_lvb()
3096 memcpy(lkb->lkb_lvbptr, ms->m_extra, len); in receive_lvb()
3111 static int receive_request_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_request_args() argument
3114 lkb->lkb_nodeid = ms->m_header.h_nodeid; in receive_request_args()
3115 lkb->lkb_ownpid = ms->m_pid; in receive_request_args()
3116 lkb->lkb_remid = ms->m_lkid; in receive_request_args()
3117 lkb->lkb_grmode = DLM_LOCK_IV; in receive_request_args()
3118 lkb->lkb_rqmode = ms->m_rqmode; in receive_request_args()
3120 lkb->lkb_bastfn = (ms->m_asts & DLM_CB_BAST) ? &fake_bastfn : NULL; in receive_request_args()
3121 lkb->lkb_astfn = (ms->m_asts & DLM_CB_CAST) ? &fake_astfn : NULL; in receive_request_args()
3123 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_request_args()
3125 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_request_args()
3126 if (!lkb->lkb_lvbptr) in receive_request_args()
3133 static int receive_convert_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_convert_args() argument
3136 if (lkb->lkb_status != DLM_LKSTS_GRANTED) in receive_convert_args()
3139 if (receive_lvb(ls, lkb, ms)) in receive_convert_args()
3142 lkb->lkb_rqmode = ms->m_rqmode; in receive_convert_args()
3143 lkb->lkb_lvbseq = ms->m_lvbseq; in receive_convert_args()
3148 static int receive_unlock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_unlock_args() argument
3151 if (receive_lvb(ls, lkb, ms)) in receive_unlock_args()
3161 struct dlm_lkb *lkb = &ls->ls_stub_lkb; in setup_stub_lkb() local
3162 lkb->lkb_nodeid = ms->m_header.h_nodeid; in setup_stub_lkb()
3163 lkb->lkb_remid = ms->m_lkid; in setup_stub_lkb()
3169 static int validate_message(struct dlm_lkb *lkb, struct dlm_message *ms) in validate_message() argument
3178 if (!is_master_copy(lkb) || lkb->lkb_nodeid != from) in validate_message()
3187 if (!is_process_copy(lkb) || lkb->lkb_nodeid != from) in validate_message()
3192 if (!is_process_copy(lkb)) in validate_message()
3194 else if (lkb->lkb_nodeid != -1 && lkb->lkb_nodeid != from) in validate_message()
3203 log_error(lkb->lkb_resource->res_ls, in validate_message()
3205 ms->m_type, from, lkb->lkb_id, lkb->lkb_remid, in validate_message()
3206 lkb->lkb_flags, lkb->lkb_nodeid); in validate_message()
3212 struct dlm_lkb *lkb; in receive_request() local
3216 error = create_lkb(ls, &lkb); in receive_request()
3220 receive_flags(lkb, ms); in receive_request()
3221 lkb->lkb_flags |= DLM_IFL_MSTCPY; in receive_request()
3222 error = receive_request_args(ls, lkb, ms); in receive_request()
3224 __put_lkb(ls, lkb); in receive_request()
3232 __put_lkb(ls, lkb); in receive_request()
3238 attach_lkb(r, lkb); in receive_request()
3239 error = do_request(r, lkb); in receive_request()
3240 send_request_reply(r, lkb, error); in receive_request()
3241 do_request_effects(r, lkb, error); in receive_request()
3249 dlm_put_lkb(lkb); in receive_request()
3259 struct dlm_lkb *lkb; in receive_convert() local
3263 error = find_lkb(ls, ms->m_remid, &lkb); in receive_convert()
3267 r = lkb->lkb_resource; in receive_convert()
3272 error = validate_message(lkb, ms); in receive_convert()
3276 receive_flags(lkb, ms); in receive_convert()
3278 error = receive_convert_args(ls, lkb, ms); in receive_convert()
3280 send_convert_reply(r, lkb, error); in receive_convert()
3284 reply = !down_conversion(lkb); in receive_convert()
3286 error = do_convert(r, lkb); in receive_convert()
3288 send_convert_reply(r, lkb, error); in receive_convert()
3289 do_convert_effects(r, lkb, error); in receive_convert()
3293 dlm_put_lkb(lkb); in receive_convert()
3303 struct dlm_lkb *lkb; in receive_unlock() local
3307 error = find_lkb(ls, ms->m_remid, &lkb); in receive_unlock()
3311 r = lkb->lkb_resource; in receive_unlock()
3316 error = validate_message(lkb, ms); in receive_unlock()
3320 receive_flags(lkb, ms); in receive_unlock()
3322 error = receive_unlock_args(ls, lkb, ms); in receive_unlock()
3324 send_unlock_reply(r, lkb, error); in receive_unlock()
3328 error = do_unlock(r, lkb); in receive_unlock()
3329 send_unlock_reply(r, lkb, error); in receive_unlock()
3330 do_unlock_effects(r, lkb, error); in receive_unlock()
3334 dlm_put_lkb(lkb); in receive_unlock()
3344 struct dlm_lkb *lkb; in receive_cancel() local
3348 error = find_lkb(ls, ms->m_remid, &lkb); in receive_cancel()
3352 receive_flags(lkb, ms); in receive_cancel()
3354 r = lkb->lkb_resource; in receive_cancel()
3359 error = validate_message(lkb, ms); in receive_cancel()
3363 error = do_cancel(r, lkb); in receive_cancel()
3364 send_cancel_reply(r, lkb, error); in receive_cancel()
3365 do_cancel_effects(r, lkb, error); in receive_cancel()
3369 dlm_put_lkb(lkb); in receive_cancel()
3379 struct dlm_lkb *lkb; in receive_grant() local
3383 error = find_lkb(ls, ms->m_remid, &lkb); in receive_grant()
3390 r = lkb->lkb_resource; in receive_grant()
3395 error = validate_message(lkb, ms); in receive_grant()
3399 receive_flags_reply(lkb, ms); in receive_grant()
3400 if (is_altmode(lkb)) in receive_grant()
3401 munge_altmode(lkb, ms); in receive_grant()
3402 grant_lock_pc(r, lkb, ms); in receive_grant()
3403 queue_cast(r, lkb, 0); in receive_grant()
3407 dlm_put_lkb(lkb); in receive_grant()
3412 struct dlm_lkb *lkb; in receive_bast() local
3416 error = find_lkb(ls, ms->m_remid, &lkb); in receive_bast()
3423 r = lkb->lkb_resource; in receive_bast()
3428 error = validate_message(lkb, ms); in receive_bast()
3432 queue_bast(r, lkb, ms->m_bastmode); in receive_bast()
3436 dlm_put_lkb(lkb); in receive_bast()
3493 struct dlm_lkb *lkb; in receive_request_reply() local
3497 error = find_lkb(ls, ms->m_remid, &lkb); in receive_request_reply()
3504 r = lkb->lkb_resource; in receive_request_reply()
3508 error = validate_message(lkb, ms); in receive_request_reply()
3512 mstype = lkb->lkb_wait_type; in receive_request_reply()
3513 error = remove_from_waiters(lkb, DLM_MSG_REQUEST_REPLY); in receive_request_reply()
3521 lkb->lkb_nodeid = r->res_nodeid; in receive_request_reply()
3530 queue_cast(r, lkb, -EAGAIN); in receive_request_reply()
3532 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_request_reply()
3538 receive_flags_reply(lkb, ms); in receive_request_reply()
3539 lkb->lkb_remid = ms->m_lkid; in receive_request_reply()
3540 if (is_altmode(lkb)) in receive_request_reply()
3541 munge_altmode(lkb, ms); in receive_request_reply()
3543 add_lkb(r, lkb, DLM_LKSTS_WAITING); in receive_request_reply()
3544 add_timeout(lkb); in receive_request_reply()
3546 grant_lock_pc(r, lkb, ms); in receive_request_reply()
3547 queue_cast(r, lkb, 0); in receive_request_reply()
3556 lkb->lkb_id, lkb->lkb_flags, r->res_nodeid, result); in receive_request_reply()
3558 lkb->lkb_nodeid = -1; in receive_request_reply()
3560 if (is_overlap(lkb)) { in receive_request_reply()
3562 queue_cast_overlap(r, lkb); in receive_request_reply()
3564 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_request_reply()
3566 _request_lock(r, lkb); in receive_request_reply()
3571 lkb->lkb_id, result); in receive_request_reply()
3574 if (is_overlap_unlock(lkb) && (result == 0 || result == -EINPROGRESS)) { in receive_request_reply()
3576 lkb->lkb_id, result); in receive_request_reply()
3577 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
3578 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
3579 send_unlock(r, lkb); in receive_request_reply()
3580 } else if (is_overlap_cancel(lkb) && (result == -EINPROGRESS)) { in receive_request_reply()
3581 log_debug(ls, "receive_request_reply %x cancel", lkb->lkb_id); in receive_request_reply()
3582 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
3583 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
3584 send_cancel(r, lkb); in receive_request_reply()
3586 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
3587 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
3592 dlm_put_lkb(lkb); in receive_request_reply()
3595 static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, in __receive_convert_reply() argument
3602 queue_cast(r, lkb, -EAGAIN); in __receive_convert_reply()
3606 receive_flags_reply(lkb, ms); in __receive_convert_reply()
3607 revert_lock_pc(r, lkb); in __receive_convert_reply()
3608 queue_cast(r, lkb, -EDEADLK); in __receive_convert_reply()
3613 receive_flags_reply(lkb, ms); in __receive_convert_reply()
3614 if (is_demoted(lkb)) in __receive_convert_reply()
3615 munge_demoted(lkb, ms); in __receive_convert_reply()
3616 del_lkb(r, lkb); in __receive_convert_reply()
3617 add_lkb(r, lkb, DLM_LKSTS_CONVERT); in __receive_convert_reply()
3618 add_timeout(lkb); in __receive_convert_reply()
3623 receive_flags_reply(lkb, ms); in __receive_convert_reply()
3624 if (is_demoted(lkb)) in __receive_convert_reply()
3625 munge_demoted(lkb, ms); in __receive_convert_reply()
3626 grant_lock_pc(r, lkb, ms); in __receive_convert_reply()
3627 queue_cast(r, lkb, 0); in __receive_convert_reply()
3632 lkb->lkb_id, ms->m_result); in __receive_convert_reply()
3636 static void _receive_convert_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_convert_reply() argument
3638 struct dlm_rsb *r = lkb->lkb_resource; in _receive_convert_reply()
3644 error = validate_message(lkb, ms); in _receive_convert_reply()
3649 error = remove_from_waiters_ms(lkb, ms); in _receive_convert_reply()
3653 __receive_convert_reply(r, lkb, ms); in _receive_convert_reply()
3661 struct dlm_lkb *lkb; in receive_convert_reply() local
3664 error = find_lkb(ls, ms->m_remid, &lkb); in receive_convert_reply()
3671 _receive_convert_reply(lkb, ms); in receive_convert_reply()
3672 dlm_put_lkb(lkb); in receive_convert_reply()
3675 static void _receive_unlock_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_unlock_reply() argument
3677 struct dlm_rsb *r = lkb->lkb_resource; in _receive_unlock_reply()
3683 error = validate_message(lkb, ms); in _receive_unlock_reply()
3688 error = remove_from_waiters_ms(lkb, ms); in _receive_unlock_reply()
3696 receive_flags_reply(lkb, ms); in _receive_unlock_reply()
3697 remove_lock_pc(r, lkb); in _receive_unlock_reply()
3698 queue_cast(r, lkb, -DLM_EUNLOCK); in _receive_unlock_reply()
3704 lkb->lkb_id, ms->m_result); in _receive_unlock_reply()
3713 struct dlm_lkb *lkb; in receive_unlock_reply() local
3716 error = find_lkb(ls, ms->m_remid, &lkb); in receive_unlock_reply()
3723 _receive_unlock_reply(lkb, ms); in receive_unlock_reply()
3724 dlm_put_lkb(lkb); in receive_unlock_reply()
3727 static void _receive_cancel_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_cancel_reply() argument
3729 struct dlm_rsb *r = lkb->lkb_resource; in _receive_cancel_reply()
3735 error = validate_message(lkb, ms); in _receive_cancel_reply()
3740 error = remove_from_waiters_ms(lkb, ms); in _receive_cancel_reply()
3748 receive_flags_reply(lkb, ms); in _receive_cancel_reply()
3749 revert_lock_pc(r, lkb); in _receive_cancel_reply()
3750 queue_cast(r, lkb, -DLM_ECANCEL); in _receive_cancel_reply()
3756 lkb->lkb_id, ms->m_result); in _receive_cancel_reply()
3765 struct dlm_lkb *lkb; in receive_cancel_reply() local
3768 error = find_lkb(ls, ms->m_remid, &lkb); in receive_cancel_reply()
3775 _receive_cancel_reply(lkb, ms); in receive_cancel_reply()
3776 dlm_put_lkb(lkb); in receive_cancel_reply()
3781 struct dlm_lkb *lkb; in receive_lookup_reply() local
3785 error = find_lkb(ls, ms->m_lkid, &lkb); in receive_lookup_reply()
3794 r = lkb->lkb_resource; in receive_lookup_reply()
3798 error = remove_from_waiters(lkb, DLM_MSG_LOOKUP_REPLY); in receive_lookup_reply()
3812 if (is_overlap(lkb)) { in receive_lookup_reply()
3814 lkb->lkb_id, lkb->lkb_flags); in receive_lookup_reply()
3815 queue_cast_overlap(r, lkb); in receive_lookup_reply()
3816 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_lookup_reply()
3820 _request_lock(r, lkb); in receive_lookup_reply()
3828 dlm_put_lkb(lkb); in receive_lookup_reply()
3999 static void recover_convert_waiter(struct dlm_ls *ls, struct dlm_lkb *lkb) in recover_convert_waiter() argument
4001 if (middle_conversion(lkb)) { in recover_convert_waiter()
4002 hold_lkb(lkb); in recover_convert_waiter()
4005 ls->ls_stub_ms.m_flags = lkb->lkb_flags; in recover_convert_waiter()
4006 ls->ls_stub_ms.m_header.h_nodeid = lkb->lkb_nodeid; in recover_convert_waiter()
4007 _receive_convert_reply(lkb, &ls->ls_stub_ms); in recover_convert_waiter()
4010 lkb->lkb_grmode = DLM_LOCK_IV; in recover_convert_waiter()
4011 rsb_set_flag(lkb->lkb_resource, RSB_RECOVER_CONVERT); in recover_convert_waiter()
4012 unhold_lkb(lkb); in recover_convert_waiter()
4014 } else if (lkb->lkb_rqmode >= lkb->lkb_grmode) { in recover_convert_waiter()
4015 lkb->lkb_flags |= DLM_IFL_RESEND; in recover_convert_waiter()
4025 static int waiter_needs_recovery(struct dlm_ls *ls, struct dlm_lkb *lkb) in waiter_needs_recovery() argument
4027 if (dlm_is_removed(ls, lkb->lkb_nodeid)) in waiter_needs_recovery()
4033 if (dlm_dir_nodeid(lkb->lkb_resource) != lkb->lkb_nodeid) in waiter_needs_recovery()
4047 struct dlm_lkb *lkb, *safe; in dlm_recover_waiters_pre() local
4052 list_for_each_entry_safe(lkb, safe, &ls->ls_waiters, lkb_wait_reply) { in dlm_recover_waiters_pre()
4054 lkb->lkb_id, lkb->lkb_wait_type, lkb->lkb_flags); in dlm_recover_waiters_pre()
4059 if (lkb->lkb_wait_type == DLM_MSG_LOOKUP) { in dlm_recover_waiters_pre()
4060 lkb->lkb_flags |= DLM_IFL_RESEND; in dlm_recover_waiters_pre()
4064 if (!waiter_needs_recovery(ls, lkb)) in dlm_recover_waiters_pre()
4067 wait_type = lkb->lkb_wait_type; in dlm_recover_waiters_pre()
4077 if (is_overlap_cancel(lkb)) { in dlm_recover_waiters_pre()
4079 if (lkb->lkb_grmode == DLM_LOCK_IV) in dlm_recover_waiters_pre()
4082 if (is_overlap_unlock(lkb)) { in dlm_recover_waiters_pre()
4084 if (lkb->lkb_grmode == DLM_LOCK_IV) in dlm_recover_waiters_pre()
4089 lkb->lkb_id, lkb->lkb_flags, wait_type, in dlm_recover_waiters_pre()
4096 lkb->lkb_flags |= DLM_IFL_RESEND; in dlm_recover_waiters_pre()
4100 recover_convert_waiter(ls, lkb); in dlm_recover_waiters_pre()
4104 hold_lkb(lkb); in dlm_recover_waiters_pre()
4107 ls->ls_stub_ms.m_flags = lkb->lkb_flags; in dlm_recover_waiters_pre()
4108 ls->ls_stub_ms.m_header.h_nodeid = lkb->lkb_nodeid; in dlm_recover_waiters_pre()
4109 _receive_unlock_reply(lkb, &ls->ls_stub_ms); in dlm_recover_waiters_pre()
4110 dlm_put_lkb(lkb); in dlm_recover_waiters_pre()
4114 hold_lkb(lkb); in dlm_recover_waiters_pre()
4117 ls->ls_stub_ms.m_flags = lkb->lkb_flags; in dlm_recover_waiters_pre()
4118 ls->ls_stub_ms.m_header.h_nodeid = lkb->lkb_nodeid; in dlm_recover_waiters_pre()
4119 _receive_cancel_reply(lkb, &ls->ls_stub_ms); in dlm_recover_waiters_pre()
4120 dlm_put_lkb(lkb); in dlm_recover_waiters_pre()
4125 lkb->lkb_wait_type, wait_type); in dlm_recover_waiters_pre()
4134 struct dlm_lkb *lkb; in find_resend_waiter() local
4138 list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { in find_resend_waiter()
4139 if (lkb->lkb_flags & DLM_IFL_RESEND) { in find_resend_waiter()
4140 hold_lkb(lkb); in find_resend_waiter()
4148 lkb = NULL; in find_resend_waiter()
4149 return lkb; in find_resend_waiter()
4170 struct dlm_lkb *lkb; in dlm_recover_waiters_post() local
4181 lkb = find_resend_waiter(ls); in dlm_recover_waiters_post()
4182 if (!lkb) in dlm_recover_waiters_post()
4185 r = lkb->lkb_resource; in dlm_recover_waiters_post()
4189 mstype = lkb->lkb_wait_type; in dlm_recover_waiters_post()
4190 oc = is_overlap_cancel(lkb); in dlm_recover_waiters_post()
4191 ou = is_overlap_unlock(lkb); in dlm_recover_waiters_post()
4195 lkb->lkb_id, mstype, lkb->lkb_flags, r->res_name); in dlm_recover_waiters_post()
4201 lkb->lkb_flags &= ~DLM_IFL_RESEND; in dlm_recover_waiters_post()
4202 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in dlm_recover_waiters_post()
4203 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in dlm_recover_waiters_post()
4204 lkb->lkb_wait_type = 0; in dlm_recover_waiters_post()
4205 lkb->lkb_wait_count = 0; in dlm_recover_waiters_post()
4207 list_del_init(&lkb->lkb_wait_reply); in dlm_recover_waiters_post()
4209 unhold_lkb(lkb); /* for waiters list */ in dlm_recover_waiters_post()
4216 queue_cast(r, lkb, ou ? -DLM_EUNLOCK : in dlm_recover_waiters_post()
4218 unhold_lkb(lkb); /* undoes create_lkb() */ in dlm_recover_waiters_post()
4222 queue_cast(r, lkb, -DLM_ECANCEL); in dlm_recover_waiters_post()
4224 lkb->lkb_exflags |= DLM_LKF_FORCEUNLOCK; in dlm_recover_waiters_post()
4225 _unlock_lock(r, lkb); in dlm_recover_waiters_post()
4235 _request_lock(r, lkb); in dlm_recover_waiters_post()
4240 _convert_lock(r, lkb); in dlm_recover_waiters_post()
4249 lkb->lkb_id, mstype, lkb->lkb_flags, oc, ou); in dlm_recover_waiters_post()
4252 dlm_put_lkb(lkb); in dlm_recover_waiters_post()
4259 int (*test)(struct dlm_ls *ls, struct dlm_lkb *lkb)) in purge_queue() argument
4262 struct dlm_lkb *lkb, *safe; in purge_queue() local
4264 list_for_each_entry_safe(lkb, safe, queue, lkb_statequeue) { in purge_queue()
4265 if (test(ls, lkb)) { in purge_queue()
4267 del_lkb(r, lkb); in purge_queue()
4269 if (!dlm_put_lkb(lkb)) in purge_queue()
4275 static int purge_dead_test(struct dlm_ls *ls, struct dlm_lkb *lkb) in purge_dead_test() argument
4277 return (is_master_copy(lkb) && dlm_is_removed(ls, lkb->lkb_nodeid)); in purge_dead_test()
4280 static int purge_mstcpy_test(struct dlm_ls *ls, struct dlm_lkb *lkb) in purge_mstcpy_test() argument
4282 return is_master_copy(lkb); in purge_mstcpy_test()
4367 struct dlm_lkb *lkb; in search_remid_list() local
4369 list_for_each_entry(lkb, head, lkb_statequeue) { in search_remid_list()
4370 if (lkb->lkb_nodeid == nodeid && lkb->lkb_remid == remid) in search_remid_list()
4371 return lkb; in search_remid_list()
4379 struct dlm_lkb *lkb; in search_remid() local
4381 lkb = search_remid_list(&r->res_grantqueue, nodeid, remid); in search_remid()
4382 if (lkb) in search_remid()
4383 return lkb; in search_remid()
4384 lkb = search_remid_list(&r->res_convertqueue, nodeid, remid); in search_remid()
4385 if (lkb) in search_remid()
4386 return lkb; in search_remid()
4387 lkb = search_remid_list(&r->res_waitqueue, nodeid, remid); in search_remid()
4388 if (lkb) in search_remid()
4389 return lkb; in search_remid()
4394 static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_rcom_lock_args() argument
4399 lkb->lkb_nodeid = rc->rc_header.h_nodeid; in receive_rcom_lock_args()
4400 lkb->lkb_ownpid = le32_to_cpu(rl->rl_ownpid); in receive_rcom_lock_args()
4401 lkb->lkb_remid = le32_to_cpu(rl->rl_lkid); in receive_rcom_lock_args()
4402 lkb->lkb_exflags = le32_to_cpu(rl->rl_exflags); in receive_rcom_lock_args()
4403 lkb->lkb_flags = le32_to_cpu(rl->rl_flags) & 0x0000FFFF; in receive_rcom_lock_args()
4404 lkb->lkb_flags |= DLM_IFL_MSTCPY; in receive_rcom_lock_args()
4405 lkb->lkb_lvbseq = le32_to_cpu(rl->rl_lvbseq); in receive_rcom_lock_args()
4406 lkb->lkb_rqmode = rl->rl_rqmode; in receive_rcom_lock_args()
4407 lkb->lkb_grmode = rl->rl_grmode; in receive_rcom_lock_args()
4410 lkb->lkb_bastfn = (rl->rl_asts & DLM_CB_BAST) ? &fake_bastfn : NULL; in receive_rcom_lock_args()
4411 lkb->lkb_astfn = (rl->rl_asts & DLM_CB_CAST) ? &fake_astfn : NULL; in receive_rcom_lock_args()
4413 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_rcom_lock_args()
4418 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_rcom_lock_args()
4419 if (!lkb->lkb_lvbptr) in receive_rcom_lock_args()
4421 memcpy(lkb->lkb_lvbptr, rl->rl_lvb, lvblen); in receive_rcom_lock_args()
4429 middle_conversion(lkb)) { in receive_rcom_lock_args()
4431 lkb->lkb_grmode = DLM_LOCK_IV; in receive_rcom_lock_args()
4449 struct dlm_lkb *lkb; in dlm_recover_master_copy() local
4464 lkb = search_remid(r, rc->rc_header.h_nodeid, le32_to_cpu(rl->rl_lkid)); in dlm_recover_master_copy()
4465 if (lkb) { in dlm_recover_master_copy()
4470 error = create_lkb(ls, &lkb); in dlm_recover_master_copy()
4474 error = receive_rcom_lock_args(ls, lkb, r, rc); in dlm_recover_master_copy()
4476 __put_lkb(ls, lkb); in dlm_recover_master_copy()
4480 attach_lkb(r, lkb); in dlm_recover_master_copy()
4481 add_lkb(r, lkb, rl->rl_status); in dlm_recover_master_copy()
4487 rl->rl_remid = cpu_to_le32(lkb->lkb_id); in dlm_recover_master_copy()
4505 struct dlm_lkb *lkb; in dlm_recover_process_copy() local
4508 error = find_lkb(ls, le32_to_cpu(rl->rl_lkid), &lkb); in dlm_recover_process_copy()
4515 DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); in dlm_recover_process_copy()
4519 r = lkb->lkb_resource; in dlm_recover_process_copy()
4528 log_debug(ls, "master copy not ready %x r %lx %s", lkb->lkb_id, in dlm_recover_process_copy()
4530 dlm_send_rcom_lock(r, lkb); in dlm_recover_process_copy()
4533 log_debug(ls, "master copy exists %x", lkb->lkb_id); in dlm_recover_process_copy()
4536 lkb->lkb_remid = le32_to_cpu(rl->rl_remid); in dlm_recover_process_copy()
4540 error, lkb->lkb_id); in dlm_recover_process_copy()
4549 dlm_put_lkb(lkb); in dlm_recover_process_copy()
4558 struct dlm_lkb *lkb; in dlm_user_request() local
4564 error = create_lkb(ls, &lkb); in dlm_user_request()
4574 __put_lkb(ls, lkb); in dlm_user_request()
4586 lkb->lkb_flags |= DLM_IFL_USER; in dlm_user_request()
4589 __put_lkb(ls, lkb); in dlm_user_request()
4593 error = request_lock(ls, lkb, name, namelen, &args); in dlm_user_request()
4605 __put_lkb(ls, lkb); in dlm_user_request()
4611 hold_lkb(lkb); in dlm_user_request()
4612 list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks); in dlm_user_request()
4623 struct dlm_lkb *lkb; in dlm_user_convert() local
4630 error = find_lkb(ls, lkid, &lkb); in dlm_user_convert()
4637 ua = lkb->lkb_ua; in dlm_user_convert()
4661 error = convert_lock(ls, lkb, &args); in dlm_user_convert()
4666 dlm_put_lkb(lkb); in dlm_user_convert()
4676 struct dlm_lkb *lkb; in dlm_user_unlock() local
4683 error = find_lkb(ls, lkid, &lkb); in dlm_user_unlock()
4687 ua = lkb->lkb_ua; in dlm_user_unlock()
4699 error = unlock_lock(ls, lkb, &args); in dlm_user_unlock()
4711 if (!list_empty(&lkb->lkb_ownqueue)) in dlm_user_unlock()
4712 list_move(&lkb->lkb_ownqueue, &ua->proc->unlocking); in dlm_user_unlock()
4715 dlm_put_lkb(lkb); in dlm_user_unlock()
4725 struct dlm_lkb *lkb; in dlm_user_cancel() local
4732 error = find_lkb(ls, lkid, &lkb); in dlm_user_cancel()
4736 ua = lkb->lkb_ua; in dlm_user_cancel()
4745 error = cancel_lock(ls, lkb, &args); in dlm_user_cancel()
4753 dlm_put_lkb(lkb); in dlm_user_cancel()
4762 struct dlm_lkb *lkb; in dlm_user_deadlock() local
4770 error = find_lkb(ls, lkid, &lkb); in dlm_user_deadlock()
4774 ua = lkb->lkb_ua; in dlm_user_deadlock()
4782 r = lkb->lkb_resource; in dlm_user_deadlock()
4786 error = validate_unlock_args(lkb, &args); in dlm_user_deadlock()
4789 lkb->lkb_flags |= DLM_IFL_DEADLOCK_CANCEL; in dlm_user_deadlock()
4791 error = _cancel_lock(r, lkb); in dlm_user_deadlock()
4802 dlm_put_lkb(lkb); in dlm_user_deadlock()
4811 static int orphan_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) in orphan_proc_lock() argument
4816 hold_lkb(lkb); in orphan_proc_lock()
4818 list_add_tail(&lkb->lkb_ownqueue, &ls->ls_orphans); in orphan_proc_lock()
4821 set_unlock_args(0, lkb->lkb_ua, &args); in orphan_proc_lock()
4823 error = cancel_lock(ls, lkb, &args); in orphan_proc_lock()
4832 static int unlock_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) in unlock_proc_lock() argument
4837 set_unlock_args(DLM_LKF_FORCEUNLOCK, lkb->lkb_ua, &args); in unlock_proc_lock()
4839 error = unlock_lock(ls, lkb, &args); in unlock_proc_lock()
4852 struct dlm_lkb *lkb = NULL; in del_proc_lock() local
4858 lkb = list_entry(proc->locks.next, struct dlm_lkb, lkb_ownqueue); in del_proc_lock()
4859 list_del_init(&lkb->lkb_ownqueue); in del_proc_lock()
4861 if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) in del_proc_lock()
4862 lkb->lkb_flags |= DLM_IFL_ORPHAN; in del_proc_lock()
4864 lkb->lkb_flags |= DLM_IFL_DEAD; in del_proc_lock()
4867 return lkb; in del_proc_lock()
4882 struct dlm_lkb *lkb, *safe; in dlm_clear_proc_locks() local
4887 lkb = del_proc_lock(ls, proc); in dlm_clear_proc_locks()
4888 if (!lkb) in dlm_clear_proc_locks()
4890 del_timeout(lkb); in dlm_clear_proc_locks()
4891 if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) in dlm_clear_proc_locks()
4892 orphan_proc_lock(ls, lkb); in dlm_clear_proc_locks()
4894 unlock_proc_lock(ls, lkb); in dlm_clear_proc_locks()
4900 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
4906 list_for_each_entry_safe(lkb, safe, &proc->unlocking, lkb_ownqueue) { in dlm_clear_proc_locks()
4907 list_del_init(&lkb->lkb_ownqueue); in dlm_clear_proc_locks()
4908 lkb->lkb_flags |= DLM_IFL_DEAD; in dlm_clear_proc_locks()
4909 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
4912 list_for_each_entry_safe(lkb, safe, &proc->asts, lkb_astqueue) { in dlm_clear_proc_locks()
4913 memset(&lkb->lkb_callbacks, 0, in dlm_clear_proc_locks()
4915 list_del_init(&lkb->lkb_astqueue); in dlm_clear_proc_locks()
4916 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
4925 struct dlm_lkb *lkb, *safe; in purge_proc_locks() local
4928 lkb = NULL; in purge_proc_locks()
4931 lkb = list_entry(proc->locks.next, struct dlm_lkb, in purge_proc_locks()
4933 list_del_init(&lkb->lkb_ownqueue); in purge_proc_locks()
4937 if (!lkb) in purge_proc_locks()
4940 lkb->lkb_flags |= DLM_IFL_DEAD; in purge_proc_locks()
4941 unlock_proc_lock(ls, lkb); in purge_proc_locks()
4942 dlm_put_lkb(lkb); /* ref from proc->locks list */ in purge_proc_locks()
4946 list_for_each_entry_safe(lkb, safe, &proc->unlocking, lkb_ownqueue) { in purge_proc_locks()
4947 list_del_init(&lkb->lkb_ownqueue); in purge_proc_locks()
4948 lkb->lkb_flags |= DLM_IFL_DEAD; in purge_proc_locks()
4949 dlm_put_lkb(lkb); in purge_proc_locks()
4954 list_for_each_entry_safe(lkb, safe, &proc->asts, lkb_astqueue) { in purge_proc_locks()
4955 memset(&lkb->lkb_callbacks, 0, in purge_proc_locks()
4957 list_del_init(&lkb->lkb_astqueue); in purge_proc_locks()
4958 dlm_put_lkb(lkb); in purge_proc_locks()
4967 struct dlm_lkb *lkb, *safe; in do_purge() local
4970 list_for_each_entry_safe(lkb, safe, &ls->ls_orphans, lkb_ownqueue) { in do_purge()
4971 if (pid && lkb->lkb_ownpid != pid) in do_purge()
4973 unlock_proc_lock(ls, lkb); in do_purge()
4974 list_del_init(&lkb->lkb_ownqueue); in do_purge()
4975 dlm_put_lkb(lkb); in do_purge()