Lines Matching refs:lkb
76 static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb);
77 static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb);
78 static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb);
79 static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb);
80 static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb);
81 static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode);
82 static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb);
84 static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb);
85 static int _cancel_lock(struct dlm_rsb *r, struct dlm_lkb *lkb);
86 static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb,
90 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, lkb->lkb_wait_nodeid, in dlm_print_lkb()
167 (unsigned long long)lkb->lkb_recover_seq); in dlm_print_lkb()
181 struct dlm_lkb *lkb; in dlm_dump_rsb() local
188 list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) in dlm_dump_rsb()
189 dlm_print_lkb(lkb); in dlm_dump_rsb()
191 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) in dlm_dump_rsb()
192 dlm_print_lkb(lkb); in dlm_dump_rsb()
194 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) in dlm_dump_rsb()
195 dlm_print_lkb(lkb); in dlm_dump_rsb()
197 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) in dlm_dump_rsb()
198 dlm_print_lkb(lkb); in dlm_dump_rsb()
218 static inline int can_be_queued(struct dlm_lkb *lkb) in can_be_queued() argument
220 return !(lkb->lkb_exflags & DLM_LKF_NOQUEUE); in can_be_queued()
223 static inline int force_blocking_asts(struct dlm_lkb *lkb) in force_blocking_asts() argument
225 return (lkb->lkb_exflags & DLM_LKF_NOQUEUEBAST); in force_blocking_asts()
228 static inline int is_demoted(struct dlm_lkb *lkb) in is_demoted() argument
230 return (lkb->lkb_sbflags & DLM_SBF_DEMOTED); in is_demoted()
233 static inline int is_altmode(struct dlm_lkb *lkb) in is_altmode() argument
235 return (lkb->lkb_sbflags & DLM_SBF_ALTMODE); in is_altmode()
238 static inline int is_granted(struct dlm_lkb *lkb) in is_granted() argument
240 return (lkb->lkb_status == DLM_LKSTS_GRANTED); in is_granted()
249 static inline int is_process_copy(struct dlm_lkb *lkb) in is_process_copy() argument
251 return (lkb->lkb_nodeid && !(lkb->lkb_flags & DLM_IFL_MSTCPY)); in is_process_copy()
254 static inline int is_master_copy(struct dlm_lkb *lkb) in is_master_copy() argument
256 return (lkb->lkb_flags & DLM_IFL_MSTCPY) ? 1 : 0; in is_master_copy()
259 static inline int middle_conversion(struct dlm_lkb *lkb) in middle_conversion() argument
261 if ((lkb->lkb_grmode==DLM_LOCK_PR && lkb->lkb_rqmode==DLM_LOCK_CW) || in middle_conversion()
262 (lkb->lkb_rqmode==DLM_LOCK_PR && lkb->lkb_grmode==DLM_LOCK_CW)) in middle_conversion()
267 static inline int down_conversion(struct dlm_lkb *lkb) in down_conversion() argument
269 return (!middle_conversion(lkb) && lkb->lkb_rqmode < lkb->lkb_grmode); in down_conversion()
272 static inline int is_overlap_unlock(struct dlm_lkb *lkb) in is_overlap_unlock() argument
274 return lkb->lkb_flags & DLM_IFL_OVERLAP_UNLOCK; in is_overlap_unlock()
277 static inline int is_overlap_cancel(struct dlm_lkb *lkb) in is_overlap_cancel() argument
279 return lkb->lkb_flags & DLM_IFL_OVERLAP_CANCEL; in is_overlap_cancel()
282 static inline int is_overlap(struct dlm_lkb *lkb) in is_overlap() argument
284 return (lkb->lkb_flags & (DLM_IFL_OVERLAP_UNLOCK | in is_overlap()
288 static void queue_cast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in queue_cast() argument
290 if (is_master_copy(lkb)) in queue_cast()
293 del_timeout(lkb); in queue_cast()
295 DLM_ASSERT(lkb->lkb_lksb, dlm_print_lkb(lkb);); in queue_cast()
299 if (rv == -DLM_ECANCEL && (lkb->lkb_flags & DLM_IFL_TIMEOUT_CANCEL)) { in queue_cast()
300 lkb->lkb_flags &= ~DLM_IFL_TIMEOUT_CANCEL; in queue_cast()
304 if (rv == -DLM_ECANCEL && (lkb->lkb_flags & DLM_IFL_DEADLOCK_CANCEL)) { in queue_cast()
305 lkb->lkb_flags &= ~DLM_IFL_DEADLOCK_CANCEL; in queue_cast()
309 dlm_add_cb(lkb, DLM_CB_CAST, lkb->lkb_grmode, rv, lkb->lkb_sbflags); in queue_cast()
312 static inline void queue_cast_overlap(struct dlm_rsb *r, struct dlm_lkb *lkb) in queue_cast_overlap() argument
314 queue_cast(r, lkb, in queue_cast_overlap()
315 is_overlap_unlock(lkb) ? -DLM_EUNLOCK : -DLM_ECANCEL); in queue_cast_overlap()
318 static void queue_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rqmode) in queue_bast() argument
320 if (is_master_copy(lkb)) { in queue_bast()
321 send_bast(r, lkb, rqmode); in queue_bast()
323 dlm_add_cb(lkb, DLM_CB_BAST, rqmode, 0, 0); in queue_bast()
1167 static void attach_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) in attach_lkb() argument
1170 lkb->lkb_resource = r; in attach_lkb()
1173 static void detach_lkb(struct dlm_lkb *lkb) in detach_lkb() argument
1175 if (lkb->lkb_resource) { in detach_lkb()
1176 put_rsb(lkb->lkb_resource); in detach_lkb()
1177 lkb->lkb_resource = NULL; in detach_lkb()
1183 struct dlm_lkb *lkb; in create_lkb() local
1186 lkb = dlm_allocate_lkb(ls); in create_lkb()
1187 if (!lkb) in create_lkb()
1190 lkb->lkb_nodeid = -1; in create_lkb()
1191 lkb->lkb_grmode = DLM_LOCK_IV; in create_lkb()
1192 kref_init(&lkb->lkb_ref); in create_lkb()
1193 INIT_LIST_HEAD(&lkb->lkb_ownqueue); in create_lkb()
1194 INIT_LIST_HEAD(&lkb->lkb_rsb_lookup); in create_lkb()
1195 INIT_LIST_HEAD(&lkb->lkb_time_list); in create_lkb()
1196 INIT_LIST_HEAD(&lkb->lkb_cb_list); in create_lkb()
1197 mutex_init(&lkb->lkb_cb_mutex); in create_lkb()
1198 INIT_WORK(&lkb->lkb_cb_work, dlm_callback_work); in create_lkb()
1202 rv = idr_alloc(&ls->ls_lkbidr, lkb, 1, 0, GFP_NOWAIT); in create_lkb()
1204 lkb->lkb_id = rv; in create_lkb()
1210 dlm_free_lkb(lkb); in create_lkb()
1214 *lkb_ret = lkb; in create_lkb()
1220 struct dlm_lkb *lkb; in find_lkb() local
1223 lkb = idr_find(&ls->ls_lkbidr, lkid); in find_lkb()
1224 if (lkb) in find_lkb()
1225 kref_get(&lkb->lkb_ref); in find_lkb()
1228 *lkb_ret = lkb; in find_lkb()
1229 return lkb ? 0 : -ENOENT; in find_lkb()
1234 struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref); in kill_lkb() local
1239 DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); in kill_lkb()
1245 static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb) in __put_lkb() argument
1247 uint32_t lkid = lkb->lkb_id; in __put_lkb()
1250 if (kref_put(&lkb->lkb_ref, kill_lkb)) { in __put_lkb()
1254 detach_lkb(lkb); in __put_lkb()
1257 if (lkb->lkb_lvbptr && is_master_copy(lkb)) in __put_lkb()
1258 dlm_free_lvb(lkb->lkb_lvbptr); in __put_lkb()
1259 dlm_free_lkb(lkb); in __put_lkb()
1267 int dlm_put_lkb(struct dlm_lkb *lkb) in dlm_put_lkb() argument
1271 DLM_ASSERT(lkb->lkb_resource, dlm_print_lkb(lkb);); in dlm_put_lkb()
1272 DLM_ASSERT(lkb->lkb_resource->res_ls, dlm_print_lkb(lkb);); in dlm_put_lkb()
1274 ls = lkb->lkb_resource->res_ls; in dlm_put_lkb()
1275 return __put_lkb(ls, lkb); in dlm_put_lkb()
1281 static inline void hold_lkb(struct dlm_lkb *lkb) in hold_lkb() argument
1283 kref_get(&lkb->lkb_ref); in hold_lkb()
1291 static inline void unhold_lkb(struct dlm_lkb *lkb) in unhold_lkb() argument
1294 rv = kref_put(&lkb->lkb_ref, kill_lkb); in unhold_lkb()
1295 DLM_ASSERT(!rv, dlm_print_lkb(lkb);); in unhold_lkb()
1301 struct dlm_lkb *lkb = NULL; in lkb_add_ordered() local
1303 list_for_each_entry(lkb, head, lkb_statequeue) in lkb_add_ordered()
1304 if (lkb->lkb_rqmode < mode) in lkb_add_ordered()
1307 __list_add(new, lkb->lkb_statequeue.prev, &lkb->lkb_statequeue); in lkb_add_ordered()
1312 static void add_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int status) in add_lkb() argument
1314 kref_get(&lkb->lkb_ref); in add_lkb()
1316 DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); in add_lkb()
1318 lkb->lkb_timestamp = ktime_get(); in add_lkb()
1320 lkb->lkb_status = status; in add_lkb()
1324 if (lkb->lkb_exflags & DLM_LKF_HEADQUE) in add_lkb()
1325 list_add(&lkb->lkb_statequeue, &r->res_waitqueue); in add_lkb()
1327 list_add_tail(&lkb->lkb_statequeue, &r->res_waitqueue); in add_lkb()
1331 lkb_add_ordered(&lkb->lkb_statequeue, &r->res_grantqueue, in add_lkb()
1332 lkb->lkb_grmode); in add_lkb()
1335 if (lkb->lkb_exflags & DLM_LKF_HEADQUE) in add_lkb()
1336 list_add(&lkb->lkb_statequeue, &r->res_convertqueue); in add_lkb()
1338 list_add_tail(&lkb->lkb_statequeue, in add_lkb()
1342 DLM_ASSERT(0, dlm_print_lkb(lkb); printk("sts=%d\n", status);); in add_lkb()
1346 static void del_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) in del_lkb() argument
1348 lkb->lkb_status = 0; in del_lkb()
1349 list_del(&lkb->lkb_statequeue); in del_lkb()
1350 unhold_lkb(lkb); in del_lkb()
1353 static void move_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int sts) in move_lkb() argument
1355 hold_lkb(lkb); in move_lkb()
1356 del_lkb(r, lkb); in move_lkb()
1357 add_lkb(r, lkb, sts); in move_lkb()
1358 unhold_lkb(lkb); in move_lkb()
1395 struct dlm_lkb *lkb; in dlm_scan_waiters() local
1408 list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { in dlm_scan_waiters()
1409 if (!lkb->lkb_wait_time) in dlm_scan_waiters()
1414 us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_wait_time)); in dlm_scan_waiters()
1419 lkb->lkb_wait_time = 0; in dlm_scan_waiters()
1431 if (nodeid_warned(lkb->lkb_wait_nodeid, num_nodes, warned)) in dlm_scan_waiters()
1435 "node %d", lkb->lkb_id, (long long)us, in dlm_scan_waiters()
1436 dlm_config.ci_waitwarn_us, lkb->lkb_wait_nodeid); in dlm_scan_waiters()
1450 static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid) in add_to_waiters() argument
1452 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in add_to_waiters()
1457 if (is_overlap_unlock(lkb) || in add_to_waiters()
1458 (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL))) { in add_to_waiters()
1463 if (lkb->lkb_wait_type || is_overlap_cancel(lkb)) { in add_to_waiters()
1466 lkb->lkb_flags |= DLM_IFL_OVERLAP_UNLOCK; in add_to_waiters()
1469 lkb->lkb_flags |= DLM_IFL_OVERLAP_CANCEL; in add_to_waiters()
1475 lkb->lkb_wait_count++; in add_to_waiters()
1476 hold_lkb(lkb); in add_to_waiters()
1479 lkb->lkb_id, lkb->lkb_wait_type, mstype, in add_to_waiters()
1480 lkb->lkb_wait_count, lkb->lkb_flags); in add_to_waiters()
1484 DLM_ASSERT(!lkb->lkb_wait_count, in add_to_waiters()
1485 dlm_print_lkb(lkb); in add_to_waiters()
1486 printk("wait_count %d\n", lkb->lkb_wait_count);); in add_to_waiters()
1488 lkb->lkb_wait_count++; in add_to_waiters()
1489 lkb->lkb_wait_type = mstype; in add_to_waiters()
1490 lkb->lkb_wait_time = ktime_get(); in add_to_waiters()
1491 lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */ in add_to_waiters()
1492 hold_lkb(lkb); in add_to_waiters()
1493 list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); in add_to_waiters()
1497 lkb->lkb_id, error, lkb->lkb_flags, mstype, in add_to_waiters()
1498 lkb->lkb_wait_type, lkb->lkb_resource->res_name); in add_to_waiters()
1508 static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype, in _remove_from_waiters() argument
1511 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in _remove_from_waiters()
1514 if (is_overlap_unlock(lkb) && (mstype == DLM_MSG_UNLOCK_REPLY)) { in _remove_from_waiters()
1515 log_debug(ls, "remwait %x unlock_reply overlap", lkb->lkb_id); in _remove_from_waiters()
1516 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in _remove_from_waiters()
1521 if (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL_REPLY)) { in _remove_from_waiters()
1522 log_debug(ls, "remwait %x cancel_reply overlap", lkb->lkb_id); in _remove_from_waiters()
1523 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in _remove_from_waiters()
1532 (lkb->lkb_wait_type != DLM_MSG_CANCEL)) { in _remove_from_waiters()
1534 lkb->lkb_id, lkb->lkb_wait_type); in _remove_from_waiters()
1547 (lkb->lkb_wait_type == DLM_MSG_CONVERT) && in _remove_from_waiters()
1548 is_overlap_cancel(lkb) && ms && !ms->m_result) { in _remove_from_waiters()
1550 lkb->lkb_id); in _remove_from_waiters()
1551 lkb->lkb_wait_type = 0; in _remove_from_waiters()
1552 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in _remove_from_waiters()
1553 lkb->lkb_wait_count--; in _remove_from_waiters()
1554 unhold_lkb(lkb); in _remove_from_waiters()
1561 if (lkb->lkb_wait_type) { in _remove_from_waiters()
1562 lkb->lkb_wait_type = 0; in _remove_from_waiters()
1567 lkb->lkb_id, ms ? ms->m_header.h_nodeid : 0, lkb->lkb_remid, in _remove_from_waiters()
1568 mstype, lkb->lkb_flags); in _remove_from_waiters()
1577 if (overlap_done && lkb->lkb_wait_type) { in _remove_from_waiters()
1579 lkb->lkb_id, mstype, lkb->lkb_wait_type); in _remove_from_waiters()
1580 lkb->lkb_wait_count--; in _remove_from_waiters()
1581 unhold_lkb(lkb); in _remove_from_waiters()
1582 lkb->lkb_wait_type = 0; in _remove_from_waiters()
1585 DLM_ASSERT(lkb->lkb_wait_count, dlm_print_lkb(lkb);); in _remove_from_waiters()
1587 lkb->lkb_flags &= ~DLM_IFL_RESEND; in _remove_from_waiters()
1588 lkb->lkb_wait_count--; in _remove_from_waiters()
1589 if (!lkb->lkb_wait_count) in _remove_from_waiters()
1590 list_del_init(&lkb->lkb_wait_reply); in _remove_from_waiters()
1591 unhold_lkb(lkb); in _remove_from_waiters()
1595 static int remove_from_waiters(struct dlm_lkb *lkb, int mstype) in remove_from_waiters() argument
1597 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in remove_from_waiters()
1601 error = _remove_from_waiters(lkb, mstype, NULL); in remove_from_waiters()
1609 static int remove_from_waiters_ms(struct dlm_lkb *lkb, struct dlm_message *ms) in remove_from_waiters_ms() argument
1611 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in remove_from_waiters_ms()
1616 error = _remove_from_waiters(lkb, ms->m_type, ms); in remove_from_waiters_ms()
1814 static void add_timeout(struct dlm_lkb *lkb) in add_timeout() argument
1816 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in add_timeout()
1818 if (is_master_copy(lkb)) in add_timeout()
1822 !(lkb->lkb_exflags & DLM_LKF_NODLCKWT)) { in add_timeout()
1823 lkb->lkb_flags |= DLM_IFL_WATCH_TIMEWARN; in add_timeout()
1826 if (lkb->lkb_exflags & DLM_LKF_TIMEOUT) in add_timeout()
1831 DLM_ASSERT(list_empty(&lkb->lkb_time_list), dlm_print_lkb(lkb);); in add_timeout()
1833 hold_lkb(lkb); in add_timeout()
1834 list_add_tail(&lkb->lkb_time_list, &ls->ls_timeout); in add_timeout()
1838 static void del_timeout(struct dlm_lkb *lkb) in del_timeout() argument
1840 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in del_timeout()
1843 if (!list_empty(&lkb->lkb_time_list)) { in del_timeout()
1844 list_del_init(&lkb->lkb_time_list); in del_timeout()
1845 unhold_lkb(lkb); in del_timeout()
1859 struct dlm_lkb *lkb = NULL, *iter; in dlm_scan_timeout() local
1886 lkb = iter; in dlm_scan_timeout()
1891 if (!lkb) in dlm_scan_timeout()
1894 r = lkb->lkb_resource; in dlm_scan_timeout()
1900 lkb->lkb_flags &= ~DLM_IFL_WATCH_TIMEWARN; in dlm_scan_timeout()
1901 if (!(lkb->lkb_exflags & DLM_LKF_TIMEOUT)) in dlm_scan_timeout()
1902 del_timeout(lkb); in dlm_scan_timeout()
1903 dlm_timeout_warn(lkb); in dlm_scan_timeout()
1908 lkb->lkb_id, lkb->lkb_nodeid, r->res_name); in dlm_scan_timeout()
1909 lkb->lkb_flags &= ~DLM_IFL_WATCH_TIMEWARN; in dlm_scan_timeout()
1910 lkb->lkb_flags |= DLM_IFL_TIMEOUT_CANCEL; in dlm_scan_timeout()
1911 del_timeout(lkb); in dlm_scan_timeout()
1912 _cancel_lock(r, lkb); in dlm_scan_timeout()
1917 dlm_put_lkb(lkb); in dlm_scan_timeout()
1926 struct dlm_lkb *lkb; in dlm_adjust_timeouts() local
1931 list_for_each_entry(lkb, &ls->ls_timeout, lkb_time_list) in dlm_adjust_timeouts()
1932 lkb->lkb_timestamp = ktime_add_us(lkb->lkb_timestamp, adj_us); in dlm_adjust_timeouts()
1939 list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { in dlm_adjust_timeouts()
1940 if (ktime_to_us(lkb->lkb_wait_time)) in dlm_adjust_timeouts()
1941 lkb->lkb_wait_time = ktime_get(); in dlm_adjust_timeouts()
1948 static void set_lvb_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_lvb_lock() argument
1956 b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; in set_lvb_lock()
1959 if (!lkb->lkb_lvbptr) in set_lvb_lock()
1962 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock()
1968 memcpy(lkb->lkb_lvbptr, r->res_lvbptr, len); in set_lvb_lock()
1969 lkb->lkb_lvbseq = r->res_lvbseq; in set_lvb_lock()
1972 if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { in set_lvb_lock()
1977 if (!lkb->lkb_lvbptr) in set_lvb_lock()
1980 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock()
1989 memcpy(r->res_lvbptr, lkb->lkb_lvbptr, len); in set_lvb_lock()
1991 lkb->lkb_lvbseq = r->res_lvbseq; in set_lvb_lock()
1996 lkb->lkb_sbflags |= DLM_SBF_VALNOTVALID; in set_lvb_lock()
1999 static void set_lvb_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_lvb_unlock() argument
2001 if (lkb->lkb_grmode < DLM_LOCK_PW) in set_lvb_unlock()
2004 if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { in set_lvb_unlock()
2009 if (!lkb->lkb_lvbptr) in set_lvb_unlock()
2012 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_unlock()
2021 memcpy(r->res_lvbptr, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); in set_lvb_unlock()
2028 static void set_lvb_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, in set_lvb_lock_pc() argument
2033 if (!lkb->lkb_lvbptr) in set_lvb_lock_pc()
2036 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock_pc()
2039 b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; in set_lvb_lock_pc()
2044 memcpy(lkb->lkb_lvbptr, ms->m_extra, len); in set_lvb_lock_pc()
2045 lkb->lkb_lvbseq = ms->m_lvbseq; in set_lvb_lock_pc()
2059 static void _remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _remove_lock() argument
2061 del_lkb(r, lkb); in _remove_lock()
2062 lkb->lkb_grmode = DLM_LOCK_IV; in _remove_lock()
2065 unhold_lkb(lkb); in _remove_lock()
2068 static void remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in remove_lock() argument
2070 set_lvb_unlock(r, lkb); in remove_lock()
2071 _remove_lock(r, lkb); in remove_lock()
2074 static void remove_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) in remove_lock_pc() argument
2076 _remove_lock(r, lkb); in remove_lock_pc()
2083 static int revert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in revert_lock() argument
2087 lkb->lkb_rqmode = DLM_LOCK_IV; in revert_lock()
2089 switch (lkb->lkb_status) { in revert_lock()
2093 move_lkb(r, lkb, DLM_LKSTS_GRANTED); in revert_lock()
2097 del_lkb(r, lkb); in revert_lock()
2098 lkb->lkb_grmode = DLM_LOCK_IV; in revert_lock()
2101 unhold_lkb(lkb); in revert_lock()
2105 log_print("invalid status for revert %d", lkb->lkb_status); in revert_lock()
2110 static int revert_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) in revert_lock_pc() argument
2112 return revert_lock(r, lkb); in revert_lock_pc()
2115 static void _grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _grant_lock() argument
2117 if (lkb->lkb_grmode != lkb->lkb_rqmode) { in _grant_lock()
2118 lkb->lkb_grmode = lkb->lkb_rqmode; in _grant_lock()
2119 if (lkb->lkb_status) in _grant_lock()
2120 move_lkb(r, lkb, DLM_LKSTS_GRANTED); in _grant_lock()
2122 add_lkb(r, lkb, DLM_LKSTS_GRANTED); in _grant_lock()
2125 lkb->lkb_rqmode = DLM_LOCK_IV; in _grant_lock()
2126 lkb->lkb_highbast = 0; in _grant_lock()
2129 static void grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in grant_lock() argument
2131 set_lvb_lock(r, lkb); in grant_lock()
2132 _grant_lock(r, lkb); in grant_lock()
2135 static void grant_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, in grant_lock_pc() argument
2138 set_lvb_lock_pc(r, lkb, ms); in grant_lock_pc()
2139 _grant_lock(r, lkb); in grant_lock_pc()
2146 static void grant_lock_pending(struct dlm_rsb *r, struct dlm_lkb *lkb) in grant_lock_pending() argument
2148 grant_lock(r, lkb); in grant_lock_pending()
2149 if (is_master_copy(lkb)) in grant_lock_pending()
2150 send_grant(r, lkb); in grant_lock_pending()
2152 queue_cast(r, lkb, 0); in grant_lock_pending()
2163 static void munge_demoted(struct dlm_lkb *lkb) in munge_demoted() argument
2165 if (lkb->lkb_rqmode == DLM_LOCK_IV || lkb->lkb_grmode == DLM_LOCK_IV) { in munge_demoted()
2167 lkb->lkb_id, lkb->lkb_grmode, lkb->lkb_rqmode); in munge_demoted()
2171 lkb->lkb_grmode = DLM_LOCK_NL; in munge_demoted()
2174 static void munge_altmode(struct dlm_lkb *lkb, struct dlm_message *ms) in munge_altmode() argument
2179 lkb->lkb_id, ms->m_type); in munge_altmode()
2183 if (lkb->lkb_exflags & DLM_LKF_ALTPR) in munge_altmode()
2184 lkb->lkb_rqmode = DLM_LOCK_PR; in munge_altmode()
2185 else if (lkb->lkb_exflags & DLM_LKF_ALTCW) in munge_altmode()
2186 lkb->lkb_rqmode = DLM_LOCK_CW; in munge_altmode()
2188 log_print("munge_altmode invalid exflags %x", lkb->lkb_exflags); in munge_altmode()
2189 dlm_print_lkb(lkb); in munge_altmode()
2193 static inline int first_in_list(struct dlm_lkb *lkb, struct list_head *head) in first_in_list() argument
2197 if (lkb->lkb_id == first->lkb_id) in first_in_list()
2205 static int queue_conflict(struct list_head *head, struct dlm_lkb *lkb) in queue_conflict() argument
2210 if (this == lkb) in queue_conflict()
2212 if (!modes_compat(this, lkb)) in queue_conflict()
2298 static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now, in _can_be_granted() argument
2301 int8_t conv = (lkb->lkb_grmode != DLM_LOCK_IV); in _can_be_granted()
2322 if (lkb->lkb_exflags & DLM_LKF_EXPEDITE) in _can_be_granted()
2330 if (queue_conflict(&r->res_grantqueue, lkb)) in _can_be_granted()
2339 if (queue_conflict(&r->res_convertqueue, lkb)) in _can_be_granted()
2382 if (now && conv && !(lkb->lkb_exflags & DLM_LKF_QUECVT)) in _can_be_granted()
2390 if (now && conv && (lkb->lkb_exflags & DLM_LKF_QUECVT)) { in _can_be_granted()
2402 if (lkb->lkb_exflags & DLM_LKF_NOORDER) in _can_be_granted()
2411 if (!now && conv && first_in_list(lkb, &r->res_convertqueue)) in _can_be_granted()
2438 first_in_list(lkb, &r->res_waitqueue)) in _can_be_granted()
2444 static int can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now, in can_be_granted() argument
2448 int8_t alt = 0, rqmode = lkb->lkb_rqmode; in can_be_granted()
2449 int8_t is_convert = (lkb->lkb_grmode != DLM_LOCK_IV); in can_be_granted()
2454 rv = _can_be_granted(r, lkb, now, recover); in can_be_granted()
2464 if (is_convert && can_be_queued(lkb) && in can_be_granted()
2465 conversion_deadlock_detect(r, lkb)) { in can_be_granted()
2466 if (lkb->lkb_exflags & DLM_LKF_CONVDEADLK) { in can_be_granted()
2467 lkb->lkb_grmode = DLM_LOCK_NL; in can_be_granted()
2468 lkb->lkb_sbflags |= DLM_SBF_DEMOTED; in can_be_granted()
2473 lkb->lkb_id, now); in can_be_granted()
2486 if (rqmode != DLM_LOCK_PR && (lkb->lkb_exflags & DLM_LKF_ALTPR)) in can_be_granted()
2488 else if (rqmode != DLM_LOCK_CW && (lkb->lkb_exflags & DLM_LKF_ALTCW)) in can_be_granted()
2492 lkb->lkb_rqmode = alt; in can_be_granted()
2493 rv = _can_be_granted(r, lkb, now, 0); in can_be_granted()
2495 lkb->lkb_sbflags |= DLM_SBF_ALTMODE; in can_be_granted()
2497 lkb->lkb_rqmode = rqmode; in can_be_granted()
2509 struct dlm_lkb *lkb, *s; in grant_pending_convert() local
2520 list_for_each_entry_safe(lkb, s, &r->res_convertqueue, lkb_statequeue) { in grant_pending_convert()
2521 demoted = is_demoted(lkb); in grant_pending_convert()
2524 if (can_be_granted(r, lkb, 0, recover, &deadlk)) { in grant_pending_convert()
2525 grant_lock_pending(r, lkb); in grant_pending_convert()
2532 if (!demoted && is_demoted(lkb)) { in grant_pending_convert()
2534 lkb->lkb_id, lkb->lkb_nodeid, r->res_name); in grant_pending_convert()
2545 if (lkb->lkb_exflags & DLM_LKF_NODLCKWT) { in grant_pending_convert()
2546 if (lkb->lkb_highbast < lkb->lkb_rqmode) { in grant_pending_convert()
2547 queue_bast(r, lkb, lkb->lkb_rqmode); in grant_pending_convert()
2548 lkb->lkb_highbast = lkb->lkb_rqmode; in grant_pending_convert()
2552 lkb->lkb_id, lkb->lkb_nodeid, in grant_pending_convert()
2559 hi = max_t(int, lkb->lkb_rqmode, hi); in grant_pending_convert()
2561 if (cw && lkb->lkb_rqmode == DLM_LOCK_CW) in grant_pending_convert()
2578 struct dlm_lkb *lkb, *s; in grant_pending_wait() local
2580 list_for_each_entry_safe(lkb, s, &r->res_waitqueue, lkb_statequeue) { in grant_pending_wait()
2581 if (can_be_granted(r, lkb, 0, 0, NULL)) { in grant_pending_wait()
2582 grant_lock_pending(r, lkb); in grant_pending_wait()
2586 high = max_t(int, lkb->lkb_rqmode, high); in grant_pending_wait()
2587 if (lkb->lkb_rqmode == DLM_LOCK_CW) in grant_pending_wait()
2616 struct dlm_lkb *lkb, *s; in grant_pending_locks() local
2638 list_for_each_entry_safe(lkb, s, &r->res_grantqueue, lkb_statequeue) { in grant_pending_locks()
2639 if (lkb->lkb_bastfn && lock_requires_bast(lkb, high, cw)) { in grant_pending_locks()
2641 lkb->lkb_grmode == DLM_LOCK_PR) in grant_pending_locks()
2642 queue_bast(r, lkb, DLM_LOCK_CW); in grant_pending_locks()
2644 queue_bast(r, lkb, high); in grant_pending_locks()
2645 lkb->lkb_highbast = high; in grant_pending_locks()
2665 struct dlm_lkb *lkb) in send_bast_queue() argument
2671 if (gr == lkb) in send_bast_queue()
2673 if (gr->lkb_bastfn && modes_require_bast(gr, lkb)) { in send_bast_queue()
2674 queue_bast(r, gr, lkb->lkb_rqmode); in send_bast_queue()
2675 gr->lkb_highbast = lkb->lkb_rqmode; in send_bast_queue()
2680 static void send_blocking_asts(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_blocking_asts() argument
2682 send_bast_queue(r, &r->res_grantqueue, lkb); in send_blocking_asts()
2685 static void send_blocking_asts_all(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_blocking_asts_all() argument
2687 send_bast_queue(r, &r->res_grantqueue, lkb); in send_blocking_asts_all()
2688 send_bast_queue(r, &r->res_convertqueue, lkb); in send_blocking_asts_all()
2710 static int set_master(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_master() argument
2716 r->res_first_lkid = lkb->lkb_id; in set_master()
2717 lkb->lkb_nodeid = r->res_nodeid; in set_master()
2721 if (r->res_first_lkid && r->res_first_lkid != lkb->lkb_id) { in set_master()
2722 list_add_tail(&lkb->lkb_rsb_lookup, &r->res_lookup); in set_master()
2727 lkb->lkb_nodeid = 0; in set_master()
2732 lkb->lkb_nodeid = r->res_master_nodeid; in set_master()
2744 lkb->lkb_id, r->res_master_nodeid, r->res_dir_nodeid, in set_master()
2748 lkb->lkb_nodeid = 0; in set_master()
2754 r->res_first_lkid = lkb->lkb_id; in set_master()
2755 send_lookup(r, lkb); in set_master()
2761 struct dlm_lkb *lkb, *safe; in process_lookup_list() local
2763 list_for_each_entry_safe(lkb, safe, &r->res_lookup, lkb_rsb_lookup) { in process_lookup_list()
2764 list_del_init(&lkb->lkb_rsb_lookup); in process_lookup_list()
2765 _request_lock(r, lkb); in process_lookup_list()
2774 struct dlm_lkb *lkb; in confirm_master() local
2796 lkb = list_entry(r->res_lookup.next, struct dlm_lkb, in confirm_master()
2798 list_del_init(&lkb->lkb_rsb_lookup); in confirm_master()
2799 r->res_first_lkid = lkb->lkb_id; in confirm_master()
2800 _request_lock(r, lkb); in confirm_master()
2889 static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in validate_lock_args() argument
2895 if (lkb->lkb_status != DLM_LKSTS_GRANTED) in validate_lock_args()
2898 if (lkb->lkb_wait_type) in validate_lock_args()
2901 if (is_overlap(lkb)) in validate_lock_args()
2905 if (lkb->lkb_flags & DLM_IFL_MSTCPY) in validate_lock_args()
2909 !__quecvt_compat_matrix[lkb->lkb_grmode+1][args->mode+1]) in validate_lock_args()
2913 lkb->lkb_exflags = args->flags; in validate_lock_args()
2914 lkb->lkb_sbflags = 0; in validate_lock_args()
2915 lkb->lkb_astfn = args->astfn; in validate_lock_args()
2916 lkb->lkb_astparam = args->astparam; in validate_lock_args()
2917 lkb->lkb_bastfn = args->bastfn; in validate_lock_args()
2918 lkb->lkb_rqmode = args->mode; in validate_lock_args()
2919 lkb->lkb_lksb = args->lksb; in validate_lock_args()
2920 lkb->lkb_lvbptr = args->lksb->sb_lvbptr; in validate_lock_args()
2921 lkb->lkb_ownpid = (int) current->pid; in validate_lock_args()
2922 lkb->lkb_timeout_cs = args->timeout; in validate_lock_args()
2927 rv, lkb->lkb_id, lkb->lkb_flags, args->flags, in validate_lock_args()
2928 lkb->lkb_status, lkb->lkb_wait_type, in validate_lock_args()
2929 lkb->lkb_resource->res_name); in validate_lock_args()
2940 static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) in validate_unlock_args() argument
2942 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in validate_unlock_args()
2945 if (lkb->lkb_flags & DLM_IFL_MSTCPY) { in validate_unlock_args()
2946 log_error(ls, "unlock on MSTCPY %x", lkb->lkb_id); in validate_unlock_args()
2947 dlm_print_lkb(lkb); in validate_unlock_args()
2955 if (lkb->lkb_flags & DLM_IFL_ENDOFLIFE) { in validate_unlock_args()
2956 log_debug(ls, "unlock on ENDOFLIFE %x", lkb->lkb_id); in validate_unlock_args()
2964 if (!list_empty(&lkb->lkb_rsb_lookup)) { in validate_unlock_args()
2966 log_debug(ls, "unlock on rsb_lookup %x", lkb->lkb_id); in validate_unlock_args()
2967 list_del_init(&lkb->lkb_rsb_lookup); in validate_unlock_args()
2968 queue_cast(lkb->lkb_resource, lkb, in validate_unlock_args()
2971 unhold_lkb(lkb); /* undoes create_lkb() */ in validate_unlock_args()
2981 if (lkb->lkb_exflags & DLM_LKF_CANCEL) in validate_unlock_args()
2984 if (is_overlap(lkb)) in validate_unlock_args()
2988 del_timeout(lkb); in validate_unlock_args()
2990 if (lkb->lkb_flags & DLM_IFL_RESEND) { in validate_unlock_args()
2991 lkb->lkb_flags |= DLM_IFL_OVERLAP_CANCEL; in validate_unlock_args()
2997 if (lkb->lkb_status == DLM_LKSTS_GRANTED && in validate_unlock_args()
2998 !lkb->lkb_wait_type) { in validate_unlock_args()
3003 switch (lkb->lkb_wait_type) { in validate_unlock_args()
3006 lkb->lkb_flags |= DLM_IFL_OVERLAP_CANCEL; in validate_unlock_args()
3022 if (lkb->lkb_exflags & DLM_LKF_FORCEUNLOCK) in validate_unlock_args()
3025 if (is_overlap_unlock(lkb)) in validate_unlock_args()
3029 del_timeout(lkb); in validate_unlock_args()
3031 if (lkb->lkb_flags & DLM_IFL_RESEND) { in validate_unlock_args()
3032 lkb->lkb_flags |= DLM_IFL_OVERLAP_UNLOCK; in validate_unlock_args()
3037 switch (lkb->lkb_wait_type) { in validate_unlock_args()
3040 lkb->lkb_flags |= DLM_IFL_OVERLAP_UNLOCK; in validate_unlock_args()
3052 if (lkb->lkb_wait_type || lkb->lkb_wait_count) in validate_unlock_args()
3057 lkb->lkb_exflags |= args->flags; in validate_unlock_args()
3058 lkb->lkb_sbflags = 0; in validate_unlock_args()
3059 lkb->lkb_astparam = args->astparam; in validate_unlock_args()
3064 lkb->lkb_id, lkb->lkb_flags, lkb->lkb_exflags, in validate_unlock_args()
3065 args->flags, lkb->lkb_wait_type, in validate_unlock_args()
3066 lkb->lkb_resource->res_name); in validate_unlock_args()
3077 static int do_request(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_request() argument
3081 if (can_be_granted(r, lkb, 1, 0, NULL)) { in do_request()
3082 grant_lock(r, lkb); in do_request()
3083 queue_cast(r, lkb, 0); in do_request()
3087 if (can_be_queued(lkb)) { in do_request()
3089 add_lkb(r, lkb, DLM_LKSTS_WAITING); in do_request()
3090 add_timeout(lkb); in do_request()
3095 queue_cast(r, lkb, -EAGAIN); in do_request()
3100 static void do_request_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_request_effects() argument
3105 if (force_blocking_asts(lkb)) in do_request_effects()
3106 send_blocking_asts_all(r, lkb); in do_request_effects()
3109 send_blocking_asts(r, lkb); in do_request_effects()
3114 static int do_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_convert() argument
3121 if (can_be_granted(r, lkb, 1, 0, &deadlk)) { in do_convert()
3122 grant_lock(r, lkb); in do_convert()
3123 queue_cast(r, lkb, 0); in do_convert()
3131 if (deadlk && !(lkb->lkb_exflags & DLM_LKF_NODLCKWT)) { in do_convert()
3133 revert_lock(r, lkb); in do_convert()
3134 queue_cast(r, lkb, -EDEADLK); in do_convert()
3145 if (is_demoted(lkb)) { in do_convert()
3147 if (_can_be_granted(r, lkb, 1, 0)) { in do_convert()
3148 grant_lock(r, lkb); in do_convert()
3149 queue_cast(r, lkb, 0); in do_convert()
3155 if (can_be_queued(lkb)) { in do_convert()
3157 del_lkb(r, lkb); in do_convert()
3158 add_lkb(r, lkb, DLM_LKSTS_CONVERT); in do_convert()
3159 add_timeout(lkb); in do_convert()
3164 queue_cast(r, lkb, -EAGAIN); in do_convert()
3169 static void do_convert_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_convert_effects() argument
3178 if (force_blocking_asts(lkb)) in do_convert_effects()
3179 send_blocking_asts_all(r, lkb); in do_convert_effects()
3182 send_blocking_asts(r, lkb); in do_convert_effects()
3187 static int do_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_unlock() argument
3189 remove_lock(r, lkb); in do_unlock()
3190 queue_cast(r, lkb, -DLM_EUNLOCK); in do_unlock()
3194 static void do_unlock_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_unlock_effects() argument
3202 static int do_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_cancel() argument
3206 error = revert_lock(r, lkb); in do_cancel()
3208 queue_cast(r, lkb, -DLM_ECANCEL); in do_cancel()
3214 static void do_cancel_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_cancel_effects() argument
3228 static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _request_lock() argument
3234 error = set_master(r, lkb); in _request_lock()
3244 error = send_request(r, lkb); in _request_lock()
3246 error = do_request(r, lkb); in _request_lock()
3249 do_request_effects(r, lkb, error); in _request_lock()
3257 static int _convert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _convert_lock() argument
3263 error = send_convert(r, lkb); in _convert_lock()
3265 error = do_convert(r, lkb); in _convert_lock()
3268 do_convert_effects(r, lkb, error); in _convert_lock()
3276 static int _unlock_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _unlock_lock() argument
3282 error = send_unlock(r, lkb); in _unlock_lock()
3284 error = do_unlock(r, lkb); in _unlock_lock()
3287 do_unlock_effects(r, lkb, error); in _unlock_lock()
3295 static int _cancel_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _cancel_lock() argument
3301 error = send_cancel(r, lkb); in _cancel_lock()
3303 error = do_cancel(r, lkb); in _cancel_lock()
3306 do_cancel_effects(r, lkb, error); in _cancel_lock()
3317 static int request_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, char *name, in request_lock() argument
3323 error = validate_lock_args(ls, lkb, args); in request_lock()
3333 attach_lkb(r, lkb); in request_lock()
3334 lkb->lkb_lksb->sb_lkid = lkb->lkb_id; in request_lock()
3336 error = _request_lock(r, lkb); in request_lock()
3343 static int convert_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in convert_lock() argument
3349 r = lkb->lkb_resource; in convert_lock()
3354 error = validate_lock_args(ls, lkb, args); in convert_lock()
3358 error = _convert_lock(r, lkb); in convert_lock()
3365 static int unlock_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in unlock_lock() argument
3371 r = lkb->lkb_resource; in unlock_lock()
3376 error = validate_unlock_args(lkb, args); in unlock_lock()
3380 error = _unlock_lock(r, lkb); in unlock_lock()
3387 static int cancel_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in cancel_lock() argument
3393 r = lkb->lkb_resource; in cancel_lock()
3398 error = validate_unlock_args(lkb, args); in cancel_lock()
3402 error = _cancel_lock(r, lkb); in cancel_lock()
3425 struct dlm_lkb *lkb; in dlm_lock() local
3436 error = find_lkb(ls, lksb->sb_lkid, &lkb); in dlm_lock()
3438 error = create_lkb(ls, &lkb); in dlm_lock()
3449 error = convert_lock(ls, lkb, &args); in dlm_lock()
3451 error = request_lock(ls, lkb, name, namelen, &args); in dlm_lock()
3457 __put_lkb(ls, lkb); in dlm_lock()
3473 struct dlm_lkb *lkb; in dlm_unlock() local
3483 error = find_lkb(ls, lkid, &lkb); in dlm_unlock()
3492 error = cancel_lock(ls, lkb, &args); in dlm_unlock()
3494 error = unlock_lock(ls, lkb, &args); in dlm_unlock()
3501 dlm_put_lkb(lkb); in dlm_unlock()
3562 static int create_message(struct dlm_rsb *r, struct dlm_lkb *lkb, in create_message() argument
3580 if (lkb && lkb->lkb_lvbptr) in create_message()
3599 static void send_args(struct dlm_rsb *r, struct dlm_lkb *lkb, in send_args() argument
3602 ms->m_nodeid = lkb->lkb_nodeid; in send_args()
3603 ms->m_pid = lkb->lkb_ownpid; in send_args()
3604 ms->m_lkid = lkb->lkb_id; in send_args()
3605 ms->m_remid = lkb->lkb_remid; in send_args()
3606 ms->m_exflags = lkb->lkb_exflags; in send_args()
3607 ms->m_sbflags = lkb->lkb_sbflags; in send_args()
3608 ms->m_flags = lkb->lkb_flags; in send_args()
3609 ms->m_lvbseq = lkb->lkb_lvbseq; in send_args()
3610 ms->m_status = lkb->lkb_status; in send_args()
3611 ms->m_grmode = lkb->lkb_grmode; in send_args()
3612 ms->m_rqmode = lkb->lkb_rqmode; in send_args()
3618 if (lkb->lkb_bastfn) in send_args()
3620 if (lkb->lkb_astfn) in send_args()
3636 if (!lkb->lkb_lvbptr || !(lkb->lkb_exflags & DLM_LKF_VALBLK)) in send_args()
3638 memcpy(ms->m_extra, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); in send_args()
3643 static int send_common(struct dlm_rsb *r, struct dlm_lkb *lkb, int mstype) in send_common() argument
3651 error = add_to_waiters(lkb, mstype, to_nodeid); in send_common()
3655 error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); in send_common()
3659 send_args(r, lkb, ms); in send_common()
3667 remove_from_waiters(lkb, msg_reply_type(mstype)); in send_common()
3671 static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_request() argument
3673 return send_common(r, lkb, DLM_MSG_REQUEST); in send_request()
3676 static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_convert() argument
3680 error = send_common(r, lkb, DLM_MSG_CONVERT); in send_convert()
3683 if (!error && down_conversion(lkb)) { in send_convert()
3684 remove_from_waiters(lkb, DLM_MSG_CONVERT_REPLY); in send_convert()
3688 __receive_convert_reply(r, lkb, &r->res_ls->ls_stub_ms); in send_convert()
3698 static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_unlock() argument
3700 return send_common(r, lkb, DLM_MSG_UNLOCK); in send_unlock()
3703 static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_cancel() argument
3705 return send_common(r, lkb, DLM_MSG_CANCEL); in send_cancel()
3708 static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_grant() argument
3714 to_nodeid = lkb->lkb_nodeid; in send_grant()
3716 error = create_message(r, lkb, to_nodeid, DLM_MSG_GRANT, &ms, &mh); in send_grant()
3720 send_args(r, lkb, ms); in send_grant()
3729 static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode) in send_bast() argument
3735 to_nodeid = lkb->lkb_nodeid; in send_bast()
3741 send_args(r, lkb, ms); in send_bast()
3750 static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_lookup() argument
3758 error = add_to_waiters(lkb, DLM_MSG_LOOKUP, to_nodeid); in send_lookup()
3766 send_args(r, lkb, ms); in send_lookup()
3774 remove_from_waiters(lkb, DLM_MSG_LOOKUP_REPLY); in send_lookup()
3798 static int send_common_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, in send_common_reply() argument
3805 to_nodeid = lkb->lkb_nodeid; in send_common_reply()
3807 error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); in send_common_reply()
3811 send_args(r, lkb, ms); in send_common_reply()
3820 static int send_request_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_request_reply() argument
3822 return send_common_reply(r, lkb, DLM_MSG_REQUEST_REPLY, rv); in send_request_reply()
3825 static int send_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_convert_reply() argument
3827 return send_common_reply(r, lkb, DLM_MSG_CONVERT_REPLY, rv); in send_convert_reply()
3830 static int send_unlock_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_unlock_reply() argument
3832 return send_common_reply(r, lkb, DLM_MSG_UNLOCK_REPLY, rv); in send_unlock_reply()
3835 static int send_cancel_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_cancel_reply() argument
3837 return send_common_reply(r, lkb, DLM_MSG_CANCEL_REPLY, rv); in send_cancel_reply()
3865 static void receive_flags(struct dlm_lkb *lkb, struct dlm_message *ms) in receive_flags() argument
3867 lkb->lkb_exflags = ms->m_exflags; in receive_flags()
3868 lkb->lkb_sbflags = ms->m_sbflags; in receive_flags()
3869 lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | in receive_flags()
3873 static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in receive_flags_reply() argument
3878 lkb->lkb_sbflags = ms->m_sbflags; in receive_flags_reply()
3879 lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | in receive_flags_reply()
3888 static int receive_lvb(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_lvb() argument
3893 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_lvb()
3894 if (!lkb->lkb_lvbptr) in receive_lvb()
3895 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_lvb()
3896 if (!lkb->lkb_lvbptr) in receive_lvb()
3901 memcpy(lkb->lkb_lvbptr, ms->m_extra, len); in receive_lvb()
3916 static int receive_request_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_request_args() argument
3919 lkb->lkb_nodeid = ms->m_header.h_nodeid; in receive_request_args()
3920 lkb->lkb_ownpid = ms->m_pid; in receive_request_args()
3921 lkb->lkb_remid = ms->m_lkid; in receive_request_args()
3922 lkb->lkb_grmode = DLM_LOCK_IV; in receive_request_args()
3923 lkb->lkb_rqmode = ms->m_rqmode; in receive_request_args()
3925 lkb->lkb_bastfn = (ms->m_asts & DLM_CB_BAST) ? &fake_bastfn : NULL; in receive_request_args()
3926 lkb->lkb_astfn = (ms->m_asts & DLM_CB_CAST) ? &fake_astfn : NULL; in receive_request_args()
3928 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_request_args()
3930 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_request_args()
3931 if (!lkb->lkb_lvbptr) in receive_request_args()
3938 static int receive_convert_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_convert_args() argument
3941 if (lkb->lkb_status != DLM_LKSTS_GRANTED) in receive_convert_args()
3944 if (receive_lvb(ls, lkb, ms)) in receive_convert_args()
3947 lkb->lkb_rqmode = ms->m_rqmode; in receive_convert_args()
3948 lkb->lkb_lvbseq = ms->m_lvbseq; in receive_convert_args()
3953 static int receive_unlock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_unlock_args() argument
3956 if (receive_lvb(ls, lkb, ms)) in receive_unlock_args()
3966 struct dlm_lkb *lkb = &ls->ls_stub_lkb; in setup_stub_lkb() local
3967 lkb->lkb_nodeid = ms->m_header.h_nodeid; in setup_stub_lkb()
3968 lkb->lkb_remid = ms->m_lkid; in setup_stub_lkb()
3974 static int validate_message(struct dlm_lkb *lkb, struct dlm_message *ms) in validate_message() argument
3980 if (ms->m_flags & DLM_IFL_USER && ~lkb->lkb_flags & DLM_IFL_USER) { in validate_message()
3981 log_error(lkb->lkb_resource->res_ls, in validate_message()
3991 if (!is_master_copy(lkb) || lkb->lkb_nodeid != from) in validate_message()
4000 if (!is_process_copy(lkb) || lkb->lkb_nodeid != from) in validate_message()
4005 if (!is_process_copy(lkb)) in validate_message()
4007 else if (lkb->lkb_nodeid != -1 && lkb->lkb_nodeid != from) in validate_message()
4017 log_error(lkb->lkb_resource->res_ls, in validate_message()
4019 ms->m_type, from, lkb->lkb_id, lkb->lkb_remid, in validate_message()
4020 lkb->lkb_flags, lkb->lkb_nodeid); in validate_message()
4085 struct dlm_lkb *lkb; in receive_request() local
4092 error = create_lkb(ls, &lkb); in receive_request()
4096 receive_flags(lkb, ms); in receive_request()
4097 lkb->lkb_flags |= DLM_IFL_MSTCPY; in receive_request()
4098 error = receive_request_args(ls, lkb, ms); in receive_request()
4100 __put_lkb(ls, lkb); in receive_request()
4115 __put_lkb(ls, lkb); in receive_request()
4126 __put_lkb(ls, lkb); in receive_request()
4131 attach_lkb(r, lkb); in receive_request()
4132 error = do_request(r, lkb); in receive_request()
4133 send_request_reply(r, lkb, error); in receive_request()
4134 do_request_effects(r, lkb, error); in receive_request()
4142 dlm_put_lkb(lkb); in receive_request()
4178 struct dlm_lkb *lkb; in receive_convert() local
4182 error = find_lkb(ls, ms->m_remid, &lkb); in receive_convert()
4186 if (lkb->lkb_remid != ms->m_lkid) { in receive_convert()
4188 "remote %d %x", lkb->lkb_id, lkb->lkb_remid, in receive_convert()
4189 (unsigned long long)lkb->lkb_recover_seq, in receive_convert()
4192 dlm_put_lkb(lkb); in receive_convert()
4196 r = lkb->lkb_resource; in receive_convert()
4201 error = validate_message(lkb, ms); in receive_convert()
4205 receive_flags(lkb, ms); in receive_convert()
4207 error = receive_convert_args(ls, lkb, ms); in receive_convert()
4209 send_convert_reply(r, lkb, error); in receive_convert()
4213 reply = !down_conversion(lkb); in receive_convert()
4215 error = do_convert(r, lkb); in receive_convert()
4217 send_convert_reply(r, lkb, error); in receive_convert()
4218 do_convert_effects(r, lkb, error); in receive_convert()
4222 dlm_put_lkb(lkb); in receive_convert()
4233 struct dlm_lkb *lkb; in receive_unlock() local
4237 error = find_lkb(ls, ms->m_remid, &lkb); in receive_unlock()
4241 if (lkb->lkb_remid != ms->m_lkid) { in receive_unlock()
4243 lkb->lkb_id, lkb->lkb_remid, in receive_unlock()
4246 dlm_put_lkb(lkb); in receive_unlock()
4250 r = lkb->lkb_resource; in receive_unlock()
4255 error = validate_message(lkb, ms); in receive_unlock()
4259 receive_flags(lkb, ms); in receive_unlock()
4261 error = receive_unlock_args(ls, lkb, ms); in receive_unlock()
4263 send_unlock_reply(r, lkb, error); in receive_unlock()
4267 error = do_unlock(r, lkb); in receive_unlock()
4268 send_unlock_reply(r, lkb, error); in receive_unlock()
4269 do_unlock_effects(r, lkb, error); in receive_unlock()
4273 dlm_put_lkb(lkb); in receive_unlock()
4284 struct dlm_lkb *lkb; in receive_cancel() local
4288 error = find_lkb(ls, ms->m_remid, &lkb); in receive_cancel()
4292 receive_flags(lkb, ms); in receive_cancel()
4294 r = lkb->lkb_resource; in receive_cancel()
4299 error = validate_message(lkb, ms); in receive_cancel()
4303 error = do_cancel(r, lkb); in receive_cancel()
4304 send_cancel_reply(r, lkb, error); in receive_cancel()
4305 do_cancel_effects(r, lkb, error); in receive_cancel()
4309 dlm_put_lkb(lkb); in receive_cancel()
4320 struct dlm_lkb *lkb; in receive_grant() local
4324 error = find_lkb(ls, ms->m_remid, &lkb); in receive_grant()
4328 r = lkb->lkb_resource; in receive_grant()
4333 error = validate_message(lkb, ms); in receive_grant()
4337 receive_flags_reply(lkb, ms); in receive_grant()
4338 if (is_altmode(lkb)) in receive_grant()
4339 munge_altmode(lkb, ms); in receive_grant()
4340 grant_lock_pc(r, lkb, ms); in receive_grant()
4341 queue_cast(r, lkb, 0); in receive_grant()
4345 dlm_put_lkb(lkb); in receive_grant()
4351 struct dlm_lkb *lkb; in receive_bast() local
4355 error = find_lkb(ls, ms->m_remid, &lkb); in receive_bast()
4359 r = lkb->lkb_resource; in receive_bast()
4364 error = validate_message(lkb, ms); in receive_bast()
4368 queue_bast(r, lkb, ms->m_bastmode); in receive_bast()
4369 lkb->lkb_highbast = ms->m_bastmode; in receive_bast()
4373 dlm_put_lkb(lkb); in receive_bast()
4492 struct dlm_lkb *lkb; in receive_request_reply() local
4497 error = find_lkb(ls, ms->m_remid, &lkb); in receive_request_reply()
4501 r = lkb->lkb_resource; in receive_request_reply()
4505 error = validate_message(lkb, ms); in receive_request_reply()
4509 mstype = lkb->lkb_wait_type; in receive_request_reply()
4510 error = remove_from_waiters(lkb, DLM_MSG_REQUEST_REPLY); in receive_request_reply()
4513 lkb->lkb_id, from_nodeid, ms->m_lkid, ms->m_result); in receive_request_reply()
4523 lkb->lkb_nodeid = from_nodeid; in receive_request_reply()
4532 queue_cast(r, lkb, -EAGAIN); in receive_request_reply()
4534 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_request_reply()
4540 receive_flags_reply(lkb, ms); in receive_request_reply()
4541 lkb->lkb_remid = ms->m_lkid; in receive_request_reply()
4542 if (is_altmode(lkb)) in receive_request_reply()
4543 munge_altmode(lkb, ms); in receive_request_reply()
4545 add_lkb(r, lkb, DLM_LKSTS_WAITING); in receive_request_reply()
4546 add_timeout(lkb); in receive_request_reply()
4548 grant_lock_pc(r, lkb, ms); in receive_request_reply()
4549 queue_cast(r, lkb, 0); in receive_request_reply()
4558 "master %d dir %d first %x %s", lkb->lkb_id, in receive_request_reply()
4567 lkb->lkb_nodeid = -1; in receive_request_reply()
4570 if (is_overlap(lkb)) { in receive_request_reply()
4572 queue_cast_overlap(r, lkb); in receive_request_reply()
4574 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_request_reply()
4576 _request_lock(r, lkb); in receive_request_reply()
4585 lkb->lkb_id, result); in receive_request_reply()
4588 if (is_overlap_unlock(lkb) && (result == 0 || result == -EINPROGRESS)) { in receive_request_reply()
4590 lkb->lkb_id, result); in receive_request_reply()
4591 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
4592 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
4593 send_unlock(r, lkb); in receive_request_reply()
4594 } else if (is_overlap_cancel(lkb) && (result == -EINPROGRESS)) { in receive_request_reply()
4595 log_debug(ls, "receive_request_reply %x cancel", lkb->lkb_id); in receive_request_reply()
4596 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
4597 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
4598 send_cancel(r, lkb); in receive_request_reply()
4600 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
4601 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
4606 dlm_put_lkb(lkb); in receive_request_reply()
4610 static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, in __receive_convert_reply() argument
4617 queue_cast(r, lkb, -EAGAIN); in __receive_convert_reply()
4621 receive_flags_reply(lkb, ms); in __receive_convert_reply()
4622 revert_lock_pc(r, lkb); in __receive_convert_reply()
4623 queue_cast(r, lkb, -EDEADLK); in __receive_convert_reply()
4628 receive_flags_reply(lkb, ms); in __receive_convert_reply()
4629 if (is_demoted(lkb)) in __receive_convert_reply()
4630 munge_demoted(lkb); in __receive_convert_reply()
4631 del_lkb(r, lkb); in __receive_convert_reply()
4632 add_lkb(r, lkb, DLM_LKSTS_CONVERT); in __receive_convert_reply()
4633 add_timeout(lkb); in __receive_convert_reply()
4638 receive_flags_reply(lkb, ms); in __receive_convert_reply()
4639 if (is_demoted(lkb)) in __receive_convert_reply()
4640 munge_demoted(lkb); in __receive_convert_reply()
4641 grant_lock_pc(r, lkb, ms); in __receive_convert_reply()
4642 queue_cast(r, lkb, 0); in __receive_convert_reply()
4647 lkb->lkb_id, ms->m_header.h_nodeid, ms->m_lkid, in __receive_convert_reply()
4650 dlm_print_lkb(lkb); in __receive_convert_reply()
4654 static void _receive_convert_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_convert_reply() argument
4656 struct dlm_rsb *r = lkb->lkb_resource; in _receive_convert_reply()
4662 error = validate_message(lkb, ms); in _receive_convert_reply()
4667 error = remove_from_waiters_ms(lkb, ms); in _receive_convert_reply()
4671 __receive_convert_reply(r, lkb, ms); in _receive_convert_reply()
4679 struct dlm_lkb *lkb; in receive_convert_reply() local
4682 error = find_lkb(ls, ms->m_remid, &lkb); in receive_convert_reply()
4686 _receive_convert_reply(lkb, ms); in receive_convert_reply()
4687 dlm_put_lkb(lkb); in receive_convert_reply()
4691 static void _receive_unlock_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_unlock_reply() argument
4693 struct dlm_rsb *r = lkb->lkb_resource; in _receive_unlock_reply()
4699 error = validate_message(lkb, ms); in _receive_unlock_reply()
4704 error = remove_from_waiters_ms(lkb, ms); in _receive_unlock_reply()
4712 receive_flags_reply(lkb, ms); in _receive_unlock_reply()
4713 remove_lock_pc(r, lkb); in _receive_unlock_reply()
4714 queue_cast(r, lkb, -DLM_EUNLOCK); in _receive_unlock_reply()
4720 lkb->lkb_id, ms->m_result); in _receive_unlock_reply()
4729 struct dlm_lkb *lkb; in receive_unlock_reply() local
4732 error = find_lkb(ls, ms->m_remid, &lkb); in receive_unlock_reply()
4736 _receive_unlock_reply(lkb, ms); in receive_unlock_reply()
4737 dlm_put_lkb(lkb); in receive_unlock_reply()
4741 static void _receive_cancel_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_cancel_reply() argument
4743 struct dlm_rsb *r = lkb->lkb_resource; in _receive_cancel_reply()
4749 error = validate_message(lkb, ms); in _receive_cancel_reply()
4754 error = remove_from_waiters_ms(lkb, ms); in _receive_cancel_reply()
4762 receive_flags_reply(lkb, ms); in _receive_cancel_reply()
4763 revert_lock_pc(r, lkb); in _receive_cancel_reply()
4764 queue_cast(r, lkb, -DLM_ECANCEL); in _receive_cancel_reply()
4770 lkb->lkb_id, ms->m_result); in _receive_cancel_reply()
4779 struct dlm_lkb *lkb; in receive_cancel_reply() local
4782 error = find_lkb(ls, ms->m_remid, &lkb); in receive_cancel_reply()
4786 _receive_cancel_reply(lkb, ms); in receive_cancel_reply()
4787 dlm_put_lkb(lkb); in receive_cancel_reply()
4793 struct dlm_lkb *lkb; in receive_lookup_reply() local
4798 error = find_lkb(ls, ms->m_lkid, &lkb); in receive_lookup_reply()
4807 r = lkb->lkb_resource; in receive_lookup_reply()
4811 error = remove_from_waiters(lkb, DLM_MSG_LOOKUP_REPLY); in receive_lookup_reply()
4827 lkb->lkb_id, ms->m_header.h_nodeid, ret_nodeid, in receive_lookup_reply()
4840 lkb->lkb_id, ms->m_header.h_nodeid); in receive_lookup_reply()
4843 lkb->lkb_nodeid = -1; in receive_lookup_reply()
4850 if (is_overlap(lkb)) { in receive_lookup_reply()
4852 lkb->lkb_id, lkb->lkb_flags); in receive_lookup_reply()
4853 queue_cast_overlap(r, lkb); in receive_lookup_reply()
4854 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_lookup_reply()
4858 _request_lock(r, lkb); in receive_lookup_reply()
4866 dlm_put_lkb(lkb); in receive_lookup_reply()
5084 static void recover_convert_waiter(struct dlm_ls *ls, struct dlm_lkb *lkb, in recover_convert_waiter() argument
5087 if (middle_conversion(lkb)) { in recover_convert_waiter()
5088 hold_lkb(lkb); in recover_convert_waiter()
5093 ms_stub->m_header.h_nodeid = lkb->lkb_nodeid; in recover_convert_waiter()
5094 _receive_convert_reply(lkb, ms_stub); in recover_convert_waiter()
5097 lkb->lkb_grmode = DLM_LOCK_IV; in recover_convert_waiter()
5098 rsb_set_flag(lkb->lkb_resource, RSB_RECOVER_CONVERT); in recover_convert_waiter()
5099 unhold_lkb(lkb); in recover_convert_waiter()
5101 } else if (lkb->lkb_rqmode >= lkb->lkb_grmode) { in recover_convert_waiter()
5102 lkb->lkb_flags |= DLM_IFL_RESEND; in recover_convert_waiter()
5112 static int waiter_needs_recovery(struct dlm_ls *ls, struct dlm_lkb *lkb, in waiter_needs_recovery() argument
5118 if (dlm_is_removed(ls, lkb->lkb_wait_nodeid)) in waiter_needs_recovery()
5132 struct dlm_lkb *lkb, *safe; in dlm_recover_waiters_pre() local
5143 list_for_each_entry_safe(lkb, safe, &ls->ls_waiters, lkb_wait_reply) { in dlm_recover_waiters_pre()
5145 dir_nodeid = dlm_dir_nodeid(lkb->lkb_resource); in dlm_recover_waiters_pre()
5150 if (lkb->lkb_wait_type != DLM_MSG_UNLOCK) { in dlm_recover_waiters_pre()
5153 lkb->lkb_id, in dlm_recover_waiters_pre()
5154 lkb->lkb_remid, in dlm_recover_waiters_pre()
5155 lkb->lkb_wait_type, in dlm_recover_waiters_pre()
5156 lkb->lkb_resource->res_nodeid, in dlm_recover_waiters_pre()
5157 lkb->lkb_nodeid, in dlm_recover_waiters_pre()
5158 lkb->lkb_wait_nodeid, in dlm_recover_waiters_pre()
5165 if (lkb->lkb_wait_type == DLM_MSG_LOOKUP) { in dlm_recover_waiters_pre()
5166 lkb->lkb_flags |= DLM_IFL_RESEND; in dlm_recover_waiters_pre()
5170 if (!waiter_needs_recovery(ls, lkb, dir_nodeid)) in dlm_recover_waiters_pre()
5173 wait_type = lkb->lkb_wait_type; in dlm_recover_waiters_pre()
5183 if (is_overlap_cancel(lkb)) { in dlm_recover_waiters_pre()
5185 if (lkb->lkb_grmode == DLM_LOCK_IV) in dlm_recover_waiters_pre()
5188 if (is_overlap_unlock(lkb)) { in dlm_recover_waiters_pre()
5190 if (lkb->lkb_grmode == DLM_LOCK_IV) in dlm_recover_waiters_pre()
5195 lkb->lkb_id, lkb->lkb_flags, wait_type, in dlm_recover_waiters_pre()
5202 lkb->lkb_flags |= DLM_IFL_RESEND; in dlm_recover_waiters_pre()
5206 recover_convert_waiter(ls, lkb, ms_stub); in dlm_recover_waiters_pre()
5210 hold_lkb(lkb); in dlm_recover_waiters_pre()
5215 ms_stub->m_header.h_nodeid = lkb->lkb_nodeid; in dlm_recover_waiters_pre()
5216 _receive_unlock_reply(lkb, ms_stub); in dlm_recover_waiters_pre()
5217 dlm_put_lkb(lkb); in dlm_recover_waiters_pre()
5221 hold_lkb(lkb); in dlm_recover_waiters_pre()
5226 ms_stub->m_header.h_nodeid = lkb->lkb_nodeid; in dlm_recover_waiters_pre()
5227 _receive_cancel_reply(lkb, ms_stub); in dlm_recover_waiters_pre()
5228 dlm_put_lkb(lkb); in dlm_recover_waiters_pre()
5233 lkb->lkb_wait_type, wait_type); in dlm_recover_waiters_pre()
5243 struct dlm_lkb *lkb = NULL, *iter; in find_resend_waiter() local
5249 lkb = iter; in find_resend_waiter()
5255 return lkb; in find_resend_waiter()
5276 struct dlm_lkb *lkb; in dlm_recover_waiters_post() local
5287 lkb = find_resend_waiter(ls); in dlm_recover_waiters_post()
5288 if (!lkb) in dlm_recover_waiters_post()
5291 r = lkb->lkb_resource; in dlm_recover_waiters_post()
5295 mstype = lkb->lkb_wait_type; in dlm_recover_waiters_post()
5296 oc = is_overlap_cancel(lkb); in dlm_recover_waiters_post()
5297 ou = is_overlap_unlock(lkb); in dlm_recover_waiters_post()
5302 "overlap %d %d", lkb->lkb_id, lkb->lkb_remid, mstype, in dlm_recover_waiters_post()
5303 r->res_nodeid, lkb->lkb_nodeid, lkb->lkb_wait_nodeid, in dlm_recover_waiters_post()
5310 lkb->lkb_flags &= ~DLM_IFL_RESEND; in dlm_recover_waiters_post()
5311 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in dlm_recover_waiters_post()
5312 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in dlm_recover_waiters_post()
5313 lkb->lkb_wait_type = 0; in dlm_recover_waiters_post()
5317 while (lkb->lkb_wait_count) { in dlm_recover_waiters_post()
5318 lkb->lkb_wait_count--; in dlm_recover_waiters_post()
5319 unhold_lkb(lkb); in dlm_recover_waiters_post()
5322 list_del_init(&lkb->lkb_wait_reply); in dlm_recover_waiters_post()
5330 queue_cast(r, lkb, ou ? -DLM_EUNLOCK : in dlm_recover_waiters_post()
5332 unhold_lkb(lkb); /* undoes create_lkb() */ in dlm_recover_waiters_post()
5336 queue_cast(r, lkb, -DLM_ECANCEL); in dlm_recover_waiters_post()
5338 lkb->lkb_exflags |= DLM_LKF_FORCEUNLOCK; in dlm_recover_waiters_post()
5339 _unlock_lock(r, lkb); in dlm_recover_waiters_post()
5349 _request_lock(r, lkb); in dlm_recover_waiters_post()
5354 _convert_lock(r, lkb); in dlm_recover_waiters_post()
5364 lkb->lkb_id, mstype, r->res_nodeid, in dlm_recover_waiters_post()
5369 dlm_put_lkb(lkb); in dlm_recover_waiters_post()
5378 struct dlm_lkb *lkb, *safe; in purge_mstcpy_list() local
5380 list_for_each_entry_safe(lkb, safe, list, lkb_statequeue) { in purge_mstcpy_list()
5381 if (!is_master_copy(lkb)) in purge_mstcpy_list()
5387 if (lkb->lkb_recover_seq == ls->ls_recover_seq) in purge_mstcpy_list()
5390 del_lkb(r, lkb); in purge_mstcpy_list()
5393 if (!dlm_put_lkb(lkb)) in purge_mstcpy_list()
5411 struct dlm_lkb *lkb, *safe; in purge_dead_list() local
5413 list_for_each_entry_safe(lkb, safe, list, lkb_statequeue) { in purge_dead_list()
5414 if (!is_master_copy(lkb)) in purge_dead_list()
5417 if ((lkb->lkb_nodeid == nodeid_gone) || in purge_dead_list()
5418 dlm_is_removed(ls, lkb->lkb_nodeid)) { in purge_dead_list()
5422 if ((lkb->lkb_exflags & DLM_LKF_VALBLK) && in purge_dead_list()
5423 (lkb->lkb_grmode >= DLM_LOCK_PW)) { in purge_dead_list()
5427 del_lkb(r, lkb); in purge_dead_list()
5430 if (!dlm_put_lkb(lkb)) in purge_dead_list()
5561 struct dlm_lkb *lkb; in search_remid_list() local
5563 list_for_each_entry(lkb, head, lkb_statequeue) { in search_remid_list()
5564 if (lkb->lkb_nodeid == nodeid && lkb->lkb_remid == remid) in search_remid_list()
5565 return lkb; in search_remid_list()
5573 struct dlm_lkb *lkb; in search_remid() local
5575 lkb = search_remid_list(&r->res_grantqueue, nodeid, remid); in search_remid()
5576 if (lkb) in search_remid()
5577 return lkb; in search_remid()
5578 lkb = search_remid_list(&r->res_convertqueue, nodeid, remid); in search_remid()
5579 if (lkb) in search_remid()
5580 return lkb; in search_remid()
5581 lkb = search_remid_list(&r->res_waitqueue, nodeid, remid); in search_remid()
5582 if (lkb) in search_remid()
5583 return lkb; in search_remid()
5588 static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_rcom_lock_args() argument
5593 lkb->lkb_nodeid = rc->rc_header.h_nodeid; in receive_rcom_lock_args()
5594 lkb->lkb_ownpid = le32_to_cpu(rl->rl_ownpid); in receive_rcom_lock_args()
5595 lkb->lkb_remid = le32_to_cpu(rl->rl_lkid); in receive_rcom_lock_args()
5596 lkb->lkb_exflags = le32_to_cpu(rl->rl_exflags); in receive_rcom_lock_args()
5597 lkb->lkb_flags = le32_to_cpu(rl->rl_flags) & 0x0000FFFF; in receive_rcom_lock_args()
5598 lkb->lkb_flags |= DLM_IFL_MSTCPY; in receive_rcom_lock_args()
5599 lkb->lkb_lvbseq = le32_to_cpu(rl->rl_lvbseq); in receive_rcom_lock_args()
5600 lkb->lkb_rqmode = rl->rl_rqmode; in receive_rcom_lock_args()
5601 lkb->lkb_grmode = rl->rl_grmode; in receive_rcom_lock_args()
5604 lkb->lkb_bastfn = (rl->rl_asts & DLM_CB_BAST) ? &fake_bastfn : NULL; in receive_rcom_lock_args()
5605 lkb->lkb_astfn = (rl->rl_asts & DLM_CB_CAST) ? &fake_astfn : NULL; in receive_rcom_lock_args()
5607 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_rcom_lock_args()
5612 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_rcom_lock_args()
5613 if (!lkb->lkb_lvbptr) in receive_rcom_lock_args()
5615 memcpy(lkb->lkb_lvbptr, rl->rl_lvb, lvblen); in receive_rcom_lock_args()
5623 middle_conversion(lkb)) { in receive_rcom_lock_args()
5625 lkb->lkb_grmode = DLM_LOCK_IV; in receive_rcom_lock_args()
5643 struct dlm_lkb *lkb; in dlm_recover_master_copy() local
5677 lkb = search_remid(r, from_nodeid, remid); in dlm_recover_master_copy()
5678 if (lkb) { in dlm_recover_master_copy()
5683 error = create_lkb(ls, &lkb); in dlm_recover_master_copy()
5687 error = receive_rcom_lock_args(ls, lkb, r, rc); in dlm_recover_master_copy()
5689 __put_lkb(ls, lkb); in dlm_recover_master_copy()
5693 attach_lkb(r, lkb); in dlm_recover_master_copy()
5694 add_lkb(r, lkb, rl->rl_status); in dlm_recover_master_copy()
5704 rl->rl_remid = cpu_to_le32(lkb->lkb_id); in dlm_recover_master_copy()
5706 lkb->lkb_recover_seq = ls->ls_recover_seq; in dlm_recover_master_copy()
5724 struct dlm_lkb *lkb; in dlm_recover_process_copy() local
5732 error = find_lkb(ls, lkid, &lkb); in dlm_recover_process_copy()
5739 r = lkb->lkb_resource; in dlm_recover_process_copy()
5743 if (!is_process_copy(lkb)) { in dlm_recover_process_copy()
5749 dlm_put_lkb(lkb); in dlm_recover_process_copy()
5762 dlm_send_rcom_lock(r, lkb); in dlm_recover_process_copy()
5766 lkb->lkb_remid = remid; in dlm_recover_process_copy()
5779 dlm_put_lkb(lkb); in dlm_recover_process_copy()
5788 struct dlm_lkb *lkb; in dlm_user_request() local
5794 error = create_lkb(ls, &lkb); in dlm_user_request()
5804 __put_lkb(ls, lkb); in dlm_user_request()
5815 __put_lkb(ls, lkb); in dlm_user_request()
5822 lkb->lkb_flags |= DLM_IFL_USER; in dlm_user_request()
5823 error = request_lock(ls, lkb, name, namelen, &args); in dlm_user_request()
5835 __put_lkb(ls, lkb); in dlm_user_request()
5841 hold_lkb(lkb); in dlm_user_request()
5842 list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks); in dlm_user_request()
5853 struct dlm_lkb *lkb; in dlm_user_convert() local
5860 error = find_lkb(ls, lkid, &lkb); in dlm_user_convert()
5867 ua = lkb->lkb_ua; in dlm_user_convert()
5891 error = convert_lock(ls, lkb, &args); in dlm_user_convert()
5896 dlm_put_lkb(lkb); in dlm_user_convert()
5913 struct dlm_lkb *lkb = NULL, *iter; in dlm_user_adopt_orphan() local
5929 lkb = iter; in dlm_user_adopt_orphan()
5937 if (!lkb && found_other_mode) { in dlm_user_adopt_orphan()
5942 if (!lkb) { in dlm_user_adopt_orphan()
5947 lkb->lkb_exflags = flags; in dlm_user_adopt_orphan()
5948 lkb->lkb_ownpid = (int) current->pid; in dlm_user_adopt_orphan()
5950 ua = lkb->lkb_ua; in dlm_user_adopt_orphan()
5967 list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks); in dlm_user_adopt_orphan()
5977 struct dlm_lkb *lkb; in dlm_user_unlock() local
5984 error = find_lkb(ls, lkid, &lkb); in dlm_user_unlock()
5988 ua = lkb->lkb_ua; in dlm_user_unlock()
6000 error = unlock_lock(ls, lkb, &args); in dlm_user_unlock()
6012 if (!list_empty(&lkb->lkb_ownqueue)) in dlm_user_unlock()
6013 list_move(&lkb->lkb_ownqueue, &ua->proc->unlocking); in dlm_user_unlock()
6016 dlm_put_lkb(lkb); in dlm_user_unlock()
6026 struct dlm_lkb *lkb; in dlm_user_cancel() local
6033 error = find_lkb(ls, lkid, &lkb); in dlm_user_cancel()
6037 ua = lkb->lkb_ua; in dlm_user_cancel()
6046 error = cancel_lock(ls, lkb, &args); in dlm_user_cancel()
6054 dlm_put_lkb(lkb); in dlm_user_cancel()
6063 struct dlm_lkb *lkb; in dlm_user_deadlock() local
6071 error = find_lkb(ls, lkid, &lkb); in dlm_user_deadlock()
6075 ua = lkb->lkb_ua; in dlm_user_deadlock()
6083 r = lkb->lkb_resource; in dlm_user_deadlock()
6087 error = validate_unlock_args(lkb, &args); in dlm_user_deadlock()
6090 lkb->lkb_flags |= DLM_IFL_DEADLOCK_CANCEL; in dlm_user_deadlock()
6092 error = _cancel_lock(r, lkb); in dlm_user_deadlock()
6103 dlm_put_lkb(lkb); in dlm_user_deadlock()
6112 static int orphan_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) in orphan_proc_lock() argument
6117 hold_lkb(lkb); /* reference for the ls_orphans list */ in orphan_proc_lock()
6119 list_add_tail(&lkb->lkb_ownqueue, &ls->ls_orphans); in orphan_proc_lock()
6122 set_unlock_args(0, lkb->lkb_ua, &args); in orphan_proc_lock()
6124 error = cancel_lock(ls, lkb, &args); in orphan_proc_lock()
6135 static int unlock_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) in unlock_proc_lock() argument
6141 lkb->lkb_ua, &args); in unlock_proc_lock()
6143 error = unlock_lock(ls, lkb, &args); in unlock_proc_lock()
6156 struct dlm_lkb *lkb = NULL; in del_proc_lock() local
6162 lkb = list_entry(proc->locks.next, struct dlm_lkb, lkb_ownqueue); in del_proc_lock()
6163 list_del_init(&lkb->lkb_ownqueue); in del_proc_lock()
6165 if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) in del_proc_lock()
6166 lkb->lkb_flags |= DLM_IFL_ORPHAN; in del_proc_lock()
6168 lkb->lkb_flags |= DLM_IFL_DEAD; in del_proc_lock()
6171 return lkb; in del_proc_lock()
6186 struct dlm_lkb *lkb, *safe; in dlm_clear_proc_locks() local
6191 lkb = del_proc_lock(ls, proc); in dlm_clear_proc_locks()
6192 if (!lkb) in dlm_clear_proc_locks()
6194 del_timeout(lkb); in dlm_clear_proc_locks()
6195 if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) in dlm_clear_proc_locks()
6196 orphan_proc_lock(ls, lkb); in dlm_clear_proc_locks()
6198 unlock_proc_lock(ls, lkb); in dlm_clear_proc_locks()
6204 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
6210 list_for_each_entry_safe(lkb, safe, &proc->unlocking, lkb_ownqueue) { in dlm_clear_proc_locks()
6211 list_del_init(&lkb->lkb_ownqueue); in dlm_clear_proc_locks()
6212 lkb->lkb_flags |= DLM_IFL_DEAD; in dlm_clear_proc_locks()
6213 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
6216 list_for_each_entry_safe(lkb, safe, &proc->asts, lkb_cb_list) { in dlm_clear_proc_locks()
6217 memset(&lkb->lkb_callbacks, 0, in dlm_clear_proc_locks()
6219 list_del_init(&lkb->lkb_cb_list); in dlm_clear_proc_locks()
6220 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
6229 struct dlm_lkb *lkb, *safe; in purge_proc_locks() local
6232 lkb = NULL; in purge_proc_locks()
6235 lkb = list_entry(proc->locks.next, struct dlm_lkb, in purge_proc_locks()
6237 list_del_init(&lkb->lkb_ownqueue); in purge_proc_locks()
6241 if (!lkb) in purge_proc_locks()
6244 lkb->lkb_flags |= DLM_IFL_DEAD; in purge_proc_locks()
6245 unlock_proc_lock(ls, lkb); in purge_proc_locks()
6246 dlm_put_lkb(lkb); /* ref from proc->locks list */ in purge_proc_locks()
6250 list_for_each_entry_safe(lkb, safe, &proc->unlocking, lkb_ownqueue) { in purge_proc_locks()
6251 list_del_init(&lkb->lkb_ownqueue); in purge_proc_locks()
6252 lkb->lkb_flags |= DLM_IFL_DEAD; in purge_proc_locks()
6253 dlm_put_lkb(lkb); in purge_proc_locks()
6258 list_for_each_entry_safe(lkb, safe, &proc->asts, lkb_cb_list) { in purge_proc_locks()
6259 memset(&lkb->lkb_callbacks, 0, in purge_proc_locks()
6261 list_del_init(&lkb->lkb_cb_list); in purge_proc_locks()
6262 dlm_put_lkb(lkb); in purge_proc_locks()
6271 struct dlm_lkb *lkb, *safe; in do_purge() local
6274 list_for_each_entry_safe(lkb, safe, &ls->ls_orphans, lkb_ownqueue) { in do_purge()
6275 if (pid && lkb->lkb_ownpid != pid) in do_purge()
6277 unlock_proc_lock(ls, lkb); in do_purge()
6278 list_del_init(&lkb->lkb_ownqueue); in do_purge()
6279 dlm_put_lkb(lkb); in do_purge()