ocfs2-devel.oss.oracle.com archive mirror
 help / color / mirror / Atom feed
* [Ocfs2-devel] [PATCH] ocfs2/dlm: fix a dead lock
@ 2010-07-16 15:13 Wengang Wang
  2010-07-20  2:31 ` Wengang Wang
  2010-08-07 18:39 ` Joel Becker
  0 siblings, 2 replies; 4+ messages in thread
From: Wengang Wang @ 2010-07-16 15:13 UTC (permalink / raw)
  To: ocfs2-devel

When we have to take both dlm->master_lock and lockres->spinlock,
take them in order

lockres->spinlock and then dlm->master_lock.

The patch fixes a violation of the rule.
We can simply move taking dlm->master_lock to where we have dropped res->spinlock
since when we access res->state and free mle memory we don't need master_lock's
protection.

Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com>
---
 fs/ocfs2/dlm/dlmmaster.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
index 94b97fc..6d098b8 100644
--- a/fs/ocfs2/dlm/dlmmaster.c
+++ b/fs/ocfs2/dlm/dlmmaster.c
@@ -3050,8 +3050,6 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
 	/* check for pre-existing lock */
 	spin_lock(&dlm->spinlock);
 	res = __dlm_lookup_lockres(dlm, name, namelen, hash);
-	spin_lock(&dlm->master_lock);
-
 	if (res) {
 		spin_lock(&res->spinlock);
 		if (res->state & DLM_LOCK_RES_RECOVERING) {
@@ -3069,14 +3067,15 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
 		spin_unlock(&res->spinlock);
 	}
 
+	spin_lock(&dlm->master_lock);
 	/* ignore status.  only nonzero status would BUG. */
 	ret = dlm_add_migration_mle(dlm, res, mle, &oldmle,
 				    name, namelen,
 				    migrate->new_master,
 				    migrate->master);
 
-unlock:
 	spin_unlock(&dlm->master_lock);
+unlock:
 	spin_unlock(&dlm->spinlock);
 
 	if (oldmle) {
-- 
1.6.6.1

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

* [Ocfs2-devel] [PATCH] ocfs2/dlm: fix a dead lock
  2010-07-16 15:13 [Ocfs2-devel] [PATCH] ocfs2/dlm: fix a dead lock Wengang Wang
@ 2010-07-20  2:31 ` Wengang Wang
  2010-07-20 22:59   ` Sunil Mushran
  2010-08-07 18:39 ` Joel Becker
  1 sibling, 1 reply; 4+ messages in thread
From: Wengang Wang @ 2010-07-20  2:31 UTC (permalink / raw)
  To: ocfs2-devel

Just a reminder.

wengang.
On 10-07-16 23:13, Wengang Wang wrote:
> When we have to take both dlm->master_lock and lockres->spinlock,
> take them in order
> 
> lockres->spinlock and then dlm->master_lock.
> 
> The patch fixes a violation of the rule.
> We can simply move taking dlm->master_lock to where we have dropped res->spinlock
> since when we access res->state and free mle memory we don't need master_lock's
> protection.
> 
> Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com>
> ---
>  fs/ocfs2/dlm/dlmmaster.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
> index 94b97fc..6d098b8 100644
> --- a/fs/ocfs2/dlm/dlmmaster.c
> +++ b/fs/ocfs2/dlm/dlmmaster.c
> @@ -3050,8 +3050,6 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
>  	/* check for pre-existing lock */
>  	spin_lock(&dlm->spinlock);
>  	res = __dlm_lookup_lockres(dlm, name, namelen, hash);
> -	spin_lock(&dlm->master_lock);
> -
>  	if (res) {
>  		spin_lock(&res->spinlock);
>  		if (res->state & DLM_LOCK_RES_RECOVERING) {
> @@ -3069,14 +3067,15 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
>  		spin_unlock(&res->spinlock);
>  	}
>  
> +	spin_lock(&dlm->master_lock);
>  	/* ignore status.  only nonzero status would BUG. */
>  	ret = dlm_add_migration_mle(dlm, res, mle, &oldmle,
>  				    name, namelen,
>  				    migrate->new_master,
>  				    migrate->master);
>  
> -unlock:
>  	spin_unlock(&dlm->master_lock);
> +unlock:
>  	spin_unlock(&dlm->spinlock);
>  
>  	if (oldmle) {
> -- 
> 1.6.6.1
> 
> 
> _______________________________________________
> Ocfs2-devel mailing list
> Ocfs2-devel at oss.oracle.com
> http://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* [Ocfs2-devel] [PATCH] ocfs2/dlm: fix a dead lock
  2010-07-20  2:31 ` Wengang Wang
@ 2010-07-20 22:59   ` Sunil Mushran
  0 siblings, 0 replies; 4+ messages in thread
From: Sunil Mushran @ 2010-07-20 22:59 UTC (permalink / raw)
  To: ocfs2-devel

Acked-by: Sunil Mushran <sunil.mushran@oracle.com>

On 07/19/2010 07:31 PM, Wengang Wang wrote:
> Just a reminder.
>
> wengang.
> On 10-07-16 23:13, Wengang Wang wrote:
>    
>> When we have to take both dlm->master_lock and lockres->spinlock,
>> take them in order
>>
>> lockres->spinlock and then dlm->master_lock.
>>
>> The patch fixes a violation of the rule.
>> We can simply move taking dlm->master_lock to where we have dropped res->spinlock
>> since when we access res->state and free mle memory we don't need master_lock's
>> protection.
>>
>> Signed-off-by: Wengang Wang<wen.gang.wang@oracle.com>
>> ---
>>   fs/ocfs2/dlm/dlmmaster.c |    5 ++---
>>   1 files changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
>> index 94b97fc..6d098b8 100644
>> --- a/fs/ocfs2/dlm/dlmmaster.c
>> +++ b/fs/ocfs2/dlm/dlmmaster.c
>> @@ -3050,8 +3050,6 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
>>   	/* check for pre-existing lock */
>>   	spin_lock(&dlm->spinlock);
>>   	res = __dlm_lookup_lockres(dlm, name, namelen, hash);
>> -	spin_lock(&dlm->master_lock);
>> -
>>   	if (res) {
>>   		spin_lock(&res->spinlock);
>>   		if (res->state&  DLM_LOCK_RES_RECOVERING) {
>> @@ -3069,14 +3067,15 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
>>   		spin_unlock(&res->spinlock);
>>   	}
>>
>> +	spin_lock(&dlm->master_lock);
>>   	/* ignore status.  only nonzero status would BUG. */
>>   	ret = dlm_add_migration_mle(dlm, res, mle,&oldmle,
>>   				    name, namelen,
>>   				    migrate->new_master,
>>   				    migrate->master);
>>
>> -unlock:
>>   	spin_unlock(&dlm->master_lock);
>> +unlock:
>>   	spin_unlock(&dlm->spinlock);
>>
>>   	if (oldmle) {
>> -- 
>> 1.6.6.1
>>
>>
>> _______________________________________________
>> Ocfs2-devel mailing list
>> Ocfs2-devel at oss.oracle.com
>> http://oss.oracle.com/mailman/listinfo/ocfs2-devel
>>      
> _______________________________________________
> Ocfs2-devel mailing list
> Ocfs2-devel at oss.oracle.com
> http://oss.oracle.com/mailman/listinfo/ocfs2-devel
>    

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

* [Ocfs2-devel] [PATCH] ocfs2/dlm: fix a dead lock
  2010-07-16 15:13 [Ocfs2-devel] [PATCH] ocfs2/dlm: fix a dead lock Wengang Wang
  2010-07-20  2:31 ` Wengang Wang
@ 2010-08-07 18:39 ` Joel Becker
  1 sibling, 0 replies; 4+ messages in thread
From: Joel Becker @ 2010-08-07 18:39 UTC (permalink / raw)
  To: ocfs2-devel

On Fri, Jul 16, 2010 at 11:13:33PM +0800, Wengang Wang wrote:
> When we have to take both dlm->master_lock and lockres->spinlock,
> take them in order
> 
> lockres->spinlock and then dlm->master_lock.
> 
> The patch fixes a violation of the rule.
> We can simply move taking dlm->master_lock to where we have dropped res->spinlock
> since when we access res->state and free mle memory we don't need master_lock's
> protection.
> 
> Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com>

This patch is now in the fixes branch of ocfs2.git.

Joel
-- 

"Three o'clock is always too late or too early for anything you
 want to do."
        - Jean-Paul Sartre

Joel Becker
Consulting Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127

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

end of thread, other threads:[~2010-08-07 18:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-16 15:13 [Ocfs2-devel] [PATCH] ocfs2/dlm: fix a dead lock Wengang Wang
2010-07-20  2:31 ` Wengang Wang
2010-07-20 22:59   ` Sunil Mushran
2010-08-07 18:39 ` Joel Becker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).