All of lore.kernel.org
 help / color / mirror / Atom feed
* [Ocfs2-devel] [PATCH v2 RESEND] ocfs2: fix double unlock in case retry after free truncate log
@ 2016-09-14  9:32 Joseph Qi
  2016-09-18  5:28 ` Eric Ren
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Qi @ 2016-09-14  9:32 UTC (permalink / raw)
  To: ocfs2-devel

If ocfs2_reserve_cluster_bitmap_bits fails with ENOSPC, it will try to
free truncate log and then retry. Since ocfs2_try_to_free_truncate_log
will lock/unlock global bitmap inode, we have to unlock it before
calling this function. But when retry reserve and it fails with no
global bitmap inode lock taken, it will unlock again in error handling
branch and BUG.
This issue also exists if no need retry and then ocfs2_inode_lock fails.
So fix it.

Changes since v1:
Use ret instead of status to avoid return value overwritten issue.

Fixes: 2070ad1aebff ("ocfs2: retry on ENOSPC if sufficient space in
truncate log"
Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
Signed-off-by: Jiufei Xue <xuejiufei@huawei.com>
---
 fs/ocfs2/suballoc.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index ea47120..6ad3533 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -1199,14 +1199,24 @@ retry:
 			inode_unlock((*ac)->ac_inode);

 			ret = ocfs2_try_to_free_truncate_log(osb, bits_wanted);
-			if (ret == 1)
+			if (ret == 1) {
+				iput((*ac)->ac_inode);
+				(*ac)->ac_inode = NULL;
 				goto retry;
+			}

 			if (ret < 0)
 				mlog_errno(ret);

 			inode_lock((*ac)->ac_inode);
-			ocfs2_inode_lock((*ac)->ac_inode, NULL, 1);
+			ret = ocfs2_inode_lock((*ac)->ac_inode, NULL, 1);
+			if (ret < 0) {
+				mlog_errno(ret);
+				inode_unlock((*ac)->ac_inode);
+				iput((*ac)->ac_inode);
+				(*ac)->ac_inode = NULL;
+				goto bail;
+			}
 		}
 		if (status < 0) {
 			if (status != -ENOSPC)
-- 
1.8.4.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Ocfs2-devel] [PATCH v2 RESEND] ocfs2: fix double unlock in case retry after free truncate log
  2016-09-14  9:32 [Ocfs2-devel] [PATCH v2 RESEND] ocfs2: fix double unlock in case retry after free truncate log Joseph Qi
@ 2016-09-18  5:28 ` Eric Ren
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Ren @ 2016-09-18  5:28 UTC (permalink / raw)
  To: ocfs2-devel

Hi,

On 09/14/2016 05:32 PM, Joseph Qi wrote:
> If ocfs2_reserve_cluster_bitmap_bits fails with ENOSPC, it will try to
> free truncate log and then retry. Since ocfs2_try_to_free_truncate_log
> will lock/unlock global bitmap inode, we have to unlock it before
> calling this function. But when retry reserve and it fails with no
> global bitmap inode lock taken, it will unlock again in error handling
> branch and BUG.
> This issue also exists if no need retry and then ocfs2_inode_lock fails.
> So fix it.
>
> Changes since v1:
> Use ret instead of status to avoid return value overwritten issue.
>
> Fixes: 2070ad1aebff ("ocfs2: retry on ENOSPC if sufficient space in
> truncate log"
> Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
> Signed-off-by: Jiufei Xue <xuejiufei@huawei.com>
LGTM
Reviewed-by: Eric Ren <zren@suse.com>
> ---
>   fs/ocfs2/suballoc.c | 14 ++++++++++++--
>   1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
> index ea47120..6ad3533 100644
> --- a/fs/ocfs2/suballoc.c
> +++ b/fs/ocfs2/suballoc.c
> @@ -1199,14 +1199,24 @@ retry:
>   			inode_unlock((*ac)->ac_inode);
>
>   			ret = ocfs2_try_to_free_truncate_log(osb, bits_wanted);
> -			if (ret == 1)
> +			if (ret == 1) {
> +				iput((*ac)->ac_inode);
> +				(*ac)->ac_inode = NULL;
>   				goto retry;
> +			}
>
>   			if (ret < 0)
>   				mlog_errno(ret);
>
>   			inode_lock((*ac)->ac_inode);
> -			ocfs2_inode_lock((*ac)->ac_inode, NULL, 1);
> +			ret = ocfs2_inode_lock((*ac)->ac_inode, NULL, 1);
> +			if (ret < 0) {
> +				mlog_errno(ret);
> +				inode_unlock((*ac)->ac_inode);
> +				iput((*ac)->ac_inode);
> +				(*ac)->ac_inode = NULL;
> +				goto bail;
> +			}
>   		}
>   		if (status < 0) {
>   			if (status != -ENOSPC)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-18  5:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14  9:32 [Ocfs2-devel] [PATCH v2 RESEND] ocfs2: fix double unlock in case retry after free truncate log Joseph Qi
2016-09-18  5:28 ` Eric Ren

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.