Lines Matching refs:lkb
78 static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb);
79 static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb);
80 static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb);
81 static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb);
82 static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb);
83 static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode);
84 static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb);
86 static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb);
87 static int _cancel_lock(struct dlm_rsb *r, struct dlm_lkb *lkb);
88 static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb,
92 static void del_timeout(struct dlm_lkb *lkb);
162 void dlm_print_lkb(struct dlm_lkb *lkb) in dlm_print_lkb() argument
166 lkb->lkb_nodeid, lkb->lkb_id, lkb->lkb_remid, lkb->lkb_exflags, in dlm_print_lkb()
167 lkb->lkb_flags, lkb->lkb_status, lkb->lkb_rqmode, in dlm_print_lkb()
168 lkb->lkb_grmode, lkb->lkb_wait_type, lkb->lkb_wait_nodeid, in dlm_print_lkb()
169 (unsigned long long)lkb->lkb_recover_seq); in dlm_print_lkb()
183 struct dlm_lkb *lkb; in dlm_dump_rsb() local
190 list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) in dlm_dump_rsb()
191 dlm_print_lkb(lkb); in dlm_dump_rsb()
193 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) in dlm_dump_rsb()
194 dlm_print_lkb(lkb); in dlm_dump_rsb()
196 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) in dlm_dump_rsb()
197 dlm_print_lkb(lkb); in dlm_dump_rsb()
199 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) in dlm_dump_rsb()
200 dlm_print_lkb(lkb); in dlm_dump_rsb()
220 static inline int can_be_queued(struct dlm_lkb *lkb) in can_be_queued() argument
222 return !(lkb->lkb_exflags & DLM_LKF_NOQUEUE); in can_be_queued()
225 static inline int force_blocking_asts(struct dlm_lkb *lkb) in force_blocking_asts() argument
227 return (lkb->lkb_exflags & DLM_LKF_NOQUEUEBAST); in force_blocking_asts()
230 static inline int is_demoted(struct dlm_lkb *lkb) in is_demoted() argument
232 return (lkb->lkb_sbflags & DLM_SBF_DEMOTED); in is_demoted()
235 static inline int is_altmode(struct dlm_lkb *lkb) in is_altmode() argument
237 return (lkb->lkb_sbflags & DLM_SBF_ALTMODE); in is_altmode()
240 static inline int is_granted(struct dlm_lkb *lkb) in is_granted() argument
242 return (lkb->lkb_status == DLM_LKSTS_GRANTED); in is_granted()
251 static inline int is_process_copy(struct dlm_lkb *lkb) in is_process_copy() argument
253 return (lkb->lkb_nodeid && !(lkb->lkb_flags & DLM_IFL_MSTCPY)); in is_process_copy()
256 static inline int is_master_copy(struct dlm_lkb *lkb) in is_master_copy() argument
258 return (lkb->lkb_flags & DLM_IFL_MSTCPY) ? 1 : 0; in is_master_copy()
261 static inline int middle_conversion(struct dlm_lkb *lkb) in middle_conversion() argument
263 if ((lkb->lkb_grmode==DLM_LOCK_PR && lkb->lkb_rqmode==DLM_LOCK_CW) || in middle_conversion()
264 (lkb->lkb_rqmode==DLM_LOCK_PR && lkb->lkb_grmode==DLM_LOCK_CW)) in middle_conversion()
269 static inline int down_conversion(struct dlm_lkb *lkb) in down_conversion() argument
271 return (!middle_conversion(lkb) && lkb->lkb_rqmode < lkb->lkb_grmode); in down_conversion()
274 static inline int is_overlap_unlock(struct dlm_lkb *lkb) in is_overlap_unlock() argument
276 return lkb->lkb_flags & DLM_IFL_OVERLAP_UNLOCK; in is_overlap_unlock()
279 static inline int is_overlap_cancel(struct dlm_lkb *lkb) in is_overlap_cancel() argument
281 return lkb->lkb_flags & DLM_IFL_OVERLAP_CANCEL; in is_overlap_cancel()
284 static inline int is_overlap(struct dlm_lkb *lkb) in is_overlap() argument
286 return (lkb->lkb_flags & (DLM_IFL_OVERLAP_UNLOCK | in is_overlap()
290 static void queue_cast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in queue_cast() argument
292 if (is_master_copy(lkb)) in queue_cast()
295 del_timeout(lkb); in queue_cast()
297 DLM_ASSERT(lkb->lkb_lksb, dlm_print_lkb(lkb);); in queue_cast()
302 if (rv == -DLM_ECANCEL && (lkb->lkb_flags & DLM_IFL_TIMEOUT_CANCEL)) { in queue_cast()
303 lkb->lkb_flags &= ~DLM_IFL_TIMEOUT_CANCEL; in queue_cast()
308 if (rv == -DLM_ECANCEL && (lkb->lkb_flags & DLM_IFL_DEADLOCK_CANCEL)) { in queue_cast()
309 lkb->lkb_flags &= ~DLM_IFL_DEADLOCK_CANCEL; in queue_cast()
313 dlm_add_cb(lkb, DLM_CB_CAST, lkb->lkb_grmode, rv, lkb->lkb_sbflags); in queue_cast()
316 static inline void queue_cast_overlap(struct dlm_rsb *r, struct dlm_lkb *lkb) in queue_cast_overlap() argument
318 queue_cast(r, lkb, in queue_cast_overlap()
319 is_overlap_unlock(lkb) ? -DLM_EUNLOCK : -DLM_ECANCEL); in queue_cast_overlap()
322 static void queue_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rqmode) in queue_bast() argument
324 if (is_master_copy(lkb)) { in queue_bast()
325 send_bast(r, lkb, rqmode); in queue_bast()
327 dlm_add_cb(lkb, DLM_CB_BAST, rqmode, 0, 0); in queue_bast()
1188 static void attach_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) in attach_lkb() argument
1191 lkb->lkb_resource = r; in attach_lkb()
1194 static void detach_lkb(struct dlm_lkb *lkb) in detach_lkb() argument
1196 if (lkb->lkb_resource) { in detach_lkb()
1197 put_rsb(lkb->lkb_resource); in detach_lkb()
1198 lkb->lkb_resource = NULL; in detach_lkb()
1205 struct dlm_lkb *lkb; in _create_lkb() local
1208 lkb = dlm_allocate_lkb(ls); in _create_lkb()
1209 if (!lkb) in _create_lkb()
1212 lkb->lkb_nodeid = -1; in _create_lkb()
1213 lkb->lkb_grmode = DLM_LOCK_IV; in _create_lkb()
1214 kref_init(&lkb->lkb_ref); in _create_lkb()
1215 INIT_LIST_HEAD(&lkb->lkb_ownqueue); in _create_lkb()
1216 INIT_LIST_HEAD(&lkb->lkb_rsb_lookup); in _create_lkb()
1218 INIT_LIST_HEAD(&lkb->lkb_time_list); in _create_lkb()
1220 INIT_LIST_HEAD(&lkb->lkb_cb_list); in _create_lkb()
1221 mutex_init(&lkb->lkb_cb_mutex); in _create_lkb()
1222 INIT_WORK(&lkb->lkb_cb_work, dlm_callback_work); in _create_lkb()
1226 rv = idr_alloc(&ls->ls_lkbidr, lkb, start, end, GFP_NOWAIT); in _create_lkb()
1228 lkb->lkb_id = rv; in _create_lkb()
1234 dlm_free_lkb(lkb); in _create_lkb()
1238 *lkb_ret = lkb; in _create_lkb()
1249 struct dlm_lkb *lkb; in find_lkb() local
1252 lkb = idr_find(&ls->ls_lkbidr, lkid); in find_lkb()
1253 if (lkb) in find_lkb()
1254 kref_get(&lkb->lkb_ref); in find_lkb()
1257 *lkb_ret = lkb; in find_lkb()
1258 return lkb ? 0 : -ENOENT; in find_lkb()
1263 struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref); in kill_lkb() local
1268 DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); in kill_lkb()
1274 static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb) in __put_lkb() argument
1276 uint32_t lkid = lkb->lkb_id; in __put_lkb()
1279 rv = kref_put_lock(&lkb->lkb_ref, kill_lkb, in __put_lkb()
1285 detach_lkb(lkb); in __put_lkb()
1288 if (lkb->lkb_lvbptr && is_master_copy(lkb)) in __put_lkb()
1289 dlm_free_lvb(lkb->lkb_lvbptr); in __put_lkb()
1290 dlm_free_lkb(lkb); in __put_lkb()
1296 int dlm_put_lkb(struct dlm_lkb *lkb) in dlm_put_lkb() argument
1300 DLM_ASSERT(lkb->lkb_resource, dlm_print_lkb(lkb);); in dlm_put_lkb()
1301 DLM_ASSERT(lkb->lkb_resource->res_ls, dlm_print_lkb(lkb);); in dlm_put_lkb()
1303 ls = lkb->lkb_resource->res_ls; in dlm_put_lkb()
1304 return __put_lkb(ls, lkb); in dlm_put_lkb()
1310 static inline void hold_lkb(struct dlm_lkb *lkb) in hold_lkb() argument
1312 kref_get(&lkb->lkb_ref); in hold_lkb()
1317 struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref); in unhold_lkb_assert() local
1319 DLM_ASSERT(false, dlm_print_lkb(lkb);); in unhold_lkb_assert()
1327 static inline void unhold_lkb(struct dlm_lkb *lkb) in unhold_lkb() argument
1329 kref_put(&lkb->lkb_ref, unhold_lkb_assert); in unhold_lkb()
1335 struct dlm_lkb *lkb = NULL, *iter; in lkb_add_ordered() local
1339 lkb = iter; in lkb_add_ordered()
1344 if (!lkb) in lkb_add_ordered()
1350 static void add_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int status) in add_lkb() argument
1352 kref_get(&lkb->lkb_ref); in add_lkb()
1354 DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); in add_lkb()
1356 lkb->lkb_timestamp = ktime_get(); in add_lkb()
1358 lkb->lkb_status = status; in add_lkb()
1362 if (lkb->lkb_exflags & DLM_LKF_HEADQUE) in add_lkb()
1363 list_add(&lkb->lkb_statequeue, &r->res_waitqueue); in add_lkb()
1365 list_add_tail(&lkb->lkb_statequeue, &r->res_waitqueue); in add_lkb()
1369 lkb_add_ordered(&lkb->lkb_statequeue, &r->res_grantqueue, in add_lkb()
1370 lkb->lkb_grmode); in add_lkb()
1373 if (lkb->lkb_exflags & DLM_LKF_HEADQUE) in add_lkb()
1374 list_add(&lkb->lkb_statequeue, &r->res_convertqueue); in add_lkb()
1376 list_add_tail(&lkb->lkb_statequeue, in add_lkb()
1380 DLM_ASSERT(0, dlm_print_lkb(lkb); printk("sts=%d\n", status);); in add_lkb()
1384 static void del_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) in del_lkb() argument
1386 lkb->lkb_status = 0; in del_lkb()
1387 list_del(&lkb->lkb_statequeue); in del_lkb()
1388 unhold_lkb(lkb); in del_lkb()
1391 static void move_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int sts) in move_lkb() argument
1393 hold_lkb(lkb); in move_lkb()
1394 del_lkb(r, lkb); in move_lkb()
1395 add_lkb(r, lkb, sts); in move_lkb()
1396 unhold_lkb(lkb); in move_lkb()
1419 static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid) in add_to_waiters() argument
1421 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in add_to_waiters()
1426 if (is_overlap_unlock(lkb) || in add_to_waiters()
1427 (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL))) { in add_to_waiters()
1432 if (lkb->lkb_wait_type || is_overlap_cancel(lkb)) { in add_to_waiters()
1435 lkb->lkb_flags |= DLM_IFL_OVERLAP_UNLOCK; in add_to_waiters()
1438 lkb->lkb_flags |= DLM_IFL_OVERLAP_CANCEL; in add_to_waiters()
1444 lkb->lkb_wait_count++; in add_to_waiters()
1445 hold_lkb(lkb); in add_to_waiters()
1448 lkb->lkb_id, lkb->lkb_wait_type, mstype, in add_to_waiters()
1449 lkb->lkb_wait_count, lkb->lkb_flags); in add_to_waiters()
1453 DLM_ASSERT(!lkb->lkb_wait_count, in add_to_waiters()
1454 dlm_print_lkb(lkb); in add_to_waiters()
1455 printk("wait_count %d\n", lkb->lkb_wait_count);); in add_to_waiters()
1457 lkb->lkb_wait_count++; in add_to_waiters()
1458 lkb->lkb_wait_type = mstype; in add_to_waiters()
1459 lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */ in add_to_waiters()
1460 hold_lkb(lkb); in add_to_waiters()
1461 list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); in add_to_waiters()
1465 lkb->lkb_id, error, lkb->lkb_flags, mstype, in add_to_waiters()
1466 lkb->lkb_wait_type, lkb->lkb_resource->res_name); in add_to_waiters()
1476 static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype, in _remove_from_waiters() argument
1479 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in _remove_from_waiters()
1482 if (is_overlap_unlock(lkb) && (mstype == DLM_MSG_UNLOCK_REPLY)) { in _remove_from_waiters()
1483 log_debug(ls, "remwait %x unlock_reply overlap", lkb->lkb_id); in _remove_from_waiters()
1484 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in _remove_from_waiters()
1489 if (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL_REPLY)) { in _remove_from_waiters()
1490 log_debug(ls, "remwait %x cancel_reply overlap", lkb->lkb_id); in _remove_from_waiters()
1491 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in _remove_from_waiters()
1500 (lkb->lkb_wait_type != DLM_MSG_CANCEL)) { in _remove_from_waiters()
1502 lkb->lkb_id, lkb->lkb_wait_type); in _remove_from_waiters()
1515 (lkb->lkb_wait_type == DLM_MSG_CONVERT) && in _remove_from_waiters()
1516 is_overlap_cancel(lkb) && ms && !ms->m_result) { in _remove_from_waiters()
1518 lkb->lkb_id); in _remove_from_waiters()
1519 lkb->lkb_wait_type = 0; in _remove_from_waiters()
1520 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in _remove_from_waiters()
1521 lkb->lkb_wait_count--; in _remove_from_waiters()
1522 unhold_lkb(lkb); in _remove_from_waiters()
1529 if (lkb->lkb_wait_type) { in _remove_from_waiters()
1530 lkb->lkb_wait_type = 0; in _remove_from_waiters()
1535 lkb->lkb_id, ms ? le32_to_cpu(ms->m_header.h_nodeid) : 0, in _remove_from_waiters()
1536 lkb->lkb_remid, mstype, lkb->lkb_flags); in _remove_from_waiters()
1545 if (overlap_done && lkb->lkb_wait_type) { in _remove_from_waiters()
1547 lkb->lkb_id, mstype, lkb->lkb_wait_type); in _remove_from_waiters()
1548 lkb->lkb_wait_count--; in _remove_from_waiters()
1549 unhold_lkb(lkb); in _remove_from_waiters()
1550 lkb->lkb_wait_type = 0; in _remove_from_waiters()
1553 DLM_ASSERT(lkb->lkb_wait_count, dlm_print_lkb(lkb);); in _remove_from_waiters()
1555 lkb->lkb_flags &= ~DLM_IFL_RESEND; in _remove_from_waiters()
1556 lkb->lkb_wait_count--; in _remove_from_waiters()
1557 if (!lkb->lkb_wait_count) in _remove_from_waiters()
1558 list_del_init(&lkb->lkb_wait_reply); in _remove_from_waiters()
1559 unhold_lkb(lkb); in _remove_from_waiters()
1563 static int remove_from_waiters(struct dlm_lkb *lkb, int mstype) in remove_from_waiters() argument
1565 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in remove_from_waiters()
1569 error = _remove_from_waiters(lkb, mstype, NULL); in remove_from_waiters()
1577 static int remove_from_waiters_ms(struct dlm_lkb *lkb, struct dlm_message *ms) in remove_from_waiters_ms() argument
1579 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in remove_from_waiters_ms()
1584 error = _remove_from_waiters(lkb, le32_to_cpu(ms->m_type), ms); in remove_from_waiters_ms()
1787 static void add_timeout(struct dlm_lkb *lkb) in add_timeout() argument
1789 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in add_timeout()
1791 if (is_master_copy(lkb)) in add_timeout()
1795 !(lkb->lkb_exflags & DLM_LKF_NODLCKWT)) { in add_timeout()
1796 lkb->lkb_flags |= DLM_IFL_WATCH_TIMEWARN; in add_timeout()
1799 if (lkb->lkb_exflags & DLM_LKF_TIMEOUT) in add_timeout()
1804 DLM_ASSERT(list_empty(&lkb->lkb_time_list), dlm_print_lkb(lkb);); in add_timeout()
1806 hold_lkb(lkb); in add_timeout()
1807 list_add_tail(&lkb->lkb_time_list, &ls->ls_timeout); in add_timeout()
1811 static void del_timeout(struct dlm_lkb *lkb) in del_timeout() argument
1813 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in del_timeout()
1816 if (!list_empty(&lkb->lkb_time_list)) { in del_timeout()
1817 list_del_init(&lkb->lkb_time_list); in del_timeout()
1818 unhold_lkb(lkb); in del_timeout()
1832 struct dlm_lkb *lkb = NULL, *iter; in dlm_scan_timeout() local
1859 lkb = iter; in dlm_scan_timeout()
1864 if (!lkb) in dlm_scan_timeout()
1867 r = lkb->lkb_resource; in dlm_scan_timeout()
1873 lkb->lkb_flags &= ~DLM_IFL_WATCH_TIMEWARN; in dlm_scan_timeout()
1874 if (!(lkb->lkb_exflags & DLM_LKF_TIMEOUT)) in dlm_scan_timeout()
1875 del_timeout(lkb); in dlm_scan_timeout()
1876 dlm_timeout_warn(lkb); in dlm_scan_timeout()
1881 lkb->lkb_id, lkb->lkb_nodeid, r->res_name); in dlm_scan_timeout()
1882 lkb->lkb_flags &= ~DLM_IFL_WATCH_TIMEWARN; in dlm_scan_timeout()
1883 lkb->lkb_flags |= DLM_IFL_TIMEOUT_CANCEL; in dlm_scan_timeout()
1884 del_timeout(lkb); in dlm_scan_timeout()
1885 _cancel_lock(r, lkb); in dlm_scan_timeout()
1890 dlm_put_lkb(lkb); in dlm_scan_timeout()
1899 struct dlm_lkb *lkb; in dlm_adjust_timeouts() local
1904 list_for_each_entry(lkb, &ls->ls_timeout, lkb_time_list) in dlm_adjust_timeouts()
1905 lkb->lkb_timestamp = ktime_add_us(lkb->lkb_timestamp, adj_us); in dlm_adjust_timeouts()
1909 static void add_timeout(struct dlm_lkb *lkb) { } in add_timeout() argument
1910 static void del_timeout(struct dlm_lkb *lkb) { } in del_timeout() argument
1915 static void set_lvb_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_lvb_lock() argument
1923 b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; in set_lvb_lock()
1926 if (!lkb->lkb_lvbptr) in set_lvb_lock()
1929 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock()
1935 memcpy(lkb->lkb_lvbptr, r->res_lvbptr, len); in set_lvb_lock()
1936 lkb->lkb_lvbseq = r->res_lvbseq; in set_lvb_lock()
1939 if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { in set_lvb_lock()
1944 if (!lkb->lkb_lvbptr) in set_lvb_lock()
1947 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock()
1956 memcpy(r->res_lvbptr, lkb->lkb_lvbptr, len); in set_lvb_lock()
1958 lkb->lkb_lvbseq = r->res_lvbseq; in set_lvb_lock()
1963 lkb->lkb_sbflags |= DLM_SBF_VALNOTVALID; in set_lvb_lock()
1966 static void set_lvb_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_lvb_unlock() argument
1968 if (lkb->lkb_grmode < DLM_LOCK_PW) in set_lvb_unlock()
1971 if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { in set_lvb_unlock()
1976 if (!lkb->lkb_lvbptr) in set_lvb_unlock()
1979 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_unlock()
1988 memcpy(r->res_lvbptr, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); in set_lvb_unlock()
1995 static void set_lvb_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, in set_lvb_lock_pc() argument
2000 if (!lkb->lkb_lvbptr) in set_lvb_lock_pc()
2003 if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) in set_lvb_lock_pc()
2006 b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; in set_lvb_lock_pc()
2011 memcpy(lkb->lkb_lvbptr, ms->m_extra, len); in set_lvb_lock_pc()
2012 lkb->lkb_lvbseq = le32_to_cpu(ms->m_lvbseq); in set_lvb_lock_pc()
2026 static void _remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _remove_lock() argument
2028 del_lkb(r, lkb); in _remove_lock()
2029 lkb->lkb_grmode = DLM_LOCK_IV; in _remove_lock()
2032 unhold_lkb(lkb); in _remove_lock()
2035 static void remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in remove_lock() argument
2037 set_lvb_unlock(r, lkb); in remove_lock()
2038 _remove_lock(r, lkb); in remove_lock()
2041 static void remove_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) in remove_lock_pc() argument
2043 _remove_lock(r, lkb); in remove_lock_pc()
2050 static int revert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in revert_lock() argument
2054 lkb->lkb_rqmode = DLM_LOCK_IV; in revert_lock()
2056 switch (lkb->lkb_status) { in revert_lock()
2060 move_lkb(r, lkb, DLM_LKSTS_GRANTED); in revert_lock()
2064 del_lkb(r, lkb); in revert_lock()
2065 lkb->lkb_grmode = DLM_LOCK_IV; in revert_lock()
2068 unhold_lkb(lkb); in revert_lock()
2072 log_print("invalid status for revert %d", lkb->lkb_status); in revert_lock()
2077 static int revert_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) in revert_lock_pc() argument
2079 return revert_lock(r, lkb); in revert_lock_pc()
2082 static void _grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _grant_lock() argument
2084 if (lkb->lkb_grmode != lkb->lkb_rqmode) { in _grant_lock()
2085 lkb->lkb_grmode = lkb->lkb_rqmode; in _grant_lock()
2086 if (lkb->lkb_status) in _grant_lock()
2087 move_lkb(r, lkb, DLM_LKSTS_GRANTED); in _grant_lock()
2089 add_lkb(r, lkb, DLM_LKSTS_GRANTED); in _grant_lock()
2092 lkb->lkb_rqmode = DLM_LOCK_IV; in _grant_lock()
2093 lkb->lkb_highbast = 0; in _grant_lock()
2096 static void grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in grant_lock() argument
2098 set_lvb_lock(r, lkb); in grant_lock()
2099 _grant_lock(r, lkb); in grant_lock()
2102 static void grant_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, in grant_lock_pc() argument
2105 set_lvb_lock_pc(r, lkb, ms); in grant_lock_pc()
2106 _grant_lock(r, lkb); in grant_lock_pc()
2113 static void grant_lock_pending(struct dlm_rsb *r, struct dlm_lkb *lkb) in grant_lock_pending() argument
2115 grant_lock(r, lkb); in grant_lock_pending()
2116 if (is_master_copy(lkb)) in grant_lock_pending()
2117 send_grant(r, lkb); in grant_lock_pending()
2119 queue_cast(r, lkb, 0); in grant_lock_pending()
2130 static void munge_demoted(struct dlm_lkb *lkb) in munge_demoted() argument
2132 if (lkb->lkb_rqmode == DLM_LOCK_IV || lkb->lkb_grmode == DLM_LOCK_IV) { in munge_demoted()
2134 lkb->lkb_id, lkb->lkb_grmode, lkb->lkb_rqmode); in munge_demoted()
2138 lkb->lkb_grmode = DLM_LOCK_NL; in munge_demoted()
2141 static void munge_altmode(struct dlm_lkb *lkb, struct dlm_message *ms) in munge_altmode() argument
2146 lkb->lkb_id, le32_to_cpu(ms->m_type)); in munge_altmode()
2150 if (lkb->lkb_exflags & DLM_LKF_ALTPR) in munge_altmode()
2151 lkb->lkb_rqmode = DLM_LOCK_PR; in munge_altmode()
2152 else if (lkb->lkb_exflags & DLM_LKF_ALTCW) in munge_altmode()
2153 lkb->lkb_rqmode = DLM_LOCK_CW; in munge_altmode()
2155 log_print("munge_altmode invalid exflags %x", lkb->lkb_exflags); in munge_altmode()
2156 dlm_print_lkb(lkb); in munge_altmode()
2160 static inline int first_in_list(struct dlm_lkb *lkb, struct list_head *head) in first_in_list() argument
2164 if (lkb->lkb_id == first->lkb_id) in first_in_list()
2172 static int queue_conflict(struct list_head *head, struct dlm_lkb *lkb) in queue_conflict() argument
2177 if (this == lkb) in queue_conflict()
2179 if (!modes_compat(this, lkb)) in queue_conflict()
2265 static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now, in _can_be_granted() argument
2268 int8_t conv = (lkb->lkb_grmode != DLM_LOCK_IV); in _can_be_granted()
2289 if (lkb->lkb_exflags & DLM_LKF_EXPEDITE) in _can_be_granted()
2297 if (queue_conflict(&r->res_grantqueue, lkb)) in _can_be_granted()
2306 if (queue_conflict(&r->res_convertqueue, lkb)) in _can_be_granted()
2349 if (now && conv && !(lkb->lkb_exflags & DLM_LKF_QUECVT)) in _can_be_granted()
2357 if (now && conv && (lkb->lkb_exflags & DLM_LKF_QUECVT)) { in _can_be_granted()
2369 if (lkb->lkb_exflags & DLM_LKF_NOORDER) in _can_be_granted()
2378 if (!now && conv && first_in_list(lkb, &r->res_convertqueue)) in _can_be_granted()
2405 first_in_list(lkb, &r->res_waitqueue)) in _can_be_granted()
2411 static int can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now, in can_be_granted() argument
2415 int8_t alt = 0, rqmode = lkb->lkb_rqmode; in can_be_granted()
2416 int8_t is_convert = (lkb->lkb_grmode != DLM_LOCK_IV); in can_be_granted()
2421 rv = _can_be_granted(r, lkb, now, recover); in can_be_granted()
2431 if (is_convert && can_be_queued(lkb) && in can_be_granted()
2432 conversion_deadlock_detect(r, lkb)) { in can_be_granted()
2433 if (lkb->lkb_exflags & DLM_LKF_CONVDEADLK) { in can_be_granted()
2434 lkb->lkb_grmode = DLM_LOCK_NL; in can_be_granted()
2435 lkb->lkb_sbflags |= DLM_SBF_DEMOTED; in can_be_granted()
2440 lkb->lkb_id, now); in can_be_granted()
2453 if (rqmode != DLM_LOCK_PR && (lkb->lkb_exflags & DLM_LKF_ALTPR)) in can_be_granted()
2455 else if (rqmode != DLM_LOCK_CW && (lkb->lkb_exflags & DLM_LKF_ALTCW)) in can_be_granted()
2459 lkb->lkb_rqmode = alt; in can_be_granted()
2460 rv = _can_be_granted(r, lkb, now, 0); in can_be_granted()
2462 lkb->lkb_sbflags |= DLM_SBF_ALTMODE; in can_be_granted()
2464 lkb->lkb_rqmode = rqmode; in can_be_granted()
2476 struct dlm_lkb *lkb, *s; in grant_pending_convert() local
2487 list_for_each_entry_safe(lkb, s, &r->res_convertqueue, lkb_statequeue) { in grant_pending_convert()
2488 demoted = is_demoted(lkb); in grant_pending_convert()
2491 if (can_be_granted(r, lkb, 0, recover, &deadlk)) { in grant_pending_convert()
2492 grant_lock_pending(r, lkb); in grant_pending_convert()
2499 if (!demoted && is_demoted(lkb)) { in grant_pending_convert()
2501 lkb->lkb_id, lkb->lkb_nodeid, r->res_name); in grant_pending_convert()
2512 if (lkb->lkb_exflags & DLM_LKF_NODLCKWT) { in grant_pending_convert()
2513 if (lkb->lkb_highbast < lkb->lkb_rqmode) { in grant_pending_convert()
2514 queue_bast(r, lkb, lkb->lkb_rqmode); in grant_pending_convert()
2515 lkb->lkb_highbast = lkb->lkb_rqmode; in grant_pending_convert()
2519 lkb->lkb_id, lkb->lkb_nodeid, in grant_pending_convert()
2526 hi = max_t(int, lkb->lkb_rqmode, hi); in grant_pending_convert()
2528 if (cw && lkb->lkb_rqmode == DLM_LOCK_CW) in grant_pending_convert()
2545 struct dlm_lkb *lkb, *s; in grant_pending_wait() local
2547 list_for_each_entry_safe(lkb, s, &r->res_waitqueue, lkb_statequeue) { in grant_pending_wait()
2548 if (can_be_granted(r, lkb, 0, 0, NULL)) { in grant_pending_wait()
2549 grant_lock_pending(r, lkb); in grant_pending_wait()
2553 high = max_t(int, lkb->lkb_rqmode, high); in grant_pending_wait()
2554 if (lkb->lkb_rqmode == DLM_LOCK_CW) in grant_pending_wait()
2583 struct dlm_lkb *lkb, *s; in grant_pending_locks() local
2605 list_for_each_entry_safe(lkb, s, &r->res_grantqueue, lkb_statequeue) { in grant_pending_locks()
2606 if (lkb->lkb_bastfn && lock_requires_bast(lkb, high, cw)) { in grant_pending_locks()
2608 lkb->lkb_grmode == DLM_LOCK_PR) in grant_pending_locks()
2609 queue_bast(r, lkb, DLM_LOCK_CW); in grant_pending_locks()
2611 queue_bast(r, lkb, high); in grant_pending_locks()
2612 lkb->lkb_highbast = high; in grant_pending_locks()
2632 struct dlm_lkb *lkb) in send_bast_queue() argument
2638 if (gr == lkb) in send_bast_queue()
2640 if (gr->lkb_bastfn && modes_require_bast(gr, lkb)) { in send_bast_queue()
2641 queue_bast(r, gr, lkb->lkb_rqmode); in send_bast_queue()
2642 gr->lkb_highbast = lkb->lkb_rqmode; in send_bast_queue()
2647 static void send_blocking_asts(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_blocking_asts() argument
2649 send_bast_queue(r, &r->res_grantqueue, lkb); in send_blocking_asts()
2652 static void send_blocking_asts_all(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_blocking_asts_all() argument
2654 send_bast_queue(r, &r->res_grantqueue, lkb); in send_blocking_asts_all()
2655 send_bast_queue(r, &r->res_convertqueue, lkb); in send_blocking_asts_all()
2677 static int set_master(struct dlm_rsb *r, struct dlm_lkb *lkb) in set_master() argument
2683 r->res_first_lkid = lkb->lkb_id; in set_master()
2684 lkb->lkb_nodeid = r->res_nodeid; in set_master()
2688 if (r->res_first_lkid && r->res_first_lkid != lkb->lkb_id) { in set_master()
2689 list_add_tail(&lkb->lkb_rsb_lookup, &r->res_lookup); in set_master()
2694 lkb->lkb_nodeid = 0; in set_master()
2699 lkb->lkb_nodeid = r->res_master_nodeid; in set_master()
2711 lkb->lkb_id, r->res_master_nodeid, r->res_dir_nodeid, in set_master()
2715 lkb->lkb_nodeid = 0; in set_master()
2721 r->res_first_lkid = lkb->lkb_id; in set_master()
2722 send_lookup(r, lkb); in set_master()
2728 struct dlm_lkb *lkb, *safe; in process_lookup_list() local
2730 list_for_each_entry_safe(lkb, safe, &r->res_lookup, lkb_rsb_lookup) { in process_lookup_list()
2731 list_del_init(&lkb->lkb_rsb_lookup); in process_lookup_list()
2732 _request_lock(r, lkb); in process_lookup_list()
2741 struct dlm_lkb *lkb; in confirm_master() local
2763 lkb = list_entry(r->res_lookup.next, struct dlm_lkb, in confirm_master()
2765 list_del_init(&lkb->lkb_rsb_lookup); in confirm_master()
2766 r->res_first_lkid = lkb->lkb_id; in confirm_master()
2767 _request_lock(r, lkb); in confirm_master()
2866 static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in validate_lock_args() argument
2872 if (lkb->lkb_status != DLM_LKSTS_GRANTED) in validate_lock_args()
2876 if (lkb->lkb_wait_type || lkb->lkb_wait_count) in validate_lock_args()
2879 if (is_overlap(lkb)) in validate_lock_args()
2883 if (lkb->lkb_flags & DLM_IFL_MSTCPY) in validate_lock_args()
2887 !__quecvt_compat_matrix[lkb->lkb_grmode+1][args->mode+1]) in validate_lock_args()
2891 lkb->lkb_exflags = args->flags; in validate_lock_args()
2892 lkb->lkb_sbflags = 0; in validate_lock_args()
2893 lkb->lkb_astfn = args->astfn; in validate_lock_args()
2894 lkb->lkb_astparam = args->astparam; in validate_lock_args()
2895 lkb->lkb_bastfn = args->bastfn; in validate_lock_args()
2896 lkb->lkb_rqmode = args->mode; in validate_lock_args()
2897 lkb->lkb_lksb = args->lksb; in validate_lock_args()
2898 lkb->lkb_lvbptr = args->lksb->sb_lvbptr; in validate_lock_args()
2899 lkb->lkb_ownpid = (int) current->pid; in validate_lock_args()
2901 lkb->lkb_timeout_cs = args->timeout; in validate_lock_args()
2912 rv, lkb->lkb_id, lkb->lkb_flags, args->flags, in validate_lock_args()
2913 lkb->lkb_status, lkb->lkb_wait_type, in validate_lock_args()
2914 lkb->lkb_resource->res_name); in validate_lock_args()
2918 rv, lkb->lkb_id, lkb->lkb_flags, args->flags, in validate_lock_args()
2919 lkb->lkb_status, lkb->lkb_wait_type, in validate_lock_args()
2920 lkb->lkb_resource->res_name); in validate_lock_args()
2934 static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) in validate_unlock_args() argument
2936 struct dlm_ls *ls = lkb->lkb_resource->res_ls; in validate_unlock_args()
2941 (lkb->lkb_wait_type || lkb->lkb_wait_count)) in validate_unlock_args()
2947 if (!list_empty(&lkb->lkb_rsb_lookup)) { in validate_unlock_args()
2949 log_debug(ls, "unlock on rsb_lookup %x", lkb->lkb_id); in validate_unlock_args()
2950 list_del_init(&lkb->lkb_rsb_lookup); in validate_unlock_args()
2951 queue_cast(lkb->lkb_resource, lkb, in validate_unlock_args()
2954 unhold_lkb(lkb); /* undoes create_lkb() */ in validate_unlock_args()
2961 if (lkb->lkb_flags & DLM_IFL_MSTCPY) { in validate_unlock_args()
2962 log_error(ls, "unlock on MSTCPY %x", lkb->lkb_id); in validate_unlock_args()
2963 dlm_print_lkb(lkb); in validate_unlock_args()
2972 if (lkb->lkb_flags & DLM_IFL_ENDOFLIFE) { in validate_unlock_args()
2973 log_debug(ls, "unlock on ENDOFLIFE %x", lkb->lkb_id); 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()
3051 lkb->lkb_exflags |= args->flags; in validate_unlock_args()
3052 lkb->lkb_sbflags = 0; in validate_unlock_args()
3053 lkb->lkb_astparam = args->astparam; in validate_unlock_args()
3063 lkb->lkb_id, lkb->lkb_flags, lkb->lkb_exflags, in validate_unlock_args()
3064 args->flags, lkb->lkb_wait_type, in validate_unlock_args()
3065 lkb->lkb_resource->res_name); in validate_unlock_args()
3069 lkb->lkb_id, lkb->lkb_flags, lkb->lkb_exflags, in validate_unlock_args()
3070 args->flags, lkb->lkb_wait_type, in validate_unlock_args()
3071 lkb->lkb_resource->res_name); in validate_unlock_args()
3085 static int do_request(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_request() argument
3089 if (can_be_granted(r, lkb, 1, 0, NULL)) { in do_request()
3090 grant_lock(r, lkb); in do_request()
3091 queue_cast(r, lkb, 0); in do_request()
3095 if (can_be_queued(lkb)) { in do_request()
3097 add_lkb(r, lkb, DLM_LKSTS_WAITING); in do_request()
3098 add_timeout(lkb); in do_request()
3103 queue_cast(r, lkb, -EAGAIN); in do_request()
3108 static void do_request_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_request_effects() argument
3113 if (force_blocking_asts(lkb)) in do_request_effects()
3114 send_blocking_asts_all(r, lkb); in do_request_effects()
3117 send_blocking_asts(r, lkb); in do_request_effects()
3122 static int do_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_convert() argument
3129 if (can_be_granted(r, lkb, 1, 0, &deadlk)) { in do_convert()
3130 grant_lock(r, lkb); in do_convert()
3131 queue_cast(r, lkb, 0); in do_convert()
3139 if (deadlk && !(lkb->lkb_exflags & DLM_LKF_NODLCKWT)) { in do_convert()
3141 revert_lock(r, lkb); in do_convert()
3142 queue_cast(r, lkb, -EDEADLK); in do_convert()
3153 if (is_demoted(lkb)) { in do_convert()
3155 if (_can_be_granted(r, lkb, 1, 0)) { in do_convert()
3156 grant_lock(r, lkb); in do_convert()
3157 queue_cast(r, lkb, 0); in do_convert()
3163 if (can_be_queued(lkb)) { in do_convert()
3165 del_lkb(r, lkb); in do_convert()
3166 add_lkb(r, lkb, DLM_LKSTS_CONVERT); in do_convert()
3167 add_timeout(lkb); in do_convert()
3172 queue_cast(r, lkb, -EAGAIN); in do_convert()
3177 static void do_convert_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_convert_effects() argument
3186 if (force_blocking_asts(lkb)) in do_convert_effects()
3187 send_blocking_asts_all(r, lkb); in do_convert_effects()
3190 send_blocking_asts(r, lkb); in do_convert_effects()
3195 static int do_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_unlock() argument
3197 remove_lock(r, lkb); in do_unlock()
3198 queue_cast(r, lkb, -DLM_EUNLOCK); in do_unlock()
3202 static void do_unlock_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_unlock_effects() argument
3210 static int do_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) in do_cancel() argument
3214 error = revert_lock(r, lkb); in do_cancel()
3216 queue_cast(r, lkb, -DLM_ECANCEL); in do_cancel()
3222 static void do_cancel_effects(struct dlm_rsb *r, struct dlm_lkb *lkb, in do_cancel_effects() argument
3236 static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _request_lock() argument
3242 error = set_master(r, lkb); in _request_lock()
3252 error = send_request(r, lkb); in _request_lock()
3254 error = do_request(r, lkb); in _request_lock()
3257 do_request_effects(r, lkb, error); in _request_lock()
3265 static int _convert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _convert_lock() argument
3271 error = send_convert(r, lkb); in _convert_lock()
3273 error = do_convert(r, lkb); in _convert_lock()
3276 do_convert_effects(r, lkb, error); in _convert_lock()
3284 static int _unlock_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _unlock_lock() argument
3290 error = send_unlock(r, lkb); in _unlock_lock()
3292 error = do_unlock(r, lkb); in _unlock_lock()
3295 do_unlock_effects(r, lkb, error); in _unlock_lock()
3303 static int _cancel_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) in _cancel_lock() argument
3309 error = send_cancel(r, lkb); in _cancel_lock()
3311 error = do_cancel(r, lkb); in _cancel_lock()
3314 do_cancel_effects(r, lkb, error); in _cancel_lock()
3325 static int request_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in request_lock() argument
3332 error = validate_lock_args(ls, lkb, args); in request_lock()
3342 attach_lkb(r, lkb); in request_lock()
3343 lkb->lkb_lksb->sb_lkid = lkb->lkb_id; in request_lock()
3345 error = _request_lock(r, lkb); in request_lock()
3352 static int convert_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in convert_lock() argument
3358 r = lkb->lkb_resource; in convert_lock()
3363 error = validate_lock_args(ls, lkb, args); in convert_lock()
3367 error = _convert_lock(r, lkb); in convert_lock()
3374 static int unlock_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in unlock_lock() argument
3380 r = lkb->lkb_resource; in unlock_lock()
3385 error = validate_unlock_args(lkb, args); in unlock_lock()
3389 error = _unlock_lock(r, lkb); in unlock_lock()
3396 static int cancel_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, in cancel_lock() argument
3402 r = lkb->lkb_resource; in cancel_lock()
3407 error = validate_unlock_args(lkb, args); in cancel_lock()
3411 error = _cancel_lock(r, lkb); in cancel_lock()
3434 struct dlm_lkb *lkb; in dlm_lock() local
3445 error = find_lkb(ls, lksb->sb_lkid, &lkb); in dlm_lock()
3447 error = create_lkb(ls, &lkb); in dlm_lock()
3452 trace_dlm_lock_start(ls, lkb, name, namelen, mode, flags); in dlm_lock()
3465 error = convert_lock(ls, lkb, &args); in dlm_lock()
3467 error = request_lock(ls, lkb, name, namelen, &args); in dlm_lock()
3472 trace_dlm_lock_end(ls, lkb, name, namelen, mode, flags, error, true); in dlm_lock()
3475 __put_lkb(ls, lkb); in dlm_lock()
3491 struct dlm_lkb *lkb; in dlm_unlock() local
3501 error = find_lkb(ls, lkid, &lkb); in dlm_unlock()
3505 trace_dlm_unlock_start(ls, lkb, flags); in dlm_unlock()
3512 error = cancel_lock(ls, lkb, &args); in dlm_unlock()
3514 error = unlock_lock(ls, lkb, &args); in dlm_unlock()
3521 trace_dlm_unlock_end(ls, lkb, flags, error); in dlm_unlock()
3523 dlm_put_lkb(lkb); in dlm_unlock()
3584 static int create_message(struct dlm_rsb *r, struct dlm_lkb *lkb, in create_message() argument
3602 if (lkb && lkb->lkb_lvbptr) in create_message()
3620 static void send_args(struct dlm_rsb *r, struct dlm_lkb *lkb, in send_args() argument
3623 ms->m_nodeid = cpu_to_le32(lkb->lkb_nodeid); in send_args()
3624 ms->m_pid = cpu_to_le32(lkb->lkb_ownpid); in send_args()
3625 ms->m_lkid = cpu_to_le32(lkb->lkb_id); in send_args()
3626 ms->m_remid = cpu_to_le32(lkb->lkb_remid); in send_args()
3627 ms->m_exflags = cpu_to_le32(lkb->lkb_exflags); in send_args()
3628 ms->m_sbflags = cpu_to_le32(lkb->lkb_sbflags); in send_args()
3629 ms->m_flags = cpu_to_le32(lkb->lkb_flags); in send_args()
3630 ms->m_lvbseq = cpu_to_le32(lkb->lkb_lvbseq); in send_args()
3631 ms->m_status = cpu_to_le32(lkb->lkb_status); in send_args()
3632 ms->m_grmode = cpu_to_le32(lkb->lkb_grmode); in send_args()
3633 ms->m_rqmode = cpu_to_le32(lkb->lkb_rqmode); in send_args()
3639 if (lkb->lkb_bastfn) in send_args()
3641 if (lkb->lkb_astfn) in send_args()
3657 if (!lkb->lkb_lvbptr || !(lkb->lkb_exflags & DLM_LKF_VALBLK)) in send_args()
3659 memcpy(ms->m_extra, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); in send_args()
3664 static int send_common(struct dlm_rsb *r, struct dlm_lkb *lkb, int mstype) in send_common() argument
3672 error = add_to_waiters(lkb, mstype, to_nodeid); in send_common()
3676 error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); in send_common()
3680 send_args(r, lkb, ms); in send_common()
3688 remove_from_waiters(lkb, msg_reply_type(mstype)); in send_common()
3692 static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_request() argument
3694 return send_common(r, lkb, DLM_MSG_REQUEST); in send_request()
3697 static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_convert() argument
3701 error = send_common(r, lkb, DLM_MSG_CONVERT); in send_convert()
3704 if (!error && down_conversion(lkb)) { in send_convert()
3705 remove_from_waiters(lkb, DLM_MSG_CONVERT_REPLY); in send_convert()
3709 __receive_convert_reply(r, lkb, &r->res_ls->ls_stub_ms); in send_convert()
3719 static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_unlock() argument
3721 return send_common(r, lkb, DLM_MSG_UNLOCK); in send_unlock()
3724 static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_cancel() argument
3726 return send_common(r, lkb, DLM_MSG_CANCEL); in send_cancel()
3729 static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_grant() argument
3735 to_nodeid = lkb->lkb_nodeid; in send_grant()
3737 error = create_message(r, lkb, to_nodeid, DLM_MSG_GRANT, &ms, &mh); in send_grant()
3741 send_args(r, lkb, ms); in send_grant()
3750 static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode) in send_bast() argument
3756 to_nodeid = lkb->lkb_nodeid; in send_bast()
3762 send_args(r, lkb, ms); in send_bast()
3771 static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb) in send_lookup() argument
3779 error = add_to_waiters(lkb, DLM_MSG_LOOKUP, to_nodeid); in send_lookup()
3787 send_args(r, lkb, ms); in send_lookup()
3795 remove_from_waiters(lkb, DLM_MSG_LOOKUP_REPLY); in send_lookup()
3819 static int send_common_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, in send_common_reply() argument
3826 to_nodeid = lkb->lkb_nodeid; in send_common_reply()
3828 error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); in send_common_reply()
3832 send_args(r, lkb, ms); in send_common_reply()
3841 static int send_request_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_request_reply() argument
3843 return send_common_reply(r, lkb, DLM_MSG_REQUEST_REPLY, rv); in send_request_reply()
3846 static int send_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_convert_reply() argument
3848 return send_common_reply(r, lkb, DLM_MSG_CONVERT_REPLY, rv); in send_convert_reply()
3851 static int send_unlock_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_unlock_reply() argument
3853 return send_common_reply(r, lkb, DLM_MSG_UNLOCK_REPLY, rv); in send_unlock_reply()
3856 static int send_cancel_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) in send_cancel_reply() argument
3858 return send_common_reply(r, lkb, DLM_MSG_CANCEL_REPLY, rv); in send_cancel_reply()
3886 static void receive_flags(struct dlm_lkb *lkb, struct dlm_message *ms) in receive_flags() argument
3888 lkb->lkb_exflags = le32_to_cpu(ms->m_exflags); in receive_flags()
3889 lkb->lkb_sbflags = le32_to_cpu(ms->m_sbflags); in receive_flags()
3890 lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | in receive_flags()
3894 static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in receive_flags_reply() argument
3899 lkb->lkb_sbflags = le32_to_cpu(ms->m_sbflags); in receive_flags_reply()
3900 lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | in receive_flags_reply()
3910 static int receive_lvb(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_lvb() argument
3915 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_lvb()
3916 if (!lkb->lkb_lvbptr) in receive_lvb()
3917 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_lvb()
3918 if (!lkb->lkb_lvbptr) in receive_lvb()
3923 memcpy(lkb->lkb_lvbptr, ms->m_extra, len); in receive_lvb()
3938 static int receive_request_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_request_args() argument
3941 lkb->lkb_nodeid = le32_to_cpu(ms->m_header.h_nodeid); in receive_request_args()
3942 lkb->lkb_ownpid = le32_to_cpu(ms->m_pid); in receive_request_args()
3943 lkb->lkb_remid = le32_to_cpu(ms->m_lkid); in receive_request_args()
3944 lkb->lkb_grmode = DLM_LOCK_IV; in receive_request_args()
3945 lkb->lkb_rqmode = le32_to_cpu(ms->m_rqmode); in receive_request_args()
3947 lkb->lkb_bastfn = (ms->m_asts & cpu_to_le32(DLM_CB_BAST)) ? &fake_bastfn : NULL; in receive_request_args()
3948 lkb->lkb_astfn = (ms->m_asts & cpu_to_le32(DLM_CB_CAST)) ? &fake_astfn : NULL; in receive_request_args()
3950 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_request_args()
3952 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_request_args()
3953 if (!lkb->lkb_lvbptr) in receive_request_args()
3960 static int receive_convert_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_convert_args() argument
3963 if (lkb->lkb_status != DLM_LKSTS_GRANTED) in receive_convert_args()
3966 if (receive_lvb(ls, lkb, ms)) in receive_convert_args()
3969 lkb->lkb_rqmode = le32_to_cpu(ms->m_rqmode); in receive_convert_args()
3970 lkb->lkb_lvbseq = le32_to_cpu(ms->m_lvbseq); in receive_convert_args()
3975 static int receive_unlock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_unlock_args() argument
3978 if (receive_lvb(ls, lkb, ms)) in receive_unlock_args()
3988 struct dlm_lkb *lkb = &ls->ls_stub_lkb; in setup_stub_lkb() local
3989 lkb->lkb_nodeid = le32_to_cpu(ms->m_header.h_nodeid); in setup_stub_lkb()
3990 lkb->lkb_remid = le32_to_cpu(ms->m_lkid); in setup_stub_lkb()
3996 static int validate_message(struct dlm_lkb *lkb, struct dlm_message *ms) in validate_message() argument
4003 ~lkb->lkb_flags & DLM_IFL_USER) { in validate_message()
4004 log_error(lkb->lkb_resource->res_ls, in validate_message()
4014 if (!is_master_copy(lkb) || lkb->lkb_nodeid != from) in validate_message()
4023 if (!is_process_copy(lkb) || lkb->lkb_nodeid != from) in validate_message()
4028 if (!is_process_copy(lkb)) in validate_message()
4030 else if (lkb->lkb_nodeid != -1 && lkb->lkb_nodeid != from) in validate_message()
4040 log_error(lkb->lkb_resource->res_ls, in validate_message()
4042 le32_to_cpu(ms->m_type), from, lkb->lkb_id, in validate_message()
4043 lkb->lkb_remid, lkb->lkb_flags, lkb->lkb_nodeid); in validate_message()
4109 struct dlm_lkb *lkb; in receive_request() local
4116 error = create_lkb(ls, &lkb); in receive_request()
4120 receive_flags(lkb, ms); in receive_request()
4121 lkb->lkb_flags |= DLM_IFL_MSTCPY; in receive_request()
4122 error = receive_request_args(ls, lkb, ms); in receive_request()
4124 __put_lkb(ls, lkb); in receive_request()
4139 __put_lkb(ls, lkb); in receive_request()
4150 __put_lkb(ls, lkb); in receive_request()
4155 attach_lkb(r, lkb); in receive_request()
4156 error = do_request(r, lkb); in receive_request()
4157 send_request_reply(r, lkb, error); in receive_request()
4158 do_request_effects(r, lkb, error); in receive_request()
4166 dlm_put_lkb(lkb); in receive_request()
4202 struct dlm_lkb *lkb; in receive_convert() local
4206 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_convert()
4210 if (lkb->lkb_remid != le32_to_cpu(ms->m_lkid)) { in receive_convert()
4212 "remote %d %x", lkb->lkb_id, lkb->lkb_remid, in receive_convert()
4213 (unsigned long long)lkb->lkb_recover_seq, in receive_convert()
4217 dlm_put_lkb(lkb); in receive_convert()
4221 r = lkb->lkb_resource; in receive_convert()
4226 error = validate_message(lkb, ms); in receive_convert()
4230 receive_flags(lkb, ms); in receive_convert()
4232 error = receive_convert_args(ls, lkb, ms); in receive_convert()
4234 send_convert_reply(r, lkb, error); in receive_convert()
4238 reply = !down_conversion(lkb); in receive_convert()
4240 error = do_convert(r, lkb); in receive_convert()
4242 send_convert_reply(r, lkb, error); in receive_convert()
4243 do_convert_effects(r, lkb, error); in receive_convert()
4247 dlm_put_lkb(lkb); in receive_convert()
4258 struct dlm_lkb *lkb; in receive_unlock() local
4262 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_unlock()
4266 if (lkb->lkb_remid != le32_to_cpu(ms->m_lkid)) { in receive_unlock()
4268 lkb->lkb_id, lkb->lkb_remid, in receive_unlock()
4272 dlm_put_lkb(lkb); in receive_unlock()
4276 r = lkb->lkb_resource; in receive_unlock()
4281 error = validate_message(lkb, ms); in receive_unlock()
4285 receive_flags(lkb, ms); in receive_unlock()
4287 error = receive_unlock_args(ls, lkb, ms); in receive_unlock()
4289 send_unlock_reply(r, lkb, error); in receive_unlock()
4293 error = do_unlock(r, lkb); in receive_unlock()
4294 send_unlock_reply(r, lkb, error); in receive_unlock()
4295 do_unlock_effects(r, lkb, error); in receive_unlock()
4299 dlm_put_lkb(lkb); in receive_unlock()
4310 struct dlm_lkb *lkb; in receive_cancel() local
4314 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_cancel()
4318 receive_flags(lkb, ms); in receive_cancel()
4320 r = lkb->lkb_resource; in receive_cancel()
4325 error = validate_message(lkb, ms); in receive_cancel()
4329 error = do_cancel(r, lkb); in receive_cancel()
4330 send_cancel_reply(r, lkb, error); in receive_cancel()
4331 do_cancel_effects(r, lkb, error); in receive_cancel()
4335 dlm_put_lkb(lkb); in receive_cancel()
4346 struct dlm_lkb *lkb; in receive_grant() local
4350 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_grant()
4354 r = lkb->lkb_resource; in receive_grant()
4359 error = validate_message(lkb, ms); in receive_grant()
4363 receive_flags_reply(lkb, ms); in receive_grant()
4364 if (is_altmode(lkb)) in receive_grant()
4365 munge_altmode(lkb, ms); in receive_grant()
4366 grant_lock_pc(r, lkb, ms); in receive_grant()
4367 queue_cast(r, lkb, 0); in receive_grant()
4371 dlm_put_lkb(lkb); in receive_grant()
4377 struct dlm_lkb *lkb; in receive_bast() local
4381 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_bast()
4385 r = lkb->lkb_resource; in receive_bast()
4390 error = validate_message(lkb, ms); in receive_bast()
4394 queue_bast(r, lkb, le32_to_cpu(ms->m_bastmode)); in receive_bast()
4395 lkb->lkb_highbast = le32_to_cpu(ms->m_bastmode); in receive_bast()
4399 dlm_put_lkb(lkb); in receive_bast()
4518 struct dlm_lkb *lkb; in receive_request_reply() local
4523 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_request_reply()
4527 r = lkb->lkb_resource; in receive_request_reply()
4531 error = validate_message(lkb, ms); in receive_request_reply()
4535 mstype = lkb->lkb_wait_type; in receive_request_reply()
4536 error = remove_from_waiters(lkb, DLM_MSG_REQUEST_REPLY); in receive_request_reply()
4539 lkb->lkb_id, from_nodeid, le32_to_cpu(ms->m_lkid), in receive_request_reply()
4550 lkb->lkb_nodeid = from_nodeid; in receive_request_reply()
4559 queue_cast(r, lkb, -EAGAIN); in receive_request_reply()
4561 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_request_reply()
4567 receive_flags_reply(lkb, ms); in receive_request_reply()
4568 lkb->lkb_remid = le32_to_cpu(ms->m_lkid); in receive_request_reply()
4569 if (is_altmode(lkb)) in receive_request_reply()
4570 munge_altmode(lkb, ms); in receive_request_reply()
4572 add_lkb(r, lkb, DLM_LKSTS_WAITING); in receive_request_reply()
4573 add_timeout(lkb); in receive_request_reply()
4575 grant_lock_pc(r, lkb, ms); in receive_request_reply()
4576 queue_cast(r, lkb, 0); in receive_request_reply()
4585 "master %d dir %d first %x %s", lkb->lkb_id, in receive_request_reply()
4594 lkb->lkb_nodeid = -1; in receive_request_reply()
4597 if (is_overlap(lkb)) { in receive_request_reply()
4599 queue_cast_overlap(r, lkb); in receive_request_reply()
4601 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_request_reply()
4603 _request_lock(r, lkb); in receive_request_reply()
4612 lkb->lkb_id, result); in receive_request_reply()
4615 if (is_overlap_unlock(lkb) && (result == 0 || result == -EINPROGRESS)) { in receive_request_reply()
4617 lkb->lkb_id, result); in receive_request_reply()
4618 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
4619 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
4620 send_unlock(r, lkb); in receive_request_reply()
4621 } else if (is_overlap_cancel(lkb) && (result == -EINPROGRESS)) { in receive_request_reply()
4622 log_debug(ls, "receive_request_reply %x cancel", lkb->lkb_id); in receive_request_reply()
4623 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
4624 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
4625 send_cancel(r, lkb); in receive_request_reply()
4627 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in receive_request_reply()
4628 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in receive_request_reply()
4633 dlm_put_lkb(lkb); in receive_request_reply()
4637 static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, in __receive_convert_reply() argument
4644 queue_cast(r, lkb, -EAGAIN); in __receive_convert_reply()
4648 receive_flags_reply(lkb, ms); in __receive_convert_reply()
4649 revert_lock_pc(r, lkb); in __receive_convert_reply()
4650 queue_cast(r, lkb, -EDEADLK); in __receive_convert_reply()
4655 receive_flags_reply(lkb, ms); in __receive_convert_reply()
4656 if (is_demoted(lkb)) in __receive_convert_reply()
4657 munge_demoted(lkb); in __receive_convert_reply()
4658 del_lkb(r, lkb); in __receive_convert_reply()
4659 add_lkb(r, lkb, DLM_LKSTS_CONVERT); in __receive_convert_reply()
4660 add_timeout(lkb); in __receive_convert_reply()
4665 receive_flags_reply(lkb, ms); in __receive_convert_reply()
4666 if (is_demoted(lkb)) in __receive_convert_reply()
4667 munge_demoted(lkb); in __receive_convert_reply()
4668 grant_lock_pc(r, lkb, ms); in __receive_convert_reply()
4669 queue_cast(r, lkb, 0); in __receive_convert_reply()
4674 lkb->lkb_id, le32_to_cpu(ms->m_header.h_nodeid), in __receive_convert_reply()
4678 dlm_print_lkb(lkb); in __receive_convert_reply()
4682 static void _receive_convert_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_convert_reply() argument
4684 struct dlm_rsb *r = lkb->lkb_resource; in _receive_convert_reply()
4690 error = validate_message(lkb, ms); in _receive_convert_reply()
4695 error = remove_from_waiters_ms(lkb, ms); in _receive_convert_reply()
4699 __receive_convert_reply(r, lkb, ms); in _receive_convert_reply()
4707 struct dlm_lkb *lkb; in receive_convert_reply() local
4710 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_convert_reply()
4714 _receive_convert_reply(lkb, ms); in receive_convert_reply()
4715 dlm_put_lkb(lkb); in receive_convert_reply()
4719 static void _receive_unlock_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_unlock_reply() argument
4721 struct dlm_rsb *r = lkb->lkb_resource; in _receive_unlock_reply()
4727 error = validate_message(lkb, ms); in _receive_unlock_reply()
4732 error = remove_from_waiters_ms(lkb, ms); in _receive_unlock_reply()
4740 receive_flags_reply(lkb, ms); in _receive_unlock_reply()
4741 remove_lock_pc(r, lkb); in _receive_unlock_reply()
4742 queue_cast(r, lkb, -DLM_EUNLOCK); in _receive_unlock_reply()
4748 lkb->lkb_id, from_dlm_errno(le32_to_cpu(ms->m_result))); in _receive_unlock_reply()
4757 struct dlm_lkb *lkb; in receive_unlock_reply() local
4760 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_unlock_reply()
4764 _receive_unlock_reply(lkb, ms); in receive_unlock_reply()
4765 dlm_put_lkb(lkb); in receive_unlock_reply()
4769 static void _receive_cancel_reply(struct dlm_lkb *lkb, struct dlm_message *ms) in _receive_cancel_reply() argument
4771 struct dlm_rsb *r = lkb->lkb_resource; in _receive_cancel_reply()
4777 error = validate_message(lkb, ms); in _receive_cancel_reply()
4782 error = remove_from_waiters_ms(lkb, ms); in _receive_cancel_reply()
4790 receive_flags_reply(lkb, ms); in _receive_cancel_reply()
4791 revert_lock_pc(r, lkb); in _receive_cancel_reply()
4792 queue_cast(r, lkb, -DLM_ECANCEL); in _receive_cancel_reply()
4798 lkb->lkb_id, in _receive_cancel_reply()
4808 struct dlm_lkb *lkb; in receive_cancel_reply() local
4811 error = find_lkb(ls, le32_to_cpu(ms->m_remid), &lkb); in receive_cancel_reply()
4815 _receive_cancel_reply(lkb, ms); in receive_cancel_reply()
4816 dlm_put_lkb(lkb); in receive_cancel_reply()
4822 struct dlm_lkb *lkb; in receive_lookup_reply() local
4827 error = find_lkb(ls, le32_to_cpu(ms->m_lkid), &lkb); in receive_lookup_reply()
4837 r = lkb->lkb_resource; in receive_lookup_reply()
4841 error = remove_from_waiters(lkb, DLM_MSG_LOOKUP_REPLY); in receive_lookup_reply()
4857 lkb->lkb_id, le32_to_cpu(ms->m_header.h_nodeid), in receive_lookup_reply()
4870 lkb->lkb_id, le32_to_cpu(ms->m_header.h_nodeid)); in receive_lookup_reply()
4873 lkb->lkb_nodeid = -1; in receive_lookup_reply()
4880 if (is_overlap(lkb)) { in receive_lookup_reply()
4882 lkb->lkb_id, lkb->lkb_flags); in receive_lookup_reply()
4883 queue_cast_overlap(r, lkb); in receive_lookup_reply()
4884 unhold_lkb(lkb); /* undoes create_lkb() */ in receive_lookup_reply()
4888 _request_lock(r, lkb); in receive_lookup_reply()
4896 dlm_put_lkb(lkb); in receive_lookup_reply()
5124 static void recover_convert_waiter(struct dlm_ls *ls, struct dlm_lkb *lkb, in recover_convert_waiter() argument
5127 if (middle_conversion(lkb)) { in recover_convert_waiter()
5128 hold_lkb(lkb); in recover_convert_waiter()
5133 ms_stub->m_header.h_nodeid = cpu_to_le32(lkb->lkb_nodeid); in recover_convert_waiter()
5134 _receive_convert_reply(lkb, ms_stub); in recover_convert_waiter()
5137 lkb->lkb_grmode = DLM_LOCK_IV; in recover_convert_waiter()
5138 rsb_set_flag(lkb->lkb_resource, RSB_RECOVER_CONVERT); in recover_convert_waiter()
5139 unhold_lkb(lkb); in recover_convert_waiter()
5141 } else if (lkb->lkb_rqmode >= lkb->lkb_grmode) { in recover_convert_waiter()
5142 lkb->lkb_flags |= DLM_IFL_RESEND; in recover_convert_waiter()
5152 static int waiter_needs_recovery(struct dlm_ls *ls, struct dlm_lkb *lkb, in waiter_needs_recovery() argument
5158 if (dlm_is_removed(ls, lkb->lkb_wait_nodeid)) in waiter_needs_recovery()
5172 struct dlm_lkb *lkb, *safe; in dlm_recover_waiters_pre() local
5183 list_for_each_entry_safe(lkb, safe, &ls->ls_waiters, lkb_wait_reply) { in dlm_recover_waiters_pre()
5185 dir_nodeid = dlm_dir_nodeid(lkb->lkb_resource); in dlm_recover_waiters_pre()
5190 if (lkb->lkb_wait_type != DLM_MSG_UNLOCK) { in dlm_recover_waiters_pre()
5193 lkb->lkb_id, in dlm_recover_waiters_pre()
5194 lkb->lkb_remid, in dlm_recover_waiters_pre()
5195 lkb->lkb_wait_type, in dlm_recover_waiters_pre()
5196 lkb->lkb_resource->res_nodeid, in dlm_recover_waiters_pre()
5197 lkb->lkb_nodeid, in dlm_recover_waiters_pre()
5198 lkb->lkb_wait_nodeid, in dlm_recover_waiters_pre()
5205 if (lkb->lkb_wait_type == DLM_MSG_LOOKUP) { in dlm_recover_waiters_pre()
5206 lkb->lkb_flags |= DLM_IFL_RESEND; in dlm_recover_waiters_pre()
5210 if (!waiter_needs_recovery(ls, lkb, dir_nodeid)) in dlm_recover_waiters_pre()
5213 wait_type = lkb->lkb_wait_type; in dlm_recover_waiters_pre()
5223 if (is_overlap_cancel(lkb)) { in dlm_recover_waiters_pre()
5225 if (lkb->lkb_grmode == DLM_LOCK_IV) in dlm_recover_waiters_pre()
5228 if (is_overlap_unlock(lkb)) { in dlm_recover_waiters_pre()
5230 if (lkb->lkb_grmode == DLM_LOCK_IV) in dlm_recover_waiters_pre()
5235 lkb->lkb_id, lkb->lkb_flags, wait_type, in dlm_recover_waiters_pre()
5242 lkb->lkb_flags |= DLM_IFL_RESEND; in dlm_recover_waiters_pre()
5246 recover_convert_waiter(ls, lkb, ms_stub); in dlm_recover_waiters_pre()
5250 hold_lkb(lkb); in dlm_recover_waiters_pre()
5255 ms_stub->m_header.h_nodeid = cpu_to_le32(lkb->lkb_nodeid); in dlm_recover_waiters_pre()
5256 _receive_unlock_reply(lkb, ms_stub); in dlm_recover_waiters_pre()
5257 dlm_put_lkb(lkb); in dlm_recover_waiters_pre()
5261 hold_lkb(lkb); in dlm_recover_waiters_pre()
5266 ms_stub->m_header.h_nodeid = cpu_to_le32(lkb->lkb_nodeid); in dlm_recover_waiters_pre()
5267 _receive_cancel_reply(lkb, ms_stub); in dlm_recover_waiters_pre()
5268 dlm_put_lkb(lkb); in dlm_recover_waiters_pre()
5273 lkb->lkb_wait_type, wait_type); in dlm_recover_waiters_pre()
5283 struct dlm_lkb *lkb = NULL, *iter; in find_resend_waiter() local
5289 lkb = iter; in find_resend_waiter()
5295 return lkb; in find_resend_waiter()
5316 struct dlm_lkb *lkb; in dlm_recover_waiters_post() local
5327 lkb = find_resend_waiter(ls); in dlm_recover_waiters_post()
5328 if (!lkb) in dlm_recover_waiters_post()
5331 r = lkb->lkb_resource; in dlm_recover_waiters_post()
5335 mstype = lkb->lkb_wait_type; in dlm_recover_waiters_post()
5336 oc = is_overlap_cancel(lkb); in dlm_recover_waiters_post()
5337 ou = is_overlap_unlock(lkb); in dlm_recover_waiters_post()
5342 "overlap %d %d", lkb->lkb_id, lkb->lkb_remid, mstype, in dlm_recover_waiters_post()
5343 r->res_nodeid, lkb->lkb_nodeid, lkb->lkb_wait_nodeid, in dlm_recover_waiters_post()
5350 lkb->lkb_flags &= ~DLM_IFL_RESEND; in dlm_recover_waiters_post()
5351 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; in dlm_recover_waiters_post()
5352 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; in dlm_recover_waiters_post()
5353 lkb->lkb_wait_type = 0; in dlm_recover_waiters_post()
5357 while (lkb->lkb_wait_count) { in dlm_recover_waiters_post()
5358 lkb->lkb_wait_count--; in dlm_recover_waiters_post()
5359 unhold_lkb(lkb); in dlm_recover_waiters_post()
5362 list_del_init(&lkb->lkb_wait_reply); in dlm_recover_waiters_post()
5370 queue_cast(r, lkb, ou ? -DLM_EUNLOCK : in dlm_recover_waiters_post()
5372 unhold_lkb(lkb); /* undoes create_lkb() */ in dlm_recover_waiters_post()
5376 queue_cast(r, lkb, -DLM_ECANCEL); in dlm_recover_waiters_post()
5378 lkb->lkb_exflags |= DLM_LKF_FORCEUNLOCK; in dlm_recover_waiters_post()
5379 _unlock_lock(r, lkb); in dlm_recover_waiters_post()
5389 _request_lock(r, lkb); in dlm_recover_waiters_post()
5394 _convert_lock(r, lkb); in dlm_recover_waiters_post()
5404 lkb->lkb_id, mstype, r->res_nodeid, in dlm_recover_waiters_post()
5409 dlm_put_lkb(lkb); in dlm_recover_waiters_post()
5418 struct dlm_lkb *lkb, *safe; in purge_mstcpy_list() local
5420 list_for_each_entry_safe(lkb, safe, list, lkb_statequeue) { in purge_mstcpy_list()
5421 if (!is_master_copy(lkb)) in purge_mstcpy_list()
5427 if (lkb->lkb_recover_seq == ls->ls_recover_seq) in purge_mstcpy_list()
5430 del_lkb(r, lkb); in purge_mstcpy_list()
5433 if (!dlm_put_lkb(lkb)) in purge_mstcpy_list()
5451 struct dlm_lkb *lkb, *safe; in purge_dead_list() local
5453 list_for_each_entry_safe(lkb, safe, list, lkb_statequeue) { in purge_dead_list()
5454 if (!is_master_copy(lkb)) in purge_dead_list()
5457 if ((lkb->lkb_nodeid == nodeid_gone) || in purge_dead_list()
5458 dlm_is_removed(ls, lkb->lkb_nodeid)) { in purge_dead_list()
5462 if ((lkb->lkb_exflags & DLM_LKF_VALBLK) && in purge_dead_list()
5463 (lkb->lkb_grmode >= DLM_LOCK_PW)) { in purge_dead_list()
5467 del_lkb(r, lkb); in purge_dead_list()
5470 if (!dlm_put_lkb(lkb)) in purge_dead_list()
5601 struct dlm_lkb *lkb; in search_remid_list() local
5603 list_for_each_entry(lkb, head, lkb_statequeue) { in search_remid_list()
5604 if (lkb->lkb_nodeid == nodeid && lkb->lkb_remid == remid) in search_remid_list()
5605 return lkb; in search_remid_list()
5613 struct dlm_lkb *lkb; in search_remid() local
5615 lkb = search_remid_list(&r->res_grantqueue, nodeid, remid); in search_remid()
5616 if (lkb) in search_remid()
5617 return lkb; in search_remid()
5618 lkb = search_remid_list(&r->res_convertqueue, nodeid, remid); in search_remid()
5619 if (lkb) in search_remid()
5620 return lkb; in search_remid()
5621 lkb = search_remid_list(&r->res_waitqueue, nodeid, remid); in search_remid()
5622 if (lkb) in search_remid()
5623 return lkb; in search_remid()
5628 static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, in receive_rcom_lock_args() argument
5633 lkb->lkb_nodeid = le32_to_cpu(rc->rc_header.h_nodeid); in receive_rcom_lock_args()
5634 lkb->lkb_ownpid = le32_to_cpu(rl->rl_ownpid); in receive_rcom_lock_args()
5635 lkb->lkb_remid = le32_to_cpu(rl->rl_lkid); in receive_rcom_lock_args()
5636 lkb->lkb_exflags = le32_to_cpu(rl->rl_exflags); in receive_rcom_lock_args()
5637 lkb->lkb_flags = le32_to_cpu(rl->rl_flags) & 0x0000FFFF; in receive_rcom_lock_args()
5638 lkb->lkb_flags |= DLM_IFL_MSTCPY; in receive_rcom_lock_args()
5639 lkb->lkb_lvbseq = le32_to_cpu(rl->rl_lvbseq); in receive_rcom_lock_args()
5640 lkb->lkb_rqmode = rl->rl_rqmode; in receive_rcom_lock_args()
5641 lkb->lkb_grmode = rl->rl_grmode; in receive_rcom_lock_args()
5644 lkb->lkb_bastfn = (rl->rl_asts & DLM_CB_BAST) ? &fake_bastfn : NULL; in receive_rcom_lock_args()
5645 lkb->lkb_astfn = (rl->rl_asts & DLM_CB_CAST) ? &fake_astfn : NULL; in receive_rcom_lock_args()
5647 if (lkb->lkb_exflags & DLM_LKF_VALBLK) { in receive_rcom_lock_args()
5652 lkb->lkb_lvbptr = dlm_allocate_lvb(ls); in receive_rcom_lock_args()
5653 if (!lkb->lkb_lvbptr) in receive_rcom_lock_args()
5655 memcpy(lkb->lkb_lvbptr, rl->rl_lvb, lvblen); in receive_rcom_lock_args()
5663 middle_conversion(lkb)) { in receive_rcom_lock_args()
5665 lkb->lkb_grmode = DLM_LOCK_IV; in receive_rcom_lock_args()
5683 struct dlm_lkb *lkb; in dlm_recover_master_copy() local
5717 lkb = search_remid(r, from_nodeid, remid); in dlm_recover_master_copy()
5718 if (lkb) { in dlm_recover_master_copy()
5723 error = create_lkb(ls, &lkb); in dlm_recover_master_copy()
5727 error = receive_rcom_lock_args(ls, lkb, r, rc); in dlm_recover_master_copy()
5729 __put_lkb(ls, lkb); in dlm_recover_master_copy()
5733 attach_lkb(r, lkb); in dlm_recover_master_copy()
5734 add_lkb(r, lkb, rl->rl_status); in dlm_recover_master_copy()
5743 rl->rl_remid = cpu_to_le32(lkb->lkb_id); in dlm_recover_master_copy()
5745 lkb->lkb_recover_seq = ls->ls_recover_seq; in dlm_recover_master_copy()
5763 struct dlm_lkb *lkb; in dlm_recover_process_copy() local
5771 error = find_lkb(ls, lkid, &lkb); in dlm_recover_process_copy()
5779 r = lkb->lkb_resource; in dlm_recover_process_copy()
5783 if (!is_process_copy(lkb)) { in dlm_recover_process_copy()
5790 dlm_put_lkb(lkb); in dlm_recover_process_copy()
5804 dlm_send_rcom_lock(r, lkb); in dlm_recover_process_copy()
5808 lkb->lkb_remid = remid; in dlm_recover_process_copy()
5822 dlm_put_lkb(lkb); in dlm_recover_process_copy()
5836 struct dlm_lkb *lkb; in dlm_user_request() local
5843 error = create_lkb(ls, &lkb); in dlm_user_request()
5849 trace_dlm_lock_start(ls, lkb, name, namelen, mode, flags); in dlm_user_request()
5876 lkb->lkb_flags |= DLM_IFL_USER; in dlm_user_request()
5877 error = request_lock(ls, lkb, name, namelen, &args); in dlm_user_request()
5894 hold_lkb(lkb); in dlm_user_request()
5895 list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks); in dlm_user_request()
5899 trace_dlm_lock_end(ls, lkb, name, namelen, mode, flags, error, false); in dlm_user_request()
5901 __put_lkb(ls, lkb); in dlm_user_request()
5916 struct dlm_lkb *lkb; in dlm_user_convert() local
5923 error = find_lkb(ls, lkid, &lkb); in dlm_user_convert()
5927 trace_dlm_lock_start(ls, lkb, NULL, 0, mode, flags); in dlm_user_convert()
5932 ua = lkb->lkb_ua; in dlm_user_convert()
5961 error = convert_lock(ls, lkb, &args); in dlm_user_convert()
5966 trace_dlm_lock_end(ls, lkb, NULL, 0, mode, flags, error, false); in dlm_user_convert()
5967 dlm_put_lkb(lkb); in dlm_user_convert()
5984 struct dlm_lkb *lkb = NULL, *iter; in dlm_user_adopt_orphan() local
6000 lkb = iter; in dlm_user_adopt_orphan()
6008 if (!lkb && found_other_mode) { in dlm_user_adopt_orphan()
6013 if (!lkb) { in dlm_user_adopt_orphan()
6018 lkb->lkb_exflags = flags; in dlm_user_adopt_orphan()
6019 lkb->lkb_ownpid = (int) current->pid; in dlm_user_adopt_orphan()
6021 ua = lkb->lkb_ua; in dlm_user_adopt_orphan()
6038 list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks); in dlm_user_adopt_orphan()
6048 struct dlm_lkb *lkb; in dlm_user_unlock() local
6055 error = find_lkb(ls, lkid, &lkb); in dlm_user_unlock()
6059 trace_dlm_unlock_start(ls, lkb, flags); in dlm_user_unlock()
6061 ua = lkb->lkb_ua; in dlm_user_unlock()
6073 error = unlock_lock(ls, lkb, &args); in dlm_user_unlock()
6085 if (!list_empty(&lkb->lkb_ownqueue)) in dlm_user_unlock()
6086 list_move(&lkb->lkb_ownqueue, &ua->proc->unlocking); in dlm_user_unlock()
6089 trace_dlm_unlock_end(ls, lkb, flags, error); in dlm_user_unlock()
6090 dlm_put_lkb(lkb); in dlm_user_unlock()
6100 struct dlm_lkb *lkb; in dlm_user_cancel() local
6107 error = find_lkb(ls, lkid, &lkb); in dlm_user_cancel()
6111 trace_dlm_unlock_start(ls, lkb, flags); in dlm_user_cancel()
6113 ua = lkb->lkb_ua; in dlm_user_cancel()
6122 error = cancel_lock(ls, lkb, &args); in dlm_user_cancel()
6130 trace_dlm_unlock_end(ls, lkb, flags, error); in dlm_user_cancel()
6131 dlm_put_lkb(lkb); in dlm_user_cancel()
6140 struct dlm_lkb *lkb; in dlm_user_deadlock() local
6148 error = find_lkb(ls, lkid, &lkb); in dlm_user_deadlock()
6152 trace_dlm_unlock_start(ls, lkb, flags); in dlm_user_deadlock()
6154 ua = lkb->lkb_ua; in dlm_user_deadlock()
6162 r = lkb->lkb_resource; in dlm_user_deadlock()
6166 error = validate_unlock_args(lkb, &args); in dlm_user_deadlock()
6169 lkb->lkb_flags |= DLM_IFL_DEADLOCK_CANCEL; in dlm_user_deadlock()
6171 error = _cancel_lock(r, lkb); in dlm_user_deadlock()
6182 trace_dlm_unlock_end(ls, lkb, flags, error); in dlm_user_deadlock()
6183 dlm_put_lkb(lkb); in dlm_user_deadlock()
6192 static int orphan_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) in orphan_proc_lock() argument
6197 hold_lkb(lkb); /* reference for the ls_orphans list */ in orphan_proc_lock()
6199 list_add_tail(&lkb->lkb_ownqueue, &ls->ls_orphans); in orphan_proc_lock()
6202 set_unlock_args(0, lkb->lkb_ua, &args); in orphan_proc_lock()
6204 error = cancel_lock(ls, lkb, &args); in orphan_proc_lock()
6215 static int unlock_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) in unlock_proc_lock() argument
6221 lkb->lkb_ua, &args); in unlock_proc_lock()
6223 error = unlock_lock(ls, lkb, &args); in unlock_proc_lock()
6236 struct dlm_lkb *lkb = NULL; in del_proc_lock() local
6242 lkb = list_entry(proc->locks.next, struct dlm_lkb, lkb_ownqueue); in del_proc_lock()
6243 list_del_init(&lkb->lkb_ownqueue); in del_proc_lock()
6245 if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) in del_proc_lock()
6246 lkb->lkb_flags |= DLM_IFL_ORPHAN; in del_proc_lock()
6248 lkb->lkb_flags |= DLM_IFL_DEAD; in del_proc_lock()
6251 return lkb; in del_proc_lock()
6266 struct dlm_lkb *lkb, *safe; in dlm_clear_proc_locks() local
6271 lkb = del_proc_lock(ls, proc); in dlm_clear_proc_locks()
6272 if (!lkb) in dlm_clear_proc_locks()
6274 del_timeout(lkb); in dlm_clear_proc_locks()
6275 if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) in dlm_clear_proc_locks()
6276 orphan_proc_lock(ls, lkb); in dlm_clear_proc_locks()
6278 unlock_proc_lock(ls, lkb); in dlm_clear_proc_locks()
6284 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
6290 list_for_each_entry_safe(lkb, safe, &proc->unlocking, lkb_ownqueue) { in dlm_clear_proc_locks()
6291 list_del_init(&lkb->lkb_ownqueue); in dlm_clear_proc_locks()
6292 lkb->lkb_flags |= DLM_IFL_DEAD; in dlm_clear_proc_locks()
6293 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
6296 list_for_each_entry_safe(lkb, safe, &proc->asts, lkb_cb_list) { in dlm_clear_proc_locks()
6297 memset(&lkb->lkb_callbacks, 0, in dlm_clear_proc_locks()
6299 list_del_init(&lkb->lkb_cb_list); in dlm_clear_proc_locks()
6300 dlm_put_lkb(lkb); in dlm_clear_proc_locks()
6309 struct dlm_lkb *lkb, *safe; in purge_proc_locks() local
6312 lkb = NULL; in purge_proc_locks()
6315 lkb = list_entry(proc->locks.next, struct dlm_lkb, in purge_proc_locks()
6317 list_del_init(&lkb->lkb_ownqueue); in purge_proc_locks()
6321 if (!lkb) in purge_proc_locks()
6324 lkb->lkb_flags |= DLM_IFL_DEAD; in purge_proc_locks()
6325 unlock_proc_lock(ls, lkb); in purge_proc_locks()
6326 dlm_put_lkb(lkb); /* ref from proc->locks list */ in purge_proc_locks()
6330 list_for_each_entry_safe(lkb, safe, &proc->unlocking, lkb_ownqueue) { in purge_proc_locks()
6331 list_del_init(&lkb->lkb_ownqueue); in purge_proc_locks()
6332 lkb->lkb_flags |= DLM_IFL_DEAD; in purge_proc_locks()
6333 dlm_put_lkb(lkb); in purge_proc_locks()
6338 list_for_each_entry_safe(lkb, safe, &proc->asts, lkb_cb_list) { in purge_proc_locks()
6339 memset(&lkb->lkb_callbacks, 0, in purge_proc_locks()
6341 list_del_init(&lkb->lkb_cb_list); in purge_proc_locks()
6342 dlm_put_lkb(lkb); in purge_proc_locks()
6351 struct dlm_lkb *lkb, *safe; in do_purge() local
6354 list_for_each_entry_safe(lkb, safe, &ls->ls_orphans, lkb_ownqueue) { in do_purge()
6355 if (pid && lkb->lkb_ownpid != pid) in do_purge()
6357 unlock_proc_lock(ls, lkb); in do_purge()
6358 list_del_init(&lkb->lkb_ownqueue); in do_purge()
6359 dlm_put_lkb(lkb); in do_purge()
6403 struct dlm_lkb *lkb; in dlm_debug_add_lkb() local
6415 error = _create_lkb(ls, &lkb, lkb_id, lkb_id + 1); in dlm_debug_add_lkb()
6421 lkb->lkb_flags = lkb_flags; in dlm_debug_add_lkb()
6422 lkb->lkb_nodeid = lkb_nodeid; in dlm_debug_add_lkb()
6423 lkb->lkb_lksb = lksb; in dlm_debug_add_lkb()
6426 lkb->lkb_astparam = (void *)0xDEADBEEF; in dlm_debug_add_lkb()
6431 __put_lkb(ls, lkb); in dlm_debug_add_lkb()
6436 attach_lkb(r, lkb); in dlm_debug_add_lkb()
6437 add_lkb(r, lkb, lkb_status); in dlm_debug_add_lkb()
6447 struct dlm_lkb *lkb; in dlm_debug_add_lkb_to_waiters() local
6450 error = find_lkb(ls, lkb_id, &lkb); in dlm_debug_add_lkb_to_waiters()
6454 error = add_to_waiters(lkb, mstype, to_nodeid); in dlm_debug_add_lkb_to_waiters()
6455 dlm_put_lkb(lkb); in dlm_debug_add_lkb_to_waiters()