forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/fs/dlm/lock.c
....@@ -1,11 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /******************************************************************************
23 *******************************************************************************
34 **
45 ** Copyright (C) 2005-2010 Red Hat, Inc. All rights reserved.
56 **
6
-** This copyrighted material is made available to anyone wishing to use,
7
-** modify, copy, or redistribute it subject to the terms and conditions
8
-** of the GNU General Public License v.2.
97 **
108 *******************************************************************************
119 ******************************************************************************/
....@@ -1553,6 +1551,7 @@
15531551 lkb->lkb_wait_type = 0;
15541552 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL;
15551553 lkb->lkb_wait_count--;
1554
+ unhold_lkb(lkb);
15561555 goto out_del;
15571556 }
15581557
....@@ -1579,6 +1578,7 @@
15791578 log_error(ls, "remwait error %x reply %d wait_type %d overlap",
15801579 lkb->lkb_id, mstype, lkb->lkb_wait_type);
15811580 lkb->lkb_wait_count--;
1581
+ unhold_lkb(lkb);
15821582 lkb->lkb_wait_type = 0;
15831583 }
15841584
....@@ -2888,17 +2888,9 @@
28882888 static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
28892889 struct dlm_args *args)
28902890 {
2891
- int rv = -EINVAL;
2891
+ int rv = -EBUSY;
28922892
28932893 if (args->flags & DLM_LKF_CONVERT) {
2894
- if (lkb->lkb_flags & DLM_IFL_MSTCPY)
2895
- goto out;
2896
-
2897
- if (args->flags & DLM_LKF_QUECVT &&
2898
- !__quecvt_compat_matrix[lkb->lkb_grmode+1][args->mode+1])
2899
- goto out;
2900
-
2901
- rv = -EBUSY;
29022894 if (lkb->lkb_status != DLM_LKSTS_GRANTED)
29032895 goto out;
29042896
....@@ -2906,6 +2898,14 @@
29062898 goto out;
29072899
29082900 if (is_overlap(lkb))
2901
+ goto out;
2902
+
2903
+ rv = -EINVAL;
2904
+ if (lkb->lkb_flags & DLM_IFL_MSTCPY)
2905
+ goto out;
2906
+
2907
+ if (args->flags & DLM_LKF_QUECVT &&
2908
+ !__quecvt_compat_matrix[lkb->lkb_grmode+1][args->mode+1])
29092909 goto out;
29102910 }
29112911
....@@ -4067,13 +4067,14 @@
40674067 rv = _create_message(ls, sizeof(struct dlm_message) + len,
40684068 dir_nodeid, DLM_MSG_REMOVE, &ms, &mh);
40694069 if (rv)
4070
- return;
4070
+ goto out;
40714071
40724072 memcpy(ms->m_extra, name, len);
40734073 ms->m_hash = hash;
40744074
40754075 send_message(mh, ms);
40764076
4077
+out:
40774078 spin_lock(&ls->ls_remove_spin);
40784079 ls->ls_remove_len = 0;
40794080 memset(ls->ls_remove_name, 0, DLM_RESNAME_MAXLEN);
....@@ -5314,11 +5315,16 @@
53145315 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK;
53155316 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL;
53165317 lkb->lkb_wait_type = 0;
5317
- lkb->lkb_wait_count = 0;
5318
+ /* drop all wait_count references we still
5319
+ * hold a reference for this iteration.
5320
+ */
5321
+ while (lkb->lkb_wait_count) {
5322
+ lkb->lkb_wait_count--;
5323
+ unhold_lkb(lkb);
5324
+ }
53185325 mutex_lock(&ls->ls_waiters_mutex);
53195326 list_del_init(&lkb->lkb_wait_reply);
53205327 mutex_unlock(&ls->ls_waiters_mutex);
5321
- unhold_lkb(lkb); /* for waiters list */
53225328
53235329 if (oc || ou) {
53245330 /* do an unlock or cancel instead of resending */
....@@ -5828,7 +5834,7 @@
58285834 break;
58295835 case -EAGAIN:
58305836 error = 0;
5831
- /* fall through */
5837
+ fallthrough;
58325838 default:
58335839 __put_lkb(ls, lkb);
58345840 goto out;