diff mbox series

ocfs2: fix unbalanced locking

Message ID 20200724124443.GA28164@duo.ucw.cz (mailing list archive)
State New, archived
Headers show
Series ocfs2: fix unbalanced locking | expand

Commit Message

Pavel Machek July 24, 2020, 12:44 p.m. UTC
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.

Signed-off-by: Pavel Machek (CIP) <pavel@denx.de>

Comments

Joseph Qi July 27, 2020, 7:15 a.m. UTC | #1
On 2020/7/24 20:44, Pavel Machek wrote:
> 
> 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.
> 
> Signed-off-by: Pavel Machek (CIP) <pavel@denx.de>

Looks good.

Fixes: 4cd9973f9ff6 ("ocfs2: avoid inode removal while nfsd is accessing it")
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> 
> diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
> index 751bc4dc7466..8e3a369086db 100644
> --- a/fs/ocfs2/dlmglue.c
> +++ b/fs/ocfs2/dlmglue.c
> @@ -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;
>  }
>  
>
diff mbox series

Patch

diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
index 751bc4dc7466..8e3a369086db 100644
--- a/fs/ocfs2/dlmglue.c
+++ b/fs/ocfs2/dlmglue.c
@@ -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;
 }