Skip to contentSkip to conversation

ocfs2/dlm: fix a dead lock

PATCH New Wengang Wang 3 participants 4 messages Jul 16, 2010 – Aug 7, 2010 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2/dlm: fix a dead lock

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.

---
 fs/ocfs2/dlm/dlmmaster.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
fs/ocfs2/dlm/dlmmaster.c +2 -3
index 94b97fc..6d098b8 100644
@@ -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) {
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 1/1 ocfs2/dlm: fix a dead lock

Just a reminder.

wengang.

Quoted 53 lines · Wengang Wang

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.

---
 fs/ocfs2/dlm/dlmmaster.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
fs/ocfs2/dlm/dlmmaster.c +2 -3
index 94b97fc..6d098b8 100644
@@ -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) {
Signature · 7 lines
1.6.6.1


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
http://oss.oracle.com/mailman/listinfo/ocfs2-devel
#2 lore raw

PATCH 1/1 ocfs2/dlm: fix a dead lock

Quoted 64 lines · Wengang Wang

Just a reminder.

wengang.

Quoted 54 lines · Wengang Wang

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.

---
  fs/ocfs2/dlm/dlmmaster.c |    5 ++---
  1 files changed, 2 insertions(+), 3 deletions(-)
fs/ocfs2/dlm/dlmmaster.c +2 -3
index 94b97fc..6d098b8 100644
@@ -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) {
Signature · 7 lines
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

#3 lore raw

PATCH 1/1 ocfs2/dlm: fix a dead lock

In reply to Wengang Wang
Quoted 11 lines · Wengang Wang

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.

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

Joel

Signature · 9 lines
"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