Skip to contentSkip to conversation

ocfs2: fix unbalanced locking

PATCH Applied Pavel Machek 2 participants 2 messages Jul 24, 2020 – Jul 27, 2020 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: fix unbalanced locking

Based on what fails, function can return with nfs_sync_rwlock either locked or unlocked. That can not be right.

Always return with lock unlocked on error.

fs/ocfs2/dlmglue.c +7 -1
index 751bc4dc7466..8e3a369086db 100644
@@ -2871,9 +2871,15 @@ int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex)
 
 	status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE : LKM_PRMODE,
 				    0, 0);
-	if (status < 0)
+	if (status < 0) {
 		mlog(ML_ERROR, "lock on nfs sync lock failed %d\n", status);
 
+		if (ex)
+			up_write(&osb->nfs_sync_rwlock);
+		else
+			up_read(&osb->nfs_sync_rwlock);
+	}
+
 	return status;
 }
 
Signature · 9 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://oss.oracle.com/pipermail/ocfs2-devel/attachments/20200724/907bc246/attachment.bin 
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Pavel Machek

Based on what fails, function can return with nfs_sync_rwlock either locked or unlocked. That can not be right.

Always return with lock unlocked on error.

Looks good.

Fixes 4cd9973f9ff6 ("ocfs2: avoid inode removal while nfsd is accessing it")
Quoted 23 lines
fs/ocfs2/dlmglue.c +7 -1
index 751bc4dc7466..8e3a369086db 100644
@@ -2871,9 +2871,15 @@ int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex)
 
 	status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE : LKM_PRMODE,
 				    0, 0);
-	if (status < 0)
+	if (status < 0) {
 		mlog(ML_ERROR, "lock on nfs sync lock failed %d\n", status);
 
+		if (ex)
+			up_write(&osb->nfs_sync_rwlock);
+		else
+			up_read(&osb->nfs_sync_rwlock);
+	}
+
 	return status;
 }