hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/fs/ocfs2/dlmfs/userdlm.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- mode: c; c-basic-offset: 8; -*-
23 * vim: noexpandtab sw=8 ts=8 sts=0:
34 *
....@@ -10,21 +11,6 @@
1011 * functions.
1112 *
1213 * Copyright (C) 2003, 2004 Oracle. All rights reserved.
13
- *
14
- * This program is free software; you can redistribute it and/or
15
- * modify it under the terms of the GNU General Public
16
- * License as published by the Free Software Foundation; either
17
- * version 2 of the License, or (at your option) any later version.
18
- *
19
- * This program is distributed in the hope that it will be useful,
20
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
- * General Public License for more details.
23
- *
24
- * You should have received a copy of the GNU General Public
25
- * License along with this program; if not, write to the
26
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27
- * Boston, MA 021110-1307, USA.
2814 */
2915
3016 #include <linux/signal.h>
....@@ -35,12 +21,12 @@
3521 #include <linux/types.h>
3622 #include <linux/crc32.h>
3723
38
-#include "ocfs2_lockingver.h"
39
-#include "stackglue.h"
24
+#include "../ocfs2_lockingver.h"
25
+#include "../stackglue.h"
4026 #include "userdlm.h"
4127
4228 #define MLOG_MASK_PREFIX ML_DLMFS
43
-#include "cluster/masklog.h"
29
+#include "../cluster/masklog.h"
4430
4531
4632 static inline struct user_lock_res *user_lksb_to_lock_res(struct ocfs2_dlm_lksb *lksb)
....@@ -449,6 +435,11 @@
449435 }
450436
451437 spin_lock(&lockres->l_lock);
438
+ if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) {
439
+ spin_unlock(&lockres->l_lock);
440
+ status = -EAGAIN;
441
+ goto bail;
442
+ }
452443
453444 /* We only compare against the currently granted level
454445 * here. If the lock is blocked waiting on a downconvert,
....@@ -561,24 +552,20 @@
561552 spin_unlock(&lockres->l_lock);
562553 }
563554
564
-ssize_t user_dlm_read_lvb(struct inode *inode,
565
- char *val,
566
- unsigned int len)
555
+bool user_dlm_read_lvb(struct inode *inode, char *val)
567556 {
568557 struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres;
569558 char *lvb;
570
- ssize_t ret = len;
571
-
572
- BUG_ON(len > DLM_LVB_LEN);
559
+ bool ret = true;
573560
574561 spin_lock(&lockres->l_lock);
575562
576563 BUG_ON(lockres->l_level < DLM_LOCK_PR);
577564 if (ocfs2_dlm_lvb_valid(&lockres->l_lksb)) {
578565 lvb = ocfs2_dlm_lvb(&lockres->l_lksb);
579
- memcpy(val, lvb, len);
566
+ memcpy(val, lvb, DLM_LVB_LEN);
580567 } else
581
- ret = 0;
568
+ ret = false;
582569
583570 spin_unlock(&lockres->l_lock);
584571 return ret;
....@@ -615,7 +602,7 @@
615602 spin_lock(&lockres->l_lock);
616603 if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) {
617604 spin_unlock(&lockres->l_lock);
618
- return 0;
605
+ goto bail;
619606 }
620607
621608 lockres->l_flags |= USER_LOCK_IN_TEARDOWN;
....@@ -629,12 +616,17 @@
629616 }
630617
631618 if (lockres->l_ro_holders || lockres->l_ex_holders) {
619
+ lockres->l_flags &= ~USER_LOCK_IN_TEARDOWN;
632620 spin_unlock(&lockres->l_lock);
633621 goto bail;
634622 }
635623
636624 status = 0;
637625 if (!(lockres->l_flags & USER_LOCK_ATTACHED)) {
626
+ /*
627
+ * lock is never requested, leave USER_LOCK_IN_TEARDOWN set
628
+ * to avoid new lock request coming in.
629
+ */
638630 spin_unlock(&lockres->l_lock);
639631 goto bail;
640632 }
....@@ -645,6 +637,10 @@
645637
646638 status = ocfs2_dlm_unlock(conn, &lockres->l_lksb, DLM_LKF_VALBLK);
647639 if (status) {
640
+ spin_lock(&lockres->l_lock);
641
+ lockres->l_flags &= ~USER_LOCK_IN_TEARDOWN;
642
+ lockres->l_flags &= ~USER_LOCK_BUSY;
643
+ spin_unlock(&lockres->l_lock);
648644 user_log_dlm_error("ocfs2_dlm_unlock", status, lockres);
649645 goto bail;
650646 }