lock.c (70cf2fecf87354be09c0ab4c233fccea36256d3c) | lock.c (75a7d60134ce84209f2c61ec4619ee543aa8f466) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/****************************************************************************** 3******************************************************************************* 4** 5** Copyright (C) 2005-2010 Red Hat, Inc. All rights reserved. 6** 7** 8******************************************************************************* --- 1393 unchanged lines hidden (view full) --- 1402 1403/* add/remove lkb from global waiters list of lkb's waiting for 1404 a reply from a remote node */ 1405 1406static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid) 1407{ 1408 struct dlm_ls *ls = lkb->lkb_resource->res_ls; 1409 int error = 0; | 1// SPDX-License-Identifier: GPL-2.0-only 2/****************************************************************************** 3******************************************************************************* 4** 5** Copyright (C) 2005-2010 Red Hat, Inc. All rights reserved. 6** 7** 8******************************************************************************* --- 1393 unchanged lines hidden (view full) --- 1402 1403/* add/remove lkb from global waiters list of lkb's waiting for 1404 a reply from a remote node */ 1405 1406static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid) 1407{ 1408 struct dlm_ls *ls = lkb->lkb_resource->res_ls; 1409 int error = 0; |
1410 int wc; |
|
1410 1411 mutex_lock(&ls->ls_waiters_mutex); 1412 1413 if (is_overlap_unlock(lkb) || 1414 (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL))) { 1415 error = -EINVAL; 1416 goto out; 1417 } --- 5 unchanged lines hidden (view full) --- 1423 break; 1424 case DLM_MSG_CANCEL: 1425 set_bit(DLM_IFL_OVERLAP_CANCEL_BIT, &lkb->lkb_iflags); 1426 break; 1427 default: 1428 error = -EBUSY; 1429 goto out; 1430 } | 1411 1412 mutex_lock(&ls->ls_waiters_mutex); 1413 1414 if (is_overlap_unlock(lkb) || 1415 (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL))) { 1416 error = -EINVAL; 1417 goto out; 1418 } --- 5 unchanged lines hidden (view full) --- 1424 break; 1425 case DLM_MSG_CANCEL: 1426 set_bit(DLM_IFL_OVERLAP_CANCEL_BIT, &lkb->lkb_iflags); 1427 break; 1428 default: 1429 error = -EBUSY; 1430 goto out; 1431 } |
1431 lkb->lkb_wait_count++; | 1432 wc = atomic_inc_return(&lkb->lkb_wait_count); |
1432 hold_lkb(lkb); 1433 1434 log_debug(ls, "addwait %x cur %d overlap %d count %d f %x", | 1433 hold_lkb(lkb); 1434 1435 log_debug(ls, "addwait %x cur %d overlap %d count %d f %x", |
1435 lkb->lkb_id, lkb->lkb_wait_type, mstype, 1436 lkb->lkb_wait_count, dlm_iflags_val(lkb)); | 1436 lkb->lkb_id, lkb->lkb_wait_type, mstype, wc, 1437 dlm_iflags_val(lkb)); |
1437 goto out; 1438 } 1439 | 1438 goto out; 1439 } 1440 |
1440 DLM_ASSERT(!lkb->lkb_wait_count, 1441 dlm_print_lkb(lkb); 1442 printk("wait_count %d\n", lkb->lkb_wait_count);); 1443 1444 lkb->lkb_wait_count++; | 1441 wc = atomic_fetch_inc(&lkb->lkb_wait_count); 1442 DLM_ASSERT(!wc, dlm_print_lkb(lkb); printk("wait_count %d\n", wc);); |
1445 lkb->lkb_wait_type = mstype; 1446 lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */ 1447 hold_lkb(lkb); 1448 list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); 1449 out: 1450 if (error) 1451 log_error(ls, "addwait error %x %d flags %x %d %d %s", 1452 lkb->lkb_id, error, dlm_iflags_val(lkb), mstype, --- 46 unchanged lines hidden (view full) --- 1499 lingering state of the cancel and fail with -EBUSY. */ 1500 1501 if ((mstype == DLM_MSG_CONVERT_REPLY) && 1502 (lkb->lkb_wait_type == DLM_MSG_CONVERT) && ms && !ms->m_result && 1503 test_and_clear_bit(DLM_IFL_OVERLAP_CANCEL_BIT, &lkb->lkb_iflags)) { 1504 log_debug(ls, "remwait %x convert_reply zap overlap_cancel", 1505 lkb->lkb_id); 1506 lkb->lkb_wait_type = 0; | 1443 lkb->lkb_wait_type = mstype; 1444 lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */ 1445 hold_lkb(lkb); 1446 list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); 1447 out: 1448 if (error) 1449 log_error(ls, "addwait error %x %d flags %x %d %d %s", 1450 lkb->lkb_id, error, dlm_iflags_val(lkb), mstype, --- 46 unchanged lines hidden (view full) --- 1497 lingering state of the cancel and fail with -EBUSY. */ 1498 1499 if ((mstype == DLM_MSG_CONVERT_REPLY) && 1500 (lkb->lkb_wait_type == DLM_MSG_CONVERT) && ms && !ms->m_result && 1501 test_and_clear_bit(DLM_IFL_OVERLAP_CANCEL_BIT, &lkb->lkb_iflags)) { 1502 log_debug(ls, "remwait %x convert_reply zap overlap_cancel", 1503 lkb->lkb_id); 1504 lkb->lkb_wait_type = 0; |
1507 lkb->lkb_wait_count--; | 1505 atomic_dec(&lkb->lkb_wait_count); |
1508 unhold_lkb(lkb); 1509 goto out_del; 1510 } 1511 1512 /* N.B. type of reply may not always correspond to type of original 1513 msg due to lookup->request optimization, verify others? */ 1514 1515 if (lkb->lkb_wait_type) { --- 10 unchanged lines hidden (view full) --- 1526 /* the force-unlock/cancel has completed and we haven't recvd a reply 1527 to the op that was in progress prior to the unlock/cancel; we 1528 give up on any reply to the earlier op. FIXME: not sure when/how 1529 this would happen */ 1530 1531 if (overlap_done && lkb->lkb_wait_type) { 1532 log_error(ls, "remwait error %x reply %d wait_type %d overlap", 1533 lkb->lkb_id, mstype, lkb->lkb_wait_type); | 1506 unhold_lkb(lkb); 1507 goto out_del; 1508 } 1509 1510 /* N.B. type of reply may not always correspond to type of original 1511 msg due to lookup->request optimization, verify others? */ 1512 1513 if (lkb->lkb_wait_type) { --- 10 unchanged lines hidden (view full) --- 1524 /* the force-unlock/cancel has completed and we haven't recvd a reply 1525 to the op that was in progress prior to the unlock/cancel; we 1526 give up on any reply to the earlier op. FIXME: not sure when/how 1527 this would happen */ 1528 1529 if (overlap_done && lkb->lkb_wait_type) { 1530 log_error(ls, "remwait error %x reply %d wait_type %d overlap", 1531 lkb->lkb_id, mstype, lkb->lkb_wait_type); |
1534 lkb->lkb_wait_count--; | 1532 atomic_dec(&lkb->lkb_wait_count); |
1535 unhold_lkb(lkb); 1536 lkb->lkb_wait_type = 0; 1537 } 1538 | 1533 unhold_lkb(lkb); 1534 lkb->lkb_wait_type = 0; 1535 } 1536 |
1539 DLM_ASSERT(lkb->lkb_wait_count, dlm_print_lkb(lkb);); | 1537 DLM_ASSERT(atomic_read(&lkb->lkb_wait_count), dlm_print_lkb(lkb);); |
1540 1541 clear_bit(DLM_IFL_RESEND_BIT, &lkb->lkb_iflags); | 1538 1539 clear_bit(DLM_IFL_RESEND_BIT, &lkb->lkb_iflags); |
1542 lkb->lkb_wait_count--; 1543 if (!lkb->lkb_wait_count) | 1540 if (atomic_dec_and_test(&lkb->lkb_wait_count)) |
1544 list_del_init(&lkb->lkb_wait_reply); 1545 unhold_lkb(lkb); 1546 return 0; 1547} 1548 1549static int remove_from_waiters(struct dlm_lkb *lkb, int mstype) 1550{ 1551 struct dlm_ls *ls = lkb->lkb_resource->res_ls; --- 1112 unchanged lines hidden (view full) --- 2664{ 2665 int rv = -EBUSY; 2666 2667 if (args->flags & DLM_LKF_CONVERT) { 2668 if (lkb->lkb_status != DLM_LKSTS_GRANTED) 2669 goto out; 2670 2671 /* lock not allowed if there's any op in progress */ | 1541 list_del_init(&lkb->lkb_wait_reply); 1542 unhold_lkb(lkb); 1543 return 0; 1544} 1545 1546static int remove_from_waiters(struct dlm_lkb *lkb, int mstype) 1547{ 1548 struct dlm_ls *ls = lkb->lkb_resource->res_ls; --- 1112 unchanged lines hidden (view full) --- 2661{ 2662 int rv = -EBUSY; 2663 2664 if (args->flags & DLM_LKF_CONVERT) { 2665 if (lkb->lkb_status != DLM_LKSTS_GRANTED) 2666 goto out; 2667 2668 /* lock not allowed if there's any op in progress */ |
2672 if (lkb->lkb_wait_type || lkb->lkb_wait_count) | 2669 if (lkb->lkb_wait_type || atomic_read(&lkb->lkb_wait_count)) |
2673 goto out; 2674 2675 if (is_overlap(lkb)) 2676 goto out; 2677 2678 rv = -EINVAL; 2679 if (test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags)) 2680 goto out; --- 45 unchanged lines hidden (view full) --- 2726 2727static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) 2728{ 2729 struct dlm_ls *ls = lkb->lkb_resource->res_ls; 2730 int rv = -EBUSY; 2731 2732 /* normal unlock not allowed if there's any op in progress */ 2733 if (!(args->flags & (DLM_LKF_CANCEL | DLM_LKF_FORCEUNLOCK)) && | 2670 goto out; 2671 2672 if (is_overlap(lkb)) 2673 goto out; 2674 2675 rv = -EINVAL; 2676 if (test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags)) 2677 goto out; --- 45 unchanged lines hidden (view full) --- 2723 2724static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) 2725{ 2726 struct dlm_ls *ls = lkb->lkb_resource->res_ls; 2727 int rv = -EBUSY; 2728 2729 /* normal unlock not allowed if there's any op in progress */ 2730 if (!(args->flags & (DLM_LKF_CANCEL | DLM_LKF_FORCEUNLOCK)) && |
2734 (lkb->lkb_wait_type || lkb->lkb_wait_count)) | 2731 (lkb->lkb_wait_type || atomic_read(&lkb->lkb_wait_count))) |
2735 goto out; 2736 2737 /* an lkb may be waiting for an rsb lookup to complete where the 2738 lookup was initiated by another lock */ 2739 2740 if (!list_empty(&lkb->lkb_rsb_lookup)) { 2741 if (args->flags & (DLM_LKF_CANCEL | DLM_LKF_FORCEUNLOCK)) { 2742 log_debug(ls, "unlock on rsb_lookup %x", lkb->lkb_id); --- 2318 unchanged lines hidden (view full) --- 5061 previous op or overlap op on this lock. First, do a big 5062 remove_from_waiters() for all previous ops. */ 5063 5064 clear_bit(DLM_IFL_RESEND_BIT, &lkb->lkb_iflags); 5065 lkb->lkb_wait_type = 0; 5066 /* drop all wait_count references we still 5067 * hold a reference for this iteration. 5068 */ | 2732 goto out; 2733 2734 /* an lkb may be waiting for an rsb lookup to complete where the 2735 lookup was initiated by another lock */ 2736 2737 if (!list_empty(&lkb->lkb_rsb_lookup)) { 2738 if (args->flags & (DLM_LKF_CANCEL | DLM_LKF_FORCEUNLOCK)) { 2739 log_debug(ls, "unlock on rsb_lookup %x", lkb->lkb_id); --- 2318 unchanged lines hidden (view full) --- 5058 previous op or overlap op on this lock. First, do a big 5059 remove_from_waiters() for all previous ops. */ 5060 5061 clear_bit(DLM_IFL_RESEND_BIT, &lkb->lkb_iflags); 5062 lkb->lkb_wait_type = 0; 5063 /* drop all wait_count references we still 5064 * hold a reference for this iteration. 5065 */ |
5069 while (lkb->lkb_wait_count) { 5070 lkb->lkb_wait_count--; | 5066 while (!atomic_dec_and_test(&lkb->lkb_wait_count)) |
5071 unhold_lkb(lkb); | 5067 unhold_lkb(lkb); |
5072 } | 5068 |
5073 mutex_lock(&ls->ls_waiters_mutex); 5074 list_del_init(&lkb->lkb_wait_reply); 5075 mutex_unlock(&ls->ls_waiters_mutex); 5076 5077 if (oc || ou) { 5078 /* do an unlock or cancel instead of resending */ 5079 switch (mstype) { 5080 case DLM_MSG_LOOKUP: --- 1065 unchanged lines hidden --- | 5069 mutex_lock(&ls->ls_waiters_mutex); 5070 list_del_init(&lkb->lkb_wait_reply); 5071 mutex_unlock(&ls->ls_waiters_mutex); 5072 5073 if (oc || ou) { 5074 /* do an unlock or cancel instead of resending */ 5075 switch (mstype) { 5076 case DLM_MSG_LOOKUP: --- 1065 unchanged lines hidden --- |