ocfs2: fix a deadlock when commit trans
RFC v2 1/1 ocfs2: fix a deadlock when commit trans
commit 6f1b228529ae49b0f85ab89bcdb6c365df401558 caused a deadlock which was uncovered by our internal tests. The deadlock is as foollows:
Task 1:
A1) jbd2_journal_commit_transaction()
A2) spin_lock(&jh->b_state_lock);
A3) __jbd2_journal_remove_checkpoint()
A4) jbd2_journal_put_journal_head()
A5) jbd_lock_bh_journal_head()
Task 2:
B1) ocfs2_test_bg_bit_allocatable()
B2) jbd_lock_bh_journal_head()
B3) spin_lock(&jh->b_state_lock);
A1->A2->A3->A4->B1->B2->B3(blocked)->A5(blocked)
Now cause process 2 has the jbd lock, it doesn’t let process 1 to continue after A5. Process 2 now is waiting for b_state_lock to be released by process 1.
This patch resolves the deadlock.
--- fs/ocfs2/suballoc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ocfs2/suballoc.c +3 -4
@@ -1259,9 +1259,8 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,if (!buffer_jbd (bg_bh))return 1 ; -jbd_lock_bh_journal_head (bg_bh); -if (buffer_jbd (bg_bh)) { - jh =bh2jh (bg_bh); + jh =jbd2_journal_grab_journal_head (bg_bh); +if (jh) {spin_lock (&jh->b_state_lock); bg = (struct ocfs2_group_desc *) jh->b_committed_data;if (bg)
@@ -1269,8 +1268,8 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,else ret =1 ;spin_unlock (&jh->b_state_lock); +jbd2_journal_put_journal_head (bg_bh); } -jbd_unlock_bh_journal_head (bg_bh);return ret; }
Signature · 7 lines
1.8.3.1 _______________________________________________ Ocfs2-devel mailing list [email protected] https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Seems you still sent a patch that couldn't build.
Have you checked my previous comments and tried my suggested way?
Thanks,
Joseph
Quoted 44 lines · Gautham Ananthakrishna
commit
6f1b228529ae49b0f85ab89bcdb6c365df401558caused a deadlock which was uncovered by our internal tests. The deadlock is as foollows:Task 1:
A1)jbd2_journal_commit_transaction()
A2)spin_lock(&jh->b_state_lock);
A3)__jbd2_journal_remove_checkpoint()
A4)jbd2_journal_put_journal_head()
A5)jbd_lock_bh_journal_head()Task 2:
B1)ocfs2_test_bg_bit_allocatable()
B2)jbd_lock_bh_journal_head()
B3)spin_lock(&jh->b_state_lock);A1->A2->A3->A4->B1->B2->B3(blocked)->A5(blocked)
Now cause process 2 has the jbd lock, it doesn’t let process 1 to continue after A5. Process 2 now is waiting for
b_state_lockto be released by process 1.This patch resolves the deadlock.
Signed-off-by Gautham Ananthakrishna <[email protected]>--- fs/ocfs2/suballoc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/ocfs2/suballoc.c +2
-3@@ -1259,9 +1259,8 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,if (!buffer_jbd (bg_bh))return 1 ; -jbd_lock_bh_journal_head (bg_bh); -if (buffer_jbd (bg_bh)) { - jh =bh2jh (bg_bh); + jh =jbd2_journal_grab_journal_head (bg_bh); +if (jh) {spin_lock (&jh->b_state_lock); bg = (struct ocfs2_group_desc *) jh->b_committed_data;if (bg)
fs/ocfs2/suballoc.c static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh, · line 1275
Quoted 9 lines
fs/ocfs2/suballoc.c +1
-1@@ -1269,8 +1268,8 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,else ret =1 ;spin_unlock (&jh->b_state_lock); +jbd2_journal_put_journal_head (bg_bh); } -jbd_unlock_bh_journal_head (bg_bh);return ret; }
_______________________________________________
Ocfs2-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/ocfs2-devel